- NVIDIA 显卡
- 去官网(http://www.nvidia.com/Download/index.aspx?lang=en-us)查询合适的GPU驱动,如图
-
- 驱动安装
- 删除原来驱动:
- 驱动安装
sudo apt-get purge nvidia-*
-
-
- 添加第三方驱动源:
-
sudo apt-get install python-software-properties software-properties-common
sudo add-apt-repository ppa:graphics-drivers/ppa
-
-
- 更新源:
-
sudo apt-get update
-
-
- 查看可用的驱动版本:
-
sudo apt-cache search nvidia-*
-
-
- 安装驱动:
-
sudo apt-get install nvidia-375
-
-
- 安装第三方库:
-
sudo apt-get install mesa-common-dev
sudo apt-get install freeglut3-dev
-
-
- 重启服务器,控制台输入 nvidia-smi
-
或输入nvidia-settings
-
- cuda 配置
-
-
- 安装:
-
sudo dpkg -i cuda-repo-ubuntu1604-8-0-rc_8.0.27-1_amd64.deb
sudo apt-get update
sudo apt-get install cuda
-
-
- gcc版本降级: ubuntu的gcc编译器是5.4.0,然而cuda8.0不支持5.0以上的编译器,因此需要降级,把编译器版本降到4.9;
-
sudo apt-get install gcc -4.9 gcc-5 g++-4.9 g++-5
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 20
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 10
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30
sudo update-alternatives --set cc /usr/bin/gcc
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30
sudo update-alternatives --set c++ /usr/bin/g++
-
-
- 添加环境变量(~/.bashrc, /etc/profile):(注意等号两边不能有空格)
-
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}}
sudo gedit /etc/profile
添加: export PATH=/usr/local/cuda/bin:$PATH
-
-
- 创建链接:
-
sudo gedit /etc/ld.so.conf.d/cuda.conf
添加: /usr/local/cuda/lib64
-
-
- 使链接生效:
-
sudo ldconfig
-
-
- 测试cuda的Samples:
-
命令行输入(注意cuda-8.0是要相对应自己的cuda版本)
cd /usr/local/cuda-8.0/samples/1_Utilities/deviceQuery
make
sudo ./deviceQuery
返回GPU的信息则表示配置成功
-
- cudnn配置
- 下载: 官网(https://developer.nvidia.com/cudnn) 下载对应的cudnn
- cudnn配置
-
-
- 安装: (ubuntu为本机用户名)
-
cd home/ubuntu/Downloads/
tar zxvf cudnn-8.0-linux-x64-v5.1.tgz
cd cuda/include
sudo cp cudnn.h /usr/local/cuda/include/ #复制头文件
cd ../lib64
lib文件的复制和链接(注意:查看lib64,修改相对应的版本号)
sudo cp lib* /usr/local/cuda/lib64/ #复制动态链接库
cd /usr/local/cuda/lib64/
sudo rm -rf libcudnn.so libcudnn.so.5 #删除原有动态文件
sudo ln -s libcudnn.so.5.1.5 libcudnn.so.5 #生成软衔接
sudo ln -s libcudnn.so.5 libcudnn.so #生成软链接
sudo ldconfig
- Opencv3.3.0 编译
为了加快编译速度,下载ippicv_2017u2_lnx_intel64_20170418.tgz,命名为87cbdeb627415d8e4bc811156289fa3a-ippicv_2017u2_lnx_intel64_20170418.tgz放到opencv/.cache/ippicv/
-
- 安装编译环境
sudo apt-get install --assume-yes libopencv-dev build-essential cmake git libgtk2.0-dev pkg-config python-dev python-numpy libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libtiff5-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libxine2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev libtbb-dev libqt4-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils unzip ffmpeg libgtk-3-dev python3-numpy libgstreamer1.0-dev qtbase5-dev
-
- 编译
cd opencv #解压的那个文件夹
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D BUILD_EXAMPLES=ON \
-D BUILD_TIFF=ON\
-D WITH_TBB=ON\
-D WITH_V4L=ON\
-D WITH_QT=ON\
-D WITH_OPENGL=ON\
-D CUDA_NVCC_FLAGS="-D_FORCE_INLINES" .. #最后两点不要漏掉
make –j8
sudo make install
sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig
- Anaconda配置python环境
- 安装
bash Anaconda3-2.4.1-Linux-x86_64.sh
-
- 添加环境变量
sudo gedit ~/.bashrc
export LD_LIBRARY_PATH="/home/jials/anaconda2/lib:$LD_LIBRARY_PATH"
export LD_LIBRARY_PATH="/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH"
source ~/.bashrc
- 配置caffe环境
- 切换g++ 到5.0以上版本
sudo update-alternatives --config g++
sudo update-alternatives --config gcc
-
- 安装依赖库
sudo add-apt-repository universe
sudo apt-get update -y
sudo apt-get install cmake -y
# General Dependencies
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libhdf5-serial-dev protobuf-compiler -y
sudo apt-get install --no-install-recommends libboost-all-dev -y
# BLAS
sudo apt-get install libatlas-base-dev -y
# Remaining Dependencies
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev -y
sudo apt-get install python-dev python-numpy –y
sudo apt-get install -y python-pip
sudo apt-get install -y python-dev
sudo apt-get install -y python-numpy python-scipy
-
- 下载,编译caffe
- 下载
- 下载,编译caffe
git clone --recursive https://github.com/BVLC/caffe.git
-
-
- 修改 Makefile.config
-
cd caffe
cp Makefile.config.example Makefile.config
gedit Makefile.config
# cuDNN acceleration switch (uncomment to build with cuDNN).
USE_CUDNN := 1
# Uncomment if you're using OpenCV 3 如果用的是opencv3版本
OPENCV_VERSION := 3
# Uncomment to support layers written in Python (will link against Python libs)
WITH_PYTHON_LAYER := 1
#python 2.7 或使用python3.5
ANACONDA_HOME := $(HOME)
PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
$(ANACONDA_HOME)/include/python2.7 \
$(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include
#python 3.5 查看/usr/lib/x86_64-linux-gnu/ 中boost_python3 修改为对应的版本
PYTHON_LIBRARIES := boost_python-py35 python3.5m
ANACONDA_HOME := $(HOME)/anaconda2/envs/py35
PYTHON_INCLUDE := $(ANACONDA_HOME)/include \ $(ANACONDA_HOME)/include/python3.5m/site-packages/numpy/core/include \
$(ANACONDA_HOME)/include/python3.5m\
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/hdf5/serial
-
-
- 安装 python 接口依赖库
-
cd ~/caffe/python
pip install -r requirements.txt
-
-
- caffe 编译
-
make clean
make all -j8
make test -j8
make runtest -j8
#Python 接口编译
make pycaffe
#添加环境变量
sudo gedit ~/.bashrc
export PYTHONPATH="/home/jials/caffe/python:$PYTHONPATH"
-
-
- caffe 测试
-
cd ~/caffe
./build/tools/caffe time --gpu 0 --model ./models/bvlc_alexnet/deploy.prototxt