未分類

Tensorflowに画像認識させてみる

以前、chainerに画像認識させてみたのだが、今回はgoogleの誇るディープラーニングのフレームワーク、Tensorflowに画像認識させてみようと。

Tensorflowのgit cloneで、tensorflow/tensorflow/models/image/imagenetフォルダに中に、classify_image.pyという画像認識コードがある。
これをpythonで実行させると、デフォルトで用意されたパンダ画像を自動で認識してくれる。

ちなみに、ここで採用されているInception-v3ってやつは、エラー率3.4%だそうです。人間のエラー率が5%程度らしいので、人間より認識率は高いとのこと。すごいですねえ。

それでは、そのすんごい認識システム。
まずはやってみましょう。

$ cd tensorflow/tensorflow/models/image/imagenet
$ python classify_image.py

すると初回のみダウンロードされ自動実行される。
giant panda, panda, panda bear, coon bear, Ailuropoda melanoleuca (score = 0.89233)
indri, indris, Indri indri, Indri brevicaudatus (score = 0.00859)
lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens (score = 0.00264)
custard apple (score = 0.00141)
earthstar (score = 0.00107)

パンダの確率が89%と出た。

これだけではつまらないので、こちらで用意した画像を認識させてみよう。
以前と同じライオンをまず。

$ python classify_image.py –image_file raion_osu.jpg

すると
lion, king of beasts, Panthera leo (score = 0.92273)
Arabian camel, dromedary, Camelus dromedarius (score = 0.00058)
cheetah, chetah, Acinonyx jubatus (score = 0.00053)
macaque (score = 0.00047)
pencil box, pencil case (score = 0.00044)

ライオンである確率92%。
ペンシルボックスが0.00044%。
そうですか。

以前、何かに間違えたこちらの写真。
馬なのだが、これをどうみる、テンソル君。

$ python classify_image.py –image_file uma2.jpg

llama (score = 0.93735)
ram, tup (score = 0.00507)
Newfoundland, Newfoundland dog (score = 0.00196)
ostrich, Struthio camelus (score = 0.00139)
Border collie (score = 0.00133)

llamaである確率が93%。
llamaってなんぞや。

検索したらこんなのが出てきました。

色は違うが見た目は似てますなあ。
間違えるのも無理はない。

ちなみに、イラストなんかは認識できるのだろうか。
これとか。

やってみよう。

$ python classify_image.py –image_file pico.jpg

stole (score = 0.07498)
wig (score = 0.07489)
suit, suit of clothes (score = 0.05217)
ear, spike, capitulum (score = 0.05153)
corn (score = 0.05042)

軒並み10%を切っている。ちょい自信が無いね、テンソル君。
ストールが7%。
人間というより、着てる服に目がいくのね。

じゃあ、こいつはどうだ。

by おむレツ さん、フリー画像ありがとう。

$ python classify_image.py –image_file irasuto1.jpg

comic book (score = 0.77033)
mask (score = 0.05580)
lampshade, lamp shade (score = 0.00679)
crash helmet (score = 0.00420)
jack-o’-lantern (score = 0.00317)

コミックブックが77%。
なるほど、わかってるのね。

総じて感想だが、chainerよりは解析が早いですね。
さすが、天下のgoogleさんが作っただけのことはある。
こんなすごいシステムが自由に使えるなんて。
ディープラーニング製作チームは、各社とも太っ腹ですなあ。
感謝です。

 

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です