caffe 画出train与loss曲线(使用log.train文件和log.test文件)

1.记录训练日志

#!/usr/bin/env sh
set -e

echo "begin:"
TOOLS=/home/yangjian/caffe-master/build/tools
LOG=/home/yangjian/caffe-master/myfile_jian/log/log-`date +%Y-%m-%d-%H-%M-%S`.log
$TOOLS/caffe train \
    --solver=/home/yangjian/caffe-master/myfile_jian/solver50.prototxt 2>&1 | tee $LOG $@
echo "end"

2.解析训练日志

./parse_log.sh log-2018-07-27-10-37-42.log

此时,在log文件下面生成了log-2018-07-27-10-37-42.log.train和log-2018-07-27-10-37-42.log.test文件,里面保存了提取出来的seconds,loss,accuracy信息。

3.绘图程序

不用caffe自带的绘图程序,自己写 py绘图程序

#!/usr/bin/env python
import matplotlib.pyplot as plt
file =open('log-2018-07-27-10-37-42.log.train')
filelines=file.readlines()
print len(filelines)
#Iters=[]
Seconds=[]
TrainingLoss=[]
temp=[]
for i  in range (1,len(filelines)):
    line=filelines[i].split(' ')
    #print line
    for j in range(0,len(line)):
        if line[j] !='':
           #print line[j]
           temp.append(line[j])
 
print len(temp)
for i in range(0,len(temp)):
    #if i%4==0:
        #Iters.append(int(temp[i]))
    if i%4==1:
        Seconds.append(float(temp[i]))
 
    if i%4==2:
        TrainingLoss.append(float(temp[i]))
 
#plt.plot(Iters, TrainingLoss, 'b')
#plt.title('Trainloss  VS Iters')
#plt.xlabel('Iters')
#plt.plot(Seconds, TrainingLoss, 'r*-')
plt.plot(Seconds, TrainingLoss, 'r-',marker='d')
plt.title('Trainloss  VS Seconds')
plt.xlabel('Seconds')

plt.ylabel('Trainloss')
plt.savefig('trainloss.png')
plt.show()

4 结果图

5 用到Python绘图知识

(1)基本颜色格式命令

颜色 
‘b’蓝色
'g'绿色
'r'红色
'c'青色
'm'品色
'y'黄色
'k'黑色
'w'

白色

(2)基本线型格式命令

线型 
'-'实线
'--'虚线
':'

点线

(3)基本绘制标记格式命令 

标记 
'.'
'o'圆圈
's'正方形
'*'星形
'+'加号
'x'叉号

plot(x,y,marker='*') 用marker参数来指定:

========== ==========================
marker description
========== ==========================
'.' point
',' pixel
'o' circle
'v' triangle_down
'^' triangle_up
'<' triangle_left
'>' triangle_right
'1' tri_down
'2' tri_up
'3' tri_left
'4' tri_right
's' square
'p' pentagon
'*' star
'h' hexagon1
'H' hexagon2
'+' plus
'x' x
'D' diamond
'd' thin_diamond
'|' vline
'_' hline
TICKLEFT tickleft
TICKRIGHT tickright
TICKUP tickup
TICKDOWN tickdown
CARETLEFT caretleft
CARETRIGHT caretright
CARETUP caretup
CARETDOWN caretdown
'None' nothing
' ' nothing
'' nothing
========== ==========================
ACCEPTS: [ '+' | '*' | ',' | '.' | '1' | '2' | '3' | '4'
| '<' | '>' | 'D' | 'H' | '^' | '_' | 'd'
| 'h' | 'o' | 'p' | 's' | 'v' | 'x' | '|'
| TICKUP | TICKDOWN | TICKLEFT | TICKRIGHT
| 'None' | ' ' | '' ]
"""

参考资料

(1)caffe 画出train与loss曲线: https://blog.csdn.net/zhikangfu/article/details/53583088

(2)Python绘制点线: https://blog.csdn.net/kingroc/article/details/73088510

(3)python matplotlib 如何画点 而不要画点之间的连线?

https://zhidao.baidu.com/question/209620370.html

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值