Faster RCNN安装以及Demo运行

1. 下载

git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git

2. 依赖库安装

pip install cython 
pip install easydict 
apt-get install python-opencv
pip install easydict
sudo apt-get install python-tk

3. 修改配置文件

复制../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: PythonAborted (core dumped)

4. 文件替换

因为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

5. 安装

2.1 Cython模块编译
cd lib
make -j
2.2 caffe和pycaffe的编译
cd caffe-fast-rcnn
make -j && make pycaffe

6. 运行Demo

6.1 下载预训练模型
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

不出意外的话会弹出一些图片识别的结果图,到此就安装成功了。

7. 可能出现错误

错误1: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
错误2: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

  • 0
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值