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,最后运行成功!

最新文章

  1. 【推荐】CentOS安装Subversion-1.8.11+HTTP协议支持配置
  2. SQL Server performance tips
  3. [maven] 使用Nexus创建maven私有仓库
  4. 网游中的网络编程3:在UDP上建立虚拟连接
  5. html5移动web开发笔记
  6. js实现模拟自动点击按钮,并且在10秒倒计时之后疯狂点击
  7. OData 集成
  8. Recommended add-ons/plugins for Microsoft Visual Studio [closed]
  9. Tortoise-SVN 出现“unable to connect to a repository at url no element found”解决办法
  10. ES6的Iterator遍历器
  11. Spring NoSuchBeanDefinitionException六大原因总结
  12. 6、什么是TypeScript、TypeScript的安装、转换为.js文件
  13. python中实现排序list
  14. session一直报错Session store not set on request
  15. eslint 在VSCode中不能使用
  16. Razor视图引擎 语法学习
  17. Asp.Net从相对路径获取绝对路径的方法(不需要httpcontext上下文也可)
  18. oracle删除死锁进程
  19. Selenium2+python自动化-CSS定位语法
  20. Spring 注解大全与详解

热门文章

  1. 【bzoj4580】[Usaco2016 Open]248 区间dp
  2. 配置bond和vlan
  3. (六)Redis有序集合Sorted set操作
  4. CentOS 安装MariaDB
  5. MySQL - General error: 1390 Prepared statement contains too many placeholders
  6. 【BZOJ 4455】 [Zjoi2016]小星星 容斥计数
  7. 【树状数组】【P2345】 奶牛集会
  8. The Usage of Pymongo
  9. Codeforces Round #546 (Div. 2) 题解
  10. mysql中的case when 与if else