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一下。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值