win7 caffe使用笔记——绘制学习曲线
2017-02-16 20:10
567 查看
1.命令控制台输出重定向,保存训练的日志文件。
train.bat
2.筛选日志文件中的loss,accuracy,迭代行,并绘制曲线。
drawcurve.m
输出3个txt文件,train loss,test loss,accuracy。
绘制loss曲线和accuracy曲线。
train.bat
G: cd G:\caffe-master set GLOG_logtostderr=1 set BIN=Build/x64/Release "%BIN%/caffe.exe" train --solver=examples/Planthopper_test/Planthopper_solver-leveldb.prototxt >examples/Planthopper_test/Log/net.log 2>&1 pause
2.筛选日志文件中的loss,accuracy,迭代行,并绘制曲线。
drawcurve.m
% Well, this is a function that write the % iteration vs accurancy % iteration vs loss % To a file clc; clear; % log file of caffe model logName = 'net.log'; fid = fopen(logName, 'r'); fid_accuracy = fopen('output_accuracy.txt', 'w'); fid_test_loss = fopen('output_test_loss.txt','w'); fid_train_loss = fopen('output_train_loss.txt', 'w'); tline = fgetl(fid); accur=zeros(401,1); %max_iteration/test_interval 精度,测试损失数量 testloss=zeros(401,1); m=1; trainloss=zeros(2001,1); %max_iteration/display 训练损失数量 n=1; while ischar(tline) %读入每一行 % First find the accuracy line k = strfind(tline, 'Test net output'); if (k) k = strfind(tline, 'accuracy'); if (k) % If the string contain test and accuracy at the same time % The bias from 'accuracy' to the float number indexStart = k + 11; %定位到精度数值 indexEnd = size(tline); str = tline(indexStart : indexEnd(2)); %读入精度 fprintf(fid_accuracy, '%s\r\n', str); accur(m)=str2double(str); end end % next,find the test loss line k5 = strfind(tline, 'Test net output'); if (k5) k5 = strfind(tline, 'loss'); if (k5) indexStart = k5 + 7; %定位到test loss数值 indexEnd = indexStart + 6; str5 = tline(indexStart : indexEnd); %读入test loss fprintf(fid_test_loss, '%s\r\n', str5); testloss(m)=str2double(str5); m=m+1; end end % Then find the loss line k1 = strfind(tline, 'Iteration'); if (k1) k2 = strfind(tline, 'loss'); if (k2) indexStart = k2 + 7; %定位到train loss数值 indexEnd = size(tline); str1 = tline(indexStart:indexEnd(2)); %取train loss indexStart = k1 + 10; %定位到iteration indexEnd = strfind(tline, ',') - 1; str2 = tline(indexStart:indexEnd); %取迭代序号 res_str1 = strcat(str2, '/', str1); fprintf(fid_train_loss, '%s\r\n', res_str1); trainloss(n)=str2double(str1); n=n+1; end end tline = fgetl(fid); end fclose(fid); fclose(fid_accuracy); testidx = 0:400; idx_test = testidx * 500; trainidx = 0:2000; idx_train = trainidx * 100; figure;plot(idx_test,accur); grid on; legend('test accuracy'); xlabel('iterations'); ylabel('accuracy'); figure; plot(idx_test,testloss); hold on; plot(idx_train,trainloss); grid on; legend('test loss', 'train loss'); xlabel('iterations'); ylabel('loss');
输出3个txt文件,train loss,test loss,accuracy。
绘制loss曲线和accuracy曲线。
相关文章推荐
- js参数中不能出现有反斜杠
- 说说JSON和JSONP,也许你会豁然开朗,含jQuery用例
- Bootstrap 排版
- nodejs+socket.io实现websocket通信初探
- String和StringBuffer的区别
- bootstrap的select2既可以查询又可以输入
- {题解}[jzoj4064]【JSOI2015】套娃(doll)
- 第一百四十四节,JavaScript,列队动画
- JavaScript-原型、原型链
- POJ1013 Counterfeit Dollar
- DOM(一)
- Abaqus的历史数据输出的问题
- Extjs中用url动态传参到后台的汉字为乱码
- 浏览器内核分析5 -- CSS解释器和样式布局
- 闭包
- webpack 与 热编译webpack-dev-server
- nodejs基础常用技术栈
- Bootstrap 网格系统
- Javascript函数调用与this解析
- 利用jackson在json~bean~list之间的转换