py-faster-rcnn的配置具体参考github主页https://github.com/rbgirshick/py-faster-rcnn,并且下载时一定要使用--recursive递归下载。cpu模式下需要修改几个配置文件,具体可参考博客http://www.cnblogs.com/justinzhang/p/5386837.html
配置起来并不麻烦,但是运行./tools/demo.py --cpu --net zf 时出现以下两个错误
Error parsing text-formate caffe.NetParameter:47:11 Message type “caffe.LRNParameter" has no field named "engine" .
Error parsing text-formate caffe.NetParameter:232:14 Message type “caffe.PythonParameter" has no field named "param_str" .
百度了一下并没有找到这个问题的解决办法,问了一下网友,要么就是caffe的版本不对,要么就是python接口没有配置好。之前我将py-faster-rcnn和caffe-fast-rcnn分开来在windows上下载的,于是乎我重新clone --recursive了整个py-faster-rcnn,运行demo.py时还是出现同样的错误,那只能是python接口没配置成功,可是我使用import caffe时并没有报错,找了网上的各个caffe配置python的博客,我发现自己漏了一步。
make pycaffe 后添加环境变量
sudo gedit /etc/profile或者sudo vim /etc/profile ,注意gedit和vim 后面有空格
加入export PYTHONPATH=~/py-faster-rcnn/caffe-fast-rcnn/python:$PYTHONPATH
还有重要一步,要使文件生效
source /etc/profile
这时再运行demo.py --cpu --net zf 就成功了
---------------------------------------------------------训练自己的数据----------------------------------------------------------------------------
首先要准备数据集,我准备的是VOC2007格式的数据,网上有很多博客有介绍。我先用matlab版的faste-rcnn训练,在日志文件中出现smooth_l1_loss_layer.cpp:49 Not Implemented Yet 之后就再没动静了,搜了一下才发现这是报错了,faster-rcnn默认只能用GPU来训练,运行demo.py可以使用CPU。在运行python版本时直接提示只能用GPU训练,训练还是使用python版本的好。
在CPU下训练数据集,需要对py-faster-rcnn内的roi_pooling_layer和smooth_L1_loss_layer改为CPU版本,github上已经有人改了原代码使之能运行在CPU上。
并重新编译。可直接从github上下载替换。https://github.com/neuleaf/faster-rcnn-cpu
CPU训练时还有修改一些配置文件,可以参考http://blog.youkuaiyun.com/wjx2012yt/article/details/52197698
折腾了几天,终于可以在CPU上训练自己的数据了。