forked from dsp6414/mmdetection-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisualize.py
68 lines (50 loc) · 2.11 KB
/
visualize.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import json
import matplotlib.pyplot as plt
import sys
import os
from collections import OrderedDict
import matplotlib
class visualize_mmdetection():
def __init__(self, path):
self.log = open(path)
self.dict_list = list()
self.loss_bbox = list()
self.loss_cls = list()
self.loss = list()
def load_data(self):
for line in self.log:
info = json.loads(line)
self.dict_list.append(info)
#print(self.dict_list[-1]['mode'])
for i in range(1, len(self.dict_list)):
mode = dict(self.dict_list[i]).get('mode')
if mode == 'train':
#print(dict(self.dict_list[i]))
#for key, value in dict(self.dict_list[i]).items():
# ------------find key for every iter-------------------#
loss_bbox_value = dict(self.dict_list[i])['loss_bbox']
loss_cls_value = dict(self.dict_list[i])['loss_cls']
loss_value = dict(self.dict_list[i])['loss']
# -------------list append------------------------------#
self.loss_bbox.append(loss_bbox_value)
self.loss_cls.append(loss_cls_value)
self.loss.append(loss_value)
# -------------clear repeated value---------------------#
self.loss_bbox = list(OrderedDict.fromkeys(self.loss_bbox))
self.loss_cls = list(OrderedDict.fromkeys(self.loss_cls))
self.loss = list(OrderedDict.fromkeys(self.loss))
def show_chart(self):
plt.rcParams.update({'font.size': 15})
plt.figure(figsize=(20, 20))
plt.subplot(221, title='loss_cls', ylabel='loss')
plt.plot(self.loss_cls)
plt.subplot(222, title='loss_bbox', ylabel='loss')
plt.plot(self.loss_bbox)
plt.subplot(223, title='total loss', ylabel='loss')
plt.plot(self.loss)
plt.show()
#plt.savefig('outputs/results/result.png')
if __name__ == '__main__':
x = visualize_mmdetection('/home/chen/OD/mmdet_tutorial/tutorial_exps/tood_licence/None.log.json')
x.load_data()
x.show_chart()