ubuntu16.04+cuda9.0+cudnn7.0+caffe

准备工作

  • 删除原有cuda

    sudo apt autoremove cuda

  • 删除原有软件更新

    系统设置-软件和更新-其他软件

cuda9.0

  • 下载链接: cuda9.0
    ubuntu16.04+cuda9.0+cudnn7.0+caffe_第1张图片

  • 在下载目录打开terminal

    sudo dpkg -i cuda-repo-ubuntu1604-9-0-local_9.0.176-1_amd64.deb
    sudo apt-key add /var/cuda-repo-9-0-local/7fa2af80.pub

  • 上述指令打印OK然而并没什么卵用,可手动在 系统设置-软件和更新-其他软件 添加源

    deb file:///var/cuda-repo-9-0-local /

  • 然后

    sudo apt-get update
    sudo apt-get install cuda

cudnn7.0

  • 下载链接:cudnn7.0

    ubuntu16.04+cuda9.0+cudnn7.0+caffe_第2张图片

  • 进入下载目录

    tar -xzvf cudnn-9.0-linux-x64-v7.tgz #解压

  • 复制

    sudo cp cuda/include/cudnn.h /usr/local/cuda/include/
    sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/
    sudo chmod a+r /usr/local/cuda/include/cudnn.h
    sudo chmod a+r /usr/local/cuda/lib64/libcudnn*

  • 在系统环境设置cuda路径

    gedit ~/.bashrc #打开

  • 在文末添加或修改(以前用过8.0的改成9.0就ok)

    export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64:/usr/local/cuda-9.0/extras/CUPTI/lib64:$LD_LIBRARY_PATH
    export CUDA_HOME=/usr/local/cuda-9.0
    export PATH=/usr/local/cuda-9.0/bin:$PATH

  • 保存

    source ~/.bashrc

  • 验证

    nvcc -V #查询cuda版本

ubuntu16.04+cuda9.0+cudnn7.0+caffe_第3张图片

cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2 #查询cudnn版本

ubuntu16.04+cuda9.0+cudnn7.0+caffe_第4张图片

caffe

  • 安装依赖包

    sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
    sudo apt-get install –no-install-recommends libboost-all-dev
    sudo apt-get install libopenblas-dev liblapack-dev libatlas-base-dev
    sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
    sudo apt-get install git cmake build-essential

  • caffe下载包

    git clone http://github.com/weiliu89/caffe.git

  • 备份Makefile.config

    sudo cp Makefile.config.example Makefile.config

  • 编辑Makefile.config

    sudo gedit Makefile.config

  • 打开后做如下修改

    1. 应用cuDNN

      USE_CUDNN := 1

    2. 应用OpenCV

      USE_OPENCV := 1

    3. 根据CUDA版本进行相关的注释

    4. 应用python接口

      WITH_PYTHON_LAYER := 1

    5. 修改PYTHON路径

      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

  • 修改Makefile文档

    NVCCFLAGS +=-ccbin=$(CXX) -Xcompiler-fPIC $(COMMON_FLAGS)
    改为:
    NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)

  • LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5
    改为:
    LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial

  • 编译

    make all -j8

  • 测试

    make runtest

Caffe Python 接口

  • 无脑依赖库安装

    sudo apt-get install python-numpy python-scipy python-matplotlib python-sklearn python-skimage python-h5py python-protobuf python-leveldb python-networkx python-nose python-pandas python-flags Cython ipython
    sudo apt-get install protobuf-c-compiler protobuf-compiler

  • 或者进入caffe/python 根据所提供的清单进行安装

    for req in $(cat requirements.txt); do sudo pip install $req; done

  • 完成后执行如下命令反馈安装结果

    sudo pip install -r requirements.txt #打印出一堆Requirement already satisfied即可

ubuntu16.04+cuda9.0+cudnn7.0+caffe_第5张图片

  • 回到caffe根目录编译

    make pycaffe

  • 全部完成后可以运行jupyter notebook开始你的caffe之旅
    ubuntu16.04+cuda9.0+cudnn7.0+caffe_第6张图片

你可能感兴趣的:(ubuntu16.04+cuda9.0+cudnn7.0+caffe)