caffe版faster-RCNN環境搭建
阿新 • • 發佈:2017-11-19
mit argument .com tail uil check otto pip __init__
- faster-rcnn提出論文: 《Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks》
- faster-rcnn 的算法詳解可看這篇博文(清晰易懂,良心博文!): http://blog.csdn.net/shenxiaolu1984/article/details/51152614
- faster-rcnn Python版本源碼地址:https://github.com/rbgirshick/py-faster-rcnn
- 基本按照官網上的readme
1.電腦上已經有可運行caffe所需的環境
2.下載faster-rcnn python版本源碼
git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git
3. 進入/py-faster-rcnn/lib 進行編譯,build the Cython modules
cd py-faster-rcnn/lib
make
問題:
python setup.py build_ext --inplace running build_ext cythoning utils/bbox.pyx to utils/bbox.c Error compiling Cython file:------------------------------------------------------------ ... # Copyright (c) 2015 Microsoft # Licensed under The MIT License [see LICENSE for details] # Written by Sergey Karayev # -------------------------------------------------------- cimport cython ^ ------------------------------------------------------------ utils/bbox.pyx:8:8: Compiler crash in AnalyseDeclarationsTransform File ‘ModuleNode.py‘, line 122, in analyse_declarations: ModuleNode(bbox.pyx:1:0, full_module_name = ‘utils.cython_bbox‘) File ‘Nodes.py‘, line 408, in analyse_declarations: StatListNode(bbox.pyx:8:0) File ‘Nodes.py‘, line 408, in analyse_declarations: StatListNode(bbox.pyx:8:8) File ‘Nodes.py‘, line 7396, in analyse_declarations: CImportStatNode(bbox.pyx:8:8, module_name = u‘cython‘) File "/home/dsp/anaconda2/lib/python2.7/site-packages/Cython/Utils.py", line 148, in search_include_directories path = os.path.join(dir, dotted_filename) File "/home/dsp/anaconda2/lib/python2.7/posixpath.py", line 73, in join path += ‘/‘ + b UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0xe6 in position 10: ordinal not in range(128) building ‘utils.cython_bbox‘ extension gcc -pthread -B /home/dsp/anaconda2/compiler_compat -Wl,--sysroot=/ -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/dsp/anaconda2/lib/python2.7/site-packages/numpy/core/include -I/home/dsp/anaconda2/include/python2.7 -c utils/bbox.c -o build/temp.linux-x86_64-2.7/utils/bbox.o -Wno-cpp -Wno-unused-function utils/bbox.c:1:2: error: #error Do not use this file, it is the result of a failed Cython compilation. #error Do not use this file, it is the result of a failed Cython compilation. ^ error: command ‘gcc‘ failed with exit status 1 Makefile:2: recipe for target ‘all‘ failed make: *** [all] Error 1
- 先各種百度,安裝cython等;結果發現時路徑的坑
- 神坑:路徑;py-faster-rcnn存放位置路徑中不能有中文,否則報錯UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0xe6 in position
- 最後放到 /home/uername/ 下直接makec成功
4.編譯/py-faster-rcnn/caffe-fast-rcnn
cd py-faster-rcnn/caffe-fast-rcnn
make -j32 && make pycaffe
- Makefile.config文件直接用的本機配置caffe的文件
- 問題:
In file included from ./include/caffe/util/device_alternate.hpp:40:0, from ./include/caffe/common.hpp:19, from ./include/caffe/blob.hpp:8, from src/caffe/blob.cpp:4: ./include/caffe/util/cudnn.hpp:8:34: fatal error: caffe/proto/caffe.pb.h: 沒有那個文件或目錄
- 按照:解決方法: 用protoc從caffe/src/caffe/proto/caffe.proto生成caffe.pb.h和caffe.pb.cc ,http://blog.csdn.net/xmzwlw/article/details/48270225 沒有作用;後面還有一串錯誤
In file included from ./include/caffe/util/device_alternate.hpp:40:0, from ./include/caffe/common.hpp:19, from ./include/caffe/blob.hpp:8, from ./include/caffe/layers/loss_layer.hpp:6, from src/caffe/layers/loss_layer.cpp:3: ./include/caffe/util/cudnn.hpp: In function ‘const char* cudnnGetErrorString(cudnnStatus_t)’: ./include/caffe/util/cudnn.hpp:21:10: warning: enumeration value ‘CUDNN_STATUS_RUNTIME_PREREQUISITE_MISSING’ not handled in switch [-Wswitch] switch (status) { ^ ./include/caffe/util/cudnn.hpp: In function ‘void caffe::cudnn::setConvolutionDesc(cudnnConvolutionStruct**, cudnnTensorDescriptor_t, cudnnFilterDescriptor_t, int, int, int, int)’: ./include/caffe/util/cudnn.hpp:108:70: error: too few arguments to function ‘cudnnStatus_t cudnnSetConvolution2dDescriptor(cudnnConvolutionDescriptor_t, int, int, int, int, int, int, cudnnConvolutionMode_t, cudnnDataType_t)’ pad_h, pad_w, stride_h, stride_w, 1, 1, CUDNN_CROSS_CORRELATION)); ^ ./include/caffe/util/cudnn.hpp:15:28: note: in definition of macro ‘CUDNN_CHECK’ cudnnStatus_t status = condition; ^ In file included from ./include/caffe/util/cudnn.hpp:5:0, from ./include/caffe/util/device_alternate.hpp:40, from ./include/caffe/common.hpp:19, from ./include/caffe/blob.hpp:8, from ./include/caffe/layers/loss_layer.hpp:6, from src/caffe/layers/loss_layer.cpp:3: /usr/local/cuda/include/cudnn.h:500:27: note: declared here cudnnStatus_t CUDNNWINAPI cudnnSetConvolution2dDescriptor( cudnnConvolutionDescriptor_t convDesc, ^ In file included from ./include/caffe/util/device_alternate.hpp:40:0, from ./include/caffe/common.hpp:19, from ./include/caffe/blob.hpp:8, from ./include/caffe/layers/loss_layer.hpp:6, from src/caffe/layers/loss_layer.cpp:3: ./include/caffe/util/cudnn.hpp: In function ‘void caffe::cudnn::createPoolingDesc(cudnnPoolingStruct**, caffe::PoolingParameter_PoolMethod, cudnnPoolingMode_t*, int, int, int, int, int, int)’: ./include/caffe/util/cudnn.hpp:127:41: error: too few arguments to function ‘cudnnStatus_t cudnnSetPooling2dDescriptor(cudnnPoolingDescriptor_t, cudnnPoolingMode_t, cudnnNanPropagation_t, int, int, int, int, int, int)’ pad_h, pad_w, stride_h, stride_w)); ^ ./include/caffe/util/cudnn.hpp:15:28: note: in definition of macro ‘CUDNN_CHECK’ cudnnStatus_t status = condition; ^ In file included from ./include/caffe/util/cudnn.hpp:5:0, from ./include/caffe/util/device_alternate.hpp:40, from ./include/caffe/common.hpp:19, from ./include/caffe/blob.hpp:8, from ./include/caffe/layers/loss_layer.hpp:6, from src/caffe/layers/loss_layer.cpp:3:View Code
- 後面發現時cndnn版本不兼容:Faster R-CNN 和最新的版本cuDNN V5.0不兼容問題
- 重新從caffe中fetch and merge
- 遇到merge沖突,直接編輯
// Caffe utility functions bp::def("init_log", &InitLog); bp::def("init_log", &InitLogLevel); bp::def("init_log", &InitLogLevelPipe); bp::def("log", &Log); bp::def("has_nccl", &HasNCCL); bp::def("set_mode_cpu", &set_mode_cpu); bp::def("set_mode_gpu", &set_mode_gpu); bp::def("set_random_seed", &set_random_seed); bp::def("set_device", &Caffe::SetDevice); <<<<<<< HEAD bp::def("set_random_seed", &Caffe::set_random_seed); ======= bp::def("solver_count", &Caffe::solver_count); bp::def("set_solver_count", &Caffe::set_solver_count); bp::def("solver_rank", &Caffe::solver_rank); bp::def("set_solver_rank", &Caffe::set_solver_rank); bp::def("set_multiprocess", &Caffe::set_multiprocess); >>>>>>> caffe/master
- 最後編譯成功;faster-rcnn 安裝裏面也提到了處理版本不兼容,進行文件替換的方法
AR -o .build_release/lib/libcaffe.a LD -o .build_release/lib/libcaffe.so.1.0.0 CXX/LD -o .build_release/tools/convert_imageset.bin CXX/LD -o .build_release/tools/train_net.bin CXX/LD -o .build_release/tools/finetune_net.bin CXX/LD -o .build_release/tools/compute_image_mean.bin CXX/LD -o .build_release/tools/upgrade_net_proto_text.bin CXX/LD -o .build_release/tools/test_net.bin CXX/LD -o .build_release/tools/upgrade_net_proto_binary.bin CXX/LD -o .build_release/tools/upgrade_solver_proto_text.bin CXX/LD -o .build_release/tools/net_speed_benchmark.bin CXX/LD -o .build_release/tools/device_query.bin CXX/LD -o .build_release/tools/extract_features.bin CXX/LD -o .build_release/examples/cifar10/convert_cifar_data.bin CXX/LD -o .build_release/examples/mnist/convert_mnist_data.bin CXX/LD -o .build_release/examples/cpp_classification/classification.bin CXX/LD -o .build_release/tools/caffe.bin CXX/LD -o .build_release/examples/siamese/convert_mnist_siamese_data.bin CXX/LD -o python/caffe/_caffe.so python/caffe/_caffe.cpp touch python/caffe/proto/__init__.py PROTOC (python) src/caffe/proto/caffe.protoView Code
5、下載Faster R-CNN的預訓練模型
cd py-faster-rcnn
./data/scripts/fetch_faster_rcnn_models.sh
6、運行demo.py
cd py-faster-rcnn
./tools/demo.py
- Reference
CNN目標檢測(一):Faster RCNN詳解
faster-rcnn 安裝
Faster R-CNN 的Caffe實現
caffe版faster-RCNN環境搭建