官方代碼:https://github.com/rbgirshick/py-faster-rcnn
1.下載代碼到本機
git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git
--recursive 遞歸更新子文件夾
2.編輯Cython模型($FRCN_ROOT是下載后程序名稱)
cd $FRCN_ROOT/lib
make
3.編輯caffe和pycaffe
cd $FRCN_ROOT/caffe-fast-rcnn
# Now follow the Caffe installation instructions here:
# http://caffe.berkeleyvision.org/installation.html
# If you're experienced with Caffe and have all of the requirements installed
# and your Makefile.config in place, then simply do:
make -j8 && make pycaffe
4.下載Faster RCNN預訓練模型
cd $FRCN_ROOT
./data/scripts/fetch_faster_rcnn_models.sh
注意:此模型通過VOC2007進行訓練,且需要翻墻下載
5.測試模型
cd $FRCN_ROOT
./tools/demo.py
可能會遇到以下問題:
問題1:py-faster RCNN源代碼只支持cudnn v4在cudnn v5下編譯需要更改部分cudnn文件:
方案1:git版本合并
cd caffe-fast-rcnn
#將BLVC/caffe添加為遠程倉庫攘蔽,命名為caffe
git remote add caffe https://github.com/BVLC/caffe.git
#獲取BLVC/caffe代碼
git fetch caffe
#將BLVC/caffe的master分支合并到當前分支
# -X theirs指定在合并遇到沖突時以BLVC/caffe版本為主
git merge -X theirs caffe/master
可能會遇到輸入郵箱和姓名的內容,直接將提示信息復制后執(zhí)行即可许起。
圖片 1.png
執(zhí)行git merge -X theirs caffe/master
會要求輸入信息,不必輸入任何內容菩鲜,直接按Ctrl-X離開园细。
問題2:
Traceback (most recent call last):
File "./tools/demo.py", line 135, in <module>
net = caffe.Net(prototxt, caffemodel, caffe.TEST)
AttributeError: can't set attribute
方案2:需要注釋掉源碼中的一行,并重新編譯接校。include/caffe/layers/python_layer.hpp 中猛频,注釋掉:
self_.attr("phase") = static_cast(this->phase_);
問題3:需要有界面才能執(zhí)行的問題
方案3:將demo.py做以下修改:
剛開始加入兩行
import _init_paths
import matplotlib
matplotlib.use('Agg')
from fast_rcnn.config import cfg
.................
在顯示函數vis_detections加入一行保存文件,方便下載下載看
def vis_detections(im, class_name, dets, thresh=0.5):
.................
plt.savefig("/home/yourname/picFaster.jpg")
圖片 2.png