Panduan migrasi AutoML Vision Edge ML Kit

Anda dapat meneruskan model klasifikasi gambar yang dilatih AutoML ke API model kustom. Anda dapat terus memaketkan model di dalam aplikasi atau menghostingnya di Firebase Console sebagai model kustom. API pelabelan gambar AutoML telah dihapus dari ML Kit karena sepenuhnya diganti dengan API Label Image Model Kustom.

APIApa saja yang berubah?
API pelabelan gambar AutoML Vision Edge Ini sepenuhnya digantikan oleh API pelabelan gambar Model Kustom. API pelabelan gambar AutoML Vision Edge yang ada akan dihapus.

Jika saat ini Anda adalah pengguna ML Kit yang menggunakan AutoML Vision Edge API, ikuti petunjuk migrasi untuk Android dan iOS.

Pertanyaan Umum (FAQ)

Mengapa perubahan ini?

ML Kit membantu menyederhanakan API ML Kit, dan mempermudah integrasi ML Kit ke dalam aplikasi Anda. Dengan perubahan ini, Anda dapat menggunakan model yang dilatih AutoML dengan cara yang sama persis seperti model kustom. Hal ini juga memungkinkan Anda menggunakan model yang dilatih AutoML untuk Deteksi dan Pelacakan Objek, selain Pelabelan Gambar yang saat ini kami dukung. Selain itu, API model kustom mendukung kedua model dengan peta label yang disematkan dalam metadatanya, serta model dengan file manifes dan label yang terpisah.

Manfaat apa yang saya dapatkan dari bermigrasi ke SDK baru?

  • Fitur baru: Kemampuan untuk menggunakan model yang dilatih AutoML untuk Pelabelan Gambar dan Deteksi & Pelacakan Objek, serta kemampuan untuk menggunakan model dengan peta label yang disematkan dalam metadatanya.

Panduan Migrasi untuk Android

Langkah 1: Perbarui Impor Gradle

Update dependensi untuk library Android ML Kit dalam file Gradle modul (level aplikasi), biasanya app/build.gradle, sesuai dengan tabel berikut:

FiturArtefak LamaArtefak Baru
Pelabelan gambar AutoML tanpa mendownload model dari jarak jauh com.google.mlkit:image-labeling-automl:16.2.1 com.google.mlkit:image-labeling-custom:16.0.0-beta5
Pelabelan gambar AutoML dengan download model jarak jauh 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

Langkah 2: Perbarui nama kelas

Jika kelas Anda muncul dalam tabel ini, buat perubahan yang ditunjukkan:

Kelas lamaKelas baru
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

Langkah 3: Perbarui nama metode

Ada sedikit perubahan kode:

  • LocalModel kini dapat diinisialisasi dengan jalur file model (jika model memiliki metadata yang berisi peta label) atau jalur file manifes model (jika manifes, model, dan label berada dalam file terpisah).
  • Anda dapat menghosting model kustom dari jarak jauh melalui Firebase Console dan menginisialisasi CustomRemoteModel dengan FirebaseModelSource.

Berikut adalah beberapa contoh metode Kotlin lama dan baru:

Lama

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()

Baru

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()

Berikut adalah beberapa contoh metode Java lama dan baru:

Lama

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();

Baru

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();

Panduan Migrasi untuk iOS

Prasyarat

  • Memerlukan Xcode 13.2.1 atau yang lebih tinggi.

Langkah 1: Update Cocoapods

Perbarui dependensi untuk cocoapod iOS ML Kit di Podfile aplikasi Anda:

FiturNama pod lamaNama pod baru
Pelabelan gambar AutoML tanpa mendownload model dari jarak jauh GoogleMLKit/ImageLabelingAutoML GoogleMLKit/ImageLabelingCustom
Pelabelan gambar AutoML dengan download model jarak jauh GoogleMLKit/ImageLabelingAutoML
GoogleMLKit/LinkFirebase
GoogleMLKit/ImageLabelingCustom
GoogleMLKit/LinkFirebase

Langkah 2: Perbarui nama kelas

Jika kelas Anda muncul dalam tabel ini, buat perubahan yang ditunjukkan:

Swift

Kelas lamaKelas baru
AutoMLImageLabelerLocalModel LocalModel
AutoMLImageLabelerRemoteModel CustomRemoteModel
AutoMLImageLabelerOptions CustomImageLabelerOptions

Objective-C

Kelas lamaKelas baru
MLKAutoMLImageLabelerLocalModel MLKLocalModel
MLKAutoMLImageLabelerRemoteModel MLKCustomRemoteModel
MLKAutoMLImageLabelerOptions MLKCustomImageLabelerOptions

Objective-C

Langkah 3: Perbarui nama metode

Ada sedikit perubahan kode:

  • LocalModel kini dapat diinisialisasi dengan jalur file model (jika model memiliki metadata yang berisi peta label) atau jalur file manifes model (jika manifes, model, dan label berada dalam file terpisah).
  • Anda dapat menghosting model kustom dari jarak jauh melalui Firebase Console dan menginisialisasi CustomRemoteModel dengan FirebaseModelSource.

Berikut adalah beberapa contoh metode Swift lama dan baru:

Lama

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

Baru

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)

Berikut adalah beberapa contoh metode Objective-C lama dan baru:

Lama

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

Baru

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