公開されている 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',
にします。
$ 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) と判定します。
$ 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) と判定します。
でもりんごの成績はあまり良くありません。
$ 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)