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

猜你喜欢

转载自blog.csdn.net/weixin_40695510/article/details/81254101