Caffe + Ubuntu 14.04 64bit + CUDA 6.5 configuration instructions

Source: Internet
Author: User
Tags intel mkl nvcc

The author took a long time to install, mainly Cuda installation and OpenCV installation more laborious, Cuda find 32-bit installation package had to reinstall 64-bit Ubuntu system, OpenCV is also trying to solve, it is recommended to use 2.4.9 version. In fact, if the GPU does not need to install CUDA, but for subsequent compatibility considerations, the system is highly recommended 64-bit. The following is a record of their own installation process memo, some of the main reference online articles, so some process directly using the original article content.

Caffe on git Source: Https://github.com/BVLC/caffe

Environment:
Ubuntu 14.04 64-bit
No GPU
preparatory work:
* First verify that you have Nvidia's graphics card (Http://developer.nvidia.com/cuda-gpus this site to see if you have GPU-capable graphics):
$ LSPCI | Grep-i nvidia

* View Linux Distributions
Uname-m && Cat/etc/*release
Look at the first line.

* See GCC version
$ gcc--version

Step1, install Cuda (no GPU installation can skip this step directly, so skip it here.) To illustrate that Cuda 32 bit has not found a suitable installation package, so the Linux here to 64-bit)
* Download the corresponding version on the CUDA website (https://developer.nvidia.com/cuda-downloads#linux).

* After the download is complete, you can install it using the following command, note that the file name is modified to Cuda-repo-ubuntu1404_6.5-14_amd64.deb
$ sudo dpkg-i cuda-repo-<distro>_<version>_<architecture>.deb
(or double-click the downloaded Deb file directly under the graphical interface)

The difference between the Network install and the Local install: one is the file is small, the online update, the file is large, can be installed offline.
(Q:What is the difference between the Network Installer and the Local Installer?
A:The Local Installer have all of the components embedded into it (toolkit, driver, samples). This makes the installer very large, but once downloaded, it can is installed without an Internet connection. The Network Installer is a small executable that would only download the necessary components dynamically during the instal lation so a Internet connection is required.)

After the warehouse file is installed, update the local warehouse:
$ sudo apt-get update
Finally, the installation of Cuda and the graphics driver (the installation of Cuda at the same time the graphics card driver is also installed, this is really convenient.) But the download time is a bit long. )
$ sudo apt-get install Cuda

After installation you need to set environment variables:
$ export Path=/usr/local/cuda-6.5/bin: $PATH
$ export ld_library_path=/usr/local/cuda-6.5/lib64: $LD _library_path

Once setup is complete, you can also choose whether to install the sample code included with Cuda (<dir> indicates where you want to install, you can replace <dir> with ~):
$ cuda-install-samples-6.5.sh <dir>

Next do some verification work (my computer does not have a GPU, so verify skip):
View the driver version of the video card
Cat/proc/driver/nvidia/version
View the version of the NVCC compiler
Nvcc-v I
Sample code to compile Cuda:
CD ~/nvidia_cuda-6.5_samples

Then make a compile code.
Enter the bin path to run Devicequery
CD ~/nvidia_cuda-6.5_samples/bin
./Devicequery


STEP2, pre-installed dependency preparation
Caffe has several dependencies.

CUDA is required for GPU mode.
Library version 7.0 and the latest driver version was recommended, but 6.* was fine too
5.5, and 5.0 is compatible but considered legacy
BLAS via ATLAS, MKL, or Openblas.
Boost >= 1.55
OpenCV >= 2.4 including 3.0
Protobuf, Glog, gflags
IO libraries Hdf5, LEVELDB, snappy, Lmdb

Pycaffe and Matcaffe interfaces have their own natural needs.

For Python caffe:python 2.7 or Python 3.3+, numpy (>= 1.7), boost-provided Boost.python
For MATLAB Caffe:matlab with the Mex compiler.

CuDNN caffe:for fastest Operation Caffe is accelerated by drop-in integration of NVIDIA CuDNN. To your Caffe models, install CuDNN then uncomment the USE_CUDNN: = 1 flag in Makefile.config when installing CAF Fe. Acceleration is automatic. For now CuDNN V1 is integrated and see PR #1731 for v2.

Cpu-only caffe:for cold-brewed cpu-only Caffe Uncomment the cpu_only: = 1 flag in Makefile.config to configure and build Caffe without CUDA. This is a helpful for cloud or cluster deployment.
(The final step is explained before compiling Caffe)

Specific operation:
The following 3 should be in the build-essential, but here is the safe side, I first loaded.
sudo apt-get install g++
sudo apt-get install git
sudo apt-get install Freeglut3-dev
Build-essential:
sudo apt-get install build-essential
sudo apt-get update
Install Atlas for Ubuntu:
# sudo apt-get install Libatlas-base-dev
# sudo apt-get install Libprotobuf-dev
# sudo apt-get install Libleveldb-dev
# sudo apt-get install Libsnappy-dev
# sudo apt-get install Libopencv-dev
# sudo apt-get install Libboost-all-dev
# sudo apt-get install Libhdf5-serial-dev
# sudo apt-get install Libgflags-dev
# sudo apt-get install Libgoogle-glog-dev
# sudo apt-get install Liblmdb-dev
# sudo apt-get install Protobuf-compiler

Install OpenCV:
# CD ~/caffe
# git clone Https://github.com/jayrambhia/Install-OpenCV
# CD Install-opencv/ubuntu
# sudo./dependencies.sh
# CD 2.4
# sudo sh./opencv2_4_9.sh
* Here are a few things to note, but also a pit that took a long time to settle:
First, the source of 2.4.8 can not be found, so do not use 2.4.8
Second 2.4.10 compile has the problem, but can try to solve under, here useless
It's best not to put it on your own, because there's a lot of reliance, go
git clone Https://github.com/jayrambhia/Install-OpenCV
or Https://github.com/jayrambhia/Install-OpenCV can download the script.
The newest one here is 2.4.9, if you want to install 2.4.10, copy the script to make the corresponding changes.
* Because wget opencv2.4.9.zip source file is very slow, here is the way to sourceforge corresponding download page, select a different server to download the image, you can download to the local, note that at the same time modify the corresponding script, the wget commented out.
Make OpenCV will be error, here the script CMake replaced by the following:
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_cublas=off-d with_cuda=off-d With_cufft=off.
That is, add the last 3, compile OK, and then continue.

Step3: Compiling Caffe
Download Caffe installation package,: Https://github.com/BVLC/caffe
Unzip the package, unzip the command:
unzip/home/liuxiabing/Download/caffe-master.zip
Note: If there is an error in the decompression location, you can use the following command to delete the directory and all subdirectories:
sudo rm-rf caffe-master

Enter the Caffe root directory, first copy the Makefile.config, command:
CP Makefile.config.example Makefile.config

Then modify the contents, the main parameters to be modified include:
Cpu_only is only using CPU mode, because I do not have Nvidia's graphics card, there is no cuda, so I need to open this option.
Some of the remaining configurations can be modified as needed:
BLAS (using Intel MKL or Openblas)
Matlab_dir If you need to use MATLAB wrapper you need to specify the installation path of MATLAB, such as my path is/usr/local/matlab/r2013b (note that the directory needs to include the Bin folder, The Bin folder should contain the MEX binaries)
If debug is using debug mode, open this option to debug the program in Eclipse or Nsight

When the above settings are complete, start compiling:
Make All-j4
Make Test
Make Runtest

Note:-j4 refers to the use of several threads at the same time to compile, can speed up, j after the number can be based on the number of CPU core to determine, if the CPU is 4 cores, the parameter is-J4, you can not add this parameter, directly use "make all", so the speed may be a bit slower.

STEP4: Testing with a mnist data set
* Run the Download data script when found Mnist data site cannot open, fortunately before in the UFLDL experiment saved a copy of the mnist data set, put in the Data/mnist directory renamed the Last direct run OK.
Testing with a Mnist dataset
CAFFE By default will be installed in $caffe_root, that is, the extracted directory, for example: $ home/username/caffe-master, so the following work,
The working directory has been switched to this by default. The following work is mainly to test whether the Caffe is working properly and does not perform a detailed evaluation. Please refer to the website for specific settings:
Http://caffe.berkeleyvision.org/gathered/examples/mnist.html
(1) Data preprocessing
Can be downloaded with a good data set, you can re-download, the specific operation of the direct download is as follows:
$ CD Data/mnist
$ sudo sh./get_mnist.sh

(2) To rebuild the ldb file, is to process the binary data set for caffe recognition of the data set, all future data, including the JPE file to be processed into this format, execute the command as follows:
$ sudo sh./examples/mnist/create_mnist.sh

Generate mnist-train-leveldb/and mnist-test-leveldb/folders, which contain data sets in LDB format
Note: The new Caffe will need to be executed from the root directory if executed using the following command:
# CD Examples/mnist
# sudo sh./create_mnist.sh

You may encounter this error:./create_mnist.sh:16:./create_mnist.sh:build/examples/mnist/convert_mnist_data.bin:not found
(3) Training mnist
If there is no GPU, only the CPU, you need to modify the Examples/mnist directory Lenet_solver.prototxt file, the Solver_mode:gpu to SOLVER_MODE:CPU, the result is as follows:
# Solver MODE:CPU or GPU
Solver_mode:cpu

Modify can use the VI Edit command, if it is read-only files, cannot be edited, you can use the sudo command, such as:
sudo vi lenet_solver.prototxt

First enter the command mode, use a to enter the editing mode, after modifying, use ESC to exit the edit mode, enter the last line mode, and then use ": Wq" to save the changes and exit (": q!" To exit without saving changes)
After the modification is complete, execute the following command to train:
$ CD Examples/mnist
$ sudo sh./train_lenet.sh

The final trained model is stored as a binary protobuf file, and it takes about 20 minutes to train such datasets in CPU mode, which is slower. At this point, all Caffe installation steps are completed.

Reference:
Official Installation Documentation:
Http://caffe.berkeleyvision.org/installation.html
caffe+ubuntu14.0.4 64bit Environment Configuration instructions (no Cuda,caffe running on the CPU):
http://blog.csdn.net/liuxiabing150/article/details/42503389
(* Note the configuration without GPU mode)
New Ubuntu 14.04 System installation Caffe:
http://www.rthpc.com/plus/view.php?aid=356
New Ubuntu 14.04 System installation Caffe (using MKL)
http://www.rthpc.com/plus/view.php?aid=375
Instructions for installing CUDA:
http://blog.csdn.net/xizero00/article/details/43227019
Automatically install the OpenCV script:
Https://github.com/jayrambhia/Install-OpenCV
Caffe Installation Instructions Reference:
Http://www.cnblogs.com/platero/p/3993877.html
Caffe installation Configuration (CentOS + no GPU):
http://www.tuicool.com/articles/uiuA3e
Caffe + Ubuntu 14.04 64bit + CUDA 6.5 configuration instructions:
Http://www.cnblogs.com/platero/p/3993877.html

Caffe + Ubuntu 14.04 64bit + CUDA 6.5 configuration instructions

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.