caffe install

install Caffe

pre:安装CUDA8.0,cuDNN 5.1, block anaconda,gcc version =5

  1. 安装依赖包
1
2
3
4
5
6
7
8
9
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler

sudo apt-get install --no-install-recommends libboost-all-dev

sudo apt-get install libopenblas-dev liblapack-dev libatlas-base-dev

sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev

sudo apt-get install git cmake build-essential
  1. clone caffe
1
2
3
git clone https://github.com/BVLC/caffe.git
cd caffe
sudo cp Makefile.config.example Makefile.config
  1. 修改Makefile.config 和makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Makefile.config

#USE_CUDNN := 1
修改成:
USE_CUDNN := 1

#OPENCV_VERSION := 3
修改为:
OPENCV_VERSION := 3

#WITH_PYTHON_LAYER := 1
修改为
WITH_PYTHON_LAYER := 1
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
修改为:
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial

# makefile
将:
NVCCFLAGS +=-ccbin=$(CXX) -Xcompiler-fPIC $(COMMON_FLAGS)
替换为:
NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)

将:
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
  1. 修改protoc版本

    1. 下载protobuf
    1
    2
    3
    4
    5
    6
    7
    cd protobuf
    ./configure
    make
    make check
    make install
    sudo ldconfig
    protoc --version

    如果显示的版本是2.6.1则OK,若不是

    将手动编译的protoc替换到usr/bin里面

1
2
3
4
5
6
7
#将手动编译的protoc替换到usr/bin里面
sudo find/ -name protoc
cd XX
sudo rm -rf /usr/bin/protoc
sudo cp protoc /usr/bin/
sudo ldconfig
protoc --version
  1. 安装caffe
1
2
3
4
5
make -j8 
make runtest -j8
make pycaffe -j8

pip install -U scikit-image
  1. 配置环境变量
1
2
3
4
5
6
7
sudo vim ~/.bashrc
# add caffe/python

export PYTHONPATH=~/code/caffe/python
# :wq

source ~/.bashrc
  1. test
1
2
3
python(确认是不是2.7的)

import caffe

py-faster-rcnn

  1. Clone py-faster-rcnn
  2. 当前版本的caffe的cudnn实现与系统所安装的cudnn的版本不一致

    1. 将./include/caffe/util/cudnn.hpp 换成最新版的caffe里的cudnn的实现,即相应的cudnn.hpp.
    2. 将./include/caffe/layers里的,所有以cudnn开头的文件,例如cudnn_conv_layer.hpp。 都替换成最新版的caffe里的相应的同名文件。
    3. 将./src/caffe/layer里的,所有以cudnn开头的文件,例如cudnn_lrn_layer.cu,cudnn_pooling_layer.cpp,cudnn_sigmoid_layer.cu都替换成最新版的caffe里的相应的同名文件。
  3. 跟着github上的教程走

  4. 缺啥装啥
  5. 完成