1,下载编译fast-rcnn
Clone the Fast R-CNN repository
#Make sure to clone with --recursive(这样clone下来的是包含rgb大神的caffe版本)
git clone --recursive https://github.com/rbgirshick/fast-rcnn.git
安装编译参考:www.jianshu.com/writer#/notebooks/17157779/notes/17808729
接下来编译frcnn...
编译Cython模块
cd $FRCN_ROOT/lib
make
如果提示没有Cython 模块
解决办法:sudo apt-get install pip
pip install Cython
2,编译caffe
cd $FRCN_ROOT/caffe-fast-rcnn
修改Makefile.config
# In your Makefile.config, make sure to have thislineuncommented
WITH_PYTHON_LAYER :=1
make -j8 && make pycaffe
问题:cudnn6.0版本太新出现的问题,用最新的caffe版本的cudnn有关的文件替换掉旧版本的文件
3.下载预计算的R-CNN检测器
大概600多M,百度网盘
链接: https://pan.baidu.com/s/1kUAuvT9 密码: 16ar
4,测试Demo
cd$FRCN_ROOT
./tools/demo.py
报错:no module named ***
用pip安装比较慢 需要更新一下pip源
cd /home/mahxn0
mkdir .pip
vim .pip/pip.conf 输入以下保存即可
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=mirrors.aliyun.com
5.制作自己的voc数据集修改训练网络
数据放到data/VOCdevkit2007/VOC2007目录下面
我用的是ZF网络 只需要修改以下几处地方即可
6.开始训练
./experiments/scripts/faster_rcnn_end2end.sh 0 VGG_CNN_M_1024 pascal_voc
问题1:KeyError HP
标记的数据标签不能有大写的
批量替换掉:
grep -rl "HP" | xargs sed -i 's/HP/hp/g'
问题2:AttributeError: 'module' object has no attribute 'text_format'
sudo pip install --upgrade protobuf
在文件./lib/fast_rcnn/train.py增加一行import google.protobuf.text_format 即可解决问题
训练过程:
rpn迭代完报错:TypeError: 'numpy.float64' object cannot be interpreted as an index
报错原因numpy1.11以上不支持浮点运算,网上看了别人的都是说:sudo pip install -U numpy==1.11.0
但是安装之后提示ImportError: numpy.core.multiarray failed to import
最后谷歌解决了需要修改一下源码:
solution:
Try to change the file in lib/roi_data_layer/minibatch.py
change the following lines:
line 55
for im_i in xrange(num_images):
labels, overlaps, im_rois, bbox_targets, bbox_inside_weights
= _sample_rois(roidb[im_i], int(fg_rois_per_image), int(rois_per_image),
int(num_classes))
line 98
if fg_inds.size > 0:
fg_inds = npr.choice(
fg_inds, size=int(fg_rois_per_this_image), replace=False)
line 110
if bg_inds.size > 0:
bg_inds = npr.choice(
bg_inds, size=int(bg_rois_per_this_image), replace=False)
line 124
bbox_targets, bbox_inside_weights = _get_bbox_regression_labels(
roidb['bbox_targets'][keep_inds, :], int(num_classes))
add
start = int(start)
end = int (end)
after line 175
potential cause:
According to some materials, the error is caused by numpy.
the version higher than 1.11.0 may not support float. therefore int(*) is needed.
修改完之后:pip install -U python-numpy
我现在的版本是numpy-1.13.1 cudnn6.0 cuda8.0 opencv3.2
7,测试
将训练得到的py-faster-rcnn\output\faster_rcnn_alt_opt\***_trainval中ZF的caffemodel拷贝至py-faster-rcnn\data\faster_rcnn_models(如果没有这个文件夹,就新建一个),然后,修改:
py-faster-rcnn\tools\demo.py,主要修改:
a,
CLASSES = ('__background__',
'你的标签1', '你的标签2', '你的标签3', '你的标签4')
改成你的数据集标签;
b,
NETS = {'vgg16': ('VGG16',
'VGG16_faster_rcnn_final.caffemodel'),
'zf': ('ZF',
'ZF_faster_rcnn_final.caffemodel')
上面ZF的caffemodel改成你的caffemodel。
c.
im_names = ['8.jpg','75.jpg','141.jpg',
'488.jpg','966.jpg','1013.jpg','1334.jpg','1052.jpg']
改成你的测试图片。(测试图片放在py-faster-rcnn\data\demo中)
8,结果
在py-faster-rcnn下,
执行:./tools/demo.py --net zf