Mac OSX (EI Capitan) builds the Caffe environment and configures the Python interface

Source: Internet
Author: User
Tags install homebrew

Caffe is a clear and efficient framework for deep learning, and the author is a PhD graduate from UC Berkeley Jiayanqing. The Caffe is a pure C++/cuda architecture that supports command line, Python, and MATLAB interfaces, and can be seamlessly switched between CPU and GPU directly. I spent a lot of time configuring the Caffe Environment on Macbookpro (no NVIDIA graphics card), and I spend a great deal of hours configuring its Python interface.

First, download Caffe
On GitHub: https://github.  Com/bvlc/caffe
Makefile.config.example renamed to Makefile.config (My computer's user name is Cuiqi, note the modification)
git clone https://github.com/bvlc/caffe.git/users/cuiqi/downloads/caffe-master & & CP Makefile.config.example Makefile.config
Second, installation-related dependencies

For situations where a Python interface is required, the following dependencies are required


Since my Mac does not have an NVIDIA GPU, I can only use the cpu_only mode and need to modify cpu_only in makefile.config: = 1
2. BLAS via ATLAS, MKL, or Openblas. # Basic Linear Algebra subprograms, basic linear algebra assembly 3. Boost >= 1.55# Deepdream is caffe with Python and therefore requires Boost.python support
Brew Install boost--with-pythonbrew install Boost-python

4. OpenCV >= 2.4 including 3.05. Protobuf, Glog, gflags
Brew Install Protobufbrew install glogbrew install gflags
6. IO Libraries Hdf5, LEVELDB, snappy, Lmdb
Brew Install Leveldbbrew Install Lmdb
Brew Tap Homebrew/sciencebrew Install Homebrew/science/hdf5
# Python driver for Hdf5
Pip Install H5py
7. NumPy for Python
Brew Install NumPy
Third, modify the corresponding path in the Makefile.config

If you want to use Anaconda's Python environment to cancel the comment in Makefile.config, I tried, but it didn't work in CMake:

Python:interpreter:/usr/bin/python2.7 (ver. 2.7.10) Libraries:/usr/lib/libpython2.7.dylib (ver 2.7.10) NumPy:/system /library/frameworks/python.framework/versions/2.7/extras/lib/python/numpy/core/include (ver 1.8.0rc1)

So I gave up using anaconda and changed the python that comes with the system.

Python_include: =/usr/include/python2.7

Because I used homebrew to install NumPy, I modified the numpy path in Makefile.config

Python_include: =/usr/include/python2.7/usr/local/cellar/numpy/1.11.2/lib/python2.7/site-packages/numpy/core/ Include/numpy/core/include

My makefile.config file:

# # Refer to http://caffe.berkeleyvision.org/installation.html# contributions simplifying and improving our build system A Re welcome!# cuDNN acceleration switch (uncomment to build with CuDNN). # use_cudnn: = # cpu-only switch (uncomment to Bui LD without GPU support). Cpu_only: = 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 not set this flag if Y ou'll be reading Lmdbs with any# possibility of simultaneous read and write# allow_lmdb_nolock: = # uncomment If you ' re using OpenCV 3# opencv_version: = 3# To customize your choice of compiler, uncomment and set the following.# n.b. Default for Linux are g++ and the default for OSX is clang++# custom_cxx: = g++# CUDA directory contains Bin/and lib/dire Ctories that we need. Cuda_dir: =/usr/local/cuda# on Ubuntu 14.04, if Cuda tools is installed via# "sudo apt-get installNvidia-cuda-toolkit instead:# Cuda_dir: =/usr# cuda architecture setting:going with all of them.# for CUD  A<6.0, comment The *_50 lines for compatibility. Cuda_arch:=-gencodeArch=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 Arch=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:= $ (ShellBrew--prefix Openblas)/include# blas_lib:= $ (ShellBrew--prefix Openblas)/lib# This was 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 being able to find Python.h and NumPy /arrayobject.h.python_include:=/usr/include/python2.7/usr/local/cellar/numpy/1.11.2/lib/python2.7/site-packages/numpy/core/include/numpy/core/include# Anaconda Python distribution is quite popular. Include path:# Verify Anaconda location, sometimes it's in root.# anaconda_home:= $ (HOME)/anaconda# 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_python3python3.5m# python_include:=/usr/include/python3.5m#/usr/lib/python3.5/dist-packages/numpy/core/include# We need to is able to find libpythonx.x.so or. Dylib. Python_lib:=/usr/lib# Python_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 += $ (ShellBrew--prefix NumPy)/lib# uncomment to support layers written in Python (would link against Python Libs) # with_python_l AYER:= 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 @ a non standard location (for example your home directory) and you Use it for general dependencies# Include_dirs += $ (Shellbrew--prefix)/include# Library_dirs += $ (ShellBrew--prefix)/lib# uncomment to the use of ' pkg-config ' to specify OpenCV library paths.# (usually not necessary--OpenCV L Ibraries 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?= @
View CodeIv. compiling

Using the CMake tool, set the CMake sourcecode to the Caffe path, build the build folder under the Caffe directory, and set the CMake build path to the path of the build, Configure,generate.

This opens the terminal tool into the build directory, make.

Make Allmake testmake runtestmake Pycaffe

If there is no error and all passes, make is over, but it is not certain that you can import in Python.

On the terminal:

VI Etc/profile

Or

sudo vi/etc/profile

Enter the environment variable that modifies the system and caffe/python/ add it to the Python system path:

Export Pythonpath=path to Caffe/python:$PYTHONPATH
For example:
Export Pythonpath=/users/cuiqi/downloads/caffe-master/python: $PYTHONPATH

Terminal input python, confirm that the Python environment is just set in the Makefile.config, you can which Python confirmation. Since I'm not using Anaconda, mine is

/usr/local/bin/python, confirm the path that you just set in Makefile.config.

>>> Import Caffe

# Possible errors

  Importerror:no module named Skimage.io

# Solve

Pip install Scikit-image

Reference: Https://github.com/rainyear/lolita/issues/10?utm_source=tuicool&utm_medium=referral

 

Mac OSX (EI Capitan) builds the Caffe environment and configures the Python interface

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.