Ubuntu16.04+Cuda9.0+Cudnn7.0+python2.7+Caffe
以上3步见:
https://blog.csdn.net/weixin_42287851/article/details/80421821
4.opencv安装
https://blog.csdn.net/weixin_42287851/article/details/80419646
可以采用如下方法,或者https://blog.csdn.net/weixin_42287851/article/details/82833585(安装时坑少)
安装依赖包:
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
下载Caffe包:
git clone https://github.com/BVLC/caffe.git
进入Caffe目录(以下安装,默认均在Caffe目录下),复制Makefile.config.example文件,命名为Makefile.config
cd caffe
sudo cp Makefile.config.example Makefile.config
打开(gedit或者vim都行)Makefile.config
sudo gedit Makefile.config
修改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文件
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
NVCCFLAGS +=-ccbin=$(CXX) -Xcompiler-fPIC $(COMMON_FLAGS)
改为:
NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
打开 /usr/local/cuda/include/host_config.h 文件并修改,这里可能要root权限,采用vim修改,如下:
打开:
sudo vim /usr/local/cuda/include/host_config.h
修改:
#error-- unsupported GNU version! gcc versions later than 5.0 are not supported!
改为:
//#error-- unsupported GNU version! gcc versions later than 5.0 are not supported!
编译Caffe
make all -j8
编译好后,测试编译的Caffe
sudo make runtest -j8
出现下图,即编译成功
安装python接口
安装依赖包:
sudo apt-get install python-numpy
sudo apt install python-pip
sudo pip install -U scikit-image
这个包可能需要科学上网,如果失败多试几次
编译pycaffe
sudo make pycaffe -j8
终端无法import caffe
sudo vim ~/.bashrc
在最后一行增加:
export PYTHONPATH=~/caffe/python:$PYTHONPATH
退出vim,更新
source ~/.bashrc
测试是否成功,如下即安装成功:
可能会报的错:
1.nvcc fatal : Unsupported gpu architecture 'compute_20'
打开Caffe目录下的Makefile.config文件
cd caffe
sudo gedit Makefile.config
注释掉#-gencode arch=compute_20, code=sm_20
参考:
https://blog.csdn.net/yhaolpz/article/details/71375762
https://blog.csdn.net/u010417185/article/details/53559107