[Record] install caffe on MAC and record maccaffe

Source: Internet
Author: User

[Record] install caffe on MAC and record maccaffe

--- Restore content start ---

Recently tried MAC (OS X 10.11 El Capitan) I encountered some problems when installing Caffe and Python interfaces, but I did not find a solution to these problems in the official installation tutorial. I searched for a long time (mainly on the Python Interface) and finally found a solution.

In fact, Caffe's installation involves two steps: Install dependency + compile source code

First, install the dependency:

[Necessary dependencies ]:

Homebrew is officially recommended for installation:

Brew install-vd snappy leveldb gflags glog szip lmdb # add science sources to install OpenCV and hdf5brew tap homebrew/sciencebrew install hdf5 opencv

Alternatively, the Anaconda Python tool contains a large number of Python toolkit to solve the above dependency problems and it is particularly easy to install new software packages. If you use Anaconda Python, you can skip this step if HDF5 is included. And there are two lines in opencv that need to be changed:

brew edit opencv

Then, find a line similar to the following and change it to the following (the changed Python PATH uses Anaconda's Python instead of the system's built-in Python path)

  -DPYTHON_LIBRARY=#{py_prefix}/lib/libpython2.7.dylib  -DPYTHON_INCLUDE_DIR=#{py_prefix}/include/python2.7

Then, install BOOST and BOOST-Python to compile the Python interface later.

# with Python pycaffe needs dependencies built from sourcebrew install --build-from-source --with-python -vd protobufbrew install --build-from-source -vd boost boost-python

BLAS part: some people on the Internet say that the system's built-in instability is recommended to be changed to MKL, but I can also use it if I don't change it.

Python interface: Download Caffe from Github, decompress it, and use the command line to enter the Python folder. Run the following command to install Python dependencies:

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

Use the MAKE command to compile:

Before compilation, we need to modify make. config.

First, delete the. example Suffix of make. config. example.

ThenCPU_ONLY := 1Because my computer is an AMD video card and cannot use CUDA, GPU acceleration cannot be implemented.

Then there is the following Python path. Use Anaconda Python to remove the following annotations:

 ANACONDA_HOME := $(HOME)/anaconda
PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
$(ANACONDA_HOME)/include/python2.7 \
$(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include \

In this case, you must pay attention to the correct path according to the configuration of your machine.

Now you can MAKE

make allmake testmake runtest
make pycaffe

If no error is reported and a green pass is displayed after runtest is run, you can use the CPP interface after installing it. However, Python may not.

Put the caffe/python path in your PYTHONPATH. Note that/path/to/caffe/python is your caffe address. Make sure to change it.

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

Enter Python in the command line and try to import caffe. If no error is reported, you can use the Python interface normally.

 

Error:

$ brew info boost...$ otool -L /usr/local/Cellar/boost/1.57.0/lib/libboost_system.dylib # this is one of the libs that caffe links against.../usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.0.0)...$ brew info boost-python...$ otool -L /usr/local/Cellar/boost-python/1.57.0/lib/libboost_python.dylib.../usr/local/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.0)

Note that the version and path of boost and boost-python must be changed.

I found another solution on Github. First, check _ caffe. so:

    otool -L python/caffe/_caffe.so

If he hasn't linked to your anaconda Python, then use the following command to force him to link up without the segmentation fault error:

    install_name_tool -change "libpython2.7.dylib" "$HOME/anaconda/lib/libpython2.7.dylib" python/caffe/_caffe.so

 Reference:
 

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.