Hướng dẫn di chuyển Bộ công cụ học máy AutoML Vision Edge

Bạn có thể truyền mô hình phân loại hình ảnh do AutoML huấn luyện tới các API mô hình tuỳ chỉnh. Bạn có thể tiếp tục gói mô hình đó bên trong ứng dụng hoặc lưu trữ mô hình đó trên Bảng điều khiển của Firebase dưới dạng mô hình tuỳ chỉnh. API gắn nhãn hình ảnh AutoML đã bị xoá khỏi Bộ công cụ học máy vì được thay thế hoàn toàn bằng API Gắn nhãn hình ảnh mô hình tuỳ chỉnh.

APIĐiều gì sẽ thay đổi?
API gắn nhãn hình ảnh AutoML Vision Edge API này được thay thế hoàn toàn bằng API gắn nhãn hình ảnh Mô hình tuỳ chỉnh. API gắn nhãn hình ảnh AutoML Vision Edge hiện có sẽ bị xoá.

Nếu bạn đang là người dùng Bộ công cụ học máy đang sử dụng API AutoML Vision Edge, vui lòng làm theo hướng dẫn di chuyển dành cho Android và iOS.

Câu hỏi thường gặp

Tại sao lại có sự thay đổi này?

API này giúp đơn giản hoá các API của Bộ công cụ học máy và giúp bạn dễ dàng tích hợp Bộ công cụ học máy vào ứng dụng của mình hơn. Với thay đổi này, bạn có thể sử dụng mô hình được huấn luyện bằng AutoML theo cách giống hệt như mô hình tuỳ chỉnh. Ngoài tính năng Gắn nhãn hình ảnh mà chúng tôi hiện hỗ trợ, bạn cũng có thể sử dụng các mô hình đã được huấn luyện bằng AutoML để Phát hiện và theo dõi đối tượng. Hơn nữa, API mô hình tuỳ chỉnh hỗ trợ cả hai mô hình có bản đồ nhãn được nhúng trong siêu dữ liệu, và các mô hình có tệp kê khai và tệp nhãn riêng biệt.

Tôi nhận được lợi ích gì khi di chuyển sang SDK mới?

  • Tính năng mới: Có thể sử dụng các mô hình đã được huấn luyện bằng AutoML cho cả việc Gắn nhãn hình ảnh lẫn Phát hiện và theo dõi đối tượng và có thể sử dụng các mô hình có bản đồ nhãn được nhúng trong siêu dữ liệu.

Hướng dẫn di chuyển dành cho Android

Bước 1: Cập nhật các lệnh nhập Gradle

Cập nhật các phần phụ thuộc cho thư viện Android Bộ công cụ học máy trong tệp Gradle của mô-đun (cấp ứng dụng) (thường là app/build.gradle) theo bảng sau:

Tính năngCấu phần phần mềm cũCấu phần phần mềm mới
Gắn nhãn hình ảnh AutoML mà không cần tải mô hình từ xa xuống com.google.mlkit:image-labeling-automl:16.2.1 com.google.mlkit:image-labeling-custom:16.0.0-beta5
Gắn nhãn hình ảnh AutoML với mô hình từ xa được tải xuống 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

Bước 2: Cập nhật tên lớp

Nếu lớp của bạn xuất hiện trong bảng này, hãy thực hiện thay đổi được nêu:

Lớp cũLớp học mới
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

Bước 3: Cập nhật tên phương thức

Có rất ít thay đổi về mã:

  • LocalModel hiện có thể được khởi tạo bằng đường dẫn tệp mô hình (nếu mô hình có siêu dữ liệu chứa bản đồ nhãn) hoặc đường dẫn tệp kê khai mô hình (nếu tệp kê khai, mô hình và nhãn nằm trong các tệp riêng biệt).
  • Bạn có thể lưu trữ một mô hình tuỳ chỉnh từ xa thông qua Bảng điều khiển của Firebase và khởi chạy CustomRemoteModel bằng FirebaseModelSource.

Dưới đây là một số ví dụ về các phương thức Kotlin cũ và mới:

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

Mới

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

Dưới đây là một số ví dụ về các phương thức Java cũ và mới:

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

Mới

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

Hướng dẫn di chuyển cho iOS

Điều kiện tiên quyết

  • Cần có Xcode 13.2.1 trở lên.

Bước 1: Cập nhật Cocoapods

Cập nhật các phần phụ thuộc cho cocoapods dành cho iOS của Bộ công cụ học máy trong Podfile của ứng dụng:

Tính năngTên nhóm cũ(Các) tên nhóm mới
Gắn nhãn hình ảnh AutoML mà không cần tải mô hình từ xa xuống GoogleMLKit/ImageLabelingAutoML GoogleMLKit/ImageLabelingCustom
Gắn nhãn hình ảnh AutoML với mô hình từ xa được tải xuống GoogleMLKit/ImageLabelingAutoML
GoogleMLKit/LinkFirebase
GoogleMLKit/ImageLabelingCustom
GoogleMLKit/LinkFirebase

Bước 2: Cập nhật tên lớp

Nếu lớp của bạn xuất hiện trong bảng này, hãy thực hiện thay đổi được nêu:

Swift

Lớp cũLớp học mới
AutoMLImageLabelerLocalModel LocalModel
AutoMLImageLabelerRemoteModel CustomRemoteModel
AutoMLImageLabelerOptions CustomImageLabelerOptions

Objective-C

Lớp cũLớp học mới
MLKAutoMLImageLabelerLocalModel MLKLocalModel
MLKAutoMLImageLabelerRemoteModel MLKCustomRemoteModel
MLKAutoMLImageLabelerOptions MLKCustomImageLabelerOptions

Objective-C

Bước 3: Cập nhật tên phương thức

Có rất ít thay đổi về mã:

  • LocalModel hiện có thể được khởi tạo bằng đường dẫn tệp mô hình (nếu mô hình có siêu dữ liệu chứa bản đồ nhãn) hoặc đường dẫn tệp kê khai mô hình (nếu tệp kê khai, mô hình và nhãn nằm trong các tệp riêng biệt).
  • Bạn có thể lưu trữ một mô hình tuỳ chỉnh từ xa thông qua Bảng điều khiển của Firebase và khởi chạy CustomRemoteModel bằng FirebaseModelSource.

Dưới đây là một số ví dụ về các phương thức Swift cũ và mới:

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

Mới

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)

Dưới đây là một số ví dụ về các phương thức Target-C cũ và mới:

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

Mới

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