[Caffe]使用经验积累

Caffe使用经验积累

本贴记录Caffe编译好了,使用过程的常用命令与常见错误解决方式。如果对编译过程还存在问题,请参考史上最全的caffe安装过程配置Caffe环境。

1 使用方法

训练网络

xxx/caffe/build/tools/caffe train --solver xx/solver.prototxt

选择某个模型作为预训练模型

xxx/caffe/build/tools/caffe train --solver solver.protxt --weights pre_training.caffemodel 

继续之前的状态续训

xxx/caffe/build/tools/caffe train --solver solver.protxt --snapshot=train_iter_95000.solverstate

画出网络结构

python /caffe/python/draw_net.py train_alex.prototxt alexnet.png

选择多gpu进行训练

xxx/caffe/build/tools/caffe train --solver xx/solver.prototxt --gpu=0,1

设置系统环境变量使所需GPU可见

export CUDA_VISIBLE_DEVICES=1

训练log保存

nohup xxx/caffe/build/tools/caffe train –solver solver.prototxt	&
tail –f output

查看log中训练loss的值

cat output.log | grep "Train net output" | awk '{print $11}' > loss.log

其中,awk的 ‘{print $11}’ 是用来截取串中的第11个子串

2 常见使用过程报错含义

(1) errror: Check failed: error == cudaSuccess (2 vs. 0) out of memory
说明GPU内存不够用了,减少batch_size即可,参考

(2) error: ImportError: No module named pydot when python draw_net.py train_val.prototxt xxx.png
使用draw_net.py画图时所报的错误,需要安装graphviz

pip install pydot
pip install GraphViz		
sudo apt-get install graphviz

(3) error: Cannot copy param 0 weights from layer 'fc8'; shape mismatch.
Source param shape is 5 4096 (20480); target param shape is 1000 4096 (4096000). To learn this layer's parameters from scratch rather than copying from a saved net, rename the layer.
出现这个问题一般是层与层的之前blob维度对应不上,需要改prototxt

change deploy.prototxt	adapt to train_val.prototxt  

(4) error: Use hdf5 as caffe input, error: HDF5Data does not transform data
transform_param { scale: 0.00392156862745098 }
这句是说如果HDF5作为输入图像,不支持scale操作,把它注释就好了
Reference

(5) error: Loading list of HDF5 filenames from: failed to open source file
Read hdf5 data failed:

  1. source中 .txt位置用绝对路径
  2. .txt中.h5文件的要用绝对路径
  3. .prototxt中应该是:hdf5_data_param {}而非data_param{}

(6) error: Top blob 'data' produced by multiple sources.
检查数据输入层是不是多了 一层,比如定义了两遍’data’

(7) Error: Check failed: shape[i] >= 0 (-1 vs. 0)

  1. 数据维度顺序不对, blobs的顺序: [ 图像数量 N *通道数 C *图像高度 H *图像宽度 W ]
  2. kernerl size 与 feature map的大小不对应

(8) Error: Check failed: outer_num_ * inner_num_ == bottom[1]->count() (128 vs 128x51)
这层是accuracy layer出现的问题,检测accuracy的两个bottom的维度是否对应,实在解决不了的话,直接去掉。

原文地址:https://www.cnblogs.com/fariver/p/7460487.html