Ubuntu14.04 build Caffe of only CPU) tutorial

  • 2020-05-12 06:46:19
  • OfStack

First of all, I would like to make fun of the notebook of harry potter. The notebook I bought when I was 1 year old is Dell INSPIRON 4010. No Nvidia, no Nvidia, no Nvidia, no Nvidia.

Operating system: Ubuntu 14.04

Whether to use PYTHON API: yes, the goal is that CAFFE can be used as PYTHON MODULE after installation

Hardware: low-end laptop, CPU mode only

1. Install dependencies


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 libgflags-dev 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. Enter python2.7 --version will display the specific version number indicating that it is installed.

But you also need sudo apt-get install python-dev

2. Download Caffe

Using direct download Git Caffe is very simple, or go to https: / / github com/BVLC/caffe download. Since I'm used to looking for code on github, I went straight to the source code I downloaded.

Once the download is complete, caffe-master.zip will be found in the download in the home directory, unzip it in the home directory with the unzip command, and rename it caffe.

3. The compiler Caffe

(1) switch to the directory where Caffe is located


cp Makefile.config.example Makefile.config

(2) modify the configuration file Makefile.config


CPU_ONLY := 1

Configuration 1 some reference files (the added part is mainly to solve the path problem of HDF5 under the new version)


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

Computing power mkl > openlas > atlas

(3) compile Caffe


make all 
make test 
make runtest

In addition, this make by default USES CPU as a single kernel. If I want to go 1 point faster, say I want to use 4 cores, I'll put the -j4 tag after make.

If you want to try again after reporting an error on one of the four lines above, it is recommended to start make clean before starting again.

4. Compile the Python interface

Caffe has the python\C++\shell interface. python is very easy to use in Caffe.

Make sure pip is installed


sudo apt-get install python-pip

Perform installation dependencies

Under the python folder in the caffe root directory, there is a listing file for requirements.txt that lists the required dependent libraries.

When installing the scipy library, you need the fortran compiler (gfortran). If you don't have this compiler, you will get an error, so you can install 1 first.

First go back to the root directory of caffe, and then execute the installation code:


cd ~/caffe
sudo apt-get install gfortran
for req in $(cat requirements.txt); do pip install $req; done

After the installation is complete, we can execute:


sudo pip install -r python/requirements.txt

You will see that if the installation is successful, Requirement already satisfied will be displayed. If the installation is not successful, the installation will continue.

Compile the python interface

make pycaffe
-- the result shows that ALL TESTS PASSED is installed!

Run the python structure


$ python2.7
Python 2.7.12 (default, Jul 1 2016, 15:12:24) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import caffe
>>>

If no error is reported, the installation of caffe is complete!

5. Run Lenet on Mnist

Get data source


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

Since CPU is running, modify lenet_solver.prototxt in solver_mode:CPU under Mnist in examples file


cp Makefile.config.example Makefile.config
0

Training model


cp Makefile.config.example Makefile.config
1

The whole training will last for a long time. This is because the laptop in this video still has the i3 processor, and GPU is not enabled, and the default is single core, so the video has to wait for 3 hours


Related articles: