It is an open source framework of Deep Learning, which has been a hot topic recently. It seems that a graduate student of the University of California, Berkeley started making it, it's amazing! The official homepage can be used with here, C ++, Python, and MATLAB, so you can choose the one you are good at. The update is very quick, so it seems interesting to follow the latest information. You can see a demo of image classification from here, so if you are interested, please try it.
When I first started studying Deep Learning, it was a functional language and I usually use it, so I will do Deep Learning with Scala! I tried various things with a sweet idea, but at one point I realized that the number of image processing and machine learning libraries and frameworks was overwhelmingly small compared to languages such as Python. Rather than designing and building a Neural Network from scratch on my own, I wanted to move it anyway, so for the time being I decided to use Caffe, which has a relatively large amount of official documents and information in Japanese (a lot of sample code if you google). Come out). In addition, Caffe basically uses a GPU, but the CPU_ONLY option is also properly prepared, so I'm happy to handle it even for myself who does not have a powerful GPU with MacBook Pro 13inch!
However, there are rumors that it is difficult to build an environment for Caffe, and when I was looking for an easy way, I was grateful that Caffe was already built on Docker Hub containers I found? q = caffe & s = stars) and thought I did it, but most of the CPU mode containers were last updated months ago! I want to use the latest version anyway! So I decided to build it in my local environment. I want to use it in Python, so I'll do my best until I can do PyCaffe (ʻimport caffe` in Python).
There are quite a few, but most of them can be installed at once if homebrew is included.
Python is already included in the Mac, but it seems that the version is old (it often goes wrong with build?), So I put it in a new one with homebrew, this time it is troublesome so I did not use pyenv (actually it is definitely better to use it) ).
brew install python
Next, put them all together with brew!
brew install --fresh -vd snappy leveldb gflags glog szip lmdb
brew tap homebrew/science
brew install hdf5 opencv
I want to do PyCaffe this time, so I'll put this in at once.
brew install --build-from-source --with-python --fresh -vd protobuf
brew install --build-from-source --fresh -vd boost boost-python
Next, clone the Caffe body from the repository and create Makefile.config from the prepared template.
git clone https://github.com/BVLC/caffe.git
cd caffe
cp Makefile.config.example Makefile.config
Rewrite a part of Makefile.
Since the BLAS path changes depending on the Mac version, change the path of the BLAS_INCLUDE
part as follows. Since there are two places, rewrite both for the time being.
BLAS_INCLUDE ?= /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/Headers/
Rewrite Makefile.config in several places.
First uncomment the CPU_ONLY
at the top, which will allow the CPU mode Caffe to be built.
Next, change the path of PYTHON_INCLUDE
and PYTHON_LIB
to python as follows.
Makefile.config
CPU_ONLY := 1
PYTHON_INCLUDE := /usr/include/python2.7 \
/usr/local/lib/python2.7/site-packages/numpy/core/include/
PYTHON_LIB := /usr/local/Cellar/python/{python version}/Frameworks/Python.framework/Versions/2.7/lib/
Now that you're ready to build Caffe, let's build Caffe and run test. -j is the number of parallels when building, the more it is, the faster it will finish.
make clean
make all -j4
make test -j4
make runtest
If the runtest goes well, Caffe build is successful for the time being, then let's do this with PyCaffe. (It seems that make test
fails depending on the version of Xcode, but if make all
passes, you can proceed to the next step by not performing the test.)
Go to the python (caffe / python
) folder in Caffe and pip the libraries you need for PyCaffe at once.
cd python
for li in $(cat requirements.txt); do sudo pip install $li; done
Next, build PyCaffe.
cd ../
make pycaffe
make distribute
Write the following PYTHONPATH in .bashrc or .zshrc.
export PYTHONPATH=/path/to/caffe/python:$PYTHONPATH
This is the end of the installation procedure. After reading with source ~ / .bashrc
etc., try ʻimport caffe` with the Python interpreter, if there is no error, it is successful!
Thanks to homebrew, Caffe was easier to install than I expected, thank you very much.
I'm just starting to play with Caffe, but once I understand how to use it, I'd like to write an article about it as well. Thank you.
Please let me know if you have any problems or improvements.
Recommended Posts