Deep LearningのフレームワークであるcaffeをUbuntu 14.04にインストールする。今回、CUDA環境は事前にセットアップ済みを想定しているが、caffeのMakefile.configでCPUを使うようにすればインストールはできるような気もする。
まず、依存するものをインストールする。
$ sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-dev
$sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler
つぎに、caffeをcloneする。
$ git clone https://github.com/BVLC/caffe.git
$ cd caffe
Makefile.configを作成する。
$ cp Makefile.config.example Makefile.config
今回、pipで入れたpythonを使いたかったりもするので、以下のように変更。
$ diff -ub Makefile.config.example Makefile.config
--- Makefile.config.example 2015-07-23 16:17:54.488019582 +0900
+++ Makefile.config 2015-07-23 15:47:17.433038344 +0900
@@ -48,8 +48,10 @@
# NOTE: this is required only if you will compile the python interface.
# We need to be able to find Python.h and numpy/arrayobject.h.
-PYTHON_INCLUDE := /usr/include/python2.7 \
- /usr/lib/python2.7/dist-packages/numpy/core/include
+PYTHON_INCLUDE := $(HOME)/.pyenv/versions/2.7.9/include/python2.7 \
+ $(HOME)/.pyenv/versions/2.7.9/lib/python2.7/site-packages/numpy/core/include
# Anaconda Python distribution is quite popular. Include path:
# Verify anaconda location, sometimes it's in root.
# ANACONDA_HOME := $(HOME)/anaconda
@@ -58,7 +60,8 @@
# $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include \
# We need to be able to find libpythonX.X.so or .dylib.
-PYTHON_LIB := /usr/lib
+PYTHON_LIB := $(HOME)/.pyenv/versions/2.7.9/lib
# PYTHON_LIB := $(ANACONDA_HOME)/lib
# Homebrew installs numpy in a non standard path (keg only)
あとは、ビルドとテストを実行する。
$ make all
$ make test
$ make runtest
特にエラーがなければOK。そして、Pythonでcaffeを使用するための必要なものをpipで入れる。
$ for req in $(cat python/requirements.txt); do pip install $req; done
さらに、Pythonで利用したい場合は
$ make pycaffe
を実行しておく。
以上で完成。