Faster R-CNN的安装及测试(Python版本和Matlab版本)

rbg的Python版本


一、拉取源码

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

拉取完成后,在/home/cmwang/目录下增加了py-faster-rcnn文件夹【cmwang是我的ubuntu用户名】


二、安装依赖

sudo apt-get install python-opencvsudo pip install cython easydict

三、修改Makefile文件

终端输入

cd /home/cmwang/py-faster-rcnn/caffe-fast-rcnn/ 
cp Makefile.config.example Makefile.config #备份Makefile 
gedit Makefile.config

使用python层
将# WITH_PYTHON_LAYER := 1修改为 WITH_PYTHON_LAYER := 1

调用matlab
将#MATLAB_DIR := / usr/local/MATLAB/R2015b 中的#去掉。

使用cudnn加速
将# USE_CUDNN := 1修改为USE_CUDNN := 1

保留# CPU_ONLY := 1不变,使用GPU运行faster r-cnn


四、编译Cython模块

终端输入

cd ~/py-faster-rcnn/lib/make

五、编译caffe和pycaffe & matcaffe

终端输入

cd ~/py-faster-rcnn/caffe-fast-rcnn/ 
make -j8 && make pycaffe && make matcaffe

六、下载模型

终端输入

cd ~/py-faster-rcnn/./data/scripts/fetch_faster_rcnn_models.sh 

七、faster r-cnn测试

cd ~/py-faster-rcnn/ 
./tools/demo.py 

Shaoqing Ren的MATLAB版本



一、拉取源码

下载 faster_rcnn-master.zip

拉取完成后,在/home/cmwang/目录下增加了faster_rcnn_master文件夹【cmwang是我的ubuntu用户名】


二、下载补充文件夹

解压faster_rcnn-master.zip后,发现faster_rcnn-master/external/caffe 是空文件。
下载 caffe-062f2431162165c658a42d717baf8b74918aa18e.zip

unzip caffe-062f2431162165c658a42d717baf8b74918aa18e.zip
cp ./caffe-062f2431162165c658a42d717baf8b74918aa18e/ ./faster_rcnn-master/external/caffe/

三、修改Makefile文件

终端输入

cd /home/cmwang/faster_rcnn-master/external/caffe 
cp Makefile.config.example Makefile.config #备份Makefile 
gedit Makefile.config

使用python层
将# WITH_PYTHON_LAYER := 1修改为 WITH_PYTHON_LAYER := 1

调用matlab
将#MATLAB_DIR := / usr/local/MATLAB/R2015b 中的#去掉。

使用cudnn加速
将# USE_CUDNN := 1修改为USE_CUDNN := 1

保留# CPU_ONLY := 1不变,使用GPU运行faster r-cnn


四、编译caffe和pycaffe & matcaffe

终端输入

cd ~faster_rcnn-master/external/caffe
make all -j8 && make test -j8 && make runtest -j8 && make pycaffe && make matcaffe

五、下载模型

终端输入

cd ~/faster_rcnn-master/run fetch_data/fetch_model_VGG16.m

六、运行

cd ~/faster_rcnn-master/ 
run faster_rcnn_build.m
run startup.m

七、faster r-cnn测试

cd ~/faster_rcnn-master/ 
run ./experiments/script_faster_rcnn_demo.m

备注: Matlab里面有内置的

Object Detection Using Faster R-CNN Deep Learning


常出现的问题1

这里写图片描述


这是由于当前版本的caffe中cudnn实现与系统所安装的cudnn的版本不一致引起,rbgirshick的py-faster-rcnn其cudnn实现为旧版本的实现,所有出现了以上问题。

cudnn-7.0-linux-x64-v4.0-prod.tgz不会出现此问题
cudnn-7.5-linux-x64-v5.1.tgz会出现同样问题
cudnn-8.0-linux-x64-v5.1.tgz会出现同样问题

解决办法

①将/home/cmwang/py-faster-rcnn/caffe-fast-rcnn/include/caffe/util/cudnn.hpp 换成最新版caffe里的相应目录下的cudnn.hpp;②将/home/cmwang/py-faster-rcnn/caffe-fast-rcnn/include/caffe/layers/下所有cudnn开头的文件都替换为最新版caffe里相应目录下的同名文件;③将/home/cmwang/py-faster-rcnn/caffe-fast-rcnn/src/caffe/layer下所有cudnn开头的文件都替换为最新版caffe里相应目录下的同名文件

常出现的问题2

这里写图片描述

出现找不到hdf5.h错误;

解决办法:终端输入

cd /home/cmwang/py-faster-rcnn/caffe-fast-rcnn/ 
gedit Makefile.config 
在INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include 后面打上一个空格,然后添加/usr/include/hdf5/serial

如果没有这一句可能会报一个找不到hdf5.h的错误。


常出现的问题3

CXX .build_release/src/caffe/proto/caffe.pb.cc
CXX src/caffe/common.cpp
CXX src/caffe/net.cpp
CXX src/caffe/internal_thread.cpp
CXX src/caffe/layers/cudnn_softmax_layer.cpp
CXX src/caffe/layers/hinge_loss_layer.cpp
CXX src/caffe/layers/relu_layer.cpp
CXX src/caffe/layers/contrastive_loss_layer.cpp
CXX src/caffe/layers/elu_layer.cpp
CXX src/caffe/layers/hdf5_output_layer.cpp
CXX src/caffe/layers/cudnn_pooling_layer.cpp
CXX src/caffe/layers/deconv_layer.cpp
CXX src/caffe/layers/memory_data_layer.cpp
CXX src/caffe/layers/eltwise_layer.cpp
CXX src/caffe/layers/softmax_loss_layer.cpp
CXX src/caffe/layers/silence_layer.cpp
CXX src/caffe/layers/power_layer.cpp
CXX src/caffe/layers/exp_layer.cpp
CXX src/caffe/layers/threshold_layer.cpp
CXX src/caffe/layers/tanh_layer.cpp
CXX src/caffe/layers/cudnn_lrn_layer.cpp
CXX src/caffe/layers/data_layer.cpp
CXX src/caffe/layers/base_conv_layer.cpp
CXX src/caffe/layers/lstm_unit_layer.cpp
CXX src/caffe/layers/accuracy_layer.cpp
CXX src/caffe/layers/softmax_layer.cpp
CXX src/caffe/layers/im2col_layer.cpp
CXX src/caffe/layers/lstm_layer.cpp
CXX src/caffe/layers/sigmoid_cross_entropy_loss_layer.cpp
CXX src/caffe/layers/cudnn_relu_layer.cpp
CXX src/caffe/layers/image_data_layer.cpp
CXX src/caffe/layers/reshape_layer.cpp
CXX src/caffe/layers/window_data_layer.cpp
CXX src/caffe/layers/split_layer.cpp
CXX src/caffe/layers/hdf5_data_layer.cpp
CXX src/caffe/layers/flatten_layer.cpp
CXX src/caffe/layers/cudnn_lcn_layer.cpp
CXX src/caffe/layers/input_layer.cpp
CXX src/caffe/layers/rnn_layer.cpp
CXX src/caffe/layers/recurrent_layer.cpp
CXX src/caffe/layers/inner_product_layer.cpp
CXX src/caffe/layers/reduction_layer.cpp
CXX src/caffe/layers/multinomial_logistic_loss_layer.cpp
CXX src/caffe/layers/infogain_loss_layer.cpp
CXX src/caffe/layers/bias_layer.cpp
CXX src/caffe/layers/filter_layer.cpp
CXX src/caffe/layers/batch_reindex_layer.cpp
CXX src/caffe/layers/slice_layer.cpp
CXX src/caffe/layers/argmax_layer.cpp
CXX src/caffe/layers/prelu_layer.cpp
CXX src/caffe/layers/dropout_layer.cpp
CXX src/caffe/layers/absval_layer.cpp
CXX src/caffe/layers/bnll_layer.cpp
CXX src/caffe/layers/sigmoid_layer.cpp
CXX src/caffe/layers/concat_layer.cpp
CXX src/caffe/layers/dummy_data_layer.cpp
CXX src/caffe/layers/base_data_layer.cpp
CXX src/caffe/layers/log_layer.cpp
CXX src/caffe/layers/crop_layer.cpp
CXX src/caffe/layers/cudnn_tanh_layer.cpp
CXX src/caffe/layers/pooling_layer.cpp
CXX src/caffe/layers/parameter_layer.cpp
CXX src/caffe/layers/euclidean_loss_layer.cpp
CXX src/caffe/layers/mvn_layer.cpp
CXX src/caffe/layers/lrn_layer.cpp
CXX src/caffe/layers/loss_layer.cpp
CXX src/caffe/layers/conv_layer.cpp
CXX src/caffe/layers/cudnn_sigmoid_layer.cpp
CXX src/caffe/layers/scale_layer.cpp
CXX src/caffe/layers/tile_layer.cpp
CXX src/caffe/layers/embed_layer.cpp
CXX src/caffe/layers/neuron_layer.cpp
CXX src/caffe/layers/cudnn_conv_layer.cpp
CXX src/caffe/layers/batch_norm_layer.cpp
CXX src/caffe/layers/spp_layer.cpp
CXX src/caffe/layer_factory.cpp
CXX src/caffe/blob.cpp
CXX src/caffe/layer.cpp
CXX src/caffe/data_transformer.cpp
CXX src/caffe/syncedmem.cpp
CXX src/caffe/util/blocking_queue.cpp
CXX src/caffe/util/db_lmdb.cpp
CXX src/caffe/util/benchmark.cpp
CXX src/caffe/util/io.cpp
CXX src/caffe/util/insert_splits.cpp
CXX src/caffe/util/hdf5.cpp
CXX src/caffe/util/cudnn.cpp
CXX src/caffe/util/signal_handler.cpp
CXX src/caffe/util/db.cpp
CXX src/caffe/util/math_functions.cpp
CXX src/caffe/util/upgrade_proto.cpp
CXX src/caffe/util/im2col.cpp
CXX src/caffe/util/db_leveldb.cpp
CXX src/caffe/solvers/adam_solver.cpp
CXX src/caffe/solvers/adadelta_solver.cpp
CXX src/caffe/solvers/adagrad_solver.cpp
CXX src/caffe/solvers/sgd_solver.cpp
CXX src/caffe/solvers/rmsprop_solver.cpp
CXX src/caffe/solvers/nesterov_solver.cpp
CXX src/caffe/data_reader.cpp
CXX src/caffe/parallel.cpp
CXX src/caffe/solver.cpp
AR -o .build_release/lib/libcaffe.a
LD -o .build_release/lib/libcaffe.so.1.0.0-rc3
/usr/bin/ld: cannot find -lhdf5_hl
/usr/bin/ld: cannot find -lhdf5
collect2: error: ld returned 1 exit status
Makefile:566: recipe for target '.build_release/lib/libcaffe.so.1.0.0-rc3' failed
make: *** [.build_release/lib/libcaffe.so.1.0.0-rc3] Error 1

解决方法

修改Makefile 文件(注意不是)Makefile.config 
将里面的
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5改为LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial

常出现的问题4

CXX/LD -o .build_release/tools/convert_imageset.bin
.build_release/lib/libcaffe.so: undefined reference to cv::imread(cv::String const&, int)' .build_release/lib/libcaffe.so: undefined reference tocv::imencode(cv::String const&, cv::_InputArray const&, std::vector<unsigned char, std::allocator >&, std::vector<int, std::allocator > const&)'
.build_release/lib/libcaffe.so: undefined reference to `cv::imdecode(cv::_InputArray const&, int)'
collect2: error: ld returned 1 exit status
make: *** [.build_release/tools/convert_imageset.bin] Error 1CXX/LD -o .build_release/test/test_all.testbin src/caffe/test/test_caffe_main.cppLD .build_release/src/caffe/test/test_threshold_layer.o
.build_release/lib/libcaffe.so: undefined reference to cv::imread(cv::String const&, int)' .build_release/lib/libcaffe.so: undefined reference tocv::imencode(cv::String const&, cv::_InputArray const&, std::vector<unsigned char, std::allocator >&, std::vector<int, std::allocator > const&)'
.build_release/lib/libcaffe.so: undefined reference to `cv::imdecode(cv::_InputArray const&, int)'
collect2: error: ld returned 1 exit status
make: *** [.build_release/test/test_threshold_layer.testbin] Error 1

Maybe it is the related with OpenCv.

解决方法

add "opencv_imgcodecs" in Makefile.(LIBRARIES += glog gflags protobuf leveldb snappy 
lmdb boost_system hdf5_hl hdf5 m 
opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs)

常出现的问题5


执行make runtest这一命令之后,遇到了奇葩的问题”Unknown V1LayerParameter Layer type: 40”。如下图:
这里写图片描述


解决方案

在这个文件上面(external/caffe/src/caffe/util/upgrade_proto.cpp)。我们需要补上Reshape,ROIPooling以及SmoothL1Loss这三个层,具体见下:


case V1LayerParameter_LayerType_THRESHOLD:
return "Threshold";
case V1LayerParameter_LayerType_RESHAPE:
return "Reshape";
case V1LayerParameter_LayerType_ROIPOOLING:
return "ROIPooling";`
case V1LayerParameter_LayerType_SMOOTH_L1_LOSS:
return "SmoothL1Loss";


若还有其他的问题敬请查看

Faste R-CNN的安装及测试


参考文献:

安装Caffe.build_release/lib/libcaffe.so.1.0.0-rc3’ failed

Faster R-CNN的安装、测试经历

Error: ‘make all’ ‘make test’

Faster R-CNN教程

faster rcnn配置方法MATLAB 版本

Object Detection Using Faster R-CNN Deep Learning

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/246865.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

2016 亚洲共识指南:肺结节的评估

2016 年 2 月&#xff0c;亚洲肺部疾病和胸外科多学科专家小组在美国胸科医师学会&#xff08;ACCP&#xff09;制定的肺结节评估指南的基础上结合亚洲患者的自身特点制订了亚洲肺结节患者的评估指南。 亚洲肺结节的评估与 APCC 指南中所指出的重要注意事项大致相同。但该指南…

Ubuntu 15.04 安装TensorFlow(源码编译) 及测试梵高作画

介绍Google的TensorFlow机器学习开源库&#xff0c;在UbuntuKylin上的安装和和源码编译。 原始官方文档参见&#xff1a;http://www.tensorflow.org. 本电脑配置如下&#xff1a; 3.19.0-15-generic #15-Ubuntu x86_64 GNU/Linux NVIDIA Corporation GK110BGL [Tesla K40c] …

Ubuntu SSH Algorithm negotiation failed

问题 解决方法 chmod 777 /etc/ssh/sshd_configgedit /etc/ssh/sshd_config添加如下 Ciphers aes128-cbc,aes192-cbc,aes256-cbc,aes128-ctr,aes192-ctr,aes256-ctr,3des-cbc,arcfour128,arcfour256,arcfour,blowfish-cbc,cast128-cbcMACs hmac-md5,hmac-sha1,umac-64openssh.…

不同matlab版本所支持的gcc g+版本

问题 关于 GCC 和 G 版本问题 Matlab 2014a gcc/g 4.7.x, Matlab 2016a gcc/g 4.9.x Matlab 2017a gcc/g 4.9.x Ubuntu 15.04 gcc/g 4.9.x, Ubuntu 16.04 gcc/g 5.4.x 原则上Matlab需要和Ubuntu版本一致&#xff0c;由于CUDA 8只支持16.04,而且需要GCC 5.4.x 进行编译&#…

Linux 终端配置

一般Linux中的配置文件大多以点开头&#xff0c;而且多以rc结尾。比如vim的配置文件 .vimrc&#xff0c;bash shell的配置文件.bashrc&#xff0c;等等。 像这样的配置文件&#xff0c;如果用ls -l命令是列不出来的&#xff0c;需要用ls -a来列出。 “rc”&#xff0c;它是“…

caffe2 介绍

Caffe2的特性 Caffe2框架可以通过一台机器上的多个GPU或具有一个及多个GPU的多台机器来进行分布式训练。 也可以在iOS系统、Android系统和树莓派&#xff08;Raspberry Pi&#xff09;上训练和部署模型。只需要运行几行代码即可调用Caffe2中预先训练好的Model Zoo模型。Caffe2…

Python 中的numpy 库

待总结 用scikit-learn和pandas学习线性回归 用scikit-learn和pandas学习Ridge回归 待整理的 Numpy & Pandas numpy——主要对其 N 维数组对象有用 http://www.numpy.org/ Pandas数据转为 numpy数据 df_numpyMatrix df.as_matrix() df_numpyMatrixdf.values a([3.23…

Python 中的Pandas库

待总结 用scikit-learn和pandas学习线性回归 用scikit-learn和pandas学习Ridge回归 基于python的数据分析库Pandas pandas——Python 数据分析库&#xff0c;包括数据框架&#xff08;dataframes&#xff09;等结构 http://pandas.pydata.org/ 10 Minutes to Pandas&#…

weka和matlab完成完整分类实验

本文 本文简单介绍数据集介绍、weka的使用、weka与LIBSVM、matlab与LIBSVM以及分类的若干细节问题。 1. 数据集介绍 打开网址UCI数据集&#xff0c;如下图。 从右下角可以看到Iris这个数据集&#xff0c;这是使用最多的数据集&#xff0c;目前下载量超过了82万。 打开之后跳…

Python 中的绘图matplotlib mayavi库

python matplotlib 图像可视化 python-data-visualization-course Interactive Web Plotting for Python Interactive Web Plotting for Python-github 待整理的 Matplotlib Introduction to Matplotlib and basic line matplotlib——一个 2D 绘图库&#xff0c;可产生…

ubuntu 16.04 配置Python2.7 和 Python3.5 同时调用OpenCV

安装OpenCV OpenCV 官网&#xff0c;下载见 SourceForge and GitHub。 若使用官网版本安装不成功&#xff0c;则可试试Github版本。 或者 git clone https://github.com/Itseez/opencv.git 安装依赖库 sudo apt-get -y install libopencv-dev sudo apt-get -y install bui…

生成特定分布随机数的方法:Python seed() 函数numpy scikit-learn随机数据生成

描述 seed() 方法改变随机数生成器的种子&#xff0c;可以在调用其他随机模块函数之前调用此函数。。 语法 以下是 seed() 方法的语法: import random random.seed ( [x] ) 注意&#xff1a;seed(()是不能直接访问的&#xff0c;需要导入 random 模块&#xff0c;然后通过 ra…

scipy.ndimage.zoom上采样与下采样

插值 Bilinear interpolation would be order1, nearest is order0, and cubic is the default (order3). 举例说明 import numpy as np import scipy.ndimagex np.arange(64).reshape(8,8)print Original array: print xprint Resampled by a factor of 2 with nearest i…

UFLDL教程: Exercise: Sparse Autoencoder

自编码可以跟PCA 一样&#xff0c;给特征属性降维 一些matlab函数 bsxfun:Cbsxfun(fun,A,B)表达的是两个数组A和B间元素的二值操作&#xff0c;fun是函数句柄或者m文件&#xff0c;或者是内嵌的函数。在实际使用过程中fun有很多选择比如说加&#xff0c;减等&#xff0c;前面需…

UFLDL教程:Exercise:PCA in 2D PCA and Whitening

相关文章 PCA的原理及MATLAB实现 UFLDL教程&#xff1a;Exercise:PCA in 2D & PCA and Whitening python-A comparison of various Robust PCA implementations Deep Learning and Unsupervised Feature Learning Tutorial Solutions 统计学的基本概念 统计学里最基本…

UFLDL教程:Exercise:Softmax Regression

Softmax分类函数的Python实现 Deep Learning and Unsupervised Feature Learning Tutorial Solutions 逻辑回归假设函数 在线性回归问题中&#xff0c;假设函数具有如下形式&#xff1a; 在 logistic 回归中&#xff0c;我们的训练集由m 个已标记的样本构成&#xff1a;&#…

UFLDL教程: Exercise:Self-Taught Learning

自我学习 Deep Learning and Unsupervised Feature Learning Tutorial Solutions 1.先训练稀疏自编码器提取特征&#xff0c;再把特征和label给softmax分类器进行训练&#xff0c;最后用test数据集进行测试。 2.由于实际应用中找到大量有标注的样本是非常困难的&#xff0c;所…

UFLDL教程: Exercise: Implement deep networks for digit classification

Deep networks Deep Learning and Unsupervised Feature Learning Tutorial Solutions 深度网络的优势 比单层神经网络能学习到更复杂的表达。不同层的网络学习到的特征是由最底层到最高层慢慢上升的。比如在图像的学习中&#xff0c;第一个隐含层网络可能学习的是边缘特征&am…

UFLDL教程: Exercise:Learning color features with Sparse Autoencoders

Linear Decoders Deep Learning and Unsupervised Feature Learning Tutorial Solutions 以三层的稀疏编码神经网络而言&#xff0c;在sparse autoencoder中的输出层满足下面的公式 从公式中可以看出&#xff0c;a3的输出值是f函数的输出&#xff0c;而在普通的sparse autoenc…

UFLDL教程:Exercise:Convolution and Pooling

Deep Learning and Unsupervised Feature Learning Tutorial Solutions CNN的基本结构包括两层 其一为特征提取层&#xff0c;每个神经元的输入与前一层的局部接受域相连&#xff0c;并提取该局部的特征。一旦该局部特征被提取后&#xff0c;它与其它特征间的位置关系也随之确…