CUDA8.0 Configuration Caffe Tutorial under Ubuntu 16.04 system

Source: Internet
Author: User
Tags theano

Due to the recent installation of Ubuntu 16.04, this tutorial features no need to downgrade the GCC version, after all cuda8.0 has supported GCC5 above (default is not supported, actual support).

This article is in the reference Caffe official website The tutorial as well as http://www.linuxidc.com/Linux/2015-07/120449.htm unifies oneself to summarize experiences to come, expresses thanks to this.

Ubuntu 14.04 installs Nvidia CUDA7.5 and builds Python theano deep learning development environment http://www.linuxidc.com/Linux/2015-09/123562.htm

Ubuntu Cuda (including GPU card driver) installation process http://www.linuxidc.com/Linux/2015-07/120456.htm

Caffe + Ubuntu 14.04 64bit + CUDA 6.5 configuration Instructions http://www.linuxidc.com/Linux/2015-04/116444.htm

Ubuntu 14.04 Installation Configuration Cuda http://www.linuxidc.com/Linux/2014-10/107501.htm

Ubuntu 12.04 configuration nvidia CUDA5.5 transcript http://www.linuxidc.com/Linux/2014-10/107502.htm

Ubuntu installation Theano+cuda http://www.linuxidc.com/Linux/2014-10/107503.htm

For the installation of Ubuntu 12.04 under CUDA5.5, see the following link for Ubuntu 12.04 installation CUDA-5.5

CUDA7.5 Configuration Caffe Tutorial http://www.linuxidc.com/Linux/2016-07/132859.htm under Ubuntu 16.04 system

1. Download the required documents

1.1 Ubuntu16.04 in the official website to download, and then under Windows with UltraISO production, related article search has a large, here no longer repeat.

1.2 cuda8.0 Download, download version is ubuntu15.04 run file, personal feeling more convenient.

1.3 cudnn5.1 Download, if there is a registered NVIDIA account directly click Download, otherwise you need to register an account, after registration there is a survey, choose a few hooks can be, and then the next step is to accept the terms of the beginning can be downloaded.

1.4 Caffe download is available on the official GitHub download.

2. Graphics driver installation

2.1 The first method is directly in Ubuntu system settings, software and updates inside, select the Chinese server source refresh, click on the additional Driver option, select the latest version in Nvidia Corporation, then click Apply Changes, download and restart after installation.

2.2 The second method is to go to the official download of the drive run file, select the corresponding graphics model download. Then shut down the monitor to the integrated graphics interface, or the terminal

sudo gedit/etc/modprobe.d/blacklist.conf

After entering the password, on the last line of editing

Blacklist nouveau

Ctrl +c after saving terminal input

sudo update-initramfs-u

After rebooting, press CTRL+ALT+F2 in the interface, enter root and password, and

Service LIGHTDM Stop

SH The full path of your own driver file, the default option can be installed, reboot after installation

3. Cuda8.0 Installation

3.1 Take file name Cuda.run as an example, under terminal input

SH cuda.run--override start the installation program, here are a large number of terms, all the way to the last input accept, enter n (do not install the video card driver), and then all y enter, there is a place to enter the password, there are two places to confirm the installation path, directly enter can be, Complete the installation, the default installation path is/usr/local

3.2 CUDNN Installation

Will download down (Note: Please use the Linux system download, otherwise it will be other files, Nvidia is enough) after the cudnn-5.1-linux-x64-v4.0-prod.tgz decompression, the extracted Cuda folder first open the Include folder inside, Blank right-click on the terminal to open input:

sudo cp cudnn.h/usr/local/cuda/include/

CD ~/cuda/lib64

sudo cp lib*/usr/local/cuda/lib64/

Continue to update file links

cd/usr/local/cuda/lib64/

sudo rm-rf libcudnn.so libcudnn.so.4

sudo ln-s libcudnn.so.4.0.7 libcudnn.so.4

sudo ln-s libcudnn.so.4 libcudnn.so

Then set the environment variable

sudo gedit/etc/profile

Join at the end

Path=/usr/local/cuda/bin: $PATH

Export PATH

Create a linked file after saving

sudo vim/etc/ld.so.conf.d/cuda.conf

Keyboard press A To enter edit state, add text

/usr/local/cuda/lib64

Then press ESC, enter: Wq Save to exit.

Terminal Next input

sudo ldconfig

Make the link effective

4. generate Cuda sample test

Start by installing the required dependencies first, and prepare for the next make Caffe (which includes the option to install MKL or Openblas in Atlas)

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 Libatlas-base-dev

sudo apt-get install Libgflags-dev libgoogle-glog-dev Liblmdb-dev

Then start make samples, under terminal

Cd/home/gomee/nvidia_cuda-7.5_samples

sudo make All-j4

I am a 4-core computer so use J4, if not cudnn5.1 normal circumstances will definitely error "Unsupported GNU version! GCC versions later than 4.9 is not supported! ", because this cuda does not support gcc5.0 above, terminal run

Cd/usr/local/cuda-7.5/include

CP Host_config.h Host_config.h.bak

sudo gedit host_config.h

Ctrl+f looking for "4.9" where there should be only one place, above its

#if __gnuc__ > 4 | | (__gnuc__ = = 4 && __gnuc_minor__ > 9) Change two 4 to 5, save exit, continue

Cd/home/gomee/nvidia_cuda-7.5_samples

sudo make All-j4

This should start make, which is about 5 or 6 minutes. When you are done

Cd/home/gomee/nvidia_cuda-7.5_samples/bin/x86_64/linux

./devicequery

Finally, a message similar to the following will appear

CUDA Device Query (Runtime API) version (Cudart static linking)

Compute Mode:

< Default (multiple host threads can use:: Cudasetdevice () with device simultaneously) >

Devicequery, Cuda Driver = Cudart, cuda Driver version = 8.0, cuda Runtime Version = 8.0, Numdevs = 1, Device0 = GeForce G TX 960

Result = PASS

That means it's a success.

5. Python Configuration

Unzip the Caffe compressed file downloaded from github to any directory and install Python

Python versions are installed in two ways:

The first is to install Anaconda directly, go to the official website to download, choose Linux 64bit 2.7 download installation, Anaconda installation is convenient but you need to change the python include path in the final make configuration file.

The second method is to use the native version of python2.7, the terminal

sudo apt-get install PYTHON-PIP installation pip

Here we use Pip to install some Python-required dependency packages, but to avoid various problems, you can also install via Apt-get

sudo apt-get install python-numpy python-scipy python-matplotlib ipython ipython-notebook python-pandas python-sympy Python-nose

Caffe Default decompression to/home/user (your user name)/, folder name Caffe as an example

Cd/home/user/caffe/python

sudo su

For req in $ (cat requirements.txt); do pip install $req; Done

Here with PIP installation may be very slow, it is likely to download a few hours, it is recommended to use the PIP source of Tsinghua University temporary installation, so the command to read as follows:

For req in $ (cat requirements.txt); Do pip install-i https://pypi.tuna.tsinghua.edu.cn/simple $req; Done

Here if the first time a lot of red letter errors, it is recommended to run a few more times to guide the installation success, for the yellow hint, may be the PIP version needs to be updated.

6. Caffe Compilation Process

The next step is to go into the final steps, in the terminal

Cd/home/user/caffe

CP Makefile.config.example Makefile.config

Gedit Makefile.config

USE_CUDNN: = 1 Uncomment

Include_dirs: = $ (python_include)/usr/local/include after a space and then add/usr/include/hdf5/serial if there is no such sentence may be reported an error not found Hdf5.h

Python_include: =/usr/include/python2.7 \

/usr/lib/python2.7/dist-packages/numpy/core/include do not change first.

If you want to generate MATLAB Caffe wrapper please uncomment Matlab_dir and replace it with your own directory

Talk about the problems that arise in advance:

First, the error that occurs during the make process such as string.h ' Memcy ' is not declared in this scope is due to the fact that the GCC compiler version is too new, the workaround is to open makefile search and replace

Nvccflags + =-ccbin=$ (CXX)-xcompiler-fpic $ (common_flags) for nvccflags + =-d_force_inlines-ccbin=$ (CXX)-xcompiler-fpic $ (common_flags) Save exit

Second, in the make process also reported a LD can not find Libhdf5 and LIBHDF5_HL link problem, this reason may also be because of hdf5 problem, first see/USR/LIB/X86_64-LINUX-GNU There are no libhdf5.so and libhdf5_hl.so in the directory, if any, see if the property has the correct link (normally it should be without these two files), then right-click in the terminal to open

sudo ln libhdf5_serial.so.10.1.0 libhdf5.so

sudo ln libhdf5_serial_hl.so.10.0.2 libhdf5_hl.so

Note that 10.1.0 and 10.0.2 may differ depending on the PC installation, note the files that exist in the current directory and then

sudo ldconfig effective

If not,

Will # Whatever else you find need goes here.

Include_dirs: = $ (python_include)/usr/local/include

Library_dirs: = $ (python_lib)/usr/local/lib/usr/lib

Modified to:

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

This is because the ubuntu16.04 file contains a location that has changed, especially the location of the hdf5 that needs to be used, so you need to change this path

Cd/usr/lib/x86_64-linux-gnu

\ \ Then execute the following sentences according to the situation:

sudo ln-s libhdf5_serial.so.10.1.0 libhdf5.so

sudo ln-s libhdf5_serial_hl.so.10.0.2 libhdf5_hl.so

The next step is the process of direct compilation.

Cd/home/user/caffe

Make All-j4

Make Test-j4

Make Runtest

Make Pycaffe

Make Matcaffe

If the compilation does not have the correct error, the basic is no problem. Test Python Open

Cd/home/user/caffe/python

Python

Import Caffe

If you do not make an error, the compilation succeeds

Test matlab open./caffe/matlab/+caffe/private, see if there is a Caffe Mex file generated, you can run the program test inside the +test folder.

Minor problem:

When using the Python interface, there might be an error (I forgot the –!), and the error is ' Mean shape incompatible with input shape ', which is handled by the Python/caffe folder, Edit the io.py file to

If Ms! = Self.inputs[in_][1:]:

Raise ValueError (' Mean shape incompatible with input shape. ')

Replaced by

If Ms! = Self.inputs[in_][1:]:

Print (Self.inputs[in_])

In_shape = self.inputs[in_][1:]

M_min, M_max = Mean.min (), Mean.max ()

Normal_mean = (mean-m_min)/(M_max-m_min)

mean = Resize_image (Normal_mean.transpose ((1,2,0)), in_shape[1:]). Transpose ((2,0,1)) * (m_max-m_min) + m_min

Then make a clean and re-make

7. Summary

At this point, the tutorial on compiling Caffe under Ubuntu16.04 is over.

CUDA8.0 Configuration Caffe Tutorial under Ubuntu 16.04 system

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.