12
5

More than 3 years have passed since last update.

enebular x TensorFlow x LINE Botでcocossdとmobilenetを比較した

Last updated at Posted at 2020-12-13

12月1日(火)の【オンライン】enebular developer meetupでのLT内容を記事にしてまとめます。

はじめに

写真を撮って送ると「これは○○○だよ」と教えてくれるLINE Botを常備したい派です。
こんなBotを常備したいときにはenebularを使うと簡単にできることは、諸先輩方の知見で、よくわかります。

これまでの知見

Teachable Machineのnodeがある

@youtoyさんが、以下の記事を書かれています。Teachable Machineで作った学習モデルがenebularのnodeにあることが分かりました。
Node-RED で Teachable Machine を試す(Node-RED のセットアップ後にノードを追加してサンプルを動かす)https://qiita.com/youtoy/items/102c9ab8b5f25d542056

TensorFlowのnodeがある

@kazuhitoyokoiさんの以下の記事で、TensorFlowのnodeがあることをしりました。これなら、学習済みなので、多くの画像を集めて学習させる必要もないので、TensorFlowのnodeをぜひ使いたいと思いました。
TensorFlow.jsノードをNode-REDで使ってみる https://qiita.com/kazuhitoyokoi/items/e4da2dc1c39c0a11569e

enebularを使うとTeachable Machineを使ってLINEBotが簡単に作れる。

がおまるさん(@h-takaumaさん)が、enebularとTeachable MachineとLINEBotの組み合わせで、写真を撮って送ると「これは何だよ」と教えてくれるLINE Botを作るハンズオンをされました。enebularを使うと、こんなにも簡単にTeachable Machineを使ってLINEBotが簡単に作れるんですね。これは、わかりやすいというか、非常に勉強になったハンズオンでした。
enebularとTeachable Machineハンズオン(ランチ時間開催) 2020年8月10日にライブ配信
Youtube:https://www.youtube.com/watch?v=vDpCk92S-7M
connpassページ:https://enebular.connpass.com/event/179530/
connpassのページにハンズオン資料があります。

機械学習せずにenebularでTensorFlow nodeを使って、LINE Botを作った。

上記のがおまるさん(@h-takaumaさん)のハンズオンで作るflow内のTeachable Machine nodeを、@kazuhitoyokoiさん記事のtensorflow nodeに入れ替えました。

image.png

1か所だけ修正する

上記のがおまるさん(h-takaumaさん)のハンズオンで作るflowの中の画像判定nodeの下に接続されたfunction node(名前:結果取得)のコードの1行目を変更する必要があります。
Teachable Machine nodeの際に
const className = msg.payload[0].class;
となっていたところを
const className = msg.payload;
に変更します。
これでOK。ほぼノンコーディングで、Tensorflowを使って機械学習をすることなく、画像判定LINE Botが出来上がりました。

image.png

2種のモデル(cocossd と mobilenet)を比較してみた。

このTensorflowの学習モデルにはcocossdとmobilenetの2種があります。この2種のモデルを比較して見ることにしました。Teachable machineと異なり、自分で学習させていないので、一体この学習モデルは何を知っているのか試してみたい気持ちで比較することにしました。

まず、この2種について調べてみました。

cocossdとは

cocoはCommon Objects in Context。ssdは、single shot detector。
https://github.com/tensorflow/tfjs-models/blob/master/coco-ssd/README.md から抜粋すると
Object detection model that aims to localize and identify multiple objects in a single image.The model is capable of detecting 80 classes of objects. (SSD stands for Single Shot MultiBox Detection).returns an array of bounding boxes with class name and confidence level.
また、coco-ssdが認識するのは、以下の80のcommon objectらしい。
person, bicycle, car, motorcycle, airplane, bus, train, truck, traffic light, fire hydrant, stop sign, parking meter, bird, cat, dog, horse, sheep, cow, elephant, bear, zebra, giraffe, backpack, umbrella, handbag, tie, suitcase, frisbee, skis, snowboard, sports ball, kite, baseball glove, skateboard, surfboard, tennis racket, bottle, wine glass, cup, fork, knife, spoon, bowl, banana, apple, sandwhich, orange, broccoli, carrot, pizza, donut, cake, chair, couch, potted plant, bed, dining table, toilet, tv, laptop, mouse, remote,, keyboard, cell phone, microwave, oven, toaster, sink, refrigerator, book, clock, vase, scissor, teddy bear, hair drier, toothbrush

coco-ssdは80の一般的な物体を返してくれます。それ以外の物体だったらどう返してくれるのか興味がでてきました。

mobilenetとは

https://github.com/tensorflow/tfjs-models/tree/master/mobilenet から抜粋すると
MobileNets are small, low-latency, low-power models parameterized to meet the resource constraints of a variety of use cases. They can be built upon for classification, detection, embeddings and segmentation similar to how other popular large scale models, such as Inception, are used.MobileNets trade off between latency, size and accuracy while comparing favorably with popular models from the literature.

mobilenetは、何をどれだけ知っているのか興味が出てきました。

flow内で、cocossdとmobilenetの2種を入れ替えて使ってみました。
image.png

いろいろな画像をLINE Botに投げてみた。

いろいろな画像をLINE Botに投げてみたその結果のBotの画像は以下の通りです。Botの返答が小さくて読みにくくてごめんなさい。
比較する目的で、左にcocossdによる結果、右にmobilenetによる結果として並べています。
ざっくりした私の感想・コメントを赤字で書いています。

image.png
image.png
image.png
image.png
image.png
image.png
image.png
image.png
image.png
image.png
image.png
image.png
image.png

mobilenetのLINE Botを常備したい。

cocossdは80種類の物体であればしっかりと答えてくれて、間違わずに安定感がありますね。
一方、mobilenetは、間違うことも多いけれど、多くの物体を知っています。どこまで広く知っているのか、さらに興味が沸きあがってきました。
そこで、このmobilenetを使ったflowを、HerokuへDeploy しました。
写真を撮って送ると「これは○○○だよ」と教えてくれるLINE Botを常備したい派なので、このmobilenetのLINE Botを常備しています。

私はペット飼っていませんが、ペット好きの人が、自分のペットの写真を撮ってLINE Botに、「これはdog」と言われると悲しくなりますね。「これはGolden Retriever」って言ってもらいたいですね。そんな方にも、mobilenetのLINE Botがおすすめです。

楽しいTensorflowライフを!!

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