Caffe CPU version Anaconda3 Python interface installation

Source: Internet
Author: User

Please read the official documentation carefully before installing

Caffer Installation

Caffer Ubuntu Installation

Since the official documentation gives the installation requirements of each version and the meaning of some of the parameters of the config file, not careful enough (of course all the Config parameter meanings are explained in the file), here I am recording the complete process of compiling the Caffe CPU version with Anaconda3 alone.

Environment:

ubuntu 14.04anaconda3python3.5编译版本:纯cpu版
1. Reliance

For the installation of dependent libraries, see the link to the website:

Caffer Ubuntu Installation

2. Configuration

Modify the configuration file as follows:

# # Refer to http://caffe.berkeleyvision.org/installation.html# Contributions simplifying and improving our build system is welcome!# CuDNN Acceleration switch (uncomment to build with CuDNN).# Use_cudnn: = 1# cpu-only switch (uncomment to build without GPU support).Cpu_only: =1# Uncomment to disable IO dependencies and corresponding data layers# Use_opencv: = 0# Use_leveldb: = 0# Use_lmdb: = 0# Uncomment to allow Mdb_nolock when reading LMDB files (only if necessary)# You should no set this flag if you'll be a reading Lmdbs with any# Possibility of simultaneous read and write# Allow_lmdb_nolock: = 1# Uncomment if you ' re using OpenCV 3# Opencv_version: = 3# To customize your choice of compiler, uncomment and set the following.# N.B. The default for Linux are g++ and the default for OSX is clang++# Custom_cxx: = g++# CUDA directory contains Bin/and lib/directories that we need.Cuda_dir: =/usr/local/cuda# on Ubuntu 14.04, if Cuda Tools is installed via# "sudo apt-get install Nvidia-cuda-toolkit" then use this instead:# Cuda_dir: =/usr# CUDA Architecture setting:going with all of them.# for CUDA < 6.0, comment the *_50 lines for compatibility.Cuda_arch: =-gencode arch=compute_20,code=sm_20-gencode arch=compute_20,code=sm_21-gencode arch=compute _30,code=sm_30-gencode arch=compute_35,code=sm_35-gencode arch=compute_50,code=sm_50-gencode ar Ch=compute_50,code=compute_50# BLAS Choice:# Atlas for Atlas (default)# MKL for Mkl# Open for OpenblasBLAS: = Atlas# Custom (Mkl/atlas/openblas) include and Lib directories.# Leave commented to accept the defaults for your choice of BLAS# (which should work)!# Blas_include: =/path/to/your/blas# Blas_lib: =/path/to/your/blas# Homebrew puts Openblas in a directory that's not on the standard search path# Blas_include: = $ (Shell brew--prefix openblas)/include# Blas_lib: = $ (Shell brew--prefix openblas)/lib# This is required only if you'll compile the Matlab interface.# MATLAB directory should contain the MEX binary In/bin.# Matlab_dir: =/usr/local# Matlab_dir: =/applications/matlab_r2012b.app# Note:this is required only if you'll compile the Python interface.# We need to is able to find Python.h and numpy/arrayobject.h.# Python_include: =/usr/include/python2.7 \/usr/lib/python2. 7/dist-packages/numpy/core/include# Anaconda Python distribution is quite popular. Include Path:# Verify Anaconda location, sometimes it's in root.Anaconda_home: = $ (HOME)/opt/anaconda3# Python_include: = $ (anaconda_home)/include \# $ (anaconda_home)/include/python2. 7# $ (anaconda_home)/lib/python2. 7/site-packages/numpy/core/include# Uncomment to use Python 3 (default is Python 2)Python_libraries: = Boost_python3 Python3. 5Mpython_include: = $ (anaconda_home)/include $ (anaconda_home)/include/python3. 5M $ (anaconda_home)/lib/python3. 5/site-packages/numpy/core/include# We need to is able to find libpythonx.x.so or. dylib.# Python_lib: =/usr/libPython_lib: = $ (anaconda_home)/lib# Homebrew installs NumPy in a non standard path (keg only)# Python_include + = $ (dir $ (Shell python-c ' import numpy.core; print (numpy.core.__file__) '))/include# Python_lib + = $ (Shell brew--prefix numpy)/lib# Uncomment to support layers written in Python (would link against Python libs)# With_python_layer: = 1# Whatever Else you find your need goes here.Include_dirs: = $ (python_include)/usr/local/includelibrary_dirs: = $ (python_lib)/usr/local/lib/usr/lib# If Homebrew is installed at a non standard location (for example your home directory) and you use it for general DEP Endencies# Include_dirs + = $ (Shell brew--prefix)/include# Library_dirs + = $ (Shell brew--prefix)/lib# Uncomment to the use of ' Pkg-config ' to specify OpenCV library paths.# (usually not necessary--OpenCV libraries is normally installed in one of the above $LIBRARY _dirs.)# Use_pkg_config: = 1# n.b. Both build and distribute dirs is cleared on ' make clean 'Build_dir: = Builddistribute_dir: = Distribute# Uncomment for debugging. Does not work on OS X due to https://github.com/BVLC/caffe/issues/171# DEBUG: = 1# The ID of the GPU that's ' make runtest ' would use to run unit tests.Test_gpuid: =0# Enable pretty build (comment to see full commands)Q? = @

Main modified Anaconda path (68 lines), Python3 supported PTYHON_LIBRARIES and PYTHON_INCLUDE (74 to 77 rows)

Compile

The project root directory runs the following instruction to compile (-j means to turn on four thread compilations):

make pycaffe -j 4

You may experience the following issues:

CXX .build_release/src/caffe/proto/caffe.pb.ccPROTOC (python) src/caffe/proto/caffe.protoLD -o .build_release/lib/libcaffe.so.1.0.0-rc3CXX/LD -o python/caffe/_caffe.so python/caffe/_caffe.cpp/usr/bin/ld: cannot find -lboost_python3collect2: error: ld returned 1 exit statusmake: *** [python/caffe/_caffe.so] 错误 1

PYTHON_LIBRARIES := boost_python3This library file cannot be found in the system because it is in line 74th of the configuration file boost_python3.lib .

The solution is as follows:

Check if you have the following files:

ls /usr/lib/x86_64-linux-gnu/libboost_python-py34.so

If so, it means that the library file is already in our system, except the file name is different.

cd /usr/lib/x86_64-linux-gnu/sudo ln -s libboost_python-py34.so libboost_python3.so

Recompile to pass.

Test

After entering the Python interpreter environment, use the following command to test whether the installation was successful.

? /home/david/download/caffe-master >python Python 3.5.0 |Anaconda 2.4.0 (64-bit)| (default, Oct 19 2015, 21:57:25) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linuxType "help", "copyright", "credits" or "license" for more information.>>> import caffe

The following error may occur:

Failed to include caffe_pb2, things might go wrong!Traceback (most recent call last):  File "<stdin>", line 1, in <module>  File "/home/david/download/caffe-master/python/caffe/__init__.py", line 4, in <module>    from .proto.caffe_pb2 import TRAIN, TEST  File "/home/david/download/caffe-master/python/caffe/proto/caffe_pb2.py", line 7, in <module>    from google.protobuf import reflection as _reflection  File "/home/david/opt/anaconda3/lib/python3.5/site-packages/google/protobuf/reflection.py", line 68, in <module>    from google.protobuf.internal import python_message  File "/home/david/opt/anaconda3/lib/python3.5/site-packages/google/protobuf/internal/python_message.py", line 848    except struct.error, e:                       ^SyntaxError: invalid syntax

This is because PROTOBUF does not support Python3, the solution is pip install protobuf-py3 to install, a python3.x version of the replacement package.

Caffe CPU version Anaconda3 Python interface installation

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.