ubuntu16.04 cuda8.0 opencv3.2.0 Caffe Installation

Source: Internet
Author: User
Tags unsupported git clone

Installation procedure 1. Install dependent dependencies 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-devsudo apt-get Install Libopenblas-dev liblapack-dev libatlas-base-devsudo apt-get install Libgflags-dev Libgoogle-glog-dev Liblmdb-dev  2. Installing the Nvidia driver (1) query Nvidia driver first go to official website (http://www.nvidia.com/Download/index.aspx?lang=en-us) See the driver for your video card: Figure 1. Graphics driver query such as my computer's graphics drivers such as: Figure 2. Graphics driver version (2) Uninstall the existing driver version before installing the driver installation: sudo apt-get remove--purge nvidia* If the computer is an integrated graphics card (Nvidia discrete graphics ignores this step), you need to disable one item before installation: Sudo service LIGHTDM stop executes the following instructions to install the driver: sudo add-apt-repository ppa:xorg-edgers/ Ppasudo apt-get updatesudo apt-get install nvidia-367 #注意在这里指定自己的驱动版本! After the installation is complete, enter the following command to verify: sudo nvidia-smi If the list of information for the GPU is listed, the driver installation is successful.  3. Installing the Cudacuda is an Nvidia programming language platform that requires Cuda to use the GPU. (1) Download Cuda first on the official website (https://developer.nvidia.com/cuda-downloads) Download cuda: Figure 3.CUDA Download (2) after the installation Cuda download is complete, execute the following command: sudo sh cuda_ 8.0.27_linux.run Note: After execution there will be a series of prompts for you to confirm, but note that there is a choice for you to choose whether to install the nvidia361 driver, be sure to select No: Install NvidIA accelerated Graphics Driver for linux-x86_64 361.62? Because we already have a newer nvidia367 installed in front of you, don't choose to install it here. The rest are directly default or select Yes. Possible error: When "Unsupport complier" error occurs, the GCC version is too high to reduce the GCC version. The solution is as follows: Take gcc4.9 and g++4.9 as an example install the low-version gcc and G++:sudo apt-get installed gcc-4.9 g++-4.9 and then go to/usr/bin:cd/usr/bin to remove and gcc5.0 the associated GCC first: sudo rm gccsudo rm g++ Build a soft connection sudo ln-s gcc-4.9 gccsudo ln-s g++-4.9 g++ and then reinstall. (3) environment variable configuration open the ~/.BASHRC file: sudo vim ~/.BASHRC writes the following to the ~/.BASHRC tail: Export Path=/usr/local/cuda-8.0/bin${path:+:${path}} Export Ld_library_path=/usr/local/cuda8.0/lib64${ld_library_path:+:${ld_library_path}} (4) test Cuda's sammplescd/usr/ Local/cuda-8.0/samples/1_utilities/devicequerymakesudo./devicequery If some information about the GPU is realistic, the installation is successful.  4. Configuration Cudnncudnn is a library of GPU-accelerated compute deep neural networks. First go to the official website (https://developer.nvidia.com/rdp/cudnn-download) Download CUDNN, may need to register an account to download. Because my video card is GTX1080, so download version number such as: Figure 4.cuDNN download Download cuDNN5.1 after decompression, CD into the cuDNN5.1 after decompression of the Include directory, the command line to do the following: sudo cp cudnn.h/usr/ local/cuda/include/    #复制头文件再将cd进入lib64目录下的动态文件进行复制和链接: sudo cp lib*/usr/local/cuda/lib64/&NBSp   #复制动态链接库cd/usr/local/cuda/lib64/sudo rm-rf libcudnn.so libcudnn.so.5     #删除原有动态文件sudo ln-s libcudnn.so.5.0.5 libcudnn.so.5   #生成软衔接sudo ln-s libcudnn.so.5 libcudnn.so       #生成软链接  5. Install opencv3.1 from the official website (http://opencv.org/downloads.html) to download OpenCV, and unzip it to the location you want to install, assuming the decompression to the/HOME/OPENCV. Prepare before installation, create a compilation folder: CD ~/opencvmkdir BUILDCD BUILD configuration: cmake-d cmake_build_type=release-d cmake_install_prefix=/usr/local. Compile: Make-j8 #-j8 represents the parallel computing, according to the configuration of their own computer settings, the configuration of the lower computer can be small or unused, direct output make. The above is only the successful compilation of OpenCV, has not yet installed the OPENCV, you need to run the following instructions to install: sudo make install error may occur: Error content 1:gcc-4.9:error trying to exec ' cc1plus ': execvp:  no that file or directory description GCC is incompatible with the g++ version, as is the case with the GCC version: Install the lower version of GCC and g++:sudo apt-get install gcc-4.9 g++-4.9 after entering/usr/bin : Cd/usr/bin first Delete and gcc5.0 associated Gcc:sudo RM gccsudo RM g++ Build a soft connection sudo ln-s gcc-4.9 gccsudo ln-s g++-4.9 g++ Error content 2:modules/cudaleg acy/src/graphcuts.cpp:120:54:error:  ' nppigraphcutstate ' have not been declaredtypedef Nppstatus (*init_func_t) ( Nppisize OSIZE, NPPIGRAPHCUtstate** ppstate, npp8u* pdevicemem); This is due to opecv3.0 incompatibility with cuda8.0. Workaround: Modify the contents of the ~/opencv/modules/cudalegacy/src/graphcuts.cpp file, Figure 5. File modification  6. Configure Caffe (1) to place the terminal CD to the location where you want to install Caffe. (2) Get Caffe:git clone https://github.com/BVLC/caffe.git from GitHub Note: If you don't have Git installed, you'll need to install Git:sudo Apt-get Git (3) because the make command can only make Makefile.config file, and Makefile.config.example is the Makefile example given by Caffe, so first copy the contents of Makefile.config.example to Makefile.config:sudo CP Makefile.config.example Makefile.config (4) Open and modify configuration file: sudo gedit makefile.config # Open the Makefile.config file to modify the file according to your personal situation: a. If you use CUDNN, #use_cudnn: = 1 is modified to:  use_cudnn: = 1b. If the OPENCV version used is 3, the #opencv_ VERSION: = 3  modified to:  opencv_version: = 3c. To write a LAYER using PYTHON, #with_python_layer: = 1  is modified to  with_ Python_layer: = 1d. Important: Will # Whatever else you find you need goes here. Include_dirs below: = $ (python_include)/usr/local/inc Ludelibrary_dirs: = $ (python_lib)/usr/local/lib/usr/lib  modified to:  include_dirs: = $ (python_include)/usr/local /include/usr/include/hdf5/seriallibrary_dirs:= $ (python_lib)/usr/local/lib/usr/lib/usr/lib/x86_64-linux-gnu/usr/lib/x86_64-linux-gnu/hdf5/serial        This is because the ubuntu16.04 file contains location changes, especially the location of the hdf5 that needs to be used, so this path needs to be changed. (5) Modify the makefile file to open the makefile file and make the following changes: Nvccflags +=-ccbin=$ (CXX)-xcompiler-fpic $ (common_flags) replaced by: Nvccflags + =-d_force_inlines-ccbin=$ (CXX)-xcompiler-fpic $ (COMMON_FLAGS) (6) Edit/usr/local/cuda/include/host_config.h comment out the 115th line: Will #error--unsupported GNU version! GCC versions later than 4.9 is not supported! changed to//#error--Unsupported GNU version! GCC versions later than 4.9 is not supported! (7) Compile make All-j8 #-j depending on your computer configuration, the following error may occur during compilation: Error 1: "Fatal error:hdf5.h: No That file or directory "Workaround: Step1: In line 85th of the Makefile.config file, add/usr/include/hdf5/serial/to include_dirs, i.e. change the first line below to the second line of code. Will: Include_dirs: = $ (python_include)/usr/local/include replaced by: include_dirs: = $ (python_include)/usr/local/include/usr/ Include/hdf5/serial/stept2: In line 173th of the makefile file, change Hdf5_hl and Hdf5 to Hdf5_serial_hl and hdf5_serial, i.e. change the first line of code below to the second line. Will: LIBRARIES + = Glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5 instead: LIBRARIES + = Glog gflags protobuf boost_system boost_ FileSystem m HDF5_SERIAL_HL hdf5_serial error content 2: "libcudart.so.8.0 cannot open shared object File:no such file or directory" solution The solution is to copy some files to the/usr/local/lib folder: #注意自己CUDA的版本号! sudo cp/usr/local/cuda-8.0/lib64/libcudart.so.8.0/usr/local/lib/libcudart.so.8.0 && sudo ldconfigsudo CP/ usr/local/cuda-8.0/lib64/libcublas.so.8.0/usr/local/lib/libcublas.so.8.0 && sudo ldconfigsudo cp/usr/local /cuda-8.0/lib64/libcurand.so.8.0/usr/local/lib/libcurand.so.8.0 && sudo ldconfig (8) test sudo make Runtest if it appears after running, the Caffe configuration is successful. Figure 6.caffe Test results to this caffe configuration is complete! After the  mnist DataSet test Configuration Caffe is complete, we can test the Caffe with the Mnist dataset as follows:  1. Locate the terminal to the Caffe root CD ~/caffe 2. Download the Mnist database and unzip it ./data/mnist/get_mnist.sh 3. Convert it to lmdb database format./examples/mnist/create_mnist.sh 4. Training Network./examples/mnist/ TRAIN_LENET.SH training can see the loss and precision values, such as: Figure 7.MNIST Data set training can see the final training accuracy is 0.9914.

ubuntu16.04 cuda8.0 opencv3.2.0 Caffe installation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.