Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ML Kit 最新情報

Avatar for Yuki Anzai Yuki Anzai
December 14, 2019

ML Kit 最新情報

Avatar for Yuki Anzai

Yuki Anzai

December 14, 2019
Tweet

More Decks by Yuki Anzai

Other Decks in Technology

Transcript

  1. Yuki Anzai • Android App Developer (2009~) • CEO of

    uPhyca Inc. (2011~) • Google Developers Expert for Android • Organizer of GTUG Girls and droid girls • Twitter : @yanzm
  2. ML Kit の進歩 • ML Kit 発表時 • 6機能 :

    Text recognition、Face detection(主要なランドマークのみ)、 Barcode scanning、Image labeling、Landmark recognition、Custom model inference • 現在 • 11機能 : Face detection(輪郭)、Object detection & tracking、 Language identification、Translation、Smart Reply、AutoML model inference が追加
  3. On-Device or Cloud On-Device Cloud Vision Text recognition : テキスト認識

    O O Face detection : 顔検出 O - Barcode scanning : バーコードスキャン O - Image labeling : 画像のラベル付け O O Object detection & tracking : 物体検出 O - Landmark recognition : ランドマーク認識 - O
  4. On-Device or Cloud On-Device Cloud Natural Language Language identification :

    ⾔語識別 O - Translation : 翻訳 O - Smart Reply : スマートリプライ O - AutoML Vision AutoML model inference : AutoML モデル推論 O - Custom Model Custom model inference : カスタムモデル推論 O -
  5. On-Device vs Cloud • On-Device API • ローカルで動作、速い • 機械学習モデルのダウンロードは

    Firebase におまかせ • Cloud API • サーバーで処理、⾼機能 • ネットワーク接続が必要
  6. Text recognition : テキスト認識 • 画像からテキストを認識 • 看板などの短いテキスト⽤ : On-Device,

    Cloud • ⼩説など⻑く詰まったドキュメント⽤ : Cloud のみ photos by https://firebase.google.com/docs/ml-kit/recognize-text
  7. • On-Device API • 無料 • 全てのラテン⽂字を認識 • Cloud API

    • 毎⽉最初の 1000 API call は無料(1000+ からは従量課⾦) • 50 をこえる⾔語を認識(⽇本語含む) Text recognition : テキスト認識
  8. Face detection : 顔検出 • on-device API のみ • 顔の領域、ランドマーク(⽬・頬・⿐・⽿・⼝)、輪郭情報(顔の外郭・

    ⽬・眉・⿐・⼝)の位置認識 • 顔の表情(⽬の開閉度合い、笑顔の度合い)の認識 • 動画のフレーム間で同じ顔をトラック可能
  9. Barcode scanning : バーコードスキャン • on-device API のみ • ほとんどの標準フォーマットをサポート

    • 1次元 : Codabar, Code 39, Code 93, Code 128, EAN-8, EAN-13, ITF, UPC-A, UPC-E • 2次元 : Aztec, Data Matrix, PDF417, QR Code • ⾃動フォーマット検出 • structured data (WiFi情報など)の取り出し • バーコードの向きによらず検出可能
  10. format 256 (QR Code) valueType 9 (WIFI) rawValue WIFI:S:SB1Guest;P:12345;T:WEP;; displayValue

    SB1Guest 12345 boundingBox Rect(300, 457 - 669, 824) encryptionType 3 (WEP) ssid SB1Guest password 12345
  11. Image labeling : 画像のラベル付け • 画像の内容を解析し、認識したもののラベルをつける : ⼈、物、場所、活動など • on-device

    API • 無料 • 400+ labels をサポート • Cloud API • 毎⽉最初の 1000 API call は無料(1000+ からは従量課⾦) • 10,000+ labels をサポート
  12. label : Building confidence : 0.77894384 entityId : /m/0cgh4 label

    : Palace confidence : 0.75397676 entityId : /m/05zp8 label : landmark confidence : 0.9432406 entityId : /m/05_5t0l label : town confidence : 0.9333225 entityId : /m/0dx1j
  13. label : Food confidence : 0.9649049 entityId : /m/02wbm label

    : Cuisine confidence : 0.91778296 entityId : /m/01ykh label : food confidence : 0.9399401 entityId : /m/02wbm label : cuisine confidence : 0.9263104 entityId : /m/01ykh
  14. Object detection & tracking: 物体認識 • on-device API のみ •

    画像からオブジェクトを検出 • 粗い classification • 検出したオブジェクトの画像を • Cloud に投げてより精度の⾼い検索につなげる → Cloud Vision Product Search • 独⾃のモデルにつなげる → AutoML Vision Edge
  15. • モード : STREAM_MODE (default) | SINGLE_IMAGE_MODE • 複数オブジェクト検出 :

    false (default) | true • 最⼤5個まで • カテゴリ分類 : false (default) | true • UNKNOWN, HOME_GOOD, FASHION_GOOD, FOOD, PLACE, PLANT Object detection & tracking: 物体認識
  16. Landmark detection : ランドマーク認識 • Cloud API のみ • 毎⽉最初の

    1000 API call は無料(1000+ からは従量課⾦) • 画像から有名なランドマークを認識 • ランドマーク名 • 地理座標 • Knowledge Graph entity ID • 画像内でのランドマークの領域
  17. Language Identification : ⾔語ID • On-Device API のみ • ⽂字列からその⾔語を識別

    • 100以上の⾔語に対応 • https://firebase.google.com/docs/ml-kit/langid-support • 最も可能性の⾼い⾔語を1つ識別(Confidence 情報なし) or 可能性のあ る複数の⾔語を識別(Confidence 情報あり)
  18. Translation : 翻訳 • On-Device API のみ • 59 ⾔語間の翻訳が可能

    • https://firebase.google.com/docs/ml-kit/translation-language- support • Google Translate の offline mode と同じモデル
  19. Language Pack • Each language pack : 25~35 MB •

    Language packs は動的にダウンロードされる • 59 language → ~3000 pairs • English を中間⾔語として利⽤ • 例) Dutch → English → Chinese
  20. Limitations • intended for casual and simple translations • 翻訳の質は⾔語に依存する

    • より⾼い忠実度が必要なときは Cloud Translation API を試す • https://cloud.google.com/translate/
  21. Usage guidelines • Usage Guidelines for ML Kit On-device Translation

    を読むこと • https://firebase.google.com/docs/ml-kit/translation-terms • 帰属の表⽰要件 • 制限事項
  22. Smart Reply : スマートリプライ • On-Device API のみ • 会話に関連する返事を⽣成し提案

    • 単⼀のメッセージではなく会話のフルコンテキストから⽣成 • 現在は English のみサポート • 他⾔語と判定された場合提案なしになる • sensitive topics があると判定された場合提案なしになる
  23. Custom model inference : カスタムモデル推論 • Firebase で TensorFlow Lite

    のモデルをホスティング • Firebase SDK がモデルのダウンロードをハンドリング • モデルの更新も可能 • apk にバンドルしたモデルを Firebase SDK 経由で利⽤することも可能 • on-device API として利⽤
  24. AutoML model inference : AutoMLモデル推論 • Firebase console から画像をアップロードしてモデルを作成できる •

    内部で Cloud AutoML Vision service を利⽤ • 画像とラベルのセットを提供するだけで、いい感じに学習して画像分類 モデルを作ってくれるサービス • AutoML での学習は有料 • 作成したモデルはダウンロードできるし、ホスティングもできる
  25. AutoML の画像要件 • 利⽤できる画像フォーマット : JPEG, PNG, GIF, BMP, ICO

    • 画像のサイズ : 30MB以下 • ラベルごとに最低10枚、できれば100枚以上 • ラベルごとに異なる⾓度、解像度、背景を含める • 予測が⾏われる状況に可能な限り近い画像を使う • AutoML Vision Edge によって⽣成されたモデルは、実世界のオブジェクトの写真 ⽤に最適化されている
  26. CameraX • Android の Camera 機能の実装を楽にしてくれるライブラリ • もうすぐ(2019年12⽉に)beta が出る •

    Android 5.0 (API Level 21) 以降をサポート • ML Kit など機械学習との連携が簡単
  27. Android Jetpack: Understand the CameraX Camera-Support Library (Google I/O'19) https://www.youtube.com/watch?v=kuv8uK-5CLY

    プレビューのフレームデータを使って処理を⾏うためのAPIが⽤意されている
  28. Custom Model を使うとき • ML Kit で⽤意されている機能では⾜りないとき • 例)特定のカテゴリーの分類 •

    花の分類 • ⿂の分類 • ⾷べ物の分類 寿司と認識 してほしいなぁ...
  29. モデルの⼊出⼒情報 • ML Kit を使ってアプリに組み込むには、モデルの⼊出⼒の情報が必要 • classification (分類)は出⼒形式がシンプルなので⼊⾨によい • ⼊出⼒の

    Format はモデルによって異なる • 例)とある Vision のモデル • ⼊⼒ Format : Byte[バッチ数][224][224][3] • 出⼒ Format : Byte[バッチ数][1001]
  30. モデルの⼊出⼒情報 • ⼊出⼒次元を指定 : FirebaseModelInputOutputOptions • ⼊⼒ : FirebaseModelInputs •

    Vision の場合 Bitmap, Image → ByteArray, ByteBuffer → • 出⼒ : Byte の多次元配列
  31. 既存の画像分類モデルを使う • 画像からオブジェクトを認識して分類 • https://codelabs.developers.google.com/ codelabs/mlkit-android-custom-model • mobilenet_v1_1.0_224_quant.tflite • ⼊⼒

    Format : Byte[1][224][224][3] • 出⼒ Format : Byte[1][1001] 1 = バッチ数 224 = 画像の⼤きさ 3 = R,G,Bの3⾊情報 1001 = 分類の数
  32. ⼊出⼒の Format 指定 private val modelInputOutputOptions by lazy { val

    inputDims = arrayOf(1, 224, 224, 3) val outputDims = arrayOf(1, labelList.size) FirebaseModelInputOutputOptions.Builder() .setInputFormat(0, FirebaseModelDataType.BYTE, inputDims.toIntArray()) .setOutputFormat(0, FirebaseModelDataType.BYTE, outputDims.toIntArray()) .build() }
  33. val byteBuffer: ByteBuffer = convertBitmapToByteBuffer(bitmap) val modelInputs: FirebaseModelInputs = try

    { FirebaseModelInputs.Builder() .add(byteBuffer) .build() } catch (e: FirebaseMLException) { ... return } modelInterpreter .run(modelInputs, modelInputOutputOptions) .addOnSuccessListener { val inferenceOutput: Array<ByteArray> = it.getOutput(0) val topLabels = getTopLabels(inferenceOutput) ... }
  34. Colaboratory • AutoML でやった花分類のモデルを Google Colaboratory で作る • 「Recognize Flowers

    with TensorFlow Lite on Android」 • https://codelabs.developers.google.com/codelabs/recognize- flowers-with-tensorflow-on-android
  35. Codelabs • Text recognition, Face detection, Image labeling, Custom model

    • 「Recognize text, facial features, and objects in images with ML Kit for Firebase: Android」 • https://codelabs.developers.google.com/codelabs/mlkit-android • Barcode detection • 「Detect Barcodes in an Image using Firebase MLKit」 • https://codelabs.developers.google.com/codelabs/mlkit-barcode-android
  36. Codelabs • Image labeling • 「Detect objects in an Image

    using Firebase MLKit」 • https://codelabs.developers.google.com/codelabs/mlkit-image-objects- android • Object detection • 「Detect objects in images with ML Kit for Firebase: Android」 • https://codelabs.developers.google.com/codelabs/mlkit-android-odt
  37. Codelabs • Custom model • 「Identify objects in images using

    custom machine learning models with ML Kit for Firebase」 • https://codelabs.developers.google.com/codelabs/mlkit-android-custom-model • AutoML model • 「Train and deploy on-device image classification model with AutoML Vision in ML Kit」 • https://codelabs.developers.google.com/codelabs/automl-vision-edge-in-mlkit