Ubuntu14.04 Build Caffe (CPU only) detailed tutorial _linux

Source: Internet
Author: User
Tags using git gfortran

First spit the Cock's notebook, my current notebook is still a freshman buy the Dell INSPIRON 4010, no nvidia, no NVIDIA, no NVIDIA, no nvidia, important things say four times, hehe.

Operating system: Ubuntu 14.04

Whether to use the Python API: Yes, the target is Caffe can be used as Python module after installation

Hardware: Low-end notebooks, using only CPU mode

1. Installation dependency

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 Libgoogle-glog-dev liblmdb-dev
sudo apt-get install libatlas-base-de

Python requires version 2.7, which is already installed by the operating system itself. The input python2.7--version will display the specific version number description installed.

But it also requires sudo apt-get install Python-dev

2. Download Caffe

Using git to download Caffe is very simple, or go to Https://github.com/BVLC/caffe download. Because I am accustomed to GitHub to find code, so directly to download the source.

Download completed, will be downloaded in the home directory to find Caffe-master.zip, with unzip command to extract the home directory, and then renamed to Caffe.

3. Compile Caffe

(1) Switch to Caffe directory

CP Makefile.config.example Makefile.config

(2) Modify the configuration file Makefile.config

Cpu_only: = 1

Configure some reference files (the addition is mainly to solve the new version of the HDF5 path problem)

Include_dirs: = $ (python_include)/usr/local/include/usr/lib/x86_64-linux-gnu/hdf5/serial 
LIBRARY_DIRS: = $ ( Python_lib)/usr/local/lib/usr/lib/usr/lib/x86_64-linux-gnu/hdf5/serial
BLAS: = Atlas

Computational capability Mkl > Openlas >atlas

(3) Compiling Caffe

Make-all-test-make 
runtest

In addition, this make is by default CPU single core operation, if want to hurry up, for example I want to use four cores, add-j4 tag after make.

If you want to try again after an error in line 4 on a row above, it is recommended to make clean before starting again.

4. Compiling the Python interface

Caffe has a Python\c++\shell interface, which is particularly handy for using Python in Caffe, with an interface description in the instance.

Make sure PIP is installed

sudo apt-get install Python-pip

Performing installation dependencies

Under the Python folder in the Caffe root directory, there is a requirements.txt manifest file that lists the dependent libraries that are needed and is installed on this list.

In the installation of the SciPy library, the need for a FORTRAN compiler (GFORTRAN), if not the compiler will be the error, so we can install first.

First go back to Caffe's root directory, and then execute the installation code:

CD ~/caffe
sudo apt-get install Gfortran for
req in $ (cat requirements.txt), do pip install $req;

After the installation is complete, we can perform:

sudo pip install-r python/requirements.txt

You will see that the installation is successful, will show requirement already satisfied, not installed successfully, will continue to install.

Compiling the Python interface

Make Pycaffe
--The results show all TESTS passed installed!

Running the python structure

$ python2.7
Python 2.7.12 (default, June 1 2016, 15:12:24) 
[GCC 5.4.0 20160609] on linux2
Type ' help ', "Copyrig HT "," credits "or" license "for the more information.
>>> Import Caffe
>>>

If there is no error, instructions Caffe installation complete!

5. Run Lenet in Mnist

Get Data source

./data/mnist/get_mnist.sh
./examples/mnist/create_mnist.sh

Because the CPU is running, so modify the solver_mode:cpu in the Lenet_solver.prototxt under the mnist under the examples file

Solver_mode:cpu

Training model

./examples/mnist/train_lenet.sh

The entire training period lasts a long time, because this cock's laptop is still i3 processor, and the GPU is not enabled, and the default is a single core, so Ben has waited 3 hours.

The above is a small set to introduce the Ubuntu14.04 to build Caffe (CPU only) detailed tutorials, hope to help everyone, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.