LoginSignup
5
2

More than 5 years have passed since last update.

TensorFlow Models の使い方

Last updated at Posted at 2018-04-11

公開されている TensorFlow Models の使い方です。

プログラムのダウンロード

git clone https://github.com/tensorflow/models.git

サンプルの実行

cd models/tutorials/image/imagenet
python classify_image.py

このプログラムは、/tmp/imagenet/cropped_panda.jpg を処理します。パンダと判定されます。

大きいデータが、/tmp/imagenet 以下にダウンロードされます。
/tmp は、再起動で消去されるので、/var/tmp/imagenet に移します。

それに伴い、classify_image.py も修正します。
default='/tmp/imagenet',

default='/var/tmp/imagenet',
にします。

例えば、いちごの画像をダウンロードしてテストすると、
strawberry.jpg

$ export TF_CPP_MIN_LOG_LEVEL=2
$ python classify_image.py --image_file  ~/Downloads/strawberry.jpg 
strawberry (score = 0.97967)
banana (score = 0.00068)
Leonberg (score = 0.00047)
ringneck snake, ring-necked snake, ring snake (score = 0.00047)
German shepherd, German shepherd dog, German police dog, alsatian (score = 0.00046)

ちゃんと strawberry (score = 0.97967) と判定します。

バナナの画像で試すと
banana4.jpg

$ export TF_CPP_MIN_LOG_LEVEL=2
$ python classify_image.py --image_file  ~/Downloads/banana4.jpg
banana (score = 0.99953)
orange (score = 0.00002)
pineapple, ananas (score = 0.00001)
lakeside, lakeshore (score = 0.00001)
corn (score = 0.00000)

ちゃんと、 banana (score = 0.99953) と判定します。

でもりんごの成績はあまり良くありません。

apple2.jpg

$ export TF_CPP_MIN_LOG_LEVEL=2
$ python classify_image.py --image_file  ~/Downloads/apple2.jpg 
orange (score = 0.23259)
Granny Smith (score = 0.22257)
banana (score = 0.05309)
pomegranate (score = 0.04968)
strawberry (score = 0.01616)

欧米産のりんごでないと良い結果が出ないのかもしれません。

次で動作確認しました

Arch Linux (4.15.15-1-ARCH)
Raspbian GNU/Linux 9 (stretch)
Raspbian GNU/Linux 8 (jessie)

5
2
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
5
2