在caffe的训练过程中,大家难免想图形化自己的训练数据,以便更好的展示结果。如果自己写代码记录训练过程的数据,那就太麻烦了,caffe中其实已经自带了这样的小工具 caffe-master/tools/extra/parse_log.sh caffe-master/tools/extra/extract_seconds.py和 caffe-master/tools/extra/plot_training_log.py.example ,使用方法如下:
1.记录训练日志
在训练过程中的命令中加入一行参数 ,实现Log日志的记录
其中目录改成自己系统的目录,这样训练结束之后,会在Log文件夹中生成每次训练的Log日志
2.解析训练日志
将最上面说的3个脚本文件拷贝到Log 文件夹下,执行:
后面的参数为log文件名,这样就会在当前文件夹下生成一个.train文件和一个.test文件
3.生成图像。
自己写 的脚本
import matplotlib.pyplot as plt
file =open('caffe.INFO.train.log')
filelines=file.readlines()
print len(filelines)
Iters=[]
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==2:
TrainingLoss.append(float(temp[i]))
print Iters
print TrainingLoss
plt.plot(Iters, TrainingLoss, 'b')
plt.title('Trainloss VS Iters')
plt.xlabel('Iters')
plt.ylabel('Trainloss')
plt.savefig('trainloss.png')
plt.show()