先允许我哭一会,安装了五个小时,踩坑无数,安装好后赶紧记录下来!
CUDA、Cudnn、dirver、Anaconda自己装,本博客只记录caffe安装过程
1、安装依赖包
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
2、下载caffe源码,进入 /caffe,将 Makefile.config.example 文件复制一份并更名为 Makefile.config ,也可以在 caffe 目录下直接调用以下命令完成复制操作 :
git clone https://github.com/BVLC/caffe.git
cd caffe
sudo cp Makefile.config.example Makefile.config
3、最关键的一步,开始修改Makefile.config与Makefile内容
3.1、修改Makefile.config
USE_CUDNN := 1
OPENCV_VERSION := 3
CUDA_DIR := /usr/local/cuda
#因为我的CUDA版本>=9.0所以去掉*_20 and *_21
CUDA_ARCH := -gencode arch=compute_30,code=sm_30 \
-gencode arch=compute_35,code=sm_35 \
-gencode arch=compute_50,code=sm_50 \
-gencode arch=compute_52,code=sm_52 \
-gencode arch=compute_60,code=sm_60 \
-gencode arch=compute_61,code=sm_61 \
-gencode arch=compute_61,code=compute_61
BLAS := atlas
ANACONDA_HOME := $/root/anaconda3/envs/3d
PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
$(ANACONDA_HOME)/include/python3.7m \
$(ANACONDA_HOME)/lib/python3.7/site-packages/numpy/core/include
#注意下面这一步很重要
PYTHON_LIBRARIES := boost_python3 python3.7m
PYTHON_LIB := $(ANACONDA_HOME)/lib
WITH_PYTHON_LAYER := 1
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
BUILD_DIR := build
DISTRIBUTE_DIR := distribute
TEST_GPUID := 0
Q ?= @
3.2修改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
4、开始编译
按顺序执行下面的命令
make all -j16
make test -j16
make runtest -j16
5、安装pycaffe
make pycaffe -j16
6、修改~/.bashrc
sudo vim ~/.bashrc
export PYTHONPATH={Your caffe path}/python:$PYTHONPATH
source ~/.bashrc
7、上述步骤完成后可以检查是否可以import caffe
import sys
sys.path.append('{your caffe path}/python')
import caffe
撒花!!!
|