Panduan migrasi AutoML Vision Edge ML Kit

Anda dapat meneruskan model klasifikasi gambar yang dilatih AutoML ke model kustom tersebut Google Cloud Platform. 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 sudah diganti sepenuhnya dengan Custom Model Image Pelabelan API.

APIApa saja yang berubah?
API pelabelan gambar AutoML Vision Edge Fungsi ini sepenuhnya diganti dengan API pelabelan gambar Model Kustom. Yang sudah ada API pelabelan gambar AutoML Vision Edge 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)

Apa alasan perubahan ini?

Ini membantu menyederhanakan ML Kit API, dan lebih mudah untuk mengintegrasikan ML Kit ke dalam aplikasi Anda. Dengan perubahan ini, Anda dapat menggunakan model yang dilatih AutoML dengan cara yang sama seperti model kustom. Anda juga dapat menggunakan model yang dilatih AutoML untuk Deteksi dan Pelacakan Objek, selain Pelabelan Gambar yang kami saat ini didukung. Selain itu, API model kustom mendukung kedua model dengan peta label yang disematkan dalam metadatanya, dan model dengan manifes terpisah dan memberi label pada file.

Apa manfaat yang saya dapatkan dengan bermigrasi ke SDK baru?

  • Fitur baru: Kemampuan untuk menggunakan model yang dilatih AutoML untuk Pelabelan Gambar dan Deteksi Objek & Pelacakan dan kemampuan untuk menggunakan model dengan peta label yang disematkan dalam {i>metadata<i}.

Panduan Migrasi untuk Android

Langkah 1: Perbarui Impor Gradle

Mengupdate dependensi untuk library Android ML Kit di modul Anda File Gradle (level aplikasi), biasanya app/build.gradle, sesuai dengan berikut ini tabel:

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

Jika kelas Anda muncul dalam tabel ini, lakukan 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

Hanya 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 ada dalam file terpisah).
  • Anda dapat menghosting model kustom dari jarak jauh melalui Firebase Console dan melakukan inisialisasi CustomRemoteModel dengan FirebaseModelSource.

Berikut ini 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 ini 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 baru.

Langkah 1: Perbarui Cocoapod

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

FiturNama pod lamaNama pod baru
Pelabelan gambar AutoML tanpa download model jarak jauh GoogleMLKit/ImageLabelingAutoML GoogleMLKit/ImageLabelingCustom
Pelabelan gambar AutoML disertai proses download model jarak jauh GoogleMLKit/ImageLabelingAutoML
GoogleMLKit/LinkFirebase
GoogleMLKit/ImageLabelingCustom
GoogleMLKit/LinkFirebase

Langkah 2: Perbarui nama class

Jika kelas Anda muncul dalam tabel ini, lakukan 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

Hanya 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 ada dalam file terpisah).
  • Anda dapat menghosting model kustom dari jarak jauh melalui Firebase Console dan melakukan inisialisasi 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 yang 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];