Caffe学习笔记2

Caffe学习笔记2-用一个预训练模型提取特征

本文为原创作品,未经本人同意,禁止转载,禁止用于商业用途!本人对博客使用拥有最终解释权

欢迎关注我的博客:http://blog.csdn.net/hit2015spring和http://www.cnblogs.com/xujianqing

http://caffe.berkeleyvision.org/gathered/examples/feature_extraction.html

制作一个数据库

先做一个临时文件夹

mkdir examples/_temp

为待处理的文件生成一个文件列表,这些图片在examples/images文件夹下

find `pwd`/examples/images -type f -exec echo {} ; > examples/_temp/temp.txt

我们将使用预计标签之后的每一个文件名,故需要在每一行后面加0

sed "s/$/ 0/" examples/_temp/temp.txt > examples/_temp/file_list.txt

定义特征提取的网络结构

在实际运用中,把分类图片减去均值图像,对提高分类准确率具有很重要的意义,下载ILSVRC的均值文件

./data/ilsvrc12/get_ilsvrc_aux.sh

我们将在网络定义模型中使用data/ilsvrc213/imagenet_mean.binaryproto的文件来定义一个网络模型

拷贝和修改网络训练模型的定义文件,我们将要用的imagedatalayer,这个文件将调整图片大小

cp examples/feature_extraction/imagenet_val.prototxt examples/_temp

提取特征

./build/tools/extract_features.bin models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel examples/_temp/imagenet_val.prototxt fc7 examples/_temp/features 10 leveldb

其中fc7是最高层的特征,我们也可以提取例如conv5或者pool3等其它层的信息

最后一个参数是图片的最小批次

特征最后存在了examples/_temp/features,文件夹下面

如果出现"Check failed: status.ok() Failed to open leveldb examples/_temp/features"的错误,那是因为examples/_temp/features在上一层运行命令的时候就已经存在了,所以要用命令移除它

rm -rf examples/_temp/features/

最后把临时的文件删除不要

rm -r examples/_temp

 

问题:

  1. caffemodel不存在

解决:

http://www.cnblogs.com/denny402/p/5111018.html

https://github.com/BVLC/caffe/tree/master/models/bvlc_googlenet

大概233M

 

sudo ./scripts/download_model_binary.py models/bvlc_reference_caffenet

问题2:

https://github.com/BVLC/caffe/issues/3505

参数设置错误,改版之后参数没有继续更改,巨坑,最后发现是caffemodel包没有下载完全,一定要检查那个包呀,233M,最后运行成功!

原文地址:https://www.cnblogs.com/xujianqing/p/6142879.html