Mac OS 10.12安装caffe的步骤记录

准本工作:

1、安装Xcode,MacOS下的编译工作需要用到,如果没有安装,可以到AppStore里进行安装

2、Python 可以不用安装,系统自带了2.7版本的python

3、brew,这个是个智能化的安装工具,非常好用,如果没有安装可以用下面的方法来安装

ruby -e "$(curl --insecure -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

在我电脑执行上述命令的时候遇到了无法连接github的的问题

==> Downloading and installing Homebrew...
fatal: unable to access 'https://github.com/Homebrew/brew/': Empty reply from server
Failed during: git fetch origin master:refs/remotes/origin/master --tags --force

解决方法:

sudo vi /etc/hosts

在文件的末尾加入如下内容

192.30.253.113	github.com

安装依赖包:

brew install -vd snappy leveldb gflags glog szip lmdb
# 官方指导下面这句需要,但实际上不需要,可以直接安装后面的依赖包了
brew tap homebrew/science
brew install hdf5 opencv
brew install --build-from-source --with-python -vd protobuf
brew install --build-from-source -vd boost boost-python
BLAS:Mac自带BLAS,无需安装。


编译caffe

git clone https://github.com/BVLC/caffe
cd /Users/XXX/caffe #caffe的下载地址
cp Makefile.config.example Makefile.config
需要修改Makefile.config : 

1. 将 CPU_ONLY := 1的注释去掉,这样Caffe就只能在CPU上运行了

开始编译

make all
make test
make runtest

我在编译过程中遇到了opencv无法链接的问题,提示如下

Undefined symbols for architecture x86_64:
  "cv::imread(cv::String const&, int)", referenced from:
      caffe::WindowDataLayer<float>::InternalThreadEntry() in window_data_layer.o
      caffe::WindowDataLayer<double>::InternalThreadEntry() in window_data_layer.o
      caffe::ReadImageToCVMat(std::string const&, int, int, bool) in io.o
  "cv::imdecode(cv::_InputArray const&, int)", referenced from:
      caffe::DecodeDatumToCVMat(caffe::Datum const&, int, int, bool) in io.o
ld: symbol(s) not found for architecture x86_64

这个问题我到stackoverflow上查到了答案

cv::imread(cv::String const&, int) 依赖于 libopencv_imgcodecs.dylib 但是Makefile缺失这个依赖项目,在Makefile里加入对opencv_imgcodecs 等相关内容的依赖即可,具体如下

LIBRARIES += glog gflags protobuf leveldb snappy \
        lmdb \
        boost_system \
        hdf5_hl hdf5 \
        opencv_imgcodecs opencv_highgui opencv_imgproc opencv_core pthread

加入上述内容后运行make all即可成功编译caffe

最后运行完毕make runtest


大功告成!

猜你喜欢

转载自blog.csdn.net/jdx0909/article/details/79595889