Sucial commited on
Commit
0a84ee2
1 Parent(s): 43bb0dc

Delete scripts/start_tensorboard.py

Browse files
Files changed (1) hide show
  1. scripts/start_tensorboard.py +0 -89
scripts/start_tensorboard.py DELETED
@@ -1,89 +0,0 @@
1
- import re
2
- import os
3
- import numpy as np
4
- from tensorboardX import SummaryWriter
5
-
6
- writer = SummaryWriter('runs/metrics_visualization')
7
-
8
- epoch_pattern = re.compile(r'Train epoch: (\d+) Learning rate: ([\d.eE+-]+)')
9
- training_loss_pattern = re.compile(r'Training loss: ([\d.]+)')
10
- metric_pattern = re.compile(r'(\w+ \w+ \w+): ([\d.]+) \(Std: ([\d.]+)\)')
11
- avg_metric_pattern = re.compile(r'Metric avg (\w+)\s+: ([\d.]+)')
12
-
13
- data = {
14
- 'common': {
15
- 'learning_rate': [],
16
- 'training_loss': []
17
- },
18
- 'dry': {
19
- 'Instr dry sdr': [],
20
- 'Instr dry l1_freq': [],
21
- 'Instr dry si_sdr': []
22
- },
23
- 'other': {
24
- 'Instr other sdr': [],
25
- 'Instr other l1_freq': [],
26
- 'Instr other si_sdr': []
27
- },
28
- 'avg': {
29
- 'Metric avg sdr': [],
30
- 'Metric avg l1_freq': [],
31
- 'Metric avg si_sdr': []
32
- }
33
- }
34
-
35
- std_data = {
36
- 'dry': {key: [] for key in data['dry'].keys()},
37
- 'other': {key: [] for key in data['other'].keys()}
38
- }
39
-
40
- with open(r'E:\AI\datasets\msst\train.log', 'r') as f:
41
- epoch = -1
42
- for line in f:
43
- epoch_match = epoch_pattern.match(line)
44
- if epoch_match:
45
- epoch = int(epoch_match.group(1))
46
- learning_rate = float(epoch_match.group(2))
47
- data['common']['learning_rate'].append((epoch, learning_rate))
48
- continue
49
-
50
- training_loss_match = training_loss_pattern.match(line)
51
- if training_loss_match:
52
- training_loss = float(training_loss_match.group(1))
53
- data['common']['training_loss'].append((epoch, training_loss))
54
- continue
55
-
56
- metric_match = metric_pattern.match(line)
57
- if metric_match:
58
- metric_name = metric_match.group(1)
59
- metric_value = float(metric_match.group(2))
60
- std_value = float(metric_match.group(3))
61
-
62
- if metric_name in data['dry']:
63
- data['dry'][metric_name].append((epoch, metric_value))
64
- std_data['dry'][metric_name].append((epoch, std_value))
65
- elif metric_name in data['other']:
66
- data['other'][metric_name].append((epoch, metric_value))
67
- std_data['other'][metric_name].append((epoch, std_value))
68
- continue
69
-
70
- avg_metric_match = avg_metric_pattern.match(line)
71
- if avg_metric_match:
72
- avg_metric_name = f'Metric avg {avg_metric_match.group(1)}'
73
- avg_metric_value = float(avg_metric_match.group(2))
74
- data['avg'][avg_metric_name].append((epoch, avg_metric_value))
75
-
76
- for category, metrics in data.items():
77
- for key, values in metrics.items():
78
- category_path = f'{category}/{key.replace(" ", "_").lower()}'
79
- for epoch, value in values:
80
- writer.add_scalar(f'{category_path}', value, epoch)
81
-
82
- for category, metrics in std_data.items():
83
- for key, values in metrics.items():
84
- category_path = f'{category}/{key.replace(" ", "_").lower()}_std'
85
- for epoch, std in values:
86
- writer.add_scalar(f'{category_path}', std, epoch)
87
-
88
- writer.close()
89
- os.system('tensorboard --logdir=runs')