Core MLのお絵描き認識サンプルのコードを読む - Drawing Classification
iOSでお絵かき認識(drawing classification)の公式サンプルが上がっていた。
iOS 13でCore MLに追加されたMLUpdateTaskを利用し、モデルの更新もOn-Deviceで(iPhone上で)行うというもの。
ビルドして実行してみた動画:
以下そのサンプルを読みつつ書いたメモ。
## UpdatableDrawingClassifierモデル
このサンプルで使用しているお絵かき認識(分類)のモデル UpdatableDrawingClassifier.mlmodel は、
で配布されている。
推論時の入出力の仕様を見てみると、
・入力
`Image (Grayscale 28 x 28)`: Input sketch image with black background and white strokes
・出力
- `String`: Predicted label
- `Dictionary (String → Double)` : Probabilities / score
こんな感じで、分類に際してお絵かきの過程の時系列データは使っていない。
本モデルは「Updatable」であるところがポイントで、Update用の入力も次のように定義されている。
・Update
- `Image (Grayscale 28 x 28)` : Example sketch
- `String`: Associated true label of example sketch
またパラメータも渡せるようになっているが、本サンプルでは使用していないようだ。
・Parameters
- `Int64` : Number of neighbors to use for prediction
(UpdatableDrawingClassifier.mlmodelの入出力仕様)
## MLUpdateTaskを利用したモデルの更新
最後まで読んでいただきありがとうございます!もし参考になる部分があれば、スキを押していただけると励みになります。 Twitterもフォローしていただけたら嬉しいです。 https://twitter.com/shu223/