caffe-faster-rcnn环境配置

确保安装库的版本
protobuf==2.6.1
sudo pip install protobuf==2.6.1
numpy==1.110
sudo pip install -U numpy==1.11.0




### Installation (sufficient for the demo)
1. Clone the Faster R-CNN repository
  ```Shell
  # Make sure to clone with --recursive
  git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git
  ```


2. We'll call the directory that you cloned Faster R-CNN into `FRCN_ROOT`


   *Ignore notes 1 and 2 if you followed step 1 above.*


   **Note 1:** If you didn't clone Faster R-CNN with the `--recursive` flag, then you'll need to manually clone the `caffe-fast-rcnn` submodule:
    ```Shell
    git submodule update --init --recursive
    ```
    **Note 2:** The `caffe-fast-rcnn` submodule needs to be on the `faster-rcnn` branch (or equivalent detached state). This will happen automatically *if you followed step 1 instructions*.


3. Build the Cython modules
    ```Shell
    cd $FRCN_ROOT/lib
    make
    ```


4. Build Caffe and pycaffe
    ```Shell
    cd $FRCN_ROOT/caffe-fast-rcnn
    # Now follow the Caffe installation instructions here:
    #   http://caffe.berkeleyvision.org/installation.html


    # If you're experienced with Caffe and have all of the requirements installed
    # and your Makefile.config in place, then simply do:
    make -j8 && make pycaffe
    ```
或者用cmake-gui进行编译。
    cmake-gui    
    make -j8 && make pycaffe




5. Download pre-computed Faster R-CNN detectors
    ```Shell
    cd $FRCN_ROOT
    ./data/scripts/fetch_faster_rcnn_models.sh
    ```


    This will populate the `$FRCN_ROOT/data` folder with `faster_rcnn_models`. See `data/README.md` for details.
    These models were trained on VOC 2007 trainval.


6.run demo
python ./tools/demo.py 


7.install py-faster-rcnn libs
cd py-faster-rcnn
sudo python ./lib/setup.py install
cd lib
cp ./build/lib.linux-x86_64-2.7/nms/* ./nms/
cp ./build/lib.linux-x86_64-2.7/pycocotools/* ./pycocotools/
cp ./build/lib.linux-x86_64-2.7/utils/* ./utils/










训练数据集
### Beyond the demo: installation for training and testing models
1. Download the training, validation, test data and VOCdevkit


```Shell
wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtrainval_06-Nov-2007.tar
wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtest_06-Nov-2007.tar
wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCdevkit_08-Jun-2007.tar
```


2. Extract all of these tars into one directory named `VOCdevkit`


```Shell
tar xvf VOCtrainval_06-Nov-2007.tar
tar xvf VOCtest_06-Nov-2007.tar
tar xvf VOCdevkit_08-Jun-2007.tar
```


3. It should have this basic structure


```Shell
  $VOCdevkit/                           # development kit
  $VOCdevkit/VOCcode/                   # VOC utility code
  $VOCdevkit/VOC2007                    # image sets, annotations, etc.
  # ... and several other directories ...
  ```


### Download pre-trained ImageNet models


Pre-trained ImageNet models can be downloaded for the three networks described in the paper: ZF and VGG16.


```Shell
cd $FRCN_ROOT
./data/scripts/fetch_imagenet_models.sh
```
VGG16 comes from the [Caffe Model Zoo](https://github.com/BVLC/caffe/wiki/Model-Zoo), but is provided here for your convenience.
ZF was trained at MSRA.


### Usage
To train and test a Faster R-CNN detector using the **approximate joint training** method, use `experiments/scripts/faster_rcnn_end2end.sh`.
Output is written underneath `$FRCN_ROOT/output`.


```Shell
cd $FRCN_ROOT
./experiments/scripts/faster_rcnn_end2end.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
```
```
for example:
./experiments/scripts/faster_rcnn_end2end.sh 0 VGG16 pascal_voc






编译遇到问题:
a)问题: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 src/caffe/data_reader.cpp:6:
/usr/local/cuda/include/cudnn.h:799:27: note: declared here
cudnnStatus_t CUDNNWINAPI cudnnSetPooling2dDescriptor(


解决方法:
faster rcnn 代码默认是使用的cudnn v4, 但是为了体验最新的v5, 或者使用GTX1080 ,我们编译faster rcnn的时候就会报错:
手动修改文件,参考了卜居大神的博客 http://blog.csdn.net/kkk584520/article/details/51163564
步骤如下:
用最新caffe源码的以下文件替换掉faster rcnn 的对应文件
include/caffe/layers/cudnn_relu_layer.hpp, src/caffe/layers/cudnn_relu_layer.cpp, src/caffe/layers/cudnn_relu_layer.cu


include/caffe/layers/cudnn_sigmoid_layer.hpp, src/caffe/layers/cudnn_sigmoid_layer.cpp, src/caffe/layers/cudnn_sigmoid_layer.cu


include/caffe/layers/cudnn_tanh_layer.hpp, src/caffe/layers/cudnn_tanh_layer.cpp, src/caffe/layers/cudnn_tanh_layer.cu


用caffe源码中的这个文件替换掉faster rcnn 对应文件
include/caffe/util/cudnn.hpp


将 faster rcnn 中的 src/caffe/layers/cudnn_conv_layer.cu 文件中的所有
cudnnConvolutionBackwardData_v3 函数名替换为 cudnnConvolutionBackwardData
cudnnConvolutionBackwardFilter_v3函数名替换为 cudnnConvolutionBackwardFilter




b)问题:./include/caffe/util/cudnn.hpp:5:19: fatal error: cudnn.h: 没有那个文件或目录 
解决方法:在Makefile.config中添加#include<cudnn.h>




c)问题:ImportError:No module named yaml解决方案
解决方法:sudo apt-get install python-yaml


d)编译caffe-fast-rcnn使用protobuf 2.6.1版本
解决方法:下载protobuf 源码https://github.com/google/protobuf/releases/download/v2.6.1/protobuf-2.6.1.tar.gz


cd protobuf-**目录
假如 你希望编译成功后输出的目录 为 /home/work /protobuf/ 则输入如下两条命令:


    ./configure --prefix=/home/work/protobuf/  
    make && make install


    编译成功后将export PATH= /home/work /protobuf/bin:$PATH加入到环境变量中
    最后输入  protoc --version命令,如显示protobuf-**则安装成功




e):TypeError numpy.float64 object cannot be interpreted as an index
在运行py-faster-rcnn的时候碰到了这个问题,结果把numpy的版本由1.12.0降为1.11.0问题得以解决。
sudo pip install -U numpy==1.11.0


f):AttributeError: 'module' object has no attribute 'text_format'
解决方法:sudo pip install protobuf==2.6.0
或:在文件./lib/fast_rcnn/train.py增加一行:import google.protobuf.text_format


g):ImportError: numpy.core.multiarray failed to import
 没有运行文件./lib/setup.py
解决方法:编译py-faster-rcnn/lib/setup.py,并将编译好的nms,pycocotools,utils内的文件替换与lib文件夹下对应的文件
cd py-faster-rcnn
sudo python ./lib/setup.py install
cd lib
cp ./build/lib.linux-x86_64-2.7/nms/* ./nms/
cp ./build/lib.linux-x86_64-2.7/pycocotools/* ./pycocotools/
cp ./build/lib.linux-x86_64-2.7/utils/* ./utils/

猜你喜欢

转载自blog.csdn.net/PADS123/article/details/80332868
今日推荐