(注意:以下安装包尽量通过windows系统下载,比较快)
(附带各安装包以及说明文件的百度云地址:http://pan.baidu.com/s/1b40BHc,密码:qt0k)
(本机电脑配置为NVIDIA显卡GTX1050ti,64位,ubuntu14.04装驱动各种出问题。)
1.安装Ubuntu16.04
2.下载cuda安装包(deb,local),安装cuda代码:
sudo dpkg -i cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64.deb
sudo apt-get update
sudo apt-get install cuda
测试是否安装好cuda:sudo nvidia-smi 、nvcc -V
添加缺少的库:sudo apt-get install libxmu-dev libxi-dev
设置环境变量:
打开profile文件:sudo gedit /etc/profile,添加下面两句保存退出
export PATH=/usr/local/cuda-8.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64:$LD_LIBRARY_PATH
`sudo ldconfig` //环境变量立即生效
3.安装cudnn(百度csdn网下载)
tar -zxvf cudnn-7.5-linux-x64-v5.0-ga.tgz
继续执行以下拷贝指令:
sudo cp cuda/include/cudnn.h /usr/local/cuda-8.0/include/
sudo cp cuda/lib64/libcudnn* /usr/local/cuda-8.0/lib64/
sudo chmod a+r /usr/local/cuda-8.0/include/cudnn.h
sudo chmod a+r /usr/local/cuda-8.0/lib64/libcudnn*
4.安装依赖包
sudo apt-get install build-essential vim cmake git libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-dev libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler
sudo apt-get install --no-install-recommends
sudo apt-get install libatlas-base-dev
sudo apt-get install python-dev
5.下载caffe安装包
(1)生成配置文件:
cd caffe/
mv Makefile.config.example Makefile.config
(2)去掉注释:#USE_CUDNN := 1改为USE_CUDNN := 1
a.若使用的OpenCV版本是3的,则
将 #OPENCV_VERSION := 3
修改为: OPENCV_VERSION := 3
b.若要使用Python来编写layer,则
将 #WITH_PYTHON_LAYER := 1
修改为: WITH_PYTHON_LAYER := 1
c.将下面句子修改为(ubuntu16.04位置不一样,需要修改,14.04应该不用):
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
(3)编译:
make all -j4
make test
make runtest
(4)安装python:
sudo apt-get install python-pip python-dev build-essential
sudo pip install --upgrade pip
sudo apt-get install python-opencv
sudo pip install pyzmq tornado jinja2 jsonschema jupyter
sudo apt-get install gfortran libatlas-dev libblas-dev
cd caffe/python
for req in $(cat requirements.txt);do sudo pip install $req; done
(5)编译python库:
cd ..
make pycaffe
6.运行caffe
cd caffe
./data/mnist/get_mnist.sh
./examples/mnist/create_mnist.sh
./examples/mnist/train_lenet.sh
补充:遇到问题参见:http://www.linuxdiyf.com/linux/31445.html
7.python caffe安装使用:
(1)anaconda:
在windows系统找anaconda清华镜像,下载Anaconda2-4.3.1-linux-x86_64.sh
拷贝到~/中,打开终端:bash Anaconda2-4.3.1-linux-x86_64.sh,过程中各种回车,yes
安装完,输入:source ~/.bashrc
输入conda list可查看安装的库,
conda update conda 更新
conda create -n testcaffe python 创建环境
source activate testcaffe 进入环境(source deactive 退出环境)
(2)修改Makefile.config:
PYTHON_INCLUDE应使用:(其他相同的应注释)
HOME=/home/bci
ANACONDA_HOME := $(HOME)/anaconda2
PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
# $(ANACONDA_HOME)/include/python2.7 \
# $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include
以下三句去掉注释:
PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core;print(numpy.core.__file__)'))/include
PYTHON_LIB += $(shell brew --prefix numpy)/lib
WITH_PYTHON_LAYER := 1
(3)重新编译:
make clean
make all -j8
make test
make runtest -j4
make pycaffe
(4)环境变量:
vim ~/.bashrc
最后一行添加caffe的python路径(到最后一行快捷键Shift+G):
export PYTHONPATH=/home/bci/caffe/python:$PYTHONPATH
source ~/.bashrc
(5)安装一些配置:
pip install opencv-python
strings /home/bci/anaconda2/bin/../lib/libstdc++.so.6 | grep GLIBCXX
conda install libgcc
strings /home/bci/anaconda2/bin/../lib/libstdc++.so.6 | grep GLIBCXX
conda install protobuf
(6)测试:python -c "import caffe; print dir(caffe)"
或者:
python
>>>import caffe
>>>dir(caffe)