caffe save training log and draw loss, acc curve

Environment windows10 x64 + caffe

1, export training log to log file

start.bat my batch file is used to train the network

start.bat contents are:

Because I caffe added in the system path, so write directly caffe train here. --Solver is back training protocol used in file, define some parameters, such as specifying the network definition file, specify the learning rate, the model save location, learning attenuation parameters, and optimization algorithms. This last> log / train.log 2> & 1 is to save the log to train.log training log files in the folder, 2>&1is used to the standard error 2 redirected to the standard output 1 in. Here &it is to allow batto 1explain to the standard output file instead of 1.

Double-click start.bat will begin training network, and generate log files: train.log

2, using the visualization tool comes caffe log log

As shown, the tools in the root directory caffe / extra folder, there are several log file is used to visualize the log:

extract_seconds.py  , parse_log.py ,parse_log.sh ,plot_training_log.py.example

Copy it to the next log folder and plot_training_log.py.example suffix example Delete

Then open the folder in a terminal, the input python parse_log.py train.log ./ command, and generating train.log.test train.log.test log file folder for subsequent drawing:

Next we need to modify a few plot_training_log.py Code:

(1)在这个文件中不调用parse_log.sh文件,因为上一步已经单独调用了parse_log.py生成了.train和.test文件,如果在这里调用会出现生成的train.log.train和train.log.test两个文件中只有一行,sh脚本的具体代码我没看,但是这里我注释掉不调用。

(2)修改两处,#改为N,下一行的split()改为split(',')

原因:因为使用parsh_log.py生成的文件形式是下图中这样的:

第一行是以NumIters开头,所以在读取数据时这一行要跳过,判断规则就是如果一行的第一个字母是N就跳过。这样就会只读取后面的数字行。

(3)修改如下数据

修改完这些地方之后,在命令行中输入命令:python plot_training_log.py 0 test_learn_rate.png train.log

这里有三个参数:

0 表示上图中 train和test都有四个值(Iters,Seconds,Learning rate, loss),组合就会出现8种(一行是一种)图的类型如下:

['Test learning rate  vs. Iters',
 'Test learning rate  vs. Seconds',
 'Test loss  vs. Iters', 
 'Test loss  vs. Seconds',
 'Train learning rate  vs. Iters', 
 'Train learning rate  vs. Seconds', 
 'Train loss  vs. Iters', 
 'Train loss  vs. Seconds']

这个0就表示索引为0的图类型:'Test learning rate  vs. Iters'

test_learn_rate.png 表示要绘制的图保存的名字

train.log 就是前面log日志文件

运行画图命令之后,输出的图片为测试的学习率和迭代次数之间的图。想画其他变量之间的关系图就把参数0修改为其他的即可。

2 testloss/iters

4 train_learning_rate/iters

6 train_loss/iter

Guess you like

Origin blog.csdn.net/sinat_33486980/article/details/93039767