Raspberry Pi で Tensorflow [Raspberry Pi]
Raspberry Pi で Deep Learning の Tensorflow を動かしてみる。
まずはインストール
ここを見て、Raspberry Pi で動くバイナリパッケージのダウンロードの仕方を見ておく。
Python3 が入っているので Python3用のパッケージをダウンロードする。
% wget https://github.com/samjabrahams/tensorflow-on-raspberry-pi/releases/download/v1.1.0/tensorflow-1.1.0-cp34-cp34m-linux_armv7l.whl
そしてインストールしてみると、
% sudo pip3 install tensorflow-1.1.0-cp34-cp34m-linux_armv7l.whl
tensorflow-1.1.0-cp34-cp34m-linux_armv7l.whl is not a supported wheel on this platform.
エラーになった。
どうやらダウンロードしたパッケージは Python3.4 用だけど、
インストールされている Python は Python3.5 ということが判明。
ソースからビルドしてもいいけど、今の目的は「とりあえず使ってみる」なので、
Python2.7用のバイナリパッケージを使うことにしてみた。
ダウンロードしてインストールする。
% 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
今度は問題なくインストール完了。
インストール方法を見てみると、下記もやっておけと書いてあるので、やっておく。
% sudo pip uninstall mock
% sudo pip install mock
動くか確認
hello_tf.py というファイルを作って、期待通り動くかを確認する。
% vi hello-tf.py
======
#hello-tf.py
import tensorflow as tf
import multiprocessing as mp
core_num = mp.cpu_count()
config = tf.ConfigProto(
inter_op_parallelism_threads = core_num,
intra_op_parallelism_threads = core_num )
sess = tf.Session(config=config)
hello = tf.constant('hello tensorflow')
print sess.run(hello)
a = tf.constant(10)
b = tf.constant(32)
print sess.run(a+b)
======
そして実行
% python hello-tf.py
下記のように表示されれば問題なく動いたことになる。
hello tensorflow
42
サンプルの画像分類を試す
Tensorflowにサンプルで用意されている画像分類を試してみる。
既に学習まで終わった状態で提供されているので、すぐに動かして試してみることが出来る。
ただ、ネットで少し検索するとTensorflowをインストールすると
~/tensorflow/tensorflow/models/image/imagenet/classify_image.py ファイルが出来ていると
書いてあるが探してみても見つからない。
どうやらTensorflow 1.1 ではパッケージには同梱されていない様子。
よって、gihubから
classify_image.py をダウンロードしてきた。
% mkdir imagenet
% cd imagenet
% wget https://raw.githubusercontent.com/tensorflow/models/master/tutorials/image/imagenet/classify_image.py
初めの1回目は学習済みデータのダウンロードが行われてから、パンダの画像を使って
パンダと認識するかが実行される。
% python classify_image.py
>> Downloading inception-2015-12-05.tgz 100.0%
Successfully downloaded inception-2015-12-05.tgz 88931400 bytes.
giant panda, panda, panda bear, coon bear, Ailuropoda melanoleuca (score = 0.89107)
indri, indris, Indri indri, Indri brevicaudatus (score = 0.00779)
lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens (score = 0.00296)
custard apple (score = 0.00147)
earthstar (score = 0.00117)
89%の確率でパンダであると認識できた。
学習済みデータは Raspberry Pi を再起動すると消えてしまうので、ローカルに移動して
実行できるか試してみる。
% mv /tmp/imagenet/ .
% python classify_image.py --model_dir imagenet/ --image_file imagenet/cropped_panda.jpg
これで、ローカルにある学習データを使って画像の分類が出来た。
ネットからいくつか画像データをダウンロードして、試してみた。
猫画像
% python classify_image.py --model_dir imagenet/ --image_file cat_1.jpg
Egyptian cat (score = 0.49180)
tiger cat (score = 0.25432)
tabby, tabby cat (score = 0.14356)
lynx, catamount (score = 0.03078)
mouse, computer mouse (score = 0.01840)
49%で Egyptial cat と認識した。
飛行機雲 その1
% python classify_image.py --model_dir imagenet/ --image_file jet_cloud_1.jpg
airliner (score = 0.77991)
wing (score = 0.04719)
warplane, military plane (score = 0.03326)
space shuttle (score = 0.02544)
missile (score = 0.00422)
78%で airliner。5%で wing。3%でwarplane と認識された。
飛行機雲 その2
% python classify_image.py --model_dir imagenet/ --image_file jet_cloud_2.jpg
airliner (score = 0.38874)
wing (score = 0.03683)
ski (score = 0.03144)
hook, claw (score = 0.02940)
warplane, military plane (score = 0.02702)
39%で airliner。4%で wing。3%でski と認識された。
飛行機雲は分類にもなくて、学習データにもないんだろうな・・・
まずはインストール
ここを見て、Raspberry Pi で動くバイナリパッケージのダウンロードの仕方を見ておく。
Python3 が入っているので Python3用のパッケージをダウンロードする。
% wget https://github.com/samjabrahams/tensorflow-on-raspberry-pi/releases/download/v1.1.0/tensorflow-1.1.0-cp34-cp34m-linux_armv7l.whl
そしてインストールしてみると、
% sudo pip3 install tensorflow-1.1.0-cp34-cp34m-linux_armv7l.whl
tensorflow-1.1.0-cp34-cp34m-linux_armv7l.whl is not a supported wheel on this platform.
エラーになった。
どうやらダウンロードしたパッケージは Python3.4 用だけど、
インストールされている Python は Python3.5 ということが判明。
ソースからビルドしてもいいけど、今の目的は「とりあえず使ってみる」なので、
Python2.7用のバイナリパッケージを使うことにしてみた。
ダウンロードしてインストールする。
% 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
今度は問題なくインストール完了。
インストール方法を見てみると、下記もやっておけと書いてあるので、やっておく。
% sudo pip uninstall mock
% sudo pip install mock
動くか確認
hello_tf.py というファイルを作って、期待通り動くかを確認する。
% vi hello-tf.py
======
#hello-tf.py
import tensorflow as tf
import multiprocessing as mp
core_num = mp.cpu_count()
config = tf.ConfigProto(
inter_op_parallelism_threads = core_num,
intra_op_parallelism_threads = core_num )
sess = tf.Session(config=config)
hello = tf.constant('hello tensorflow')
print sess.run(hello)
a = tf.constant(10)
b = tf.constant(32)
print sess.run(a+b)
======
そして実行
% python hello-tf.py
下記のように表示されれば問題なく動いたことになる。
hello tensorflow
42
サンプルの画像分類を試す
Tensorflowにサンプルで用意されている画像分類を試してみる。
既に学習まで終わった状態で提供されているので、すぐに動かして試してみることが出来る。
ただ、ネットで少し検索するとTensorflowをインストールすると
~/tensorflow/tensorflow/models/image/imagenet/classify_image.py ファイルが出来ていると
書いてあるが探してみても見つからない。
どうやらTensorflow 1.1 ではパッケージには同梱されていない様子。
よって、gihubから
classify_image.py をダウンロードしてきた。
% mkdir imagenet
% cd imagenet
% wget https://raw.githubusercontent.com/tensorflow/models/master/tutorials/image/imagenet/classify_image.py
初めの1回目は学習済みデータのダウンロードが行われてから、パンダの画像を使って
パンダと認識するかが実行される。
% python classify_image.py
>> Downloading inception-2015-12-05.tgz 100.0%
Successfully downloaded inception-2015-12-05.tgz 88931400 bytes.
giant panda, panda, panda bear, coon bear, Ailuropoda melanoleuca (score = 0.89107)
indri, indris, Indri indri, Indri brevicaudatus (score = 0.00779)
lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens (score = 0.00296)
custard apple (score = 0.00147)
earthstar (score = 0.00117)
89%の確率でパンダであると認識できた。
学習済みデータは Raspberry Pi を再起動すると消えてしまうので、ローカルに移動して
実行できるか試してみる。
% mv /tmp/imagenet/ .
% python classify_image.py --model_dir imagenet/ --image_file imagenet/cropped_panda.jpg
これで、ローカルにある学習データを使って画像の分類が出来た。
ネットからいくつか画像データをダウンロードして、試してみた。
猫画像
% python classify_image.py --model_dir imagenet/ --image_file cat_1.jpg
Egyptian cat (score = 0.49180)
tiger cat (score = 0.25432)
tabby, tabby cat (score = 0.14356)
lynx, catamount (score = 0.03078)
mouse, computer mouse (score = 0.01840)
49%で Egyptial cat と認識した。
飛行機雲 その1
% python classify_image.py --model_dir imagenet/ --image_file jet_cloud_1.jpg
airliner (score = 0.77991)
wing (score = 0.04719)
warplane, military plane (score = 0.03326)
space shuttle (score = 0.02544)
missile (score = 0.00422)
78%で airliner。5%で wing。3%でwarplane と認識された。
飛行機雲 その2
% python classify_image.py --model_dir imagenet/ --image_file jet_cloud_2.jpg
airliner (score = 0.38874)
wing (score = 0.03683)
ski (score = 0.03144)
hook, claw (score = 0.02940)
warplane, military plane (score = 0.02702)
39%で airliner。4%で wing。3%でski と認識された。
飛行機雲は分類にもなくて、学習データにもないんだろうな・・・
2018-01-24 23:16
nice!(0)
コメント(0)
コメント 0