0%

Cuda8+OpenCV3.2+Caffe installed under Ubuntu 16

  • Chinese:

This article is synthesized from the Internet and written through its own practice.

0 Preparation

  1. System settings, change the software source.
  2. Real-time display of network speed under Ubuntu
    1
    2
    3
    sudo add-apt-repository ppa:nilarimogard/webupd8
    sudo apt-get update
    sudo apt-get install indicator-netspeed
    After installation, run indicator-sysmonitor &.Set{net} C: {cpu} M: {mem},Check “Run on startup”
  3. Install GDebi to App Store
  4. Go to Sogou to enter Judge Network to download Sogou input method and use GDebi to install it.
  5. Netease Cloud Music also provides deb package
  6. Install git,Install cmake
    1
    2
    sudo apt install git
    sudo apt install cmake

1 Install Cuda

  1. Go to System Settings → Software and Updates → Additional Drivers. Install NVIDIA private driver.
  2. Reboot。Runsudo nvidia-smi to check the information that the installation was successful.
    enter description here
  3. Download the historical version of Cuda from NVIDIA’s official website and download the Cuda8 run file. Be careful not to install drivers again.
  4. Set environment variables, modify PATH and LD_LIBRARY_PATH
    1
    sudo gedit ~/.bashrc
    Add the last document
    1
    2
    3
    exportPATH=/usr/local/cuda-8.0/bin${PATH:+:${PATH}}
    exportLD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64\
    {LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
  5. Test CUDA’ samples
    1
    2
    3
    4
    cd /usr/local/cuda-8.0/samples/1_Utilities/deviceQuery

    make
    sudo ./deviceQuery
    enter description here
    PASS,The installation was successful
  6. Install Cudnn
    1. Official website to download Cudnn: https://developer.nvidia.com/rdp/cudnn-download ,Need to log in.
    2. Open the terminal in the include directory after extracting cuDNN
      1
      sudo cp cudnn.h /usr/local/cuda/include/    #Copy header files
    3. Enter the dynamic file in the lib64 directory to copy and link:
      1
      2
      3
      4
      5
      sudo cp lib* /usr/local/cuda/lib64/    #Copy dynamic link library
      cd /usr/local/cuda/lib64/
      sudo rm -rf libcudnn.so libcudnn.so.5 #Delete the original dynamic file
      sudo ln -s libcudnn.so.5.1.10 libcudnn.so.5 #Generate soft links (Note that this corresponds to the cudnn version you downloaded yourself. You can check your version of libcudnn under /usr/local/cuda/lib64)
      sudo ln -s libcudnn.so.5 libcudnn.so #Generate soft links

2 Install Caffe

  1. Download caffe:https://github.com/BVLC/caffe
  2. Installation dependencies
    1
    2
    3
    4
    5
    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 liblapacke-dev checkinstall #This is a dependencie for OpenCV
  3. Extract the caffe package and copy it to the~/tools directory
  4. Configuration Makefile.config
    1. Copy Makefile.config.example,rename Makefile.config
    2. Modify
      1
      2
      INCLUDE_DIRS := $(PYTHON_INCLUDE)/usr/local/include
      LIBRARY_DIRS := $(PYTHON_LIB)/usr/local/lib /usr/lib
      to
      1
      2
      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
    3. Compilation
      1
      2
      3
      make all –j8
      make test
      make runtest
    4. Use the MNIST data set to test
      1. All operations need to be targeted to the caffe root directory
      2. Download the MNIST database and unzip it
        1
        ./data/mnist/get_mnist.sh
      3. Convert to Lmdb database format
        1
        ./examples/mnist/create_mnist.sh
      4. Training network
        1
        ./examples/mnist/train_lenet.sh
      5. The value of loss and precision can be seen during training, which is 0.9906 in the experiment.
        enter description here
    5. At this point, caffe installation is complete.

3 Install OpenCV3.2

  1. Download
  2. Extract the package and copy it to the~/tools directory
  3. Create a new build folder in the OpenCV directory, enter, open the terminal.
  4. Execute the following command, need networking.
    1
    sudo cmake -D CMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local ..
  5. Compile and install
    1
    2
    sudo make –j8  #Need some times
    sudo make install
  6. Compile OpenCV under caffe
    1. Switch to the caffe root directory
    2. Configure the Makefile.config file and change#OPENCV_VERSION#OPENCV_VERSION := 3toOPENCV_VERSION := 3
  7. Compilation
    1
    2
    3
    4
    make clean        #Clear previous compilation
    make all -j8
    make test
    make runtest

#4. Install Matlab

Matlab’s caffe interface is compiled with errors. Continue research.