【转载】faster-rcnn loss曲线可视化

由于要写论文需要画loss曲线,查找网上的loss曲线可视化的方法发现大多数是基于Imagenat的一些方法,在运用到Faster-Rcnn上时没法用,本人不怎么会编写代码,所以想到能否用python直接写一个代码,读取txt然后画出来,参考大神们的博客,然后总和总算一下午时间,搞出来了,大牛们不要见笑。

        首先,在训练Faster-Rcnn时会自己生成log文件,大概在/py-faster-rcnn/experiments/logs文件下,把他直接拿出来,放在任意位置即可,因为是txt格式,可以直接用,如果嫌麻烦重命名1.txt.接下来就是编写程序了

一下为log基本的格式

I0530 08:54:19.183091 10143 solver.cpp:229] Iteration 22000, loss = 0.173712
I0530 08:54:19.183137 10143 solver.cpp:245]     Train net output #0: rpn_cls_loss = 0.101713 (* 1 = 0.101713 loss)
I0530 08:54:19.183145 10143 solver.cpp:245]     Train net output #1: rpn_loss_bbox = 0.071999 (* 1 = 0.071999 loss)
I0530 08:54:19.183148 10143 sgd_solver.cpp:106] Iteration 22000, lr = 0.001

通过发现,我们只需获得 Iteration 和loss就行

[python] view plain copy
  1. #!/usr/bin/env python  
  2. import os  
  3. import sys  
  4. import numpy as np  
  5. import matplotlib.pyplot as plt  
  6. import math  
  7. import re  
  8. import pylab  
  9. from pylab import figure, show, legend  
  10. from mpl_toolkits.axes_grid1 import host_subplot  
  11.   
  12. # read the log file  
  13. fp = open('2.txt''r')  
  14.   
  15. train_iterations = []  
  16. train_loss = []  
  17. test_iterations = []  
  18. #test_accuracy = []  
  19.   
  20. for ln in fp:  
  21.   # get train_iterations and train_loss  
  22.   if '] Iteration ' in ln and 'loss = ' in ln:  
  23.     arr = re.findall(r'ion \b\d+\b,',ln)  
  24.     train_iterations.append(int(arr[0].strip(',')[4:]))  
  25.     train_loss.append(float(ln.strip().split(' = ')[-1]))  
  26.       
  27. fp.close()  
  28.   
  29. host = host_subplot(111)  
  30. plt.subplots_adjust(right=0.8# ajust the right boundary of the plot window  
  31. #par1 = host.twinx()  
  32. # set labels  
  33. host.set_xlabel("iterations")  
  34. host.set_ylabel("RPN loss")  
  35. #par1.set_ylabel("validation accuracy")  
  36.   
  37. # plot curves  
  38. p1, = host.plot(train_iterations, train_loss, label="train RPN loss")  
  39. #p2, = par1.plot(test_iterations, test_accuracy, label="validation accuracy")  
  40.   
  41. # set location of the legend,   
  42. # 1->rightup corner, 2->leftup corner, 3->leftdown corner  
  43. # 4->rightdown corner, 5->rightmid ...  
  44. host.legend(loc=1)  
  45.   
  46. # set label color  
  47. host.axis["left"].label.set_color(p1.get_color())  
  48. #par1.axis["right"].label.set_color(p2.get_color())  
  49. # set the range of x axis of host and y axis of par1  
  50. host.set_xlim([-1500,60000])  
  51. host.set_ylim([0.1.6])  
  52.   
  53. plt.draw()  
  54. plt.show()  
绘图结果

参考博客地址:

http://blog.csdn.net/YhL_Leo/article/details/51774966

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值