Ubuntu 16.04 + Opencv3.0 + gtx1080 + caffe(SSD) + ROS(Kinetic)

前端之家收集整理的这篇文章主要介绍了Ubuntu 16.04 + Opencv3.0 + gtx1080 + caffe(SSD) + ROS(Kinetic)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

this part records the process of installing opencv and caffe on ubuntu 16.04 with gtx1080 gpu.


  • Installing ubuntu16.04
    since we didn’t succeed in installing ubuntu14.04 on this server,so we installed the ubuntu16.04.
  • Installing the nvidia driver
    • check what driver should we install sudo ubuntu-drivers devices
    • add the repository sudo add-apt-repository ppa:graphics-drivers
    • install driver (change the driver num according to your own server)

      sudo apt-get update
      sudo apt-get install nvidia-367 mesa-common-dev freeglut3-dev

    • reboot to effect the driver
    • test the driver by nvidia-smi
  • Installing cuda8.0

    • download the cuda8.0 from the NVIDIA official website,recommend the run file instead of deb
    • install the cuda,e.g. sh cuda_8.0.27_linux.run,notice that:
      • DON’T INSTALL THE DRIVER IN THE RUN FILE,it will overide the driver we installed just now.
      • DON’T INSTALL THE OPENGL LIB,you cannot log in even with the correct password.
    • add the cuda/bin and lib to the PATH AND PROFILE

      sudo vim /etc/profile
      export PATH=/usr/local/cuda/bin:$PATH

      sudo vim /etc/ld.so.conf.d/cuda.conf
      /usr/local/cuda/lib64

    • test the example in ~/NVIDIA *. note that the gcc/g++ version in ubuntu 16.04 is >=5.3,maybe cause some errors,so we modified the /usr/local/cuda/include/host_config.h to support 5.3 version gcc/g++.

      sudo vim /usr/local/cuda/include/host_config.h
      find the if _GNUC_ > 5,change the 5 to 6
      cd ~/Nvidia(tab)
      make -j16
      cd bin/…/
      ./deviceQuery

    if you get the pass result,install corectly.

  • Installing Opencv3.0
    there are two things we need to pay attention to in installing opencv3.0:

    • build opencv without rebuilding the tiff lib
    • modified src file to support cuda8.0

    Installing steps are summarized below:

    • download the installing shell script from private cloud disk(code: wysa)
    • install dependencies sudo sh dependencies.sh
    • run the opencv3_0_0.sh to get src file sudo sh opencv3_0_0.sh,note that maybe we will stop at the downloading ippcv,we can pre-download this file from here and put it in OpenCV-master/3rdparty/ippicv/downloads/Linux-xxxx/
    • since in ubuntu16.04,the libtiff version is 5,not 4. so we need to modified the opencv3_0_0.sh to ignore the installation of libtiff4-dev as follows. simply delete the libtiff4-dev and add -D WITH_TIFF=ON in cmake command

    original opencv3_0_0.sh

    arch=$(uname -m)
    if [ "$arch" == "i686" -o "$arch" == "i386" -o "$arch" == "i486" -o "$arch" == "i586" ]; then
    flag=1
    else
    flag=0
    fi
    echo "Installing OpenCV 3.0.0"
    mkdir OpenCV
    cd OpenCV
    echo "Removing any pre-installed ffmpeg and x264"
    sudo apt-get -y remove ffmpeg x264 libx264-dev
    echo "Installing Dependenices"
    sudo apt-get -y install libopencv-dev
    sudo apt-get -y install build-essential checkinstall cmake pkg-config yasm
    sudo apt-get -y install libtiff4-dev libjpeg-dev libjasper-dev
    sudo apt-get -y install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev
    sudo apt-get -y install python-dev python-numpy
    sudo apt-get -y install libtbb-dev
    sudo apt-get -y install libqt4-dev libgtk2.0-dev
    sudo apt-get -y install libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev
    sudo apt-get -y install x264 v4l-utils ffmpeg
    sudo apt-get -y install libgtk2.0-dev
    echo "Downloading OpenCV 3.0.0"
    wget -O opencv-3.0.0.zip http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/3.0.0/opencv-3.0.0.zip/download
    echo "Installing OpenCV 3.0.0"
    unzip opencv-3.0.0.zip
    cd opencv-3.0.0
    mkdir build
    cd build
    cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..
    make -j4
    sudo make install
    sudo sh -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
    sudo ldconfig
    echo "OpenCV 3.0.0 ready to be used"

    modified opencv3_0_0.sh

    arch=$(uname -m)
    if [ "$arch" == "i686" -o "$arch" == "i386" -o "$arch" == "i486" -o "$arch" == "i586" ]; then
    flag=1
    else
    flag=0
    fi
    echo "Installing OpenCV 3.0.0"
    mkdir OpenCV
    cd OpenCV
    echo "Removing any pre-installed ffmpeg and x264"
    sudo apt-get -y remove ffmpeg x264 libx264-dev
    echo "Installing Dependenices"
    sudo apt-get -y install libopencv-dev
    sudo apt-get -y install build-essential checkinstall cmake pkg-config yasm
    sudo apt-get -y install libjpeg-dev libjasper-dev
    sudo apt-get -y install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev
    sudo apt-get -y install python-dev python-numpy
    sudo apt-get -y install libtbb-dev
    sudo apt-get -y install libqt4-dev libgtk2.0-dev
    sudo apt-get -y install libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev
    sudo apt-get -y install x264 v4l-utils ffmpeg
    sudo apt-get -y install libgtk2.0-dev
    echo "Downloading OpenCV 3.0.0"
    wget -O opencv-3.0.0.zip http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/3.0.0/opencv-3.0.0.zip/download
    echo "Installing OpenCV 3.0.0"
    unzip opencv-3.0.0.zip
    cd opencv-3.0.0
    mkdir build
    cd build
    cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D WITH_TIFF=ON ..
    make -j4
    sudo make install
    sudo sh -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
    sudo ldconfig
    echo "OpenCV 3.0.0 ready to be used"
  • Installing cudnn
    Installing the cudnn v5 for cuda8.0

    tar xvzf cudnn-8.0-linux-x64-v5.0-ga.tgz
    sudo cp cuda/include/cudnn.h /usr/local/cuda/include
    sudo cp cuda/lib64/. /usr/local/cuda/lib64
    sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
    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

  • Installing additionale package

package name command
python-tk sudo apt-get install python-tk
  • Installing caffe (using python2.7 not anaconda,otherwise maybe cause conflict between anaconda and system python)

    • Basic dependience

      sudo apt-get update
      sudo apt-get install -y build-essential cmake git pkg-config
      sudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev libhdf5-serial-dev protobuf-compiler
      sudo apt-get install -y libatlas-base-dev
      sudo apt-get install -y –no-install-recommends libboost-all-dev sudo apt-get install -y libgflags-dev libgoogle-glog-dev liblmdb-dev
      sudo apt-get install -y python-pip python-dev python-numpy python-scipy # (Python general)
      sudo apt-get install libopencv-dev

    • git clone caffe and install python dependience

      git clone https://github.com/BVLC/caffe.git
      cd caffe-master/python
      for req in $(cat requirements.txt); do pip install $req; done

    note which package isn’t installed correctly,re-install it.

    • modified Makefile.config
## Refer to http://caffe.berkeleyvision.org/installation.html
# Contributions simplifying and improving our build system are welcome!

# cuDNN acceleration switch (uncomment to build with cuDNN).
USE_CUDNN := 1

# cpu-only switch (uncomment to build without GPU support).
# cpu_ONLY := 1

# uncomment to disable IO dependencies and corresponding data layers
# USE_OPENCV := 0
# USE_LEVELDB := 0
# USE_LMDB := 0

# uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary)
# You should not set this flag if you will be reading LMDBs with any
# possibility of simultaneous read and write
# ALLOW_LMDB_NOLOCK := 1

# Uncomment if you're using OpenCV 3
OPENCV_VERSION := 3

# To customize your choice of compiler,uncomment and set the following.
# N.B. the default for Linux is g++ and the default for OSX is clang++
# CUSTOM_CXX := g++

# CUDA directory contains bin/ and lib/ directories that we need.
CUDA_DIR := /usr/local/cuda
# On Ubuntu 14.04,if cuda tools are installed via
# "sudo apt-get install nvidia-cuda-toolkit" then use this instead:
# CUDA_DIR := /usr

# CUDA architecture setting: going with all of them.
# For CUDA < 6.0,comment the *_50 lines for compatibility.
CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \
        -gencode arch=compute_20,code=sm_21 \
        -gencode arch=compute_30,code=sm_30 \
        -gencode arch=compute_35,code=sm_35 \
        -gencode arch=compute_50,code=sm_50 \
        -gencode arch=compute_50,code=compute_50

# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
BLAS := atlas
# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
# Leave commented to accept the defaults for your choice of BLAS
# (which should work)!
# BLAS_INCLUDE := /path/to/your/blas
# BLAS_LIB := /path/to/your/blas

# Homebrew puts openblas in a directory that is not on the standard search path
# BLAS_INCLUDE := $(shell brew --prefix openblas)/include
# BLAS_LIB := $(shell brew --prefix openblas)/lib

# This is required only if you will compile the matlab interface.
# MATLAB directory should contain the mex binary in /bin.
# MATLAB_DIR := /usr/local
# MATLAB_DIR := /Applications/MATLAB_R2012b.app

# NOTE: this is required only if you will compile the python interface.
# We need to be able to find Python.h and numpy/arrayobject.h.
PYTHON_INCLUDE := /usr/include/python2.7 \
        /usr/lib/python2.7/dist-packages/numpy/core/include
# Anaconda Python distribution is quite popular. Include path:
# Verify anaconda location,sometimes it's in root.
# ANACONDA_HOME := $(HOME)/anaconda
# PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
        # $(ANACONDA_HOME)/include/python2.7 \
        # $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include \

# Uncomment to use Python 3 (default is Python 2)
# PYTHON_LIBRARIES := boost_python3 python3.5m
# PYTHON_INCLUDE := /usr/include/python3.5m \
# /usr/lib/python3.5/dist-packages/numpy/core/include

# We need to be able to find libpythonX.X.so or .dylib.
PYTHON_LIB := /usr/lib
# PYTHON_LIB := $(ANACONDA_HOME)/lib

# Homebrew installs numpy in a non standard path (keg only)
# PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include
# PYTHON_LIB += $(shell brew --prefix numpy)/lib

# Uncomment to support layers written in Python (will link against Python libs)
WITH_PYTHON_LAYER := 1

# Whatever else you find you need goes here.
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      

# If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies
# INCLUDE_DIRS += $(shell brew --prefix)/include
# LIBRARY_DIRS += $(shell brew --prefix)/lib

# Uncomment to use `pkg-config` to specify OpenCV library paths.
# (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)
# USE_PKG_CONFIG := 1

# N.B. both build and distribute dirs are cleared on `make clean`
BUILD_DIR := build
DISTRIBUTE_DIR := distribute

# Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171
# DEBUG := 1

# The ID of the GPU that 'make runtest' will use to run unit tests.
TEST_GPUID := 0

# enable pretty build (comment to see full commands)
Q ?= @
  • compile and test

    cd ~/caffe-master
    make all -j16
    make test -j16
    make runtest -j16
    make pycaffe

  • test pycaffe

    export PYTHONPATH=~/caffe-master/python:$PYTHONPATH
    in python,import caffe

if no error occurs,we install caffe correctly

echo ‘export PYTHONPATH=~/caffe-master/python’ >> ~/.bashrc

原文链接:https://www.f2er.com/ubuntu/355556.html

猜你在找的Ubuntu相关文章