!保!障!网!络!通!畅!
-----------------------------------------------------------
安装显卡驱动
sudo apt-get update&&sudo apt-get upgrade
nvidia-smi #确认输出了有效信息,如
date
+-----------------------------------------------------------------------------+
| NVIDIA-SMI XXX.XXX Driver Version: XXX.XXX |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| GeForce GTX Off | ::00.0 On | N/A |
| % 31C P8 11W / 230W | 201MiB / 8110MiB | % Default |
+-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| G /usr/lib/xorg/Xorg 136MiB |
| G compiz 59MiB |
| G /usr/lib/firefox/firefox 3MiB |
+-----------------------------------------------------------------------------+
-----------------------------------------------------------
sudo apt-get install --no-install-recommends libboost-all-dev -y
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libhdf5-serial-dev protobuf-compiler libopenblas-dev liblapack-dev libatlas-base-dev libgflags-dev libgoogle-glog-dev liblmdb-dev -y
-----------------------------------------------------------
-----------------------------------------------------------
安装cuda
sudo sh ./cuda_[.X_XXX]_linux.run --no-opengl-libs #本体,非opengl这个参数非常重要,删掉就等着开机循环登录吧
sudo sh ./cuda_[.X.Y]_linux.run #[--no-opengl-libs] #补丁, 可以装,必要性视补丁具体内容决定,修复bug和error的肯定要装
其中,第一项显卡驱动不需要装(因为前一步已经装过了,如果前一步两种方法都安装不了NVIDIA驱动的话,再考虑装cuda这里自带的驱动),第二项cuda组件必须装,第三项cuda示例可以安装
sudo gedit ~/.bashrc
export PATH=/usr/local/cuda/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
source ~/.bashrc
-----------------------------------------------------------
终端里cd进cuda示例
cd [NVIDIA_CUDA_SAMPLES]/1_Utilities/deviceQueryDrv
sudo make
./deviceQueryDrv #确认输出了有效的显卡信息,并记下显卡算力“CUDA Capability Major/Minor version number:”,编译框架时会用上
-----------------------------------------------------------
#复制文件到系统环境
sudo cp [CUDNN]/cuda/include/cudnn.h /usr/local/cuda/include/
sudo cp [CUDNN]/cuda/lib64/lib* /usr/local/cuda/lib64/
#重建软连接
cd /usr/local/cuda/lib64/
sudo rm -rf libcudnn.so libcudnn.so.[主版本号]
sudo ln -s libcudnn.so.[全版本号] libcudnn.so.[主版本号]
sudo ln -s libcudnn.so.[主版本号] libcudnn.so
#使链接在环境中生效
sudo ldconfig
-----------------------------------------------------------
安装opencv-3.4 + contrib-master
sudo apt-get install -y build-essential cmake git libgtk2.-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394--dev
解压opencv
勾上BUILD_DOCS BUILD_JPEG BUILD_PNG WITH_OPENGL BUILD_opencv_world
cd [opencv]/build
make #这行不建议加-j4,曾出现过因为依赖次序问题引发的编译错误
sudo make install -j4
添加引用变量
sudo gedit /etc/ld.so.conf.d/opencv.conf
文件内写入
/usr/local/lib/x86_64-linux-gnu #(也可能没有最后这段文件夹路径,取决于libopencv_XXX.so文件具体在哪)
sudo ldconfig
-----------------------------------------------------------
-----------------------------------------------------------
安装caffe
安装依赖项
sudo apt-get install --no-install-recommends libboost-all-dev
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libhdf5-serial-dev protobuf-compiler libopenblas-dev liblapack-dev libatlas-base-dev libgflags-dev libgoogle-glog-dev liblmdb-dev git cmake build-essential -y
获取caffe,在希望放置caffe的目录内:
git clone https://github.com/BVLC/caffe.git
复制caffe/MakeFile.config.example为MakeFile.config
USE_CUDNN :=
USE_OPENCV := # Whatever else you find you need goes here.
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/local/include/opencv /usr/local/include/opencv2 /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 /usr/local/lib/x86_64-linux-gnu
CUDA_ARCH := #-gencode arch=compute_20,code=sm_20 \
#-gencode arch=compute_20,code=sm_21 \
...
只保留和显卡算力匹配的几行,其他的全注释掉(显卡算力详见[NVIDIA_CUDA_SAMPLES]/1_Utilities/deviceQueryDrv/deviceQueryDrv,在这个文件夹内make之后./deviceQueryDrv运行)
如果编译opencv后生成了libopencv_world.so,那么MakeFile中修改为:
ifeq ($(USE_OPENCV), ) #( 注意把空格换回制表符)
#LIBRARIES += opencv_core opencv_highgui opencv_imgproc
#ifeq ($(OPENCV_VERSION), )
#LIBRARIES += opencv_imgcodecs
#endif
LIBRARIES += opencv_world
endif
make all -j4
#增加引用变量
sudo gedit /etc/ld.so.conf.d/caffe.conf
内容为:
/usr/local/cuda/lib64
回到终端内:
sudo make install
#刷新链接
sudo ldconfig
-----------------------------------------------------------
-----------------------------------------------------------
测试caffe
cd [caffe]
sudo sh data/mnist/get_mnist.sh
sudo sh examples/mnist/create_mnist.sh
sudo sh examples/mnist/train_lenet.sh
不报错就是安装成功
-----------------------------------------------------------