- 基本按照官网上的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
  • 如果重新升级或者降级numpy依赖包,需要重新去掉之前生成的文件,重新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的文件
  • 问题:
dsp@dsp-PowerEdge-R730:/home/user/ran/Desktop/protobuf-2.6.$ protoc
[libprotobuf FATAL google/protobuf/stubs/common.cc:] This program requires version 3.4. of the Protocol Buffer runtime library, but the installed version is 2.6.. Please update your library. If you compiled the program yourself, make sure that your headers are from the same version of Protocol Buffers as your link-time library. (Version verification failed in "google/protobuf/any.pb.cc".)
terminate called after throwing an instance of 'google::protobuf::FatalException'
what(): This program requires version 3.4. of the Protocol Buffer runtime library, but the installed version is 2.6.. Please update your library. If you compiled the program yourself, make sure that your headers are from the same version of Protocol Buffers as your link-time library. (Version verification failed in "google/protobuf/any.pb.cc".)
Aborted (core dumped)

这个问题是服务器上的错误:http://blog.csdn.net/m0_37477175/article/details/78233983

https://www.cnblogs.com/javaee6/p/4849051.html

https://github.com/BVLC/caffe/issues/5711

前面两种方法都是了没有解决,后面github上的issue也没有给出解决方法,看以后能不能解决!!!

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:
  • 后面发现时cndnn版本不兼容:Faster R-CNN 和最新的版本cuDNN V5.0不兼容问题
  • 解决方法:
    
    cd py-faster-rcnn/caffe-fast-rcnn
    Git remote add caffe https://github.com/BVLC/caffe.git
    git fetch caffe
    git merge caffe/master 在合并之后注释掉include/caffe/layers/python_layer.hppa文件里的self_.attr(“phase”) = static_cast(this->phase_)
  • 重新从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.proto

5、下载Faster R-CNN的预训练模型

cd py-faster-rcnn
./data/scripts/fetch_faster_rcnn_models.sh model:https://dl.dropboxusercontent.com/s/o6ii098bu51d139/faster_rcnn_models.tgz?dl=0

6、运行demo.py

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

7.Usage:训练

To train and test a Faster R-CNN detector using the alternating optimization algorithm from our NIPS 2015 paper, use experiments/scripts/faster_rcnn_alt_opt.sh. Output is written underneath $FRCN_ROOT/output.

cd $FRCN_ROOT
./experiments/scripts/faster_rcnn_alt_opt.sh [GPU_ID] [NET] [--set ...]
# GPU_ID is the GPU you want to train on
# NET in {ZF, VGG_CNN_M_1024, VGG16} is the network arch to use
# --set ... allows you to specify fast_rcnn.config options, e.g.
# --set EXP_DIR seed_rng1701 RNG_SEED 1701

AttributeError: 'module' object has no attribute 'text_format'

在文件./lib/fast_rcnn/train.py增加一行import google.protobuf.text_format 即可解决问题

8.后续问题

I1119 21:29:42.451519 21365 net.cpp:744] Ignoring source layer pool5_spm6
I1119 21:29:42.451537 21365 net.cpp:744] Ignoring source layer pool5_spm6_flatten
I1119 21:29:42.481129 21365 net.cpp:744] Ignoring source layer fc8
I1119 21:29:42.481151 21365 net.cpp:744] Ignoring source layer prob
Solving...
Process Process-3:
Traceback (most recent call last):
File "/home/dsp/anaconda2/lib/python2.7/multiprocessing/process.py", line 267, in _bootstrap
self.run()
File "/home/dsp/anaconda2/lib/python2.7/multiprocessing/process.py", line 114, in run
self._target(*self._args, **self._kwargs)
File "./tools/train_faster_rcnn_alt_opt.py", line 195, in train_fast_rcnn
max_iters=max_iters)
File "/home/dsp/py-faster-rcnn/tools/../lib/fast_rcnn/train.py", line 162, in train_net
model_paths = sw.train_model(max_iters)
File "/home/dsp/py-faster-rcnn/tools/../lib/fast_rcnn/train.py", line 103, in train_model
self.solver.step(1)
File "/home/dsp/py-faster-rcnn/tools/../lib/roi_data_layer/layer.py", line 144, in forward
blobs = self._get_next_minibatch()
File "/home/dsp/py-faster-rcnn/tools/../lib/roi_data_layer/layer.py", line 63, in _get_next_minibatch
return get_minibatch(minibatch_db, self._num_classes)
File "/home/dsp/py-faster-rcnn/tools/../lib/roi_data_layer/minibatch.py", line 55, in get_minibatch
num_classes)
File "/home/dsp/py-faster-rcnn/tools/../lib/roi_data_layer/minibatch.py", line 100, in _sample_rois
fg_inds, size=fg_rois_per_this_image, replace=False)
File "mtrand.pyx", line 1187, in mtrand.RandomState.choice
TypeError: 'numpy.float64' object cannot be interpreted as an index TypeError: 'numpy.float64' object cannot be interpreted as an index
还是numpy版本的问题,直接换一个版本好了
sudo pip install -U numpy==1.11.0 --这个错 “ImportError: numpy.core.multiarray failed to import”好像就是lib库里面没有重新make,去掉之前
+ ./tools/train_faster_rcnn_alt_opt.py --gpu 0 --net_name ZF --weights data/imagenet_models/ZF.v2.caffemodel --imdb voc_2007_trainval --cfg experiments/cfgs/faster_rcnn_alt_opt.yml
Traceback (most recent call last):
File "./tools/train_faster_rcnn_alt_opt.py", line 19, in <module>
from datasets.factory import get_imdb
File "/home/dsp/py-faster-rcnn/tools/../lib/datasets/factory.py", line 13, in <module>
from datasets.coco import coco
File "/home/dsp/py-faster-rcnn/tools/../lib/datasets/coco.py", line 20, in <module>
from pycocotools.coco import COCO
File "/home/dsp/py-faster-rcnn/tools/../lib/pycocotools/coco.py", line 58, in <module>
import mask
File "/home/dsp/py-faster-rcnn/tools/../lib/pycocotools/mask.py", line 3, in <module>
import pycocotools._mask as _mask
File "pycocotools/_mask.pyx", line 20, in init pycocotools._mask
File "__init__.pxd", line 989, in numpy.import_array
ImportError: numpy.core.multiarray failed to import
Reading annotation for 4901/4952
Saving cached annotations to /home/dsp/py-faster-rcnn/data/VOCdevkit2007/annotations_cache/annots.pkl
AP for aeroplane = 0.0339
AP for bicycle = 0.1139
AP for bird = 0.0069
AP for boat = 0.0646
Traceback (most recent call last):
File "./tools/test_net.py", line 90, in <module>
test_net(net, imdb, max_per_image=args.max_per_image, vis=args.vis)
File "/home/dsp/py-faster-rcnn/tools/../lib/fast_rcnn/test.py", line 295, in test_net
imdb.evaluate_detections(all_boxes, output_dir)
File "/home/dsp/py-faster-rcnn/tools/../lib/datasets/pascal_voc.py", line 322, in evaluate_detections
self._do_python_eval(output_dir)
File "/home/dsp/py-faster-rcnn/tools/../lib/datasets/pascal_voc.py", line 285, in _do_python_eval
use_07_metric=use_07_metric)
File "/home/dsp/py-faster-rcnn/tools/../lib/datasets/voc_eval.py", line 148, in voc_eval
BB = BB[sorted_ind, :]
IndexError: too many indices for array

http://blog.csdn.net/weinaonao5418/article/details/54234684

    File "/home/dl-box/wei/py-faster-rcnn/tools/../lib/datasets/voc_eval.py", line 149, in voc_eval
        BB = BB[sorted_ind, :]
    IndexError: too many indices for array
    这个错是说没有学习到东西,我用了[4000,2000,4000,2000]试了一下也不行。不过能看到这个错误,如果你的数据集做的没有问题的话,用[80000,40000,80000,40000](亲测大概16小时,1341张图)运行你自己的数据集就没问题了。为了省时间我用的是[40000,20000,40000,2000](大概8小时,50张图)。这个时间好像与图片大小和图片数量关系不大。感觉只与迭代次数有关。
  • Reference

CNN目标检测(一):Faster RCNN详解

faster-rcnn 安装

Faster R-CNN 的Caffe实现

http://blog.csdn.net/mydear_11000/article/details/70241139

caffe版faster-RCNN环境搭建的更多相关文章

  1. Go版GTK:环境搭建(windows)

    Go版GTK:环境搭建(windows) https://blog.csdn.net/tennysonsky/article/details/79221507 所属专栏: Go语言开发实战     1 ...

  2. 记pytorch版faster rcnn配置运行中的一些坑

    记pytorch版faster rcnn配置运行中的一些坑 项目地址 https://github.com/jwyang/faster-rcnn.pytorch 一般安装配置参考README.md文件 ...

  3. Tensorflow版Faster RCNN源码解析(TFFRCNN) (2)推断(测试)过程不使用RPN时代码运行流程

    本blog为github上CharlesShang/TFFRCNN版源码解析系列代码笔记第二篇   推断(测试)过程不使用RPN时代码运行流程 作者:Jiang Wu  原文见:https://hom ...

  4. Windows下如何采用微软的Caffe配置Faster R-CNN

    前言 比较简单的一篇博客.https://github.com/microsoft/caffe 微软的Caffe以在Windows下编译简单而受到了很多人的喜爱(包括我),只用改改prop配置然后无脑 ...

  5. Cocos2d-x 3.0正式版及android环境搭建

    开发环境是:mac + xcode + eclipse ,在win以下的环境和这个都是一样的,唯一不一样的就是环境变量的配置. 以下主要介绍cocos2d-x环境的设置以及android的环境搭建 1 ...

  6. python 版Faster Rcnn

    直接按照官网https://github.com/rbgirshick/py-faster-rcnn上的教程对faster Rcnn进行编译的时候,会发有一些层由于cudnn版本的更新,会报错如下: ...

  7. caffe之mac下环境搭建

    参考 http://www.linuxidc.com/Linux/2016-09/135026.html 1. 安装brew,也叫homebrew,mac下类似于ubuntu的apt-get功能 cu ...

  8. Tensorflow版Faster RCNN源码解析(TFFRCNN) (1) VGGnet_test.py

    本blog为github上CharlesShang/TFFRCNN版源码解析系列代码笔记第1篇   VGGnet_test.py ----作者:Jiang Wu(吴疆),未经允许,禁止转载--- -- ...

  9. faster rcnn环境编译

    步骤和fast rcnn的编译一样,在编译中遇到了一个问题: 刚开始是以为python-numpy没有安装到位,后来发现是Makefile.config的配置出现了问题.原来的配置是: PYTHON_ ...

  10. caffe 用faster rcnn 训练自己的数据 遇到的问题

    1 . 怎么处理那些pyx和.c .h文件 在lib下有一些文件为.pyx文件,遇到不能import可以cython 那个文件,然后把lib文件夹重新make一下. 遇到.c 和 .h一样的操作. 2 ...

随机推荐

  1. Socketserver详解

    Python3中的SocketServer socket并不能多并发,只能支持一个用户,socketserver 简化了编写网络服务程序的任务,socketserver是socket的在封装.sock ...

  2. 使用 D8 分析 javascript 如何被 V8 引擎优化的

    在上一篇文章中我们讲了如何使用 GN 编译 V8 源码,文章最后编译完成的可执行文件并不是 V8,而是 D8.这篇我们讲一下如何使用 D8 调试 javascript 代码. 如果没有 d8,可以使用 ...

  3. P2564 生日礼物

    生日礼物 洛谷链接 题目描述: 在一段彩带上有不同颜色的彩珠,求出包含所有颜色彩珠的最短彩带长度. 思路: 我们可以把按彩珠的位置把所有彩珠排一下序,然后从1开始遍历这些彩珠,并记录出现过的颜色数目, ...

  4. 九度oj 题目1452:搬寝室

    题目描述: 搬寝室是很累的,xhd深有体会.时间追述2006年7月9号,那天xhd迫于无奈要从27号楼搬到3号楼,因为10号要封楼了.看着寝室里的n件物品,xhd开始发呆,因为n是一个小于2000的整 ...

  5. iOS学习笔记43-Swift(三)类

    一.Swift的类class 作为一门面向对象语言,类也是Swift的非常重要的类型,我们先来看下一个简单的类 //Swift中一个类可以不继承于任何其他基类,那么此类本身就是一个基类 class P ...

  6. NOJ——1672剪绳子(博弈)

    [1672] 剪绳子 时间限制: 500 ms 内存限制: 65535 K 问题描述 已知长度为n的线圈,两人依次截取1~m的长度,n, m为整数,不能取者为输. 输入 输入n, m:( 0 < ...

  7. [AtCoderContest015D]A or...or B Problem

    [AtCoderContest015D]A or...or B Problem 试题描述 Nukes has an integer that can be represented as the bit ...

  8. Java众神之路(1)-语言介绍

    Java语言介绍 1.Java的历史 我个人认为,学习一种技术,不止要关注技术本身,也应该去了解一下它的发展史,这一方面是对技术本身的尊重,另一方面也是希望能够通过该技术的发展历史推测出其未来可能的发 ...

  9. linux下定时任务设置

    原文http://www.blogjava.net/freeman1984/archive/2010/09/23/332715.html 觉这篇文章写的挺全的,把它拿过来存在博客里,方便以后查询. 为 ...

  10. js中加“var”和不加“var”的区别,看完觉得这么多年js白学了

    Javascript声明变量的时候,虽然用var关键字声明和不用关键字声明,很多时候运行并没有问题,但是这两种方式还是有区别的.可以正常运行的代码并不代表是合适的代码. var num = 1: 是在 ...