caffe 画 loss\accuracy曲线(train_test)

用caffe如何画loss曲线呢?

Step1、记录训练的Log

—其实就是输出重定向;将我们在屏幕看到的训练过程保存为txt

#!/usr/bin/env sh

TOOLS=./build/tools
GLOG_logtostderr=0 GLOG_log_dir=/home/bin.wang/imageRetrieval/caffe-hash/hashExample/LOG \  #记录log
$TOOLS/caffe train --solver=hashExample/solver.prototxt \
-weights=hashExample/VGG_CNN_F.caffemodel -gpu 0

—为了方便,将以下3个将用到的文件拷贝到LOG目录,即${GLOG_log_dir}

tools/extra/parse_log.sh 
tools/extra/extract_seconds.py
tools/extra/plot_training_log.py.example

#---------------拷贝完成是这样的-------------#
-bash-4.2$ tree LOG
.
├── extract_seconds.py
├── parse_log.sh
└── plot_training_log.py.example

0 directories, 3 files

Step2、开始训练得到log

训练完的LOG目录结构如下,注意:我已经做了重命名,只有caffe.***log.INFO.***.${num}项log有用,其他的都是无用信息。将这项rename成caffe.bin.wang.log 为的是看着舒服

-bash-4.2$ tree LOG
.
├── caffe.bin.wang.log 
├── extract_seconds.py
├── parse_log.sh
└── plot_training_log.py.example

0 directories, 4 files

Step3、开始画图

 ./plot_training_log.py.example 6 train_loss.png caffe.bogon.bin.wang.log

—效果是出来一大堆error,经分析,最重要的是:“ImportError: cannot import name unpack_labeled_data”

Traceback (most recent call last):
  File "./plot_training_log.py.example", line 8, in 
    import matplotlib.pyplot as plt
  File "/usr/lib64/python2.7/site-packages/matplotlib/pyplot.py", line 26, in from matplotlib.figure import Figure, figaspect
  File "/usr/lib64/python2.7/site-packages/matplotlib/figure.py", line 36, in from matplotlib.axes import Axes, SubplotBase, subplot_class_factory
  File "/usr/lib64/python2.7/site-packages/matplotlib/axes/__init__.py", line 4, in <
    from ._subplots import *
  File "/usr/lib64/python2.7/site-packages/matplotlib/axes/_subplots.py", line 10, in
    from matplotlib.axes._axes import Axes
  File "/usr/lib64/python2.7/site-packages/matplotlib/axes/_axes.py", line 14, in from matplotlib import unpack_labeled_data
ImportError: cannot import name unpack_labeled_data

Step4、解决”ImportError: cannot import name unpack_labeled_data”

yum list installed| grep matplot # 查看我系统安装matplotlib的版本
pip uninstall matplotlib    #很有可能你的linux系统安装了1.2.0 和 1.5.0 两个版本的lib
pip uninstall matplotlib    #NOte:这个语句确实跟上一个重复,但是必须执行两次,来完成彻底卸载
pip install --upgrade matplotlib

caffe 画 loss\accuracy曲线(train_test)_第1张图片

小结 0-7代表什么

画图程序的第二个参数可以是0-7,0-7的含义如下

0: Test accuracy vs. Iters
1: Test accuracy vs. Seconds
2: Test loss vs. Iters
3: Test loss vs. Seconds
4: Train learning rate vs. Iters
5: Train learning rate vs. Seconds
6: Train loss vs. Iters
7: Train loss vs. Seconds

附:用matlab将train&test训练过程.画在一张图片中

clear all; clc;

train_log_file = 'cifar.log';

train_interval = 100;  % equal solver.prototxt value[display]

test_interval = 1000; % eaual solver.prototxt value[test_interval]

[~,string_output] = dos(['cat ',train_log_file,' |grep "Train net output #0" |  awk ''{print $11}'' ']);

train_loss = str2num(string_output);

n = 1: length(train_loss);

idx_train = (n-1)* train_interval;

[~,string_output] = dos(['cat ',train_log_file,' |grep "Test net output #1" | awk ''{print $11}'' ']);

test_loss = str2num(string_output);
m = 1: length(test_loss);

idx_test = (m-1)* test_interval;

figure;plot(idx_test,test_loss);

grid on; 
legend('Train Loss', 'Test Loss');

xlabel('iterations');
ylabel('loss');
title('Train & Test Loss Curive');

你可能感兴趣的:(caffe)