"Brew coffee 1" Linux Caffe Compilation and Python environment configuration notes

Source: Internet
Author: User
Tags curl lapack automake

Caffe is a deep learning library, believe in deep learning, not to use this library is to use Theano bar. The first step to using Caffe is to configure the Caffe environment. Here, I am mainly talking about how to configure the Caffe library in the Debian Linux environment. Because Python is easy to write programs, at the end of the article, I'll also specify how to configure the Python environment. This article is my original, part of the content of the network, if there is a problem please contact me to delete. Non-profit website reprint please at the beginning of the article famous article 77695, source http://www.cnblogs.com/cj695/. For the profit-making website, please contact the author and contact us at the back of the article. If not contacted, I will recover the corresponding remuneration through all possible and lawful means. Please keep this statement when reproduced.

1. Pre-preparation

first download the Caffe library from GitHub: Https://github.com/BVLC/caffe , unzip, get these things

Use this phrase to create a copy of the Makefile.config

The next step is to modify the Makefile.config, the corresponding comments in this document is very clear, which need, bar corresponding to the previous "#" to remove the good

First take make all test, the error is as follows:

MAKE:PROTOC: Command not found
Make: * * * [. build_release/src/caffe/proto/caffe.pb.h] Error 127

2. Compiling and installing PROTOC

download protobuf, download it on GitHub, unzip it Https://github.com/google/protobuf :

Run

$ ./autogen.sh

originally to install Curl: The amount, it seems that curl installation is not successful then skip it. Because Curl is the role of prayer is to download the file, but https://googletest.googlecode.com/files/gtest-1.7.0.zip This thing or to be next, then download it directly, may need science to surf the net, this method that eight Immortals crossing each show province pass, I do not repeat.

Download the package and move the archive back in the past.

Find the corresponding position comment out Curl

Run again, prompt for errors

./autogen.sh:40:./autogen.sh:autoreconf:not found

The reason is that the Automake tool is not installed

Run command installation: sudo apt-get install autoconf automake libtool

Once again./autogen.sh, Success! Then run the following command in turn

$ ./configure$ make$ make check$ make install
执行完make check以后出现:

This means that there is no problem, so you can continue with the make install

After execution, switch to the Caffe directory, make a clean first, then make all

Or you are prompted to find the library,

3. Install a series of dependent libraries

Then install some libraries: sudo apt-get install Libprotobuf-dev libleveldb-dev libsnappy-dev Libopencv-dev Libboost-all-dev Libhdf5-serial-dev, wait a minute.

Then do clean, then make all, prompting:

./include/caffe/common.hpp:5:27:fatal Error:gflags/gflags.h: There is no file or directory. It means that Protobuf's library is almost there.

4, Installation GFlags

here continue to install GFlags: Https://github.com/schuhschuh/gflags/archive/master.zip download. Unzip

CD gflags-master mkdir build && CD Build Export cxxflags= "-fpic" && cmake: && make verbose=1 Makes sudo make install may prompt for a lower version when executing the third sentence, right here

http://www.cmake.org/install/

Download the latest version of the CMake (download. sh files to run directly on it). To configure environment variables

Then proceed to the following two commands, just fine. When you're done, go ahead and switch to the Caffe directory, make a clean first, then make all

./include/caffe/util/mkl_alternate.hpp:11:19:fatal error:cblas.h: No file or directory
Compilation terminated.

Description Gflag installation was successful,

5. Compiling and installing Atlas

The next step is to fix the cblas problem. BLAS(Basic Linear Algebra subprograms, basic linear Algebra assembly) is an application interface (API) standard. There are many implementations of Caffe, with three implementations of Atlas, MKL, or Openblas. Here I'm going to use Atlas:http://sourceforge.net/projects/math-atlas/ files/ First download, unzip. According to the official documentation, execute the following command in turn

First select the high-performance CPU mode:

/usr/bin/cpufreq-selector-g Performance then create the folder in the Atlas directory mkdir LINUX_C2D64SSE3 # Create Blddir cd linux_c2d64sse3 # Enter Blddir

.. /configure-b -D c-dpentiumcps=2800 -fa alg-fpic--with-netlib-lapack-tarfile=/home/haiyu/ Programs_install/lapack-3.5.0.tgz --prefix=/usr/local/atlas
The bold parameters
need to be modified according to the personal system:
-b Specifies the type of the compiled library (32-bit library or 64-bit library)
-D C-dpentiumcps is to specify the clock frequency of your CPU, which can be obtained by grep Mhz/proc/cpuinfo
-FA Alg-fpic Get location-independent code to generate a dynamic shared library
--prefix is the installation path
--with-netlib-lapack-tarfile is the Lapack compressed package path

Make build # tune & Build lib do check # sanity check correct answer make Ptcheck # sanity check parallel make time # Check if Lib is fast do install # Copy libs to install Dir

a lapack library is also needed here to download http://www.netlib.org/lapack/ , you can simply replace the/home/whaley/dload/lapack-3.4.1.tgz with the corresponding path after downloading .

In execution: /configure, you will be prompted Gfortran: command not found, directly with the Apt-get installation. Then make build and you can take a break. Wait one hours to see it again.

Ok.. It's the next day. I finally saw it at 3 o'clock in the morning last night and it prompted done. This speed. Too! "Quick"! The Proceed to the next command a few can be ignored, and then switch to the Caffe directory make Clean/all, still prompt

But this time there are already include/cblas.h under the specified installation path of the ATLA prefix

Execute these two, add directory to include environment variable

6, Installation Lmdb

Next make, error Lmdb not installed

git clone git://gitorious.org/mdb/mdb.git

CD Mdb/libraries/liblmdb

Make && make install

Run out and go back to Caffe directory compilation

Tips :

Ar-o. Build_release/lib/libcaffe.a
Ld-o. build_release/lib/libcaffe.so
/usr/bin/ld:cannot Find-lcblas
/usr/bin/ld:cannot Find-latlas
Collect2:error:ld returned 1 exit status

7. Install other dependent packages

Workaround: Install these packages

Apt-get Install Libatlas-dev
Apt-get Install Liblapack-dev
Apt-get Install Libatlas-base-dev

Problem solving

This error is also indicated. build_release/lib/libcaffe.so:undefined reference to ' Google::p rotobuf, recompile protobuf

Make Uninstall
Make clean

./configure --prefix=/usr
make
make checkmake install
搞定,返回caffe,编译成功!!!!!!!!!!!!!此处有掌声!!!!!

Then add the directory to the Python environment variable.

Export pythonpath= $PYTHONPATH:/home/cj695/protobuf/python/
And finally find the Protobuf python directory.

python setup.py buildpython setup.py testpython setup.py install
安装一下
激动人心的一颗来了!!!!!!!!!!!打开python,import caffe。。这一刻,我哭了!!!!!!!!!!!!!
8. Summarize
耗费两天时间,卡时间比较多的主要有两个地方,首先查错一定要从上往下查。基本上最上面的错误才是最根本的错误;其次,在安装过程中对配置做过的修改一定要记清楚,别自己把安装路径改了结果还不知道是怎么回事。

In addition, if there is a problem when installing gflags, you can experiment with Apt-get to install Gflag, the command is as follows:

sudo apt-get install Python-gflags

Caffe configuration is probably the same content, I hope this article can be of some help to you

"Brew coffee 1" Linux Caffe Compilation and Python environment configuration notes

Related Article

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.