"Record" Installs Caffe on Mac

Source: Internet
Author: User

---restore content starts---

Recent attempts to install the Caffe on Mac (OS X 10.11 El Capitan) and the Python interface have encountered some problems but the official installation tutorials did not provide a solution to these problems for a long time (mainly on the Python interface) Finally found a way out.

In fact, the installation of Caffe in two steps: Install dependencies + Compile the source code

The first is the installation dependency:

"Necessary dependencies":

Officially recommended to install with homebrew:

brew install -vd snappy leveldb gflags glog szip lmdb# 添加science源来安装 OpenCV 和 hdf5brew tap homebrew/sciencebrew install hdf5 opencv

或者使用Anaconda Python这个工具包含了大量的Python工具包来解决以上依赖问题而且安装新的软件包也特别容易。如果用Anaconda Python的话HDF5已经包含其中了 可以略过。并且opencv这里有两行需要改一下:

brew edit opencv

And then find the following two lines similar to the following (change of his Python path with Anaconda Python instead of the system comes with)

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

Then the boost and Boost-python install this is primarily for the later Python interface compilation

# 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: Online Some people say the system comes with the instability recommended for MKL but I do not change is also available.

Python interface: Download the Caffe from GitHub and then use the command line to enter the Python folder to execute the following command to install Python dependencies:

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

To compile with the make command:

Before compiling we need to modify a few places in Make.config

First remove the make.config.example. Example suffix

Then remove CPU_ONLY := 1 the comment (delete #) because my computer is AMD's graphics card is not able to use cuda so that GPU acceleration is not possible

Then there is the Python path in the back, and the following comment is removed with Anaconda python:

Anaconda_home: = $ (HOME)/anaconda
Python_include: = $ (anaconda_home)/include \
$ (anaconda_home)/include/python2.7 \
$ (anaconda_home)/lib/python2.7/site-packages/numpy/core/include \

This place must be aware that the path is correct according to the configuration of your machine.

Then you can make it.

make allmake testmake runtest
make pycaffe

If there is no error and after running Runtest saw a green pass then congratulations on your installation this time his CPP interface is available, but Python is not necessarily

Put the Caffe/python path into your Pythonpath note/path/to/caffe/python is your Caffe address, notice the change.

Export Pythonpath=/path/to/caffe/python: $PYTHONPATH

Enter Python on the command line try import Caffe if you don't make an error then congratulations. The Python interface is also available for normal use.

Error encountered:

    1. If you are running import Caffe, you are prompted by no module so that your pythonpath has a problem. Notice the change
    2. If you encounter segmentation fault it is possible that there are multiple versions of Python in your system and not a version when compiling and running (usually Boost-python-linked python is the system that comes with Python instead of Anaconda). This time you can force them to use the same python at compile time. Use the Otool-l command to check:
$ 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 need to be changed.

I found on GitHub that there is another workaround, first check the _caffe.so:

    otool -L python/caffe/_caffe.so

     如果他没有链接到你的anaconda Python上那么用下面的命令强制他链接上去就不会有segmentation fault的错误啦:

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

 Reference:
    1.   Caffe offical installation
    2.      Github:Theory of Building Caffe on OS X
    3.      Github Issue#591

       
 

"Record" Installs Caffe on Mac

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.