The deep learning framework Caffe is compiled and installed in Ubuntu.

Source: Internet
Author: User

The deep learning framework Caffe is compiled and installed in Ubuntu.

The deep learning framework Caffe features expressive, fast, and modular. The following describes how to compile and install Caffe on Ubuntu.

1. Prerequisites:
  • CUDA is used for computing in GPU mode.
    • We recommend that you use the latest version above 7.0.
  • BLAS via ATLAS, MKL, or OpenBLAS.
  • Boost >=1.55
  • protobuf,glog,gflags,hdf5
Optional dependent software packages:
  • OpenCV >=2.4 including 3.0
  • IO libraries:lmdb,leveldb(Note: leveldb requiressnappy)
  • CuDNN for GPU acceleration (v3)
Programming Interface:

Pycaffe and Matcaffe have their respective requirements:

  • For Python Caffe:Python 2.7OrPython 3.3+,numpy (>= 1.7), Boost-providedboost.python
  • For MATLAB Caffe: MATLAB withmexCompiler
Compiled version:

CuDNN Caffe: supports fast CUDA and cuDNN operations

CPU-only Caffe: No CUDA support, only CPU is used. It can be used for cloud and cluster deployment.

2. Compile

Install the dependency package (boost andprotobuf,glog,gflags,hdf5):

1 sudo apt-get install libboost-all-dev libprotobuf-dev protobuf-compiler libhdf5-serial-dev libgflags-dev libgoogle-glog-dev

Install the dependency package (atlas ):

1 sudo apt-get install libatlas-base-dev

Install the dependency package (CUDA ):

Download URL: CUDA

CUDA has several installation methods. Due to the large file size and domestic sources, you can choose to install it from the network.

Download the corresponding installation package, such as my cuda-repo-ubuntu1504_7.5-18_amd64.deb. Run the following command:

123 sudo dpkg -i cuda-repo-ubuntu1504_7.5-18_amd64.debsudo apt-get updatesudo apt-get install cuda

Set LD_LIBRARY_PATH, the simplest way is in your/etc/profile or ~ /. Add the following statement to the bashrc file:

Export LD_LIBRARY_PATH =/usr/local/cuda/lib64: $ LD_LIBRARY_PATH
  

Or execute the commandSudo vi/etc/ld. so. conf. d/cuda. conf. Add the following content to the file:

/Usr/local/cuda/lib64

Then run the following command:

1 sudo ldconfig

Install optional packages (IO libraries:lmdb,leveldb(Note: leveldb requiressnappy) And opencv ):

1 sudo apt-get install libleveldb-dev libsnappy-dev liblmdb-dev libopencv-dev

Install CUDNN:

Download URL: CUDNN (requires registration application and approval before downloading)

Decompress the downloaded file and copy include and lib64 to the/usr/local/cuda directory.

Run the following command to modify the link file:

1234 cd /usr/local/cuda/lib64rm -rf libcudnn.so libcudnn.so.4ln -s libcudnn.so.4.0.4 libcudnn.so.4ln -s libcudnn.so.4 libcudnn.so

 

Get source code:

?
1 git clone git://github.com/BVLC/caffe.git

 

Add and modify the compilation Configuration:

?
1 cp Makefile.config.example Makefile.config<br>vi Makefile.config

A. Enable CUDNN and remove "#"

USE_CUDNN: = 1

B. Configure some reference files (the added part mainly solves the HDF5 Path Problem in the new version)

INCLUDE_DIRS: = $ (PYTHON_INCLUDE)/usr/local/include/usr/lib/x86_64-linux-gnu/hdf5/serial/include

LIBRARY_DIRS: = $ (PYTHON_LIB)/usr/local/lib/usr/lib/x86_64-linux-gnu/hdf5/serial

C. Enable opencv3. If you use opencv> = 3.0.0

OPENCV_VERSION: = 3

Otherwise, an error "'cv: imdecode (cv: _ InputArray const &, int)' undefined reference" will be reported during compilation"

Execute the following command to compile:

123 make all -j4make test -j4make runtest -j4
  • To compile and use cuDNN acceleration, In the Makefile. config file, SetUSE_CUDNN := 1
  • To compile the CPU-only Caffe version, in the Makefile. config file, SetCPU_ONLY := 1 

To compile Python and MATLAB packages, usemake pycaffeAndBefore compiling the make matcaffe command, make sure thatMakefile.configIn the file, set the path of MATLAB and Python.

To install and use pycaffe, you must install the corresponding python dependency package. You can enter python and run the following command to install python:

1 for req in $(cat requirements.txt); do pip install $req; done

Note: The python package may fail to be installed because the corresponding cpp version is missing. For example, if my machine fails to install pyyaml, run the following command to install libyaml:

1 sudo apt-get install libyaml-cpp-dev

 Run the following command to compile pycaffe:

1 make pycaffe -j4

After installation, if you want to import caffePython module, add the module path to your environment variable$PYTHONPATH. For example, in your ~ /. Add the following line to bashrc:

    export PYTHONPATH=/path/to/caffe/python:$PYTHONPATH

3. test and install

Run mnist to verify that caffe is properly installed:

1. data preprocessing

1 data/mnist/get_mnist.sh

2. Recreate the lmdb file. Caffesupports multiple data format input networks, including elastic image(.jpg,. png, etc.), leveldb, lmdb, HDF5, and so on. Select different input types as needed.

12 examples/mnist/create_mnist.sh  

Generate the mnist-train-lmdb and mnist-train-lmdb folders, which contain datasets in the lmdb format.

3. Training mnist

1 examples/mnist/train_lenet.sh

Install the OpenCV3.1 + Caffe software in the open2014a + Anaconda2 + OpenCV3.1 + Ubuntu 16.04

How to configure Caffe in CUDA7.5 in Ubuntu 16.04

Caffe installation in 64-bit Ubuntu 14.04

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.