caffe 用matlab解析日志画loss和accuracy

  1. clc;
  2. clear;
  3.  
  4. % load the log file of caffe model
  5. fid = fopen('log-previous-insulator.txt', 'r');
  6. tline = fgetl(fid);
  7.  
  8. accuracyIter =[];
  9. accuracyArray =[];
  10. lossIter = [];
  11. lossArray = [];
  12.  
  13. %record the last line
  14. lastLine = '';
  15.  
  16. %read line
  17. while ischar(tline)
  18. %%%%%%%%%%%%%% the accuracy line %%%%%%%%%%%%%%
  19. k = strfind(tline, 'Test net output');
  20. if (k)
  21. k = strfind(tline, 'accuracy');
  22. if (k)
  23. % If the string contain test and accuracy at the same time
  24. % The bias from 'accuracy' to the float number
  25. indexStart = k + 11;
  26. indexEnd = size(tline);
  27. str = tline(indexStart : indexEnd(2));
  28. accuracyArray = [accuracyArray, str2num(str)];
  29. end
  30.  
  31. % Get the number of index
  32. k = strfind(lastLine, 'Iteration');
  33. if (k)
  34. indexStart = k + 10;
  35. indexEnd = strfind(lastLine, '(');
  36. str2 = lastLine(indexStart : indexEnd - 1);
  37. accuracyIter = [accuracyIter, str2num(str2)];
  38. end
  39.  
  40. % Concatenation of two string
  41. res_str = strcat(str2, '/', str);
  42. end
  43.  
  44. %%%%%%%%%%%%%% the loss line %%%%%%%%%%%%%%
  45. k1 = strfind(tline, 'Iteration');
  46. if (k1)
  47. k2 = strfind(tline, 'loss');
  48. if (k2)
  49. indexStart = k2 + 7; %loss位置到数据位置起始位置相差7
  50. indexEnd = size(tline);
  51. str1 = tline(indexStart:indexEnd(2)); %数据开始位置到结束位置,就是loss,也就是纵坐标
  52. indexStart = k1 + 10; %从iteration到迭代次数数据起始位相差10
  53. indexEnd = strfind(tline, '(') - 1; %找到左括号位置-1:根据你的txt来看是括号还是逗号
  54. str2 = tline(indexStart:indexEnd); %从起始位置到结束位置为迭代次数,也就是横坐标
  55. res_str1 = strcat(str2, '/', str1); %把横纵坐标连接起来
  56. lossIter = [lossIter, str2num(str2)]; %把迭代次数转化为数据赋值给lossiter
  57. lossArray = [lossArray, str2num(str1)]; %把loss转化为数据复给lossArray
  58. end
  59. end
  60.  
  61. lastLine = tline;
  62. tline = fgetl(fid);
  63. end
  64.  
  65. %draw figure
  66. figure;h1 = plot(accuracyIter, accuracyArray);title('iteration vs accurancy'); %绘制accuracy曲线
  67. figure;h2 = plot(lossIter, lossArray);title('iteration vs loss'); %绘制loss曲线
  68. print(2,'-dpng','iteration vs loss')%保存

  

caffe保存训练log日志文件并利用保存的log文件绘制accuary loss曲线图

  1. 1、训练模型时保存log日志文件
  2.  
  3. 方法1 一般情况下我们的训练模型标准语句是:$ sudo ./build/tools/caffe train -solver=xxx/xxx/solver.prototxt xxx/xxx/表示你的solver.prototxt文件所在位置
  4.  
  5. 需要保存log文件时的命令是:$ sudo GLOG_logtostderr=0 GLOG_log_dir='xxx/xxx/xxx/' build/tools/caffe train -solver=xxx/xxx/solver.prototxt xxx/xxx/xxx/‘表示你所保存的log文件所在位置。
  6.  
  7. 训练完成后发现在我们保存的目录xxx/xxx/xxx/下生成了两个上锁log文件caffe.INFOcaffe.ubuntu.root.log.INFO.20170611-103712.5383。点击打开后我们可以看到我们所训练的日志文件。
  8.  
  9. 方法2 ./build/tools/caffe train -solver=xn/PENLU/neural/nin/nin_solver.prototxt 2>&1 | tee xn/PENLU/snapshot/nin/nin_relu.log
  10.  
  11. 2、利用生成的log文件绘制accuary loss曲线图
  12.  
  13. 首先绘制图,caffe中其实已经自带了这样的小工具 caffe-master/tools/extra/parse_log.sh caffe-master/tools/extra/extract_seconds.py还有 caffe-master/tools/extra/plot_training_log.py.example;拷贝以上文件到当前训练模型的目录下。
  14.  
  15. 然后我们到你保存的log文件目录下将1中保存的log文件解锁,解锁命令:sudo chmod -R 777 ./caffe.ubuntu.root.log.INFO.20170611-103712.5383
  16.  
  17. 解锁后我们就可以更改该log文件名为xxx.log(注意:要画图一定是.log文件,所以不改名不可以画)。
  18.  
  19. 然后复制该xxx.log文件到你训练模型所在目录下。
  20.  
  21. 然后就可以利用命令画图了:在模型所在目录下命令: ./plot_training_log.py.example y xxx.png xxx.log xxx.png是你保存的绘制出的图片名称,xxx.log是你保存的log文件名称。y表示的是你的所绘制的图片到底是什么图片,具体解释如下:
  22.  
  23. y的数字代表意义(0~7):
  24.  
  25. Supported chart types: 0: Test accuracy vs. Iters (准确率与迭代次数图)
  26.  
  27. 1: Test accuracy vs. Seconds (准确率与时间图)
  28.  
  29. 2: Test loss vs. Iters (测试损失与迭代次数图)
  30.  
  31. 3: Test loss vs. Seconds (测试损失与时间图)
  32.  
  33. 4: Train learning rate vs. Iters (学习率与迭代次数图)
  34.  
  35. 5: Train learning rate vs. Seconds (学习率与时间图)
  36.  
  37. 6: Train loss vs. Iters (训练损失与迭代次数图)
  38.  
  39. 7: Train loss vs. Seconds (训练损失与时间图)
  40.  
  41. 运行后生成的文件有:log-data.log.testlog-data.log.testxxx.png
  42.  
  43. 3test测试log日志文件保存与绘图类似过程

Ps: windows记录训练日志

  1. 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.windows记录训练日志:在训练过程中的命令中加入一行参数 ,实现Log日志的记录,这里我使用的.bat。其实一可以像前面某位大哥一样,直接copy输出的类容。
  2. caffe train --solver=deepid/deepid2/deepid_solver.prototxt >log/XXXXX.log 2>&1
  3. pause

  

caffe 日志保存以及matlab绘制方法(windows以及ubuntu下)的更多相关文章

  1. windows、ubuntu下eclipse搭建java、Python环境问题总结

    前两篇博文分别讲述了如何在windows.ubuntu下用eclipse搭建java.python环境,下面就针对本人遇到的问题做一个总结. 一.windows下关于java环境变量JAVA_HOME ...

  2. windows和ubuntu下git commit提交后如何保存和退出,回到命令行

    问题一: windows下git commit后会进入vim界面,不知道怎么操作 解决办法: 1.输入小写字母i,此时进入编辑模式,可以输入你想输入的内容 2.按下esc键,此时退出编辑模式,输入英文 ...

  3. Windows和ubuntu下更改pip国内镜像

    windows下更改pip国内镜像 # 在C:\Users\admin路径下创建pip文件夹,然后创建pip.ini文件, 并在文件下写入 [global] index-url = http://py ...

  4. [转]windows下和Ubuntu下adb找不到设备的解决方法

    最近在做flash手机项目,用fb选择android设备调试,总会出现找不到设备的情况.看了很多帖子都解决不了问题,后来终于研究出来是adb无法找到设备的问题.最后通知这篇帖子终于解决了问题. 使用电 ...

  5. windows和ubuntu下gif动态图片的制作

    现在社交软件中, 各种各样的动图为大家交流很大的乐趣.  Gif图片比视频小, 比静态JPG图片形象生动, 更适用于产品展示和步骤演示等. 这里简单介绍一下在window系统和ubuntu系统下gif ...

  6. Elasticsearch 在 windows 和 ubuntu 下详细安装过程

    1. 前言 作为一名 .NET 平台开发者,选择开发框架时总会面临更多的局限性,不过对于搜索这种刚需服务来说,开源框架可供选择的余地还是比较大的.笔者之前用的是 Lucene.net ,现在深感其使用 ...

  7. windows和Ubuntu下安装mongodb

    windows 下载 mongodb官网下载压缩版安装包:下载地址:https://www.mongodb.com/download-center/community 注意选择版本(目前windows ...

  8. windows调用ubuntu下的sublimeText2环境搭建

    部署需求: windows: windows 7 32 sp1 32位: linux :ubuntu 12.04 LTS 64位: 环境: windows安装:xmanager 4 linux安装:g ...

  9. windows远程访问ubuntu下的jupyter notebook必要配置

    0.生成配置文件(一般采用默认) jupyter notebook --generate-config 1.打开ipython, 创建一个密文密码 In [1]: from notebook.auth ...

随机推荐

  1. 面试题:Concurrenthashmap原理分析 有用

    一.背景: 线程不安全的HashMap     因为多线程环境下,使用Hashmap进行put操作会引起死循环,导致CPU利用率接近100%,所以在并发情况下不能使用HashMap.   效率低下的H ...

  2. noi.ac day1t3 Sort

    传送门 分析 快排的原理是以任意一个数为标准,然后把所有小于它的数换到它的左边,所有大于它的数换到它的右边.我们就使用快排的思路,分治整个区间.对于每个区间以排好序的这个数列的中间位置的值为标准,然后 ...

  3. ElementUI的表单和vee-validate结合使用时发生冲突的解决

    在Vue项目中使用ElementUI表单时,同时又引入了vee-validate进行使用的时候,在浏览器上会出现这样的报错: [Vue warn]: The computed property &qu ...

  4. SQL Server 2014 清理日志

    USE [master] GO ALTER DATABASE [TempTestDb02] SET RECOVERY SIMPLE WITH NO_WAIT GO ALTER DATABASE [Te ...

  5. wpf跳转网页

    如果是本地磁盘上的网页,可以考虑利用操作系统的文件关联自动调用操作系统默认浏览器: System.Diagnostics.Process.Start("explorer.exe", ...

  6. Linux文件锁flock ,检测进程是否已经存在

    在多个进程同时操作同一份文件的过程中,很容易导致文件中的数据混乱,需要锁操作来保证数据的完整性,这里介绍的针对文件的锁,称之为“文件锁”-flock.  头文件:#include<sys/fil ...

  7. c#操作word类,进行html和word文档的互相转换

    实例引用:http://www.7es.cn/Software_development/171.shtml using Microsoft.Office.Core;using Word = Micro ...

  8. Hexo下Next主题配置与优化

    使用Next主题 在这里Downloads Next主题代码 将下载的代码放在myBlog/theme/next目录下 设置站点myBlog/_config.yml的theme字段值为next 生成新 ...

  9. JetBrains WebStorm 如何从GitHub上克隆的代码

    工作中经常会遇到要从GitHub上拉代码,详细操作记录如下: 绑定账号 1.File->Settings->Version Control->Github 成功后会出现下面的这个账户 ...

  10. IOS中录音后再播放声音太小问题解决

    1.AVAudioSessionCategory说明 1.1 AVAudioSessionCategoryAmbient 或 kAudioSessionCategory_AmbientSound 用于 ...