Skip to content

Instantly share code, notes, and snippets.

@fannheyward
Created February 15, 2019 03:06
Show Gist options
  • Save fannheyward/6a95a70415fc2322b4e47eb945c1f0ed to your computer and use it in GitHub Desktop.
Save fannheyward/6a95a70415fc2322b4e47eb945c1f0ed to your computer and use it in GitHub Desktop.
Install Caffe on macOS.

Install Caffe on macOS

install protobuf 3.5

wget https://github.com/protocolbuffers/protobuf/archive/v3.5.1.zip
unzip v3.5.1.zip
cd protobuf-3.5.1
./autogen.sh
./configure
make
make install

create an virtualenv python2

git clone git@github.com:BVLC/caffe.git
cd caffe

brew install python@2 opencv@3 glog boost@1.59 boost-python@1.59 lmdb hdf5

virtualenv -p $(which python2) .venv
source .venv/bin/activate

cp Makefile.config.example Makefile.config

change Makefile.config, fix used lib path:

CPU_ONLY := 1

USE_OPENCV := 0
OPENCV_VERSION := 3

CUSTOM_CXX := g++

# CUDA_DIR := /usr to disable CUDA

BLAS := open
BLAS_INCLUDE := $(shell brew --prefix openblas)/include
BLAS_LIB := $(shell brew --prefix openblas)/lib

PYTHON_INCLUDE := /usr/local/Cellar/python@2/2.7.15_3/Frameworks/Python.framework/Versions/2.7/include/python2.7 \
	/usr/local/lib/python2.7/site-packages/numpy/core/include

PYTHON_LIB := /usr/local/lib

WITH_PYTHON_LAYER := 1

USE_PKG_CONFIG := 1
make all -j4
make pycaffe
make distribute

pip install -r python/requirements.txt
cp -r distribute/python/caffe .venv/lib/python2.7/site-packages
cp distribute/lib/libcaffe.so.1.0.0 .venv/lib/python2.7/site-packages/caffe/
install_name_tool -change @rpath/libcaffe.so.1.0.0 .venv/lib/python2.7/site-packages/caffe/libcaffe.so.1.0.0 .venv/lib/python2.7/site-packages/caffe/_caffe.so

python -c "import caffe"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment