Mac OS Mojave(10.14)配置 caffe cpu-only

本文详细介绍了在Mac环境下使用homebrew和Anaconda配置Caffe深度学习框架的全过程,包括安装依赖项如protobuf、OpenCV、HDF5等,以及解决编译过程中可能遇到的错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考桔子毛, @vinthonyvinthony, mlj318, Jimyang1ssa

配置环境homebrew + Anaconda Python 3.7 version

安装步骤

安装依赖项

brew install -vd snappy leveldb gflags glog szip lmdb
brew install hdf5 opencv wget
brew install openblas

安装boost-python@1.59 --without-python@2 --with-python 可能会出错,boost-python3是boost1.68版本,boost@1.69暂时不支持python3

brew install boost-python3

安装protobuf3.5.1

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

配置caffe

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

修改Makefile.config文件:

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

# uncomment to disable IO dependencies and corresponding data layers
USE_OPENCV := 0
USE_HDF5 := 1

# Uncomment if you're using OpenCV 3
OPENCV_VERSION := 3

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

ANACONDA_HOME := $(HOME)/anaconda3
PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
		$(ANACONDA_HOME)/include/python3.7m \
		$(ANACONDA_HOME)/lib/python3.7/site-packages/numpy/core/include

# Uncomment to use Python 3 (default is Python 2)
PYTHON_LIBRARIES := boost_python37 python3.7m
# PYTHON_INCLUDE := /usr/include/python3.5m \
#                 /usr/lib/python3.5/dist-packages/numpy/core/include

# We need to be able to find libpythonX.X.so or .dylib.
# PYTHON_LIB := /usr/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

# If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies
# N.B. both build and distribute dirs are cleared on `make clean`
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 ?= @

修改makefile文件:
PYTHON_LIBRARIES ?= boost_python37 python3.7m

在bash_profile和bashrc中添加python路径:

vi ~/.bash_profile
export PATH="~/anaconda3/bin:$PATH"
source ~/.bash_profile

vi ~/.bashrc
export PATH="~/anaconda3/bin:$PATH"
source ~/.bashrc

编译

cd ~/caffe
make all
make test
make runtest1
make pycaffe
make distribute
在~/caffe/python/caffe目录下生_caffe.so就好了

错误解决


  1. make runtest 如果出现错误dyld: Library not loaded: @rpath/libhdf5_hl.100.dylib,将添加libhdf5_hl.100.dylib所在路径添加到rpath:
    install_name_tool -add_rpath '/Users/lxy/anaconda3/lib' /Users/lxy/caffe/build/tools/caffe
    继续make runtest,报错dyld: Library not loaded:@rpath/libhdf5_hl.100.dylib,再次添加rpath:
    install_name_tool -add_rpath '/Users/lxy/anaconda3/lib' /Users/lxy/caffe/build/test/test_all.testbin ↩︎

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值