Caffe配置與編譯-----Python3.5 & CUDA9.0

在上一篇Caffe配置與編譯-----OpenCV-3.4.1配置及編譯完成了OpenCV的配置,避免在Caffe調用OpenCV時出現無法導入OpenCV的問題,本篇將進一步介紹如何配置Caffe最終能夠順利在python中導入Caffe

硬件環境:

Ubuntu GPU : CUDA9.0

Python:python 3.5

配置過程:

1、創建虛擬環境並激活:

vituralenv --python=python3.5 caffe3

2、安裝依賴:

sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev
sudo apt-get install 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 libgdal-dev

3、 下載Caffe包:

git clone https://github.com/BVLC/caffe.git

4、更改Makefile.config配置

sudo cp Makefile.config.example Makefile.config

sudo gedit Makefile.config

更改內容如下:

lin4 # cuDNN acceleration switch (uncomment to build with cuDNN).
USE_CUDNN := 1

line 22 # Uncomment if you're using OpenCV 3
OPENCV_VERSION := 3
line 35 # CUDA architecture setting: going with all of them.
# For CUDA < 6.0, comment the *_50 through *_61 lines for compatibility.
# For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility.
# For CUDA >= 9.0, comment the *_20 and *_21 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_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
line 81 
PYTHON_LIBRARIES := boost_python3 python3.5m
PYTHON_INCLUDE := /usr/include/python3.5m \
                  /usr/lib/python3.5/dist-packages/numpy/core/include
line 96
# Whatever else you find you need goes here.
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/include/hdf5/serial /usr/local/include /usr/lib

5、配置Makefile文件:

line 181
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial
line 196
# This code is taken from https://github.com/sh1r0/caffe-android-lib
ifeq ($(USE_HDF5), 1)
	LIBRARIES += hdf5_serial_hl hdf5_serial
endif
line 208
PYTHON_LIBRARIES ?= boost_python3 python3.5m

6、編譯環境:

make all -j8
make pycaffe
make test -j8
sudo make runtest -j8 #optional

7、添加Caffe路徑:

sudo gedit ~/.bashrc

#add following path to PYTHONPATH at last
export PYTHONPATH=/path/to/caffe/python:$PYTHONPATH

source ~/.bashrc

8、 測試是否安裝成功:

 注:安裝過程中的主要問題都在Makefile.config和Makefile文件的編譯有問題,每次重新編譯時,需要make clean一下。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章