Raspberry Pi3環境によるTensorFlowのインストールと実行
TensorFlowをRaspberry Piに対応したいと思います。Googleも今後はRaspberry Piと連携していくみたいです。
まずはTensorFlowのインストール
※既にPython3やpipはインストール済み
以下の記事を参考にしました。
参考にさせていただいた記事
qiita.com
github.com
以下を実行
$ wget https://github.com/samjabrahams/tensorflow-on-raspberry-pi/releases/download/v0.12.1/tensorflow-0.12.1-cp34-cp34m-linux_armv7l.whl $ sudo pip3 install tensorflow-0.12.1-cp34-cp34m-linux_armv7l.whl
すんなりインストール完了しました。
動作テスト(hello, tensorflow!)
さっそくHello worldを実行
pi@raspberrypi:~ $ python3 Python 3.4.2 (default, Oct 19 2014, 13:31:11) [GCC 4.9.1] on linux
>>> # 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)) 'Hello, tensorflow!' >>> >>> a = tf.constant(10) >>> b = tf.constant(32) >>> print(sess.run(a+b)) 42
問題なく実行できました。適当に引っ張ってきた画像(サイ)をお借りして試しにサンプル実行をしてみます(以下記事を参考)。
arkouji.cocolog-nifty.com
$ python3 classify_image.py --image_file rhino01.jpg W tensorflow/core/framework/op_def_util.cc:332] Op BatchNormWithGlobalNormalization is deprecated. It will cease to work in GraphDef version 9. Use tf.nn.batch_normalization(). triceratops (score = 0.91139) warthog (score = 0.00875) hippopotamus, hippo, river horse, Hippopotamus amphibius (score = 0.00297)
91%でトリケラトプスと認識してます。まさかのサイは圏外。
別の画像(サイ)をお借りして試しにサンプル実行。
$ python3 classify_image.py --image_file rhino02.jpg W tensorflow/core/framework/op_def_util.cc:332] Op BatchNormWithGlobalNormalization is deprecated. It will cease to work in GraphDef version 9. Use tf.nn.batch_normalization(). triceratops (score = 0.85796) hippopotamus, hippo, river horse, Hippopotamus amphibius (score = 0.01660) Indian elephant, Elephas maximus (score = 0.01387)
85%でトリケラトプスと認識してます。カバは出てきますがサイはまたも圏外。
つぎはキリンの画像で実行
$ python3 classify_image.py --image_file giraffe01.jpg W tensorflow/core/framework/op_def_util.cc:332] Op BatchNormWithGlobalNormalization is deprecated. It will cease to work in GraphDef version 9. Use tf.nn.batch_normalization(). cheetah, chetah, Acinonyx jubatus (score = 0.17464) zebra (score = 0.05517) hyena, hyaena (score = 0.05437)
17%でチーターと認識してます。全体的にかなり低い精度です。
別の画像(キリン)をお借りして試しにサンプル実行。
$ python3 classify_image.py --image_file giraffe02.jpg W tensorflow/core/framework/op_def_util.cc:332] Op BatchNormWithGlobalNormalization is deprecated. It will cease to work in GraphDef version 9. Use tf.nn.batch_normalization(). cheetah, chetah, Acinonyx jubatus (score = 0.32205) hyena, hyaena (score = 0.27464) African hunting dog, hyena dog, Cape hunting dog, Lycaon pictus (score = 0.01903)
32%でチーターと少し精度が上がったものの、かなり低い数値。
今度は動物ではなくTensorFlowのロゴをお借りして試しにサンプル実行。
$ python3 classify_image.py --image_file tensorflow.jpg W tensorflow/core/framework/op_def_util.cc:332] Op BatchNormWithGlobalNormalization is deprecated. It will cease to work in GraphDef version 9. Use tf.nn.batch_normalization(). Band Aid (score = 0.64480) cash machine, cash dispenser, automated teller machine, automatic teller machine, automated teller, automatic teller, ATM (score = 0.05389) sunscreen, sunblock, sun blocker (score = 0.01263)
64%でバンドエイドと認識。その他5%でキャッシュディスペンサーと認識してます。ある意味イケるのかと期待しましたが、全くだめでした。
とはいえドンピシャでハマると結構良い精度で認識するものもあるようなので、機会があれば得手不得手の画像や角度を見極めて見たいと思います。