第一步:安装显卡驱动。
sudo apt-get remove --purge nvidia*
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update
Ctrl+Alt+F1 进入命令行界面:
sudo service lightdm stop
sudo apt-get install nvidia-3**
版本号:在Nvidia官网上查看对应系统和显卡的版本号,Titan Xp 对应的是390.
重启系统后,命令行输入
nvidia-smi
如果看到显卡状况的显示,说明安装成功。
第二步:安装相关依赖项。
sudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev
sudo apt-get install -y libhdf5-serial-dev libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler protobuf-c-compiler
sudo apt-get install -y protobuf-compiler python-numpy python-scipy python-matplotlib python-sklearn python-skimage python-h5py
sudo apt-get install -y python-protobuf python-leveldb python-networkx python-nose python-pandas python-gflags cython ipython
sudo apt-get install -y libopenblas-dev
sudo apt-get install -y freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libglu1-mesa libglu1-mesa-dev
第三步:安装Cuda 9.0.
官网下载run文件,切换到下载目录给予run文件可执行权限,然后运行安装。
!!!Note:安装过程中会遇到Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 3**? 一定选择No
其余的全都accpet和yes
添加环境变量,打开.bashrc文件,在里面添加
export PATH=/usr/local/cuda-9.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
然后
source ~/.bashrc
最后
nvcc --version(version前有两个短线)
如果安装成功,可以看到Cuda的版本。
第四步:安装Cudnn 7.0.
这里直接参考官网安装建议:
- Navigate to your <cudnnpath> directory containing cuDNN Debian file.
- Install the runtime library, for example:
sudo dpkg -i libcudnn7_7.0.3.11-1+cuda9.0_amd64.deb
- Install the developer library, for example:
sudo dpkg -i libcudnn7-dev_7.0.3.11-1+cuda9.0_amd64.deb
- Install the code samples and the cuDNN Library User Guide, for example:
sudo dpkg -i libcudnn7-doc_7.0.3.11-1+cuda9.0_amd64.deb
-
To verify that cuDNN is installed and is running properly, compile the mnistCUDNN sample located in the /usr/src/cudnn_samples_v7 directory in the debian file.
- Copy the cuDNN sample to a writable path.
$cp -r /usr/src/cudnn_samples_v7/ $HOME
- Go to the writable path.
$ cd $HOME/cudnn_samples_v7/mnistCUDNN
- Compile the mnistCUDNN sample.
$make clean && make
- Run the mnistCUDNN sample.
$ ./mnistCUDNN
If cuDNN is properly installed and running on your Linux system, you will see a message similar to the following:Test passed!
第五步:安装OpenBLAS.
下载地址:http://www.openblas.net/
赚到下载目录,然后:
make
sudo make install
第六步:安装Caffe.
下载地址: http://caffe.berkeleyvision.org/
切换到Caffe-master的文件夹:
cp Makefile.config.example Makefile.config
a. USE_CUDNN := 1#去掉这个注释 ;
b.WITH_PYTHON_LAYER := 1 #去掉这个注释;
c.启动OpenBLAS:
BLAS := open
d.配置文件路径。
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/lib/x86_64-linux-gnu/hdf5/serial/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial
e.其他配置。
然后根据自己的cuda文档提示删去或者注释掉相应的版本的,例如
CUDA_ARCH := #-gencode arch=compute_20,code=sm_20 \
#-gencode arch=compute_20,code=sm_21 \(要根据自己实际才cuda版本注释,文件本身有提示)
Titan xp 需要删除或者注释所有和20,21相关的。
f. 编译安装:
make all -j16
make test -j16
make runtest -j16
make pycaffe -j16
j16表示用多少个cpu进行编译,参考自己电脑的cpu配置情况。
g.测试安装是否成功。
(1)
运行MNIST例子:
进入caffe/data/mnist执行./get_mnist.sh下载MNIST数据集
运行在caffe根目录运行./examples/mnist/create_mnist.sh将数据集转换为caffe能处理的格式
在$CAFFE_ROOT/examples/mnist/lenet_solver.prototxt文件中修改训练使用CPU还是GPU
在caffe根目录下运行./examples/mnist/train_lenet.sh来运行MNIST示例。
(2)
赚到caffe-master文件夹,打开命令行界面:
python
import caffe
如果import成功则说明安装成功。