-
Notifications
You must be signed in to change notification settings - Fork 0
/
wav2vec2plot.py
45 lines (36 loc) · 1.09 KB
/
wav2vec2plot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import matplotlib.pyplot as plt
import pandas as pd
import json
import os
from wav2vec2 import *
logging_dir = "./logs"
def load_logs(logging_dir):
logs = []
for x in os.listdir(logging_dir):
if x.endswith(".json"):
with open(os.path.join(logging_dir, x), 'r') as f:
logs.append(json.load(f))
return logs
logs = load_logs(logging_dir)
def extract_metrics(logs):
steps = []
train_loss = []
eval_loss = []
for log in logs:
if 'train' in log:
steps.append(log['step'])
train_loss.append(log['train']['loss'])
if 'eval' in log:
eval_loss.append(log['eval']['eval_loss'])
return steps, train_loss, eval_loss
steps, train_loss, eval_loss = extract_metrics(logs)
plt.figure(figsize=(12, 6))
plt.plot(steps, train_loss, label='Training Loss', color='blue')
plt.plot(steps, eval_loss, label='Validation Loss', color='orange')
plt.xlabel('Training Steps')
plt.ylabel('Loss')
plt.title('Training and Validation Loss')
plt.legend()
plt.grid(True)
plt.savefig('training_loss_plot.png')
plt.show()