#coding=utf-8
import os, re, traceback
import matplotlib.pyplot as plt
class LogVisual:
def readFile(self, path):
file = open(path, 'r')
lines = [line.strip() for line in file.readlines()]
file.close()
return lines
def parse_iter(self, iter_lines):
if len(iter_lines) != 6:
pass
try:
iter_num, loss, loss_bbox, loss_cls, rpn_cls_loss, rpn_loss_bbox = None, None, None, None, None, None
for line in iter_lines:
if 'Iteration' in line and ' solver.cpp' in line:
arr = re.findall(r'ion \b\d+\b', line)
iter_num = int(arr[0].strip(',')[4:])
loss = float(line.strip().split(' = ')[-1])
elif line.find('Train net output #0:') > 0:
loss_bbox = float(line.split(' ')[-6])
elif line.find('Train net output #1:') > 0:
loss_cls = float(line.split(' ')[-6])
elif line.find('Train net output #2:') > 0:
rpn_cls_loss = float(line.split(' ')[-6])
elif line.find('Train net output #3:') > 0:
rpn_loss_bbox = float(line.split(' ')[-6])
return (iter_num, loss, loss_bbox, loss_cls, rpn_cls_loss, rpn_loss_bbox)
except Exception as err:
traceback.print_exc()
return None
def draw_loss(self):
pass
def parse_log(self,log_path,skip_num=2000):
lines = self.readFile(log_path)
iter_ress = []
iter_lines = []
for idx,line in enumerate(lines[skip_num:]):
if ('Iteration' in line and ' solver.cpp' in line) or 'Train net output' in line:
iter_lines.append(line)
if 'Iteration' in line and ' sgd_solver.cpp' in line:
iter_res = self.parse_iter(iter_lines)
iter_ress.append(iter_res)
iter_lines = []
iter_nums = [elem[0] for idx,elem in enumerate(iter_ress) if idx%10==0]
losss = [elem[1] for idx,elem in enumerate(iter_ress) if idx%10==0]
loss_bboxs = [elem[2] for idx,elem in enumerate(iter_ress) if idx%10==0]
loss_clss = [elem[3] for idx,elem in enumerate(iter_ress) if idx%10==0]
rpn_cls_losss = [elem[4] for idx,elem in enumerate(iter_ress) if idx%10==0]
rpn_loss_bboxs = [elem[5] for idx,elem in enumerate(iter_ress) if idx%10==0]
plt.subplot(511)
plt.title('loss')
plt.plot(iter_nums, losss, c='green')
plt.subplot(512)
plt.title('loss_bbox')
plt.plot(iter_nums, loss_bboxs, c='green')
plt.subplot(513)
plt.title('loss_cls')
plt.plot(iter_nums, loss_clss, c='green')
plt.subplot(514)
plt.title('rpn_cls_loss')
plt.plot(iter_nums, rpn_cls_losss, c='green')
plt.subplot(515)
plt.title('rpn_loss_bbox')
plt.plot(iter_nums, rpn_loss_bboxs, c='green')
plt.show()
if __name__ == '__main__':
logVisual = LogVisual()
log_path = r'/Users/songhongwei/Downloads/nohup_cashier.out'
logVisual.parse_log(log_path)
faster-rcnn之训练日志可视化
最新推荐文章于 2022-03-30 07:10:47 发布