Dependencies :

[TIP : Though the official documentation suggests installing Anaconda, it would be better to avoid using the same. The following installation procedure assumes the absence of Anaconda]

OS X 10.10 :
  • Get CUDA 7.0

    • Install CUDA 7.0 (for OSX) from here
    • Install latest standalone CUDA driver from here (apparently, one included in CUDA Toolkit is outdated)
  • Install dependencies via homebrew

    • We will need to edit the OpenCV installation file a bit.

      • brew edit opencv
      • replace the following lines -
      • args « "-DPYTHON#{py_ver}_LIBRARY=#{py_lib}/libpython2.7.#{dylib}"
      • args « "-DPYTHON#{py_ver}_INCLUDE_DIR=#{py_prefix}/include/python2.7"
      • with -
      • args « "-DPYTHON_LIBRARY=#{py_prefix}/lib/libpython2.7.dylib"
      • args « "-DPYTHON_INCLUDE_DIR=#{py_prefix}/include/python2.7"
    • Install snappy, leveldb, gflags, glog, szip, lmdb and opencv.
      • brew install —fresh -vd snappy leveldb gflags glog szip lmdb homebrew/science/opencv
    • Install protobuf.
      • brew install —build-from-source —with-python —fresh -vd protobuf
    • Install boost libraries for python.
      • brew install —build-from-source —fresh -vd boost boost-python
UBUNTU 14.04 :

To be updated.

Download Caffe

Create a directory where you would like to install caffe. For all future reference, this will be called the <caffe-home>
From inside the <caffe-home> directory, execute the following commands :

$> git clone https://github.com/BVLC/caffe.git
$> cd caffe
$> cp Makefile.config.example Makefile.config

Edit the Makefile.config : [Very Imp]

Keep track of all the path variables set in the the Makefile.config (the smallest of mistakes can lead you off track for days together). Here's my complete Makefile.config for the hasty ones here… We'll tackle each step in the upcoming section.

## Refer to http://caffe.berkeleyvision.org/installation.html
# Contributions simplifying and improving our build system are welcome! # cuDNN acceleration switch (uncomment to build with cuDNN).
# USE_CUDNN := 1 # CPU-only switch (uncomment to build without GPU support).
CPU_ONLY := 1 # To customize your choice of compiler, uncomment and set the following.
# N.B. the default for Linux is 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 are 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 arch=compute_50,code=compute_50 # BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
BLAS := 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 # This is required only if you will 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 will compile the python interface.
# We need to be able to find Python.h and numpy/arrayobject.h.
PYTHON_INCLUDE := /usr/include/python2.7 \
/usr/local/lib/python2.7/site-packages/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 \ # We need to be able to find libpythonX.X.so or .dylib.
PYTHON_LIB := /usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/
# PYTHON_LIB := $(ANACONDA_HOME)/lib # Uncomment to support layers written in Python (will link against Python libs)
# WITH_PYTHON_LAYER := 1 # Whatever else you find you need goes here.
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib # Uncomment to use `pkg-config` to specify OpenCV library paths.
# (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)
# USE_PKG_CONFIG := 1 BUILD_DIR := build
DISTRIBUTE_DIR := distribute # Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171
# DEBUG := 1 # The ID of the GPU that 'make runtest' will use to run unit tests.
TEST_GPUID := 0 # enable pretty build (comment to see full commands)
Q ?= @

Now lets look at the file step-by-step.

We leave this part commented out as we wont be using cuDNN in our installation. It speeds up the Caffe processes but for a general (simplistic and working) installation, it can be left out.

# cuDNN acceleration switch (uncomment to build with cuDNN).
# USE_CUDNN := 1

We build caffe without GPU support (following the idea of having a simplistic,working installation).

# CPU-only switch (uncomment to build without GPU support).
CPU_ONLY := 1

Pretty self-explanatory with the comments. This is the path to your local installation of CUDA.

# CUDA directory contains bin/ and lib/ directories that we need.
CUDA_DIR := /usr/local/cuda
# On Ubuntu 14.04, if cuda tools are installed via
# "sudo apt-get install nvidia-cuda-toolkit" then use this instead:
# CUDA_DIR := /usr

You can chose from ATLASMKL, or OpenBLAS for your BLAS choices.
OSX has in-built BLAS libs so leave the BLAS:=atlas (default)

# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
BLAS := 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

Use this only if you need MatCaffe interface for Caffe. Following our idea of simplistic installation, we will skip this part.

# This is required only if you will compile the matlab interface.
# MATLAB directory should contain the mex binary in /bin.
# MATLAB_DIR := /usr/local
# MATLAB_DIR := /Applications/MATLAB_R2012b.app

Now this is a tricky part. To install Caffe with the python interface, PyCaffe (Recommended) you need to give the paths to your python include libs and the path where you have numpy stored. Path to numpy include folder must be given with great caution. You might land into unnecessary trouble by specifying this path incorrectly.

# NOTE: this is required only if you will compile the python interface.
# We need to be able to find Python.h and numpy/arrayobject.h.
PYTHON_INCLUDE := /usr/include/python2.7 \
/usr/local/lib/python2.7/site-packages/numpy/core/include/

This was the most important tweak required to get PyCaffe up and running. You might have different versions of python installed on your local machine and in your homebrew instance. This would lead to problems when importing caffe from your python interpreter. To overcome this problem, make sure that you provide the correct path to your brewed python.

# We need to be able to find libpythonX.X.so or .dylib.
PYTHON_LIB := /usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/

The rest of the parts can be left out as they are not used anyways (commented out) and hold not much importance. You are all set to compile Caffe! Almost there!

Compile :

Now hoping that all the above steps went as planned, we can finally compile Caffe. So keeping your fingers crossed, execute the following from your <caffe-home>:

$> make clean
$> make all
$> make test
$> make runtest

These commands will take a few minutes to execute. I'd suggest you skim through the output of these commands being printed on the stdout and make sure you see no alarming warnings/errors. You might see quite a few warnings of unused variables and parallel threads (-pthread). These are not things you should worry about.

The output of the 'make runtest' command would be somewhat as the image below,

PyCaffe

Now to install and configure the python interface to Caffe, first lets make sure we have all the python dependencies installed. The requirements.txt file handles this list.

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

Now, to compile the PyCaffe interface, from the <caffe-home> do

make pycaffe

IMP : Don't forget to set the PYTHONPATH variable in your ~/.bash_profile (OSX) or ~/.bashrc (Linux) to the caffe python.

export PYTHONPATH=<caffe-home>/python:$PYTHONPATH

Some versions of the official documentation show that the PYTHONPATH variable needs to be set to <caffe-home>/python/caffe, however this is an error in the documentation and the above path should be set.

You might also run the following command to create a distribute directory with all the Caffe headers, compiled libraries, binaries, etc. needed for distribution to other machines.

make distribute

To finally import caffe in the python interpreter, go the python folder in <caffe-home> and execute

$> cd <caffe-home>/python
$> python
Python 2.7.9 (default, Jan 29 2015, 06:27:40)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import caffe

Done!

Now you are all set to rock! Play around with a few examples like Training LeNet on MNIST or see how to use the pre-trained models like ImageNet.

End-Note :

  • Hope this page helps reduce some effort required to install Caffe on your machines. To view our bigger attempts at reducing this overload, checkout the CloudCV organisation page.
  • I have taken references from a lot of sources I found online and one can easily find them through the sources cited in above bullet. This wiki is for educational purposes only.

最完整的mac安装caffe的更多相关文章

  1. 20160512关于mac安装caffe的记录

    记得2015年在mac系统上安装过一次caffe,非常顺利,但是最近群里许多同学反映mac安装caffe出现了各种问题,同时我也在帮助别人安装caffe的时候也遇到了一些坑,不再像以前这么顺利了.估计 ...

  2. 【记录】在MAC上安装caffe

    ---恢复内容开始--- 最近尝试在MAC(OS X 10.11 El Capitan)上安装Caffe 以及Python接口遇到了一些问题但是官方安装教程上并没有提出这些问题的解决办法搜索了很久(主 ...

  3. caffe Mac 安装

    参考了 https://zhuanlan.zhihu.com/p/24853767 安装caffe的依赖项 brew install --fresh -vd snappy leveldb gflags ...

  4. [caffe]linux下安装caffe(无cuda)以及python接口

    昨天在mac上折腾了一天都没有安装成功,晚上在mac上装了一个ParallelDesktop虚拟机,然后装了linux,十分钟就安装好了,我也是醉了=.= 主要过程稍微记录一下: 1.安装BLAS s ...

  5. Docker for mac安装

    Mac安装Docker docker下载地址: https://hub.docker.com/editions/community/docker-ce-desktop-mac docker for m ...

  6. Ubuntu系统---安装Caffe (+OpenCV+Python+CPU-only)

    安装配置Ubuntu14.04+Caffe (+OpenCV+Python+CPU-only) 记录 [作者:Wu Ping.时间:20180428.] 本人已经安装很多次的Caffe了:从开始的初探 ...

  7. 学习Caffe(一)安装Caffe

    Caffe是一个深度学习框架,本文讲阐述如何在linux下安装GPU加速的caffe. 系统配置是: OS: Ubuntu14.04 CPU: i5-4690 GPU: GTX960 RAM: 8G ...

  8. Caffe学习笔记2--Ubuntu 14.04 64bit 安装Caffe(GPU版本)

    0.检查配置 1. VMWare上运行的Ubuntu,并不能支持真实的GPU(除了特定版本的VMWare和特定的GPU,要求条件严格,所以我在VMWare上搭建好了Caffe环境后,又重新在Windo ...

  9. mac安装tensorflow报错

    问题:mac安装tensorflow过程中,爆出oserror:permission denied 解决方案:关闭mac的sip,然后sudo安装 关闭sip的方法:重启mac,按住command+R ...

随机推荐

  1. 在Windows下解决git ERROR: Permission to XXX.git denied to user

    这种情况一般都是由于登陆了不同的git仓库在本地记录了凭证导致的,比如登陆了两个不同的github账号. 1.控制面板 2.删除凭证再重新提交将会重新输入用户名和密码 以上.

  2. 06-python-生成器、循环器

    生成器 生成器(generator)的主要目的是构成一个用户自定义的循环对象. 生成器的编写方法和函数定义类似,只是在return的地方改为yield.生成器中可以有多个yield.当生成器遇到一个y ...

  3. 神兽保佑代码无bug O(∩_∩)O

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...

  4. ico 图标 生成 工具 网站

    http://www.faviconico.org/favicon favicon.ico在线制作,在线Favicon.ico制作转换工具

  5. 雷林鹏分享:jQuery EasyUI 表单 - 表单验证

    jQuery EasyUI 表单 - 表单验证 本教程将向您展示如何验证一个表单.easyui 框架提供一个 validatebox 插件来验证一个表单.在本教程中,我们将创建一个联系表单,并应用 v ...

  6. GEO数据下载分析(SRA、SRR、GEM、SRX、SAMN、SRS、SRP、PRJNA全面解析)

    很多时候我们需要从GEO(https://www.ncbi.nlm.nih.gov/geo/)下载RNA-seq数据,一个典型的下载页面是https://www.ncbi.nlm.nih.gov/ge ...

  7. php根据时间显示刚刚,几分钟前,几小时前的实现代码

    发布时间距现在的时间 function tranTime($time) { $rtime = date("m-d H:i", $time); $htime = date(" ...

  8. python记录_day30 多进程

    1.什么是进程 进程(Process)是计算机中的程序关于某数据集合上的一次运行活动,是系统进行资源分配和调度的基本单位,是操作系统结构的基础. 同一个程序执行两次,就会产生两个进程 ## 进程调度算 ...

  9. 『TensorFlow』SSD源码学习_其四:数据介绍及TFR文件生成

    Fork版本项目地址:SSD 一.数据格式介绍 数据文件夹命名为VOC2012,内部有5个子文件夹,如下, 我们的检测任务中使用JPEGImages文件夹和Annotations文件夹. JPEGIm ...

  10. php缓存机制

    1.全页面静态化缓存 <?php ob_start();//如果php.ini已经开启,那么这里会开启一个新的输出缓冲区; echo "<!DOCTYPE html>< ...