Caffe installation and some basic tutorials
This installation focus on the CPU version caffe.
I ran these steps on my macOS 10.12.5 and connected the caffe with python 2.7 which is build-in mac
This installation tutorial bases on the blogs:
https://blog.birkhoff.me/macos-sierra-10-12-2-build-caffe/
https://medium.com/technologymadeeasy/installing-caffe-on-os-x-el-capitan-the-correct-way-4ecb04ef904c
and github:
https://gist.github.com/doctorpangloss/f8463bddce2a91b949639522ea1dcbe4
https://github.com/humphd/have-fun-with-machine-learning
Brew is a very convenient package manager on mac.
"Homebrew installs the stuff you need that Apple didn't" quoted from Brew's website.
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install -vd snappy leveldb gflags glog szip lmdb
brew install hdf5 opencv
brew upgrade libpng
brew tap homebrew/versions
Key the following code in the terminal
brew edit opencv
and replace
args « "-DPYTHON#{py_ver}_LIBRARY=#{py_lib}/libpython2.7.#{dylib}"
args « "-DPYTHON#{py_ver}_INCLUDE_DIR=#{py_prefix}/include/python2.7"
With
args « "-DPYTHON_LIBRARY=#{py_prefix}/lib/libpython2.7.dylib"
args « "-DPYTHON_INCLUDE_DIR=#{py_prefix}/include/python2.7"
You can choose where to install this file on your own. I prefer to install my dependency at my root.
curl -LO https://github.com/google/protobuf/releases/download/v2.6.1/protobuf-2.6.1.tar.bz2
tar xvjf protobuf-2.6.1.tar.bz2
rm protobuf-2.6.1.tar.bz2
cd protobuf-2.6.1
./configure
make
make check
sudo make install
cd python
sudo python2.7 setup.py build
sudo python2.7 setup.py install
brew install --build-from-source -vd boost159 boost-python159
brew link --force boost159
If you encounter the problem that you don't have permission to unlink or like
Homebrew: Could not symlink, /usr/local/bin is not writable
You have to key in the following code to link your boost.
sudo chown -R `whoami`:admin /usr/local/bin
sudo chown -R `whoami`:admin /usr/local/share
P.s. : Pay attention to the path. There may have some difference.
git clone https://github.com/BVLC/caffe.git`
cd caffe
git checkout 20feab5771ae5cbb257cfec85e0b98da06269068
cp Makefile.config.example Makefile.config
We have to change the Command Line Tool, log in apple developer website and download Xcode Command Line Tools for 7.3.
Link: https://developer.apple.com/downloads/
After installation, key in the following code to change the CLT.
sudo xcode-select --switch /Library/Developer/CommandLineTools
cmake -DCPU_ONLY=ON
make -j8 all
sudo -H easy_install pip
If encounter the situation, pkg_resources.DistributionNotFound:
sudo python -m easy_install pip
pip install --user -r python/requirements.txt
sudo -H pip install protobuf
make -j8 pytest
When enconter python2 command not found
cd caffe/CMakeFiles/pytest.dir/build.make
find python2
and replace it into python
Add the code into vim ~/.bash_profile
to guide python to use the correct package path
export PYTHONPATH=~/your/path/to/caffe/python:$PYTHONPATH
Use source ~/.bash_profile
in the terminal to execute change.
python -c 'import caffe'
If there is nothing happened, congrats you finish the installation.
To solve the error
RuntimeError: could not open file caffe/model/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel
cd caffe
scripts/download_model_binary.py models/bvlc_reference_caffenet
1.https://stackoverflow.com/questions/26647412/homebrew-could-not-symlink-usr-local-bin-is-not-writable
2.https://groups.google.com/forum/#!searchin/caffe-users/cmakefiles%7Csort:relevance/caffe-users/ZejVbSP8oLU/8wizK2fjAQAJ
3.https://stackoverflow.com/questions/21151695/broken-easy-install-and-pip-after-upgrading-to-os-x-mavericks
4.BVLC/caffe#4142