Ubuntu16.04 Installation Configuration Caffe

Source: Internet
Author: User
Tags unsupported using git

Caffe is already the third installation configuration, why the third time? Because I really underestimated the hardware requirements of deep learning.  The first time I configured the single core in my own notebook, CPU only ... As a result, the sample data ran for 4 hours, how do you play it? The second time on the desktop, because the desktop compares the LOW,I5 processor 4 core, there is no NVIDIA GPU.  I downloaded the model trained by others, and then I tested it, found that it was really successful, and I was very excited, but when I trained my model, I trained for 7 days .... The key is 7 days, still running ...

Thought, I this poor force to own money to buy a server? How could that be. Fortunately, the teacher is very good, to find me a server ~ Now finally is the time for labor.

The whole configuration process is very long ah, more pits, no Linux base on the Don't come, you will collapse. I refer to a number of posts, basically every post has more or less problems, the end of the article, I will leave the articles of the predecessors of the address, is to their respect and help me thanks. OK, let's cut to the chase!

Computer Configuration:

System: Ubuntu16.04 gpu:nvidia Corporation GM107GL [Quadro K620] (hint: Under Linux you can pass Lspci | grep -I VGA view)

installation process

1. Installing related dependencies

1 sudo Install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-Compiler  2sudoinstall --no-install-recommends libboost-all-Dev3  sudoinstall libopenblas-dev liblapack-dev libatlas-base-Dev4 sudo Install Libgflags-dev libgoogle-glog-dev Liblmdb-dev

2. Installing the NVIDIA Driver

(1) Query Nvidia driver

First go to the official website http://www.nvidia.com/Download/index.aspx?lang=en-us View the driver for your video card and download:

The driver file suffix name should end with. Run. We want to move this file to the home directory, the reason is that below we want to switch to the text interface, if put to ~/download below, we have no way to download this directory (no Chinese input method, and Chinese is all garbled)

                         Figure 1 Enter the graphics model                                                                                                                                             Figure 2  Graphics driver search results

My graphics card model is Quadro K620, the system is Linux 64-bit, follow the required selection and click Search. Figure 2 is the result of the search, click to download just fine.

The driver file I downloaded is: nvidia-linux-x86_64-375.20.run

(2) Installation drive

在终端下输入: sudo gedit /etc/modprobe.d/blacklist.conf  

Enter the password and add it to the last line blacklist nouveau . This is the blacklist of the video driver that comes with Ubuntu.

In terminal input: sudo update-initramfs-u

Restart your computer ~
In particular, it is important to note that installing the graphics driver switches to the text interface first, (press CTRL+ALT+F1~F6). So, start the computer and enter the text interface.

Then, enter the command sudo service lightdm stop

Now you can install the driver, first go to the home directory CD ~ , and then: sudo ./nvidia-linux-x86_64-375.20.run, follow the prompts step-by-step ~

When you are finished, restart your computer again.

After the installation is complete, enter the following instructions to verify: sudo nvidia-smi , if the list of information for the GPU is listed, the driver installation is successful. Such as:

3. Installing Cuda

Cuda is the Nvidia programming language platform, and it is necessary to use the GPU to use Cuda. (1) Download Cuda first on the official website (https://developer.nvidia.com/cuda-downloads) Download Cuda:

(2) When the download is complete, execute the following command:

1 sudo chmod 777 Cuda_8. 0 . 44_linux.run 2 sudo  . /cuda_8. 0. 44_linux.run

Note: After execution there will be a series of prompts for you to confirm, but note that there is a choice to choose whether or not to install the nvidia367 driver, you must select No:
Install NVIDIA accelerated Graphics Driver for linux-x86_64 367.48?
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.

(3) environment variable configuration

Open ~/.BASHRC file: sudo gedit ~/.bashrc
Write the following to the ~/.BASHRC trailer:

1 Export path=/usr/local/cuda-8.0/bin${path:+: ${path}}2 export Ld_library_path =/usr/local/cuda8. 0/lib64${ld_library_path:+:${ld_library_path}}

(4) Test Cuda samples

1 cd/usr/local/cuda-8.0/samples/1_utilities/devicequery2make3  sudo ./devicequery

If some information about the GPU is displayed, the installation is successful.

4. Configure CUDNN
CUDNN is a library of GPU-accelerated computational deep neural networks.
First go to the official website https://developer.nvidia.com/rdp/cudnn-download download CUDNN, need to register an account to download. Download version numbers such as:

To unzip after downloading cuDNN5.1:

sudo tar -zxvf./cudnn-8.0-linux-x64-v5. 1

Go to the Include directory after cuDNN5.1 decompression and do the following at the command line:

CD cuda/includesudocp Cudnn.h/usr/local/cuda/include #复制头文件

Then copy and link the dynamic files into the lib64 directory:

CD.. CD lib64sudocp lib*/usr/local/cuda/lib64/    /usr/local/cuda/lib64/sudo  rm -rf libcudnn.so libcudnn.so. 5     #删除原有动态文件 sudoln -S libcudnn.so. 5.0. 5 libcudnn.so. 5   #生成软衔接 sudoln -S libcudnn.so. 5 libcudnn.so      #生成软链接

5. Installing opencv3.1
Download the OpenCV from the official website (http://opencv.org/downloads.html) and unzip it to the location you want to install, assuming the/HOME/OPENCV is extracted.

1 Unzip opencv-2.4. . Zip 2 sudo CP ./opencv-2.4.  /Home3sudomv opencv-2.4.  OpenCV

Before installing, create a compilation folder:

CD ~/OpenCVmkdir  BUILDCD Build

Configuration:

1 sudo Install CMake 2 sudo cmake-d cmake_build_type=release-d cmake_install_prefix=/usr/local.

Compile:

sudo make

-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

6. Configure Caffe

(1) using Git to download Caffe is very simple, or go to Https://github.com/BVLC/caffe download. Because I used to go to GitHub to find the code, so go directly to the source of the download.

After the download is complete, you will find the caffe-master.zip in the download in your home directory, unzip the home directory with the unzip command, and rename it to Caffe.

(2) 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  

(3) Open and modify the configuration file:
 sudo gedit Makefile.config #打开Makefile. config file   modify files according to your personal circumstances:
A. If you use CUDNN,
will
#USE_CUDNN: = 1
modified to:
USE_CUDNN: = 1
B. If the OPENCV version used is 3, then
Modify
#OPENCV_VERSION: = 3
To:
Opencv_version: = 3
C. To write a LAYER using PYTHON,
will         #WITH_PYTHON_LAYER: = 1  
modified to  with_python_layer: = Span style= "COLOR: #800080" >1  ,
D. Important:
will  # Whatever Span style= "COLOR: #0000ff" >else find you need goes here.   The following

1 include_dirs: = $ (python_include)/usr/local/INCLUDE2

Modified to:

1 include_dirs: = $ (python_include)/usr/local/include/usr/include/hdf5/serial2 Library_ 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 a location that has changed, especially where the hdf5 is needed, so you need to change this path.

(4) Modify the Makefile file
Open the Makefile file and make the following changes:
Will:

Nvccflags +=-ccbin=$ (CXX)-xcompiler-fpic $ (common_flags)

To be replaced by:

Nvccflags + =-d_force_inlines-ccbin=$ (CXX)-xcompiler-fpic $ (common_flags)

(5) 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! instead // #error--Unsupported GNU version! gcc versions later than 4.9 is not supported!

(6) Compiling
Make All-j8 #-j depends on your computer configuration
The following error may occur during compilation:
Error content 1:
"Fatal error:hdf5.h: No 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
To be 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
Switch
LIBRARIES + = Glog gflags protobuf boost_system boost_filesystem m HDF5_SERIAL_HL hdf5_serial
Error Content 2:
"Libcudnn.so.5 cannot open shared object File:no such file or directory"
The workaround is to copy some files to the/usr/local/lib folder:
#注意自己CUDA的版本号!

1 sudo CP/usr/local/cuda-8.0/lib64/libcudart.so.8.0/usr/local/lib/libcudart.so.8.0&&sudoLdconfig2 sudo CP/usr/local/cuda-8.0/lib64/libcublas.so.8.0/usr/local/lib/libcublas.so.8.0&&sudoLdconfig3 sudo CP/usr/local/cuda-8.0/lib64/libcurand.so.8.0/usr/local/lib/libcurand.so.8.0&&sudoLdconfig4 sudo CP/usr/local/cuda-8.0/lib64/libcudnn.so.5/usr/local/lib/libcudnn.so.5&&sudoLdconfig

(8) test

sudo  make Runtest

If it appears after running, the Caffe configuration is successful.

To this caffe configuration is complete!

Mnist Data Set Test
Once the configuration caffe is complete, we can test the Caffe with the Mnist dataset, as follows:

1. Locate the terminal to the Caffe root directory
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
When training you can see the loss and precision values, such as:

You can see that the final training accuracy is 0.9914.

The above is the success of others, I went to this step when the error:

The specific reason is unclear, ask you veteran guide!!!

Ubuntu16.04 Installation Configuration Caffe

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.