ML Kit AutoML Vision Edge 移行ガイド

AutoML でトレーニングされた画像分類モデルは、カスタムモデル API に渡すことができます。引き続き、モデルをアプリ内にバンドルすることも、Firebase コンソールでカスタムモデルとしてホストすることもできます。AutoML Image Labeling API は、Custom Model Image Labeling API に完全に置き換えられたため、ML Kit から削除されました。

API変更内容
AutoML Vision Edge 画像ラベル付け API これは、Custom Model Image Labeling API に完全に置き換わります。既存の AutoML Vision Edge 画像ラベル付け API は削除されます。

現在、AutoML Vision Edge API を使用している ML Kit を使用している場合は、Android と iOS の移行手順に沿って操作してください。

よくある質問

変更の理由

これにより、ML Kit API が簡素化され、ML Kit をアプリに簡単に統合できるようになります。この変更により、AutoML でトレーニングされたモデルをカスタムモデルとまったく同じように使用できます。また、現在サポートされている画像のラベル付けに加えて、オブジェクトの検出とトラッキングに AutoML でトレーニングされたモデルも使用できます。さらに、カスタムモデル API は、メタデータにラベルマップが埋め込まれたモデルと、個別のマニフェスト ファイルとラベル ファイルを使用するモデルの両方をサポートします。

新しい SDK に移行すると、どのようなメリットがありますか?

  • 新機能: AutoML でトレーニングされたモデルを画像ラベリングとオブジェクト検出とトラッキングの両方に使用できるようになりました。また、メタデータにラベルマップが埋め込まれたモデルを使用できます。

Android 向け移行ガイド

ステップ 1: Gradle インポートを更新する

次の表に従って、モジュール(アプリレベル)の Gradle ファイル(通常は app/build.gradle)内の ML Kit Android ライブラリの依存関係を更新します。

特徴古いアーティファクト新しいアーティファクト
リモートモデルをダウンロードせずに AutoML で画像ラベル付けを行う com.google.mlkit:image-labeling-automl:16.2.1 com.google.mlkit:image-labeling-custom:16.0.0-beta5
リモートモデルのダウンロードを使用した AutoML の画像ラベル付け com.google.mlkit:image-labeling-automl:16.2.1
com.google.mlkit:linkfirebase:16.0.1
com.google.mlkit:image-labeling-custom:16.0.0-beta5
com.google.mlkit:linkfirebase:17.0.0

ステップ 2: クラス名を更新する

クラスがこの表に表示された場合は、次のように変更します。

以前のクラス新しいクラス
com.google.mlkit.vision.label.automl.AutoMLImageLabelerLocalModel com.google.mlkit.common.model.LocalModel
com.google.mlkit.vision.label.automl.AutoMLImageLabelerRemoteModel com.google.mlkit.common.model.CustomRemoteModel
com.google.mlkit.vision.label.automl.AutoMLImageLabelerOptions com.google.mlkit.vision.label.custom.CustomImageLabelerOptions

ステップ 3: メソッド名を更新する

コードの変更が最小限で済みます。

  • LocalModel は、モデル ファイルのパス(モデルにラベルマップを含むメタデータがある場合)またはモデル マニフェスト ファイルのパス(マニフェスト、モデル、ラベルが別々のファイルにある場合)のいずれかで初期化できるようになりました。
  • Firebase コンソールを介してリモートでカスタムモデルをホストし、FirebaseModelSourceCustomRemoteModel を初期化できます。

新旧の Kotlin メソッドの例を以下に示します。

古い

val localModel = AutoMLImageLabelerLocalModel.Builder()
    .setAssetFilePath("automl/manifest.json")
    // or .setAbsoluteFilePath(absolute file path to manifest file)
    .build()

val optionsWithLocalModel = AutoMLImageLabelerOptions.Builder(localModel)
    .setConfidenceThreshold(0.5f)
    .build()

val remoteModel = AutoMLImageLabelerRemoteModel.Builder("automl_remote_model")
    .build()

val optionsWithRemoteModel = AutoMLImageLabelerOptions.Builder(remoteModel)
    .build()

新規

val localModel = LocalModel.Builder()
    .setAssetManifestFilePath("automl/manifest.json")
    // or .setAbsoluteManifestFilePath(absolute file path to manifest file)
    .build()

val optionsWithLocalModel = CustomImageLabelerOptions.Builder(localModel)
    .setConfidenceThreshold(0.5f)
    .build()

val firebaseModelSource = FirebaseModelSource.Builder("automl_remote_model")
    .build()
val remoteModel = CustomRemoteModel.Builder(firebaseModelSource).build()
val optionsWithRemoteModel = CustomImageLabelerOptions.Builder(remoteModel)
    .build()

以下に、新旧の Java メソッドの例を示します。

古い

AutoMLImageLabelerLocalModel localModel =
    new AutoMLImageLabelerLocalModel.Builder()
        .setAssetFilePath("automl/manifest.json")
        // or .setAbsoluteFilePath(absolute file path to manifest file)
        .build();
AutoMLImageLabelerOptions optionsWithLocalModel =
    new AutoMLImageLabelerOptions.Builder(localModel)
        .setConfidenceThreshold(0.5f)
        .build();
AutoMLImageLabelerRemoteModel remoteModel =
    new AutoMLImageLabelerRemoteModel.Builder("automl_remote_model").build();
AutoMLImageLabelerOptions optionsWithRemoteModel =
    new AutoMLImageLabelerOptions.Builder(remoteModel)
        .build();

新規

LocalModel localModel =
    new LocalModel.Builder()
        .setAssetManifestFilePath("automl/manifest.json")
        // or .setAbsoluteManifestFilePath(absolute file path to manifest file)
        .build()
CustomImageLabelerOptions optionsWithLocalModel =
    new CustomImageLabelerOptions.Builder(localModel)
        .setConfidenceThreshold(0.5f)
        .build();
FirebaseModelSource firebaseModelSource =
    new FirebaseModelSource.Builder("automl_remote_model").build();
CustomRemoteModel remoteModel =
    new CustomRemoteModel.Builder(firebaseModelSource).build();
CustomImageLabelerOptions optionsWithRemoteModel =
    new CustomImageLabelerOptions.Builder(remoteModel).build();

iOS 向け移行ガイド

前提条件

  • Xcode 13.2.1 以降が必要です。

手順 1: Cocoapods を更新する

アプリの Podfile で、ML Kit の iOS cocoapods の依存関係を更新します。

特徴古い Pod 名新しい Pod 名
リモートモデルをダウンロードせずに AutoML で画像ラベル付けを行う GoogleMLKit/ImageLabelingAutoML GoogleMLKit/ImageLabelingCustom
リモートモデルのダウンロードを使用した AutoML の画像ラベル付け GoogleMLKit/ImageLabelingAutoML
GoogleMLKit/LinkFirebase
GoogleMLKit/ImageLabelingCustom
GoogleMLKit/LinkFirebase

ステップ 2: クラス名を更新する

クラスがこの表に表示された場合は、次のように変更します。

Swift

以前のクラス新しいクラス
AutoMLImageLabelerLocalModel LocalModel
AutoMLImageLabelerRemoteModel CustomRemoteModel
AutoMLImageLabelerOptions CustomImageLabelerOptions

Objective-C

以前のクラス新しいクラス
MLKAutoMLImageLabelerLocalModel MLKLocalModel
MLKAutoMLImageLabelerRemoteModel MLKCustomRemoteModel
MLKAutoMLImageLabelerOptions MLKCustomImageLabelerOptions

Objective-C

ステップ 3: メソッド名を更新する

コードの変更が最小限で済みます。

  • LocalModel は、モデル ファイルのパス(モデルにラベルマップを含むメタデータがある場合)またはモデル マニフェスト ファイルのパス(マニフェスト、モデル、ラベルが別々のファイルにある場合)のいずれかで初期化できるようになりました。
  • Firebase コンソールを介してリモートでカスタムモデルをホストし、FirebaseModelSourceCustomRemoteModel を初期化できます。

新旧の Swift メソッドの例を以下に示します。

古い

let localModel =
    AutoMLImageLabelerLocalModel(manifestPath: "automl/manifest.json")
let optionsWithLocalModel = AutoMLImageLabelerOptions(localModel: localModel)
let remoteModel = AutoMLImageLabelerRemoteModel(name: "automl_remote_model")
let optionsWithRemoteModel = AutoMLImageLabelerOptions(remoteModel: remoteModel)

新規

guard let localModel = LocalModel(manifestPath: "automl/manifest.json") else { return }
let optionsWithLocalModel = CustomImageLabelerOptions(localModel: localModel)
let firebaseModelSource = FirebaseModelSource(name: "automl_remote_model")
let remoteModel = CustomRemoteModel(remoteModelSource: firebaseModelSource)
let optionsWithRemoteModel = CustomImageLabelerOptions(remoteModel: remoteModel)

新旧の Objective-C メソッドの例を以下に示します。

古い

MLKAutoMLImageLabelerLocalModel *localModel =
    [[MLKAutoMLImageLabelerLocalModel alloc]
        initWithManifestPath:"automl/manifest.json"];
MLKAutoMLImageLabelerOptions *optionsWithLocalModel =
    [[MLKAutoMLImageLabelerOptions alloc] initWithLocalModel:localModel];
MLKAutoMLImageLabelerRemoteModel *remoteModel =
    [[MLKAutoMLImageLabelerRemoteModel alloc]
        initWithManifestPath:"automl/manifest.json"];
MLKAutoMLImageLabelerOptions *optionsWithRemoteModel =
    [[MLKAutoMLImageLabelerOptions alloc] initWithRemoteModel:remoteModel];

新規

MLKLocalModel *localModel =
    [[MLKLocalModel alloc] initWithManifestPath:"automl/manifest.json"];
MLKCustomImageLabelerOptions *optionsWithLocalModel =
    [[MLKCustomImageLabelerOptions alloc] initWithLocalModel:localModel];
MLKFirebaseModelSource *firebaseModelSource =
    [[MLKFirebaseModelSource alloc] initWithName:@"automl_remote_model"];
MLKCustomRemoteModel *remoteModel =
    [[MLKCustomRemoteModel alloc] initWithRemoteModelSource:firebaseModelSource];
MLKCustomImageLabelerOptions *optionsWithRemoteModel =
    [[MLKCustomImageLabelerOptions alloc] initWithRemoteModel:remoteModel];