Skip to content

Instantly share code, notes, and snippets.

@krared
Forked from doctorpangloss/install_caffe.sh
Last active October 31, 2016 05:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krared/57dc7be572f3dce327ac17925149d57e to your computer and use it in GitHub Desktop.
Save krared/57dc7be572f3dce327ac17925149d57e to your computer and use it in GitHub Desktop.
Installing Caffe on Mac 10.11.6 and later in the 10.11 series
#!/bin/sh
# Install brew
# Tested on macbook pro 15 2014 w/gt750m | OS X 10.11.6
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# Install XCode 7.3 from the App Store (tested)
# Install XCode command line tools
xcode-select --install
brew install git
# Install CUDA toolkit 8.0 release candidate
# Register and download from https://developer.nvidia.com/cuda-release-candidate-download
# or this path from https://developer.nvidia.com/compute/cuda/8.0/rc/local_installers/cuda_8.0.29_mac-dmg
# Select both the driver and the toolkit, no documentation necessary
# Install the experimental NVIDIA Mac drivers
# Download from http://www.nvidia.com/download/driverResults.aspx/105646/en-us
# Install cuDNN v5 for 8.0 RC or use the latest when it's available
# Register and download from https://developer.nvidia.com/rdp/cudnn-download
# or this path: https://developer.nvidia.com/rdp/assets/cudnn-8.0-osx-x64-v5.0-ga-tgz
# extract to the NVIDIA CUDA folder and perform necessary linking
# into your /usr/local/cuda/lib and /usr/local/cuda/include folders
# You will need to use sudo because the CUDA folder is owned by root
sudo tar -xvf ~/Downloads/cudnn-8.0-osx-x64-v5.0-ga.tar /Developer/NVIDIA/CUDA-8.0/
sudo ln -s /Developer/NVIDIA/CUDA-8.0/lib/libcudnn.dylib /usr/local/cuda/lib/libcudnn.dylib
sudo ln -s /Developer/NVIDIA/CUDA-8.0/lib/libcudnn.5.dylib /usr/local/cuda/lib/libcudnn.5.dylib
sudo ln -s /Developer/NVIDIA/CUDA-8.0/lib/libcudnn_static.a /usr/local/cuda/lib/libcudnn_static.a
sudo rm /usr/local/cuda/include/cudnn.h
sudo cp /Developer/NVIDIA/CUDA-8.0/include/cudnn.h /usr/local/cuda/include/cudnn.h
# Install the brew dependencies
# Do not install python through brew. Only misery lies there
# We'll use the versions repository to get the right version of boost and boost-python
# We'll also explicitly upgrade libpng because it's out of date
# Do not install numpy via brew. Your system python already has it.
brew install -vd snappy leveldb gflags glog szip lmdb libpng
brew install hdf5 opencv
# brew upgrade libpng
brew tap homebrew/versions
brew install --build-from-source --with-python -vd protobuf
brew install --build-from-source -vd boost159 boost-python159
# Clone the caffe repo
cd ~/Documents
git clone https://github.com/BVLC/caffe.git
curl https://dl.dropboxusercontent.com/u/2891540/Makefile.config -o Makefile.config
make -j8 all
# To get python going, first we need the dependencies
# On a super-clean Mac install, you'll need to easy_install pip.
sudo -H easy_install pip
# Now, we'll install the requirements system-wide. You may also muck about with a virtualenv.
# Astonishingly, --user is not better known.
pip install --user -r python/requirements.txt
pip install --user "ipython[all]"
pip install --user "jupyter"
# Go ahead and run pytest now. Horrible @rpath warnings which can be ignored.
make -j8 pytest
# Now, install the package
# Make the distribution folder
make distribute
# Install the caffe package into your local site-packages
cp -r distribute/python/caffe ~/Library/Python/2.7/lib/python/site-packages/
# Finally, we have to update references to where the libcaffe libraries are located.
# You can see how the paths to libraries are referenced relatively
# otool -L ~/Library/Python/2.7/lib/python/site-packages/caffe/_caffe.so
# Generally, on a System Integrity Protection -enabled (SIP-enabled) Mac this is no good.
# So we're just going to change the paths to be direct
cp distribute/lib/libcaffe.so.1.0.0-rc3 ~/Library/Python/2.7/lib/python/site-packages/caffe/libcaffe.so.1.0.0-rc3
install_name_tool -change @rpath/libcaffe.so.1.0.0-rc3 ~/Library/Python/2.7/lib/python/site-packages/caffe/libcaffe.so.1.0.0-rc3 ~/Library/Python/2.7/lib/python/site-packages/caffe/_caffe.so
# Verify that everything works
# start python and try to import caffe
python -c 'import caffe'
# If you got this far without errors, congratulations, you installed Caffe on a modern Mac OS X
# .pydistutils.cfg
# # [global]
# verbose=1
# [install]
# install-scripts=$HOME/bin
# [easy_install]
# install-scripts=$HOME/bin
# pip install -U --user ipython[all]
# export PATH="$HOME/bin:$PATH"
#
git clone https://github.com/google/deepdream.git
cd deepdream
# import os
# >>> os.path
# <module 'posixpath' from '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.pyc'>
# primary source - https://gist.github.com/doctorpangloss/f8463bddce2a91b949639522ea1dcbe4
# http://playittodeath.ru/how-to-install-caffe-on-mac-os-x-yosemite-10-10-4/
# http://caffe.berkeleyvision.org/install_osx.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment