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