git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git
pip install cython
pip install easydict
apt-get install python-opencv
pip install easydict
sudo apt-get install python-tk
复制../caffe-fast-rcnn 的Makefile.config.example,然后重命名为Makefile.config,修改Makefile.config 文件
USE_CUDNN := 0
改为
USE_CUDNN := 1
CUDA_DIR := /usr/local/cuda
改为
CUDA_DIR := /usr/local/cuda-8.0
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
改为
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/lib/x86_64-linux-gnu/hdf5/serial/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial/
在终端中输入python
进入到python环境以后输入下边命令
import numpy as np
np.get_include()
这时会显示numpy路径,复制添加到
PYTHON_INCLUDE := /usr/include/python2.7 \
/usr/local/lib/python2.7/dist-packages/numpy/core/include
的后边,否则就会报错fatal error: numpy/arrayobject.h: No such file or directory
# WITH_PYTHON_LAYER := 1
去掉注释,改为
WITH_PYTHON_LAYER := 1
不然会在运行Demo的时候提示] Check failed: registry.count(type) == 1 (0 vs. 1) Unknown layer type: Python
,Aborted (core dumped)
。
因为py-faster-rcnn其cudnn实现为旧版本的实现,在现在的环境中编译会出错,需要将一部分文件替换为最新的文件
将./include/caffe/util/cudnn.hpp 换成最新版的caffe里的cudnn的实现,即相应的cudnn.hpp.
将./include/caffe/layers里的,所有以cudnn开头的文件,例如cudnn_conv_layer.hpp。 都替换成最新版的caffe里的相应的同名文件。
将./src/caffe/layer里的,所有以cudnn开头的文件,例如cudnn_lrn_layer.cu,cudnn_pooling_layer.cpp,cudnn_sigmoid_layer.cu。
都替换成最新版的caffe里的相应的同名文件
不执行上边的操作时,会报错make: *** [.build_release/src/caffe/common.o] Error 1
cd lib
make -j
cd caffe-fast-rcnn
make -j && make pycaffe
cd py-faster-rcnn
./data/scripts/fetch_faster_rcnn_models.sh
因为Faster Rcnn发布时间太早了,最近权重文件已经失效了,可以使用这个百度云链接进行下载,下载结束以后解压,将解压以后的文件放到下边的路径../Data/faster_rcnn_models/
。
####6.2 运行Demo
就将终端的目录设置为faster rcnn根目录,运行下边的程序就可以进行测试。
./tools/demo.py
不出意外的话会弹出一些图片识别的结果图,到此就安装成功了。
TypeError: slice indices must be integers or None or have an index method
修改$FRCN_ROOT/lib/rpn/proposal_target_layer.py,从第123行起:
for ind in inds:
cls = clss[ind]
start = 4 * cls
end = start + 4
bbox_targets[ind, start:end] = bbox_target_data[ind, 1:]
bbox_inside_weights[ind, start:end] = cfg.TRAIN.BBOX_INSIDE_WEIGHTS
return bbox_targets, bbox_inside_weights
修改为:
for ind in inds:
ind = int(ind)
cls = clss[ind]
start = int(4 * cls)
end = int(start + 4)
bbox_targets[ind, start:end] = bbox_target_data[ind, 1:]
bbox_inside_weights[ind, start:end] = cfg.TRAIN.BBOX_INSIDE_WEIGHTS
return bbox_targets, bbox_inside_weights
TypeError: 'numpy.float64' object cannot be interpreted as an index
这个报错也是numpy的版本问题,需要修改源码。
1) $FRCN_ROOT/lib/roi_data_layer/minibatch.py
将第26行:
fg_rois_per_image = np.round(cfg.TRAIN.FG_FRACTION * rois_per_image)
改为:
fg_rois_per_image = np.round(cfg.TRAIN.FG_FRACTION * rois_per_image).astype(np.int)
2) $FRCN_ROOT/lib/datasets/ds_utils.py
将第12行:
hashes = np.round(boxes * scale).dot(v)
改为:
hashes = np.round(boxes * scale).dot(v).astype(np.int)
3) $FRCN_ROOT/lib/fast_rcnn/test.py
将第129行:
hashes = np.round(blobs['rois'] * cfg.DEDUP_BOXES).dot(v)
改为:
hashes = np.round(blobs['rois'] * cfg.DEDUP_BOXES).dot(v).astype(np.int)
4) $FRCN_ROOT/lib/rpn/proposal_target_layer.py
将第60行:
fg_rois_per_image = np.round(cfg.TRAIN.FG_FRACTION * rois_per_image)
改为:
fg_rois_per_image = np.round(cfg.TRAIN.FG_FRACTION * rois_per_image).astype(np.int)
Caffe学习系列——Faster-RCNN训练自己的数据集
编译caffe出现错误:make: * [.build_release/src/caffe/common.o] Error 1