LoginSignup
11
16

More than 5 years have passed since last update.

Raspberry Pi3にTensorFlowをインストールしたので備忘録としてメモっておく

Last updated at Posted at 2017-11-24

はじめに

Raspberry Pi3にTensorFlowをインストールする記事は多々ある。
以下の記載も、参考にさせて頂いた投稿と重なる部分が多い(ほぼ同じでは…)。
ここでは、自分の備忘録としてメモっておくことにする。

TensorFlowのインストール

RaspberryPi用のTensorFlowは用意されていないので、samjabrahams氏のGitHubで公開されているリポジトリを利用する。

samjabrahams/tensorflow-on-raspberry-pi

READMEに従ってインストールしていく。

$ sudo apt-get install python-pip python-dev
$ wget https://github.com/samjabrahams/tensorflow-on-raspberry-pi/releases/download/v1.1.0/tensorflow-1.1.0-cp27-none-linux_armv7l.whl
$ sudo pip install tensorflow-1.1.0-cp27-none-linux_armv7l.whl

mockライブラリは一旦uninstallしてから再度installする。

$ sudo pip uninstall mock
$ sudo pip install mock

OpenCVのインストール

後々、USB接続のwebカメラを接続し、画像をキャプチャするのでOpenCVもインストールしておく。

$ sudo apt-get install python-imaging
$ sudo apt-get install libopencv-dev
$ sudo apt-get install python-opencv

Kerasのインストール

Kerasはpipでインストールする。

$ sudo pip install keras

関連ライブラリもインストールする。
pipでインストールするより、apt-getでインストールしたほうが速いらしい。

$ sudo apt-get install python-scipy
$ sudo apt-get install python-h5py

TensorFlowのチュートリアル

TensorFlowのインストールが完了したのでチュートリアル(MNIST For ML Beginners)をやってみる。
mnist_softmax.pyのコードを1行ずつ解説していく、とあるがいきなり実行してみる。

$ python mnist_softmax.py 
Successfully downloaded train-images-idx3-ubyte.gz 9912422 bytes.
Extracting MNIST_data/train-images-idx3-ubyte.gz
Successfully downloaded train-labels-idx1-ubyte.gz 28881 bytes.
Extracting MNIST_data/train-labels-idx1-ubyte.gz
Successfully downloaded t10k-images-idx3-ubyte.gz 1648877 bytes.
Extracting MNIST_data/t10k-images-idx3-ubyte.gz
Successfully downloaded t10k-labels-idx1-ubyte.gz 4542 bytes.
Extracting MNIST_data/t10k-labels-idx1-ubyte.gz

(中略)
MemoryError

上記の様にMemoryErrorが発生。SWAP領域の容量を増やすことにした。

$ sudo vim /etc/dphys-swapfile

下記の様に"CONF_SWAPSIZE=100"とあり、100MBしか無いので1024MB位に増やしておく。

# where we want the swapfile to be, this is the default
#CONF_SWAPFILE=/var/swap

# set size to absolute value, leaving empty (default) then uses computed value
#   you most likely don't want this, unless you have an special disk situation
CONF_SWAPSIZE=100

設定を変更して保存。

$ sudo /etc/init.d/dphys-swapfile restart
$ swapon -s

SWAP領域が増えたのでMemoryErrorが解消され、MNISTのチュートリアルが実行できるようになった。
ひとまず、TensorFlowのインストールからチュートリアルまでの手順をメモっておく。

11
16
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
11
16