LoginSignup
28
30

More than 5 years have passed since last update.

Ubuntu 14.04にCaffeをインストール(GPU編)

Last updated at Posted at 2016-04-12

Caffeの導入手順について。
前に書いたのが結構微妙だったので書き直し。(ChainerばっかでCaffeは使って無いけど。)
前のやつ:Ubuntu14.04にCaffeをインストール(CPUモード)

ubuntu 14.04 上で試しました。
まあ公式HPどおりですが。メモがてら書いてきます。

CUDAのインストール

# 最新版をインストール
$ wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1404/x86_64/cuda-repo-ubuntu1404_7.5-18_amd64.deb
$ sudo dpkg -i cuda-repo-ubuntu1404_7.5-18_amd64.deb
$ sudo apt-get update
$ sudo apt-get install cuda

cuDNN

cuDNNを導入すると速くなるらしい。(NvidiaのDeveloper登録が必要)
入れなくても可。

# 登録してブラウザからダウンロード
$ tar xvf cudnn-7.5-linux-x64-v5.0-rc-tgz
$ sudo cp cuda/include/cudnn.h /usr/local/cuda/include
$ sudo cp cuda/lib64/* /usr/local/cuda/lib64

依存関係のインストール

$ sudo apt-get install libatlas-base-dev libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler

Caffe のダウンロード

# gitが入ってなければ
$ sudo apt-get install git

# home直下に置きます。わかる人は好きなところにどうぞ。
$ cd
$ git clone https://github.com/BVLC/caffe.git

Makefile.config の設定

cudnnを使わないならそのままでOK

$ cd caffe
$ cp Makefile.config.example Makefile.config

cnDNNを使うなら5行目をアンコメントアウト

Makefile.config
# USE_CUDNN := 1

USE_CUDNN := 1

コンパイル

$ make -j4 all のようにすると並列処理ができる。数字はCPUのコア数。
時間がかかるのでフルパワーでやるのがおすすめ。

$ make all
$ make test
$ make runtest

テストが全部パスできればcaffeの環境構築は終了。
失敗した時は、問題を解決してから $make cleanをして$make allからやり直し。

Python でCaffe を使うための環境構築

python系

$ sudo apt-get install python-dev python-pip python-numpy python-skimage gfortran

pipで必要なライブラリのインストール

$ sudo pip install -r ~/caffe/python/requirements.txt

コンパイル

$ make pycaffe

パスを通す。(bashの例)

$ echo 'export PYTHONPATH=~/caffe/python/:$PYTHONPATH' >> ~/.bashrc
# 反映させる
$ source ~/.bashrc

あとは

$ python
>>> import caffe

でcaffeが読み込まれればOK。

28
30
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
28
30