图片减去均值再训练,会提高训练速度和精度。因此,一般都会有这个操作。
caffe程序提供了一个计算均值的文件compute_image_mean.cpp,我们直接使用就可以了
该文件的调用格式是、
sudo build/tools/compute_image_mean examples/myfile/img_train_lmdb examples/myfile/mean.binaryproto
compute_image_mean带两个参数,第一个参数是lmdb训练数据位置,第二个参数设定均值文件的名字及保存路径。运行成功后,会在 examples/myfile/ 下面生成一个mean.binaryproto的均值文件。
但是我在在调用caffe compute_image_mean函数计算均值时出现了如下的错误
cterminate called after throwing an instance of 'std::length_error'
what(): basic_string::_S_create
后来发现是我之前建立.txt的时候出现了错误,建立txt的代码没有问题,我的txt显示路径mnist/0/*.png 所以我在建立lmdb格式时,显示不能发现 ~/mnist/mnist/0/*png
就是因为建立txt列表时多了个mnist 修改了下 cut后的参数 然后重新建立lmdb格式文件,再调用compute_image_mean 这个函数就可以了
或者在建立lmdb格式时注意一下data的路径