faster-rcnn之训练日志可视化

这里写图片描述


#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)

这里写图片描述

评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值