以前在cuda8.0下装了caffe并编译成功,后来因为装其他框架,换了cuda9.0,再次安装caffe怎么也安装不上了。
这次重装了系统,直接在cuda9.0+cudnn7.1环境下安装caffe并编译成功
默认安装好显卡驱动、cuda、cudnn、opencv
1.安装依赖
sudo apt-get install -y build-essential cmake git pkg-config
sudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install -y libatlas-base-dev
sudo apt-get install -y --no-install-recommends libboost-all-dev
sudo apt-get install -y libgflags-dev libgoogle-glog-dev liblmdb-dev
sudo apt-get install -y python-dev
sudo apt-get install -y python-numpy python-scipy
sudo apt-get install libopenblas-dev
2.下载caffe
git clone https://github.com/BVLC/caffe.git
cd caffe
- 修改配置文件
将caffe主目录下面的Makefile.config.example拷贝更名为Makefile.config
cp Makefile.config.example Makefile.config
修改
#USE_CUDNN := 1
改为
USE_CUDNN := 1
#WITH_PYTHON_LAYER := 1
改为
WITH_PYTHON_LAYER := 1
注意:opencv2.4改下面的
#USE_OPENCV := 0
USE_OPENCV := 1
opencv3改下面的
#OPENCV_VERSION := 3
OPENCV_VERSION := 3
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
cuda9不支持‘ compute-20 ’,需要修改Makefile.config文件中CUDA_ARCH设置,所以将以下两句删除
-gencode arch=compute_20,code=sm_20 \
-gencode arch=compute_20,code=sm_21
打开 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
编译 我的电脑是12核所以-j12,
make all -j12
make test -j12
make runtest -j12
make pycaffe -j12
在male pycaffe 时有可能报错,大概是没有numpy的目录
可能是因为numpy未安装
执行
sudo apt-get install python-numpy
重新编译 即可成功