ML Kit AutoML Vision Edge 移行ガイド

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

API変更内容
AutoML Vision Edge Image Labeling API この 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 メソッドと新しい 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()

New

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 メソッドと新しい 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();

New

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 メソッドと新しい 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)

New

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];

New

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];