🌱Google Cloud Vision API で生物の同定は可能?
機械学習ベースで画像認識・分類を行うGoogle Cloud Vision APIをR上で利用するコードをdichikaさんが書いてくれたので、それを使って手持ちの写真からいろいろな分類群の生物(主に植物)を同定することが可能なのかを検証してみたい。
🌿 植物編
まずは簡単そうなものから。

画像は基本的にFlickrにアップロードしたものを表示しているが、実際に使ったのはすべてローカルにあるファイル。あと、出力した結果を見やすくするために{formattable}を使って、ちょっと手を加えた。
library(magrittr) library(formattable) library(jsonlite) library(dplyr)
getResult("watermelon.jpg", "LABEL_DETECTION") %>% content(as = "text") %>% fromJSON() %$% responses$labelAnnotations
| description | score |
|---|---|
| 💮watermelon | 0.94329876 |
| produce | 0.78450352 |
| melon | 0.78298116 |
| flower | 0.77830565 |
| food | 0.76912522 |
| dish | 0.74153781 |
| fruit | 0.67084348 |
| vegetable | 0.61176038 |
| ingredient | 0.56144458 |
お、すごい。正解。低スコアの候補にdishとかingredientがあるのも面白い。
続いてはこちら。イチョウの写真。
getResult("ginkgo.jpg", "LABEL_DETECTION") %>% content(as = "text") %>% fromJSON() %$% responses$labelAnnotations
| description | score |
|---|---|
| 💮maidenhair tree | 0.99996549 |
| food | 0.96131206 |
| flower | 0.85318035 |
| tree | 0.82921141 |
| flowering plant | 0.78488386 |
| plant | 0.7846511 |
| leaf | 0.76164657 |
| fruit | 0.68922257 |
| vegetable | 0.6381712 |
| ingredient | 0.56817037 |
またしても大正解。楽しい。food???
以下、適当にやってみる。皆さんもGoogleと競うつもりで同定に挑戦してみると良い。以降は結果とスコアだけ表示する。
| description | score |
|---|---|
| flower | 0.911019 |
| food | 0.85975921 |
| tree | 0.85163939 |
| flowering plant | 0.8173213 |
| fruit | 0.80653685 |
| yellow | 0.80259567 |
| plant | 0.78482825 |
| blossom | 0.7704823 |
| acerola | 0.68401051 |
| fruit tree | 0.64611512 |
オガタマノキ Michelia compressa を当てることはできなかった。
| description | score |
|---|---|
| flower | 0.96037906 |
| flatweed | 0.83993411 |
| steppe | 0.83023411 |
| plant | 0.78563839 |
| daylily | 0.73753977 |
| food | 0.73058081 |
| flowering plant | 0.72653317 |
| argyranthemum frutescens | 0.7230733 |
| cosmos bipinnatus | 0.71721947 |
| grass | 0.71447748 |
argyranthemum frutescensとかcosmos bipinnatusとか、わりとおしい。科はあってる。オオキンケイギク Coreopsis lanceolata
| description | score |
|---|---|
| flower | 0.97986346 |
| commelinaceae | 0.85704482 |
| plant | 0.785688 |
| macro photography | 0.76786673 |
| spring | 0.72475678 |
| flowering plant | 0.70920658 |
| blossom | 0.689027 |
| viola | 0.68531573 |
| aristea | 0.61623591 |
| orris root | 0.56240678 |
いい感じ。人間が被子植物の同定をする際に花の形質に注目するように、機械も花が写っていると認識しやすいのだろうか。というわけで今度は花以外の器官でやってみる。
| description | score |
|---|---|
| flower | 0.81824714 |
| invertebrate | 0.80564487 |
| plant | 0.75781685 |
| elaeis | 0.73619395 |
| larva | 0.73076028 |
| tree | 0.71493828 |
| hand | 0.71455806 |
| insect | 0.6473183 |
| jewellery | 0.57109278 |
| zophobas morio | 0.56917435 |
別な意味で、低スコアだけどjewelleryを出してきたのは評価したい。
| description | score |
|---|---|
| yarrow | 0.94137996 |
| flower | 0.85601586 |
| fern | 0.82478225 |
| plant | 0.7856912 |
| tree | 0.78267342 |
| leaf | 0.77516282 |
| pinophyta | 0.70045578 |
| leaf vegetable | 0.53995013 |
| vegetable | 0.51923585 |
| lamiaceae | 0.51505309 |
アスナロ Thujopsis dolabrata... 結構いいところを突いているような。
| description | score |
|---|---|
| flower | 0.89638895 |
| leaf | 0.81160432 |
| plant | 0.78486365 |
| tree | 0.77973396 |
| flowering plant | 0.75048935 |
| branch | 0.61544603 |
| deciduous | 0.59794432 |
| ingredient | 0.55374187 |
| vegetable | 0.52738619 |
| shrub | 0.50056636 |
シダ植物は人間でも難しい。
| description | score |
|---|---|
| maple tree | 0.92286885 |
| tree | 0.85609412 |
| leaf | 0.85359174 |
| maple leaf | 0.84732145 |
| green | 0.81126577 |
| plant | 0.78559667 |
| macro photography | 0.77550995 |
| flower | 0.76171696 |
| deciduous | 0.72187716 |
| vitaceae | 0.71063304 |
maple treeという結果で、見事にこちらの罠に引っかかった。葉はカエデそっくりだが、実はウリノキ Alangium platanifolium 。カエデ類(ムクロジ科)ではなくてウリノキ科。
| description | score |
|---|---|
| food | 0.99774766 |
| fruit | 0.9917798 |
| mandarin orange | 0.99136841 |
| citrus | 0.98480314 |
| valencia orange | 0.92787135 |
| tangelo | 0.92241192 |
| bitter orange | 0.83552259 |
| orange | 0.78454494 |
| tree | 0.77564859 |
| meyer lemon | 0.76964122 |
こういうわかりやすいものはさすがに当ててくる。
🐄 植物以外の分類群編
🐝 昆虫綱
| description | score |
|---|---|
| invertebrate | 0.90009421 |
| insect | 0.80193478 |
| tree | 0.79411966 |
| plant | 0.75973481 |
| flower | 0.72228789 |
| hemiptera | 0.65385449 |
| branch | 0.600592 |
| piciformes | 0.58465624 |
hemipteraではありません...
| description | score |
|---|---|
| 💮odonata | 0.999776 |
| invertebrate | 0.99667281 |
| insect | 0.90847808 |
| wildlife | 0.8644641 |
| 💮dragonfly | 0.856631 |
| macro photography | 0.85131222 |
| arthropod | 0.52097416 |
被写体が大きいと正解率も高くなるのかな。
🍄 菌類
| description | score |
|---|---|
| fungus | 0.97657126 |
| edible mushroom | 0.97272766 |
| mushroom | 0.97239363 |
| champignon | 0.95831203 |
| plant | 0.7835775 |
| food | 0.71797752 |
| matsutake | 0.61801094 |
| oyster mushroom | 0.60799241 |
| ingredient | 0.56984282 |
| shiitake | 0.50944787 |
| description | score |
|---|---|
| fungus | 0.9074834 |
| flower | 0.89983678 |
| champignon | 0.87777275 |
| tree | 0.80856764 |
| leaf | 0.80069906 |
| food | 0.78961605 |
| plant | 0.7850799 |
| mushroom | 0.67598778 |
| viola | 0.64161 |
| ingredient | 0.57048512 |
🐟 魚類
| description | score |
|---|---|
| fish | 0.98713744 |
| marine biology | 0.87207329 |
| vertebrate | 0.85707277 |
| shark | 0.83812505 |
| chondrichthyes | 0.70408642 |
| cetacea | 0.63274264 |
| great white shark | 0.62773609 |
| marine mammal | 0.58265722 |
| underwater | 0.56531811 |
マンボウはサメ(軟骨魚類)だった...?
🐓 鳥類
| description | score |
|---|---|
| charadriiformes | 0.85507971 |
| gull | 0.75762254 |
| water | 0.68749034 |
| european herring gull | 0.67550778 |
| flight | 0.61130363 |
| cloud | 0.57752395 |
| hand | 0.56852466 |
| seabird | 0.56194431 |
🐶 哺乳類
| description | score |
|---|---|
| steppe | 0.88557386 |
| forest | 0.85437959 |
| tree | 0.81694543 |
| wildlife | 0.803191 |
| mist | 0.78497565 |
| pasture | 0.78379267 |
| plain | 0.72870713 |
| prairie | 0.722617 |
| fog | 0.71647382 |
| habitat | 0.71316737 |
👻 擬態編
擬態っぽく、背景に溶け込んでいる生物をきちんと発見できるのかのテスト。
| description | score |
|---|---|
| invertebrate | 0.97522974 |
| arthropod | 0.63064021 |
| description | score |
|---|---|
| flower | 0.89335757 |
| food | 0.82742327 |
| tree | 0.80050039 |
| plant | 0.78444982 |
| leaf | 0.754664 |
| flowering plant | 0.74298728 |
| fruit | 0.65254867 |
| vegetable | 0.62897795 |
| shrub | 0.59377211 |
| ingredient | 0.56855273 |
グリーンアノールは隠れるのがうまいらしい。
| description | score |
|---|---|
| invertebrate | 0.90009046 |
| arthropod | 0.63161612 |
| spider | 0.62366068 |
| zophobas morio | 0.57001925 |
| insect | 0.53996378 |
| pollen | 0.53438425 |
難しいっぽい。
🍵 所感
すげえなGoogle。ミライカン、ハンバネー
全体的に余計なものがない方が精度が高い。背景に対象が溶け込んでいたり、霧や水しぶきがあると精度が下がる感じ。
特徴的な形質がなければ細かい分類群まで落とし込むのはまだまだ厳しいが、今後ますます機械学習の精度が上がって、分類屋とか学芸員の仕事が楽になる(あるいは脅かされる)未来もありそうでなさそうで。...少なくとも教養のない学部生よりはまともな回答をしそうだ。学名まで出してくれると嬉しい。
お手軽に試せるのでお手持ちの写真でEnjoy 😎


















