電腦配置:
ubuntu 14.04 64bit
128G 內存
GTX Titan X顯卡
軟件版本:
Cuda 7.0
Cudnn-7.0
1. 安裝開發所需的依賴包
sudo apt-get install build-essential # basic requirement
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-dev libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler #required by caffe
2.安裝CUDA 7.0
安裝CUDA有兩種方法,離線.run安裝,在線.deb安裝。官網下載地址
切換到下載的deb所在目錄,執行下邊的命令
sudo dpkg -i cuda-repo-<distro>_<version>_<architecture>.deb
sudo apt-get update
sudo apt-get install cuda
我安裝的是 :cuda-repo-ubuntu1404-7-0-local_7.0-28_amd64.deb
3.安裝cudnn 7.0 v4
下載 cudnn-7.0-linux-x64-v4.0-prod.tgz,官網下載地址
注:要用學校郵箱註冊,才被允許下載
下載後,切換到下載目錄
tar -zxvf cudnn-7.0-linux-x64-v4.0-prod.tgz
cd cuda
sudo cp lib64/lib* /usr/local/cuda/lib64/
sudo cp include/cudnn.h /usr/local/cuda/include/
注:不同版本的cudnn解壓出來的文件夾名稱不一樣,根據文件名稱再執行後兩句cd /usr/local/cuda/lib64/
sudo chmod +r libcudnn.so.4.0.7
sudo ln -sf libcudnn.so.4.0.7 libcudnn.so.4
sudo ln -sf libcudnn.so.4 libcudnn.so
sudo ldconfig
4,設置環境變量
sudo gedit /etc/profile
加入以下兩句export PATH
source /etc/profile
同時需要添加lib庫路徑 cd /etc/ld.so.conf.d/
sudo touch cuda.conf
<pre name="code" class="plain" style="color: rgb(85, 85, 85); font-size: 15px; line-height: 35px;">sudo gedit cuda.conf
加入以下一句sudo ldconfig
5.安裝CUDA SAMPLE
進入/usr/local/cuda/samples, 執行下列命令來build samples
cd /usr/local/cuda/samples
sudo make all -j8
注:-j8可提升速度,-j4比較慢,-j16容易崩cd <span style="font-family: 'microsoft yahei';">/usr/local/cuda/</span><span style="font-family: 'microsoft yahei';">samples/bin/x86_64/linux/release</span>
./deviceQuery
如果出現顯卡信息, 則驅動及顯卡安裝成功。./deviceQuery Starting...
CUDA Device Query (Runtime API) version (CUDART static linking)
Detected 1 CUDA Capable device(s)
Device 0: "GeForce GTX TITAN X"
CUDA Driver Version / Runtime Version 7.5 / 7.0
CUDA Capability Major/Minor version number: 5.2
Total amount of global memory: 12287 MBytes (12884180992 bytes)
(24) Multiprocessors, (128) CUDA Cores/MP: 3072 CUDA Cores
GPU Max Clock rate: 1266 MHz (1.27 GHz)
Memory Clock rate: 3505 Mhz
Memory Bus Width: 384-bit
L2 Cache Size: 3145728 bytes
Maximum Texture Dimension Size (x,y,z) 1D=(65536), 2D=(65536, 65536), 3D=(4096, 4096, 4096)
Maximum Layered 1D Texture Size, (num) layers 1D=(16384), 2048 layers
Maximum Layered 2D Texture Size, (num) layers 2D=(16384, 16384), 2048 layers
Total amount of constant memory: 65536 bytes
Total amount of shared memory per block: 49152 bytes
Total number of registers available per block: 65536
Warp size: 32
Maximum number of threads per multiprocessor: 2048
Maximum number of threads per block: 1024
Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
Max dimension size of a grid size (x,y,z): (2147483647, 65535, 65535)
Maximum memory pitch: 2147483647 bytes
Texture alignment: 512 bytes
Concurrent copy and kernel execution: Yes with 2 copy engine(s)
Run time limit on kernels: Yes
Integrated GPU sharing Host Memory: No
Support host page-locked memory mapping: Yes
Alignment requirement for Surfaces: Yes
Device has ECC support: Disabled
Device supports Unified Addressing (UVA): Yes
Device PCI Domain ID / Bus ID / location ID: 0 / 1 / 0
Compute Mode:
< Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >
deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 7.5, CUDA Runtime Version = 7.0, NumDevs = 1, Device0 = GeForce GTX TITAN X
Result = PASS
6.安裝Intel MKL 或Atlas
sudo apt-get install libatlas-base-dev
7.安裝Caffe所需要的Python環境
bash Anaconda2-4.0.0-Linux-x86_64.sh
注:安裝過程默認安全,enter和yes互敲就行8. 添加Anaconda Library Path
sudo gedit /etc/ld.so.conf在/etc/ld.so.conf最後加入以下路徑
/home/username/anaconda/lib
注:路徑要安裝anaconda的實際情況修改,例如我的:/../../anaconda2/lib
sudo gedit ~/.bashrc
在最後添加下邊路徑sudo source ~/.bashrc
9.安裝anaconda-opencv
conda install -c https://conda.binstar.org/menpo opencv
10. 安裝python依賴庫
進入caffe-master下的python目錄,執行如下命令
for req in $(cat requirements.txt); do pip install $req; done
cp Makefile.config.example Makefile.config
sudo gedit Makefile.config
## Refer to http://caffe.berkeleyvision.org/installation.html
# Contributions simplifying and improving our build system are welcome!
# cuDNN acceleration switch (uncomment to build with cuDNN).
USE_CUDNN := 1
# CPU-only switch (uncomment to build without GPU support).
# CPU_ONLY := 1
# uncomment to disable IO dependencies and corresponding data layers
# USE_OPENCV := 0
# USE_LEVELDB := 0
# USE_LMDB := 0
# uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary)
# You should not set this flag if you will be reading LMDBs with any
# possibility of simultaneous read and write
# ALLOW_LMDB_NOLOCK := 1
# Uncomment if you're using OpenCV 3
# OPENCV_VERSION := 3
# To customize your choice of compiler, uncomment and set the following.
# N.B. the default for Linux is g++ and the default for OSX is clang++
# CUSTOM_CXX := g++
# CUDA directory contains bin/ and lib/ directories that we need.
CUDA_DIR := /usr/local/cuda
# On Ubuntu 14.04, if cuda tools are installed via
# "sudo apt-get install nvidia-cuda-toolkit" then use this instead:
# CUDA_DIR := /usr
# CUDA architecture setting: going with all of them.
# For CUDA < 6.0, comment the *_50 lines for compatibility.
CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \
-gencode arch=compute_20,code=sm_21 \
-gencode arch=compute_30,code=sm_30 \
-gencode arch=compute_35,code=sm_35 \
-gencode arch=compute_50,code=sm_50 \
-gencode arch=compute_50,code=compute_50
# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
BLAS := atlas
# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
# Leave commented to accept the defaults for your choice of BLAS
# (which should work)!
# BLAS_INCLUDE := /path/to/your/blas
# BLAS_LIB := /path/to/your/blas
# Homebrew puts openblas in a directory that is not on the standard search path
# BLAS_INCLUDE := $(shell brew --prefix openblas)/include
# BLAS_LIB := $(shell brew --prefix openblas)/lib
# This is required only if you will compile the matlab interface.
# MATLAB directory should contain the mex binary in /bin.
# MATLAB_DIR := /usr/local
# MATLAB_DIR := /Applications/MATLAB_R2012b.app
# NOTE: this is required only if you will compile the python interface.
# We need to be able to find Python.h and numpy/arrayobject.h.
# PYTHON_INCLUDE := /usr/include/python2.7 \
# /usr/lib/python2.7/dist-packages/numpy/core/include
# Anaconda Python distribution is quite popular. Include path:
# Verify anaconda location, sometimes it's in root.
ANACONDA_HOME := $(HOME)/</span><span style="color:#ff0000;">anaconda2</span><span style="color:#555555;">
PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
$(ANACONDA_HOME)/include/python2.7 \
$(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include \
# Uncomment to use Python 3 (default is Python 2)
# PYTHON_LIBRARIES := boost_python3 python3.5m
# PYTHON_INCLUDE := /usr/include/python3.5m \
# /usr/lib/python3.5/dist-packages/numpy/core/include
# We need to be able to find libpythonX.X.so or .dylib.
#PYTHON_LIB := /usr/lib
PYTHON_LIB := $(ANACONDA_HOME)/lib
# Homebrew installs numpy in a non standard path (keg only)
# PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include
# PYTHON_LIB += $(shell brew --prefix numpy)/lib
# Uncomment to support layers written in Python (will link against Python libs)
# WITH_PYTHON_LAYER := 1
# Whatever else you find you need goes here.
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
# If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies
# INCLUDE_DIRS += $(shell brew --prefix)/include
# LIBRARY_DIRS += $(shell brew --prefix)/lib
# Uncomment to use `pkg-config` to specify OpenCV library paths.
# (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)
# USE_PKG_CONFIG := 1
# N.B. both build and distribute dirs are cleared on `make clean`
BUILD_DIR := build
DISTRIBUTE_DIR := distribute
# Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171
# DEBUG := 1
# The ID of the GPU that 'make runtest' will use to run unit tests.
TEST_GPUID := 0
# enable pretty build (comment to see full commands)
Q ?= @
改好後,編譯
make all -j8
make test
make runtest
如果出現錯誤可執行:make clean,改正錯誤後重新編譯12.編譯Python wrapper
make pycaffe
~~~~~~~~~~~~~~~~~~~~~以上是caffe的安裝配置
13.從github上clone到py-faster-rcnn的庫
git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git
14.編譯
cd $py-faster-rcnn/caffe-fast-rcnn
cd py-faster-rcnn/lib/
make -j8
cd $py-faster-rcnn/caffe-fast-rcnn
make -j8 && make pycaffe
注:$py-faster-rcnn 爲解壓後所在目錄
15. 下載Faster RCNN檢測器
cd $py-faster-rcnn
./data/scripts/fetch_faster_rcnn_models.sh
16.運行demo
cd py-faster-rcnn/
./tools/demo.py
出現結果則證明配置成功。