Ubuntu 12.04上でCaffeを動かすまでの手順
基本的にはCaffeのページの手順にしたがってインストールを進めればOK。 http://caffe.berkeleyvision.org/install_apt.html
必要ライブラリのインストール
$ sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler $ sudo apt-get install --no-install-recommends libboost-all-dev
CUDAのインストール
$ wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1204/x86_64/cuda-repo-ubuntu1204_7.0-28_amd64.deb $ dpkg -i cuda-repo-ubuntu1204_7.0-28_amd64.deb $ sudo apt-get update $ sudo apt-get install cuda
結構時間がかかった。
ここで一旦Ubuntuを再起動する。
ATLASのインストール
$ sudo apt-get install libatlas-base-dev
残りの必要ライブラリのインストール
glog
$ wget https://google-glog.googlecode.com/files/glog-0.3.3.tar.gz $ tar zxvf glog-0.3.3.tar.gz $ cd glog-0.3.3 $ ./configure $ make $ sudo make install
cmake(入っていない場合、gflagsのインストールに必要)
$ http://www.cmake.org/files/v3.3/cmake-3.3.0-rc4.tar.gz $ tar xzvf cmake-3.3.0-rc4.tar.gz $ cd cmake-3.3.0-rc4/ $ ./bootstrap && make && sudo make install
gflags
$ wget https://github.com/schuhschuh/gflags/archive/master.zip $ unzip master.zip $ cd gflags-master $ mkdir build && cd build $ export CXXFLAGS="-fPIC" && cmake .. && make VERBOSE=1 $ make $ sudo make install
lmdb
$ git clone https://github.com/LMDB/lmdb $ cd mdb/libraries/liblmdb $ make $ sudo make install
Caffeのインストール
今回は ~/caffe/ にインストールする。
$ cd ~/
githubから最新版を取得。
$ wget https://github.com/BVLC/caffe/archive/master.zip
$ unzip master.zip
$ mv caffe-master caffe
$ cd caffe $ make all $ make test $ make runtest
make allに結構時間がかかるので、並列計算も可能。 例えば4スレッドの場合。
$ make all -j4 $ make test -j4 $ make runtest
PythonからCaffeを利用するための設定
$ cd ~/caffe/python
scipyのインストールにgfortranが必要なのであらかじめインストールしておく。
$ sudo apt-get install gfortran
pipを利用して必要ライブラリを一括でインストール。
$ for req in $(cat requirements.txt); do sudo pip install $req; done
numpyをインストール。
$ sudo apt-get install python-numpy
$ cd ~/caffe/
$ make pycaffe
pythonのパスにCaffeを追加する。
$ vi ~/.bashrc # 末尾に追記 export PYTHONPATH=~/caffe/python:$PYTHONPATH
pythonからimportして、エラーがでなければ成功!
$ python
>>> import caffe
(2015/07/27 追記)
libcudart.so.4: cannot open shared object fileというエラーが発生する場合
以下ように~/.bashrcに追記すればOK(64bit版 Ubuntuの場合)。
$ vi ~/.bashrc # 以下の2行を追記 export PATH=$PATH:/usr/local/cuda/bin export LD_LIBRARY_PATH=:/usr/local/cuda/lib64 # ここまで $ . ~/.bashrc