ML Kit AutoML Vision Edge 移行ガイド

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

API変更内容
AutoML Vision Edge 画像ラベリング API カスタムモデル画像ラベリング API に完全に置き換えられました。既存の AutoML Vision Edge 画像ラベリング API は削除されました。

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

よくある質問

変更の理由を教えてください。

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

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

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

Android の移行ガイド

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

次の表に従って、モジュール(アプリレベル)の Gradle ファイル(通常は app/build.gradle.kts)で 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
カスタムモデルをホストしてダウンロードするには、モデルを Cloud Storage に移動し、 LocalModel を使用してモデルを読み込むダウンロード ロジックをアプリに追加します。詳細については、 [Firebase ML から Cloud Storage への移行ガイド][migrate-storage] をご覧ください。

ステップ 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.LocalModel
アプリには、リモートでホストされているモデルをダウンロードし、 LocalModel を使用して初期化するロジックを含める必要があります。
com.google.mlkit.vision.label.automl.AutoMLImageLabelerOptions com.google.mlkit.vision.label.custom.CustomImageLabelerOptions

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

コードの変更は最小限に抑えられます。

  • LocalModel は、モデルパス(モデルにラベルマップを含むメタデータがある場合)またはモデル マニフェスト パス(マニフェスト、モデル、ラベルが別々のファイルにある場合)で初期化できるようになりました。
  • リモートでホストされているモデルをローカル ストレージにダウンロードし、LocalModel を使用して読み込むロジックをアプリに追加します。

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

val localModel = AutoMLImageLabelerLocalModel.Builder()
    .setAssetFilePath("automl/manifest.json")
    // or .setAbsoluteFilePath(absolute 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()

新規

// Similar process for both local and remotely-hosted models (that have been downloaded)
val localModel = LocalModel.Builder()
    .setAssetManifestFilePath("automl/manifest.json")
    // or .setAbsoluteManifestFilePath(absolute path to manifest file)
    .build()

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

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

AutoMLImageLabelerLocalModel localModel =
    new AutoMLImageLabelerLocalModel.Builder()
        .setAssetFilePath("automl/manifest.json")
        // or .setAbsoluteFilePath(absolute 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();

新規

// Similar process for local models and remotely-hosted models (that have been downloaded)
LocalModel localModel =
    new LocalModel.Builder()
        .setAssetManifestFilePath("automl/manifest.json")
        // or .setAbsoluteManifestFilePath(absolute path to manifest file)
        .build();
CustomImageLabelerOptions optionsWithLocalModel =
    new CustomImageLabelerOptions.Builder(localModel)
        .setConfidenceThreshold(0.5f)
        .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
カスタムモデルをホストしてダウンロードするには、モデルを Cloud Storage に移動し、 ローカルモデルとして読み込むダウンロード ロジックをアプリに追加します。詳細については、 [Firebase ML から Cloud Storage への移行ガイド][migrate-storage] をご覧ください。

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

クラスが次の表に記載されている場合は、示されている変更を行います。

Swift

古いクラス新しいクラス
AutoMLImageLabelerLocalModel LocalModel
AutoMLImageLabelerRemoteModel LocalModel
カスタムモデルをホストしてダウンロードするには、モデルを Cloud Storage に移動し、 ローカルモデルとして読み込むダウンロード ロジックをアプリに追加します。詳細については、 [Firebase ML から Cloud Storage への移行ガイド][migrate-storage] をご覧ください。
AutoMLImageLabelerOptions CustomImageLabelerOptions

Objective-C

古いクラス新しいクラス
MLKAutoMLImageLabelerLocalModel MLKLocalModel
MLKAutoMLImageLabelerRemoteModel MLKLocalModel
カスタムモデルをホストしてダウンロードするには、モデルを Cloud Storage に移動し、 ローカルモデルとして読み込むダウンロード ロジックをアプリに追加します。詳細については、 [Firebase ML から Cloud Storage への移行ガイド][migrate-storage] をご覧ください。
MLKAutoMLImageLabelerOptions MLKCustomImageLabelerOptions

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

コードの変更は最小限に抑えられます。

  • LocalModel は、モデルパス(モデルにラベルマップを含むメタデータがある場合)またはモデル マニフェスト パス(マニフェスト、モデル、ラベルが別々のファイルにある場合)で初期化できるようになりました。
  • リモートでホストされているモデルをローカル ストレージにダウンロードし、LocalModel を使用して読み込むロジックをアプリに追加します。

新旧の 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)

新規

// Similar process for local models and remotely-hosted models (that have been downloaded)
guard let localModel = LocalModel(manifestPath: "automl/manifest.json") else { return }
let optionsWithLocalModel = CustomImageLabelerOptions(localModel: localModel)

新旧の 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];

新規

// Similar process for local models and remotely-hosted models (that have been downloaded)
MLKLocalModel *localModel =
    [[MLKLocalModel alloc] initWithManifestPath:"automl/manifest.json"];
MLKCustomImageLabelerOptions *optionsWithLocalModel =
    [[MLKCustomImageLabelerOptions alloc] initWithLocalModel:localModel];