1.首先安装homebrew工具,相当于Mac下的yum或apt

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

2.安装Caffe依赖

$ brew install -vd snappy leveldb gflags glog szip lmdb
$ brew tap homebrew/science
$ brew install hdf5 opencv
$ brew install protobuf boost

3.下载Caffe源码

$ git clone https://github.com/bvlc/caffe.git
$ cd caffe/
$ mv Makefile.config.example Makefile.config
修改Makefile.config,打开CPU_ONLY选项,保存。

4.编译

make -j

5.测试安装是否成功

5.1下载数据
./data/ilsvrc12/get_ilsvrc_aux.sh

该文件中有 wget

5.2 下载模型
$ cd ../../models/bvlc_reference_caffenet/
$ curl http://dl.caffe.berkeleyvision.org/bvlc_reference_caffenet.caffemodel > bvlc_reference_caffenet.caffemodel

5.3 运行例子

回到根目录:
运行命令:

./build/examples/cpp_classification/classification.bin models/bvlc_reference_caffenet/deploy.prototxt  models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel  data/ilsvrc12/imagenet_mean.binaryproto  data/ilsvrc12/synset_words.txt  examples/images/cat.jpg 

结果:

---------- Prediction for examples/images/cat.jpg ----------
0.3134 - "n02123045 tabby, tabby cat"
0.2380 - "n02123159 tiger cat"
0.1235 - "n02124075 Egyptian cat"
0.1003 - "n02119022 red fox, Vulpes vulpes"
0.0715 - "n02127052 lynx, catamount"