sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y build-essential cmake git pkg-config nano
sudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev libhdf5-serial-dev protobuf-compiler libatlas-base-dev libboost-all-dev libgflags-dev libgoogle-glog-dev liblmdb-dev
# (Python general)
sudo apt-get install -y python-pip
# (Python 2.7 development files)
sudo apt-get install -y python-dev
sudo apt-get install -y python-numpy python-scipy
# (or, Python 3.5 development files)
sudo apt-get install -y python3-dev
sudo apt-get install -y python3-numpy python3-scipy
安装方法见其他博客,ubuntu安装显卡驱动
安装链接见我的博客文章,ubuntu安装cuda
官方工程地址:https://github.com/BVLC/caffe
百度云链接: https://pan.baidu.com/s/1k8SK_cKCXXiRBh5AYIRsQw
提取码: yu4q
配置文件修改
解压工程,cd到工程目录执行下面命令:
cp Makefile.config.example Makefile.config
修改配置文件
nano Makefile.config
配置cuda相关
打开# USE_CUDNN := 1
配置cuda路径 CUDA_DIR := /usr/local/cuda
注释掉
-gencode arch=compute_20,code=sm_20 \
-gencode arch=compute_20,code=sm_21 \
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
配置python
PYTHON_INCLUDE := /usr/include/python2.7 \
/usr/lib/python2.7/dist-packages/numpy/core/include
注释下面的Python3.5(默认情况就是已经注释好的)
# PYTHON_LIBRARIES := boost_python3 python3.5m
# PYTHON_INCLUDE := /usr/include/python3.5m \
# /usr/lib/python3.5/dist-packages/numpy/core/include
打开下面开关
WITH_PYTHON_LAYER := 1
#PYTHON_INCLUDE := /usr/include/python2.7 \
# /usr/lib/python2.7/dist-packages/numpy/core/include
打开下面的Python3.5
PYTHON_LIBRARIES := boost_python3 python3.5m
PYTHON_INCLUDE := /usr/include/python3.5m \
/usr/lib/python3.5/dist-packages/numpy/core/include
打开下面开关
WITH_PYTHON_LAYER := 1
PYTHON_LIBRARIES := boost_python3 python3.xm
PYTHON_INCLUDE := /usr/include/python3.xm \
/usr/lib/python3.x/dist-packages/numpy/core/include
其他配置
修改下面配置
# Whatever else you find you need goes here.
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
安装Python依赖
cd python
安装命令(for python2.7)
for req in $(cat requirements.txt); do pip install $req; done
安装命令(for python3)
for req in $(cat requirements.txt); do pip3 install $req; done
如需镜像加速:
for req in $(cat requirements.txt); do pip3 install $req -i https://pypi.douban.com/simple; done
一切顺利的话,进入下一步
编译caffe
依次执行下面命令:
make all
make test
make runtest
make pycaffe
加速编译:
每个命令后面加上-jn
,n为cpu核数,如果有4个空闲cpu,则命令可以为:
make all -j4
make test -j4
make runtest -j4
make pycaffe -j4
pycaffe环境配置
nano ~/.bashrc
最后面添加如下:
export PYTHONPATH=/path/to/caffe-master/python:$PYTHONPATH
问题解决