Caffe安装

caffe + ubuntu16.04 + 1080Ti + 384.13驱动 + cuda8.0Ga1 + cudnn6 + opencv3.3

参考博客:

https://blog.csdn.net/yhaolpz/article/details/71375762

https://blog.csdn.net/jiangyanting2011/article/details/78873113

安装NVIDIA驱动

查询驱动版本 :https://www.nvidia.com/Download/index.aspx?lang=en-us,查看适合自己显卡的驱动,注意一定是适合的!1080Ti版本适合的驱动:

首先下载好驱动,将NVIDIA-Linux-x86_64-384.13.run,放到HOME,安装SHH。卸载以前的驱动,键入

sudo apt-get remove --purge nvidia*

安装依赖

sudo apt-get update
sudo apt-get install dkms build-essential linux-headers-generic

把nouveau驱动加入黑名单,创建新文件:

sudo vim /etc/modprobe.d/blacklist-nouveau.conf

添加内容为

blacklist nouveau
options nouveau modeset=0

禁用nouveau内核模块并更新

echo options nouveau modeset=0 | sudo tee -a /etc/modprobe.d/nouveau-kms.conf
sudo update-initramfs -u

重启,Ctrl+Alt+F1~F6进入tty1控制台,输入用户名密码,键入

sudo start lightdm stop

安装驱动

sudo chmod u+x NVIDIA-Linux-x86_64-384.13.run
sudo ./NVIDIA-Linux-x86_64-384.13.run

安装过程中一些选项

The distribution-provided pre-install script failed! Are you sure you want to continue? 

选择 Yes

Would you like to register the kernel module souces with DKMS? This will allow DKMS to automatically build a new module, if you install a different kernel later?  

选择 No 

Nvidia's 32-bit compatibility libraries? 

选择 No

Would you like to run the nvidia-xconfigutility to automatically update your x configuration so that the NVIDIA x driver will be used when you restart x? Any pre-existing x confile will be backed up.  

选择 Yes。完成。

挂载Nvidia驱动:

modprobe nvidia

检查驱动是否安装成功:

nvidia-smi

重启

reboot

安装各种依赖库

sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev
sudo apt-get install libglu1-mesa libglu1-mesa-dev protobuf-compiler libgoogle-glog-dev liblmdb-dev
sudo apt-get install python-numpy python-pip libgflags-dev libopenblas-dev liblapack-dev
sudo apt-get install git cmake build-essential libatlas-base-dev libgl1-mesa-glx
sudo apt-get install --no-install-recommends libboost-all-dev
pip install -U scikit-image
pip install protobuf

安装CUDA

下载地址:https://developer.nvidia.com/cuda-toolkit-archive,cuda8.0GA1

安装

CUDA安装文件移动到HOME下,键入如下命名

sudo chmod 777 cuda_8.0.44_linux.run
sudo ./cuda_8.0.44_linux.run

按住enter,将声明阅读到底,accept。然后出现

Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 361.62?

选择是否安装驱动,若未安装则输入y,由于上面已经安装好了驱动这里一定一定一定要输入n

配置环境变量

sudo gedit ~/.bashrc

把下面两行加入到末尾行

export PATH=/usr/local/cuda-8.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

测试是否安装成功

cd /usr/local/cuda-8.0/samples/1_Utilities/deviceQuery
sudo make
sudo ./deviceQuery

配置cuDNN

下载地址:https://developer.nvidia.com/rdp/cudnn-archive,需注册账号下载

进入cuda/include目录,复制头文件,键入

sudo cp cudnn.h /usr/local/cuda/include

注意看cuda/lib64里的文件,修改下面的代码,6代表cudnn的版本,键入

cd /usr/local/cuda/lib64/
sudo cp lib* /usr/local/cuda/lib64/
sudo rm -rf libcudnn.so libcudnn.so.6
sudo ln -s libcudnn.so.6.0.21 libcudnn.so.6
sudo ln -s libcudnn.so.6 libcudnn.so
sudo ldconfig -v

或者

sudo ldconfig /usr/local/cuda/lib64

后面编译caffe时可能会出错,报错内容为 /usr/bin/ld: 找不到 -lcudnn,所以这里需要先查看一下自己应该链接的是哪一个,查看方法为下

locate libcudnn.so

cudnn验证

nvcc -V

安装opencv

下载地址:http://opencv.org/releases.html,3.0版本下载很慢,而且容易中途失败,推荐下载3.3.0

在opencv目录下,键入

mkdir build 
cd build 
sudo cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local .. 
sudo make -j8
sudo make install

上述过程超级慢,耐心等待。验证是否安装成功,键入

pkg-config --modversion opencv

安装caffe

cd到你想安装caffe的位置,键入

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

因make指令只能make Makefile.config文件,so将Makefile.config.example的内容复制到Makefile.config:

sudo cp Makefile.config.example Makefile.config
sudo gedit Makefile.config

修改内容

1.
#USE_CUDNN := 1
修改成: 
USE_CUDNN := 1
2.
#OPENCV_VERSION := 3 
修改为: 
OPENCV_VERSION := 3
3.
#WITH_PYTHON_LAYER := 1 
修改为 
WITH_PYTHON_LAYER := 1
4.
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

编译

make all -j8
make runtest
sudo make pycaffe -j8

编译 pycaffe 成功后,验证一下

python
import caffe
错误:
File "<stdin>", line 1, in <module>   ImportError: No module named caffe
解决方法:
sudo echo export PYTHONPATH="~/caffe/python" >> ~/.bashrc
source ~/.bashrc
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值