对训练的caffe.bat文件进行编辑,在最后加上>trainlog.txt 2>&1,即可实现将cmd打印出来的信息保存到trainlog.txt文件中。
SET GLOG_logtostderr=1
caffe.exe路径 train --solver solver.prototxt路径 >trainlog.txt 2>&1
pause
这样在训练完成之后,日志信息全都保存到了trainlog.txt文件中。

然后进行绘图。
代码以及部分注释如下所示。
%%loss示例
clc;clear
logName='C:\Users\dell\Desktop\trainlog.txt';%%trainlog.txt的路径
dir_log='C:\Users\dell\Desktop\loss\';%%保存以下五个txt文件的路径
fid = fopen(logName, 'r'); %%read 读取日志文件
test_loss = fopen([dir_log 'test_loss.txt'], 'w'); %%write 往txt文件中写内容
train_loss = fopen([dir_log 'train_loss.txt'], 'w');
train_lr = fopen([dir_log 'train_lr.txt'],'w');
test_acc = fopen([dir_log 'test_acc.txt'], 'w');
train_acc = fopen([dir_log 'train_acc.txt'], 'w');
tline = fgetl(fid);
while ischar(tline) %%按行读取日志文件中的内容
k = strfind(tline, 'Iteration'); %%查找Iteration,并返回在这一行的第几列

本文介绍如何通过编辑caffe.bat文件记录训练日志,并利用MATLAB解析日志绘制GoogLeNet的loss曲线。关键步骤包括在训练脚本末尾添加日志输出指令,以及调整代码中的特定参数以适应不同的训练情况。
最低0.47元/天 解锁文章

3507

被折叠的 条评论
为什么被折叠?



