forked from imlab-uiip/lung-segmentation-2d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrain_process_utils.py
More file actions
38 lines (28 loc) · 1.04 KB
/
train_process_utils.py
File metadata and controls
38 lines (28 loc) · 1.04 KB
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
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
plt.switch_backend('agg')
import math
import numpy as np
class TrainProcessUtil:
def __init__(self):
self.metrics = {}
def update_metrics_dict(self, metric_name, metric_value):
assert type(metric_value) == np.float32
if metric_name in self.metrics:
self.metrics[metric_name].append(metric_value)
else:
self.metrics[metric_name] = [metric_value]
def plot_metrics(self):
assert len(self.metrics) > 0
fig, ax = plt.subplots()
metric_tuple = tuple(self.metrics.items())
x = np.linspace(0,len(metric_tuple[0][1])-1,len(metric_tuple[0][1]))
for i in range(len(self.metrics)):
ax.plot(x, metric_tuple[i][1], label = metric_tuple[i][0])
ax.legend(loc='lower right')
plt.savefig('plot')
if __name__ == '__main__':
train_util = TrainProcessUtil()
train_util.metrics = { "loss":[1,2,3,4,5], "accuracy": [2,4,6,8,10] }
train_util.plot_metrics()