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 được huấn luyện bằng AutoML đến 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 cho 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 sử dụng AutoML Vision Edge API, 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?

Điều này giúp đơn giản hoá các API của Bộ công cụ học máy và giúp tích hợp Bộ công cụ học máy vào ứng dụng của bạn dễ dàng 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 đào tạo bằng công nghệ AutoML (Học máy) để Phát hiện và Theo dõi đối tượng. Ngoài ra, 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 những lợi ích gì khi chuyển sang SDK mới?

  • Các tính năng mới: Có thể sử dụng các mô hình được huấn luyện bằng công nghệ AutoML cho cả tính năng Gắn nhãn hình ảnh lẫn Phát hiện và theo dõi đối tượng, cũng như khả năng 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 dữ liệu nhập từ Gradle

Cập nhật các phần phụ thuộc cho thư viện Android của Bộ công cụ học máy trong tệp Gradle 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 bằng việc tải mô hình từ xa 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 học của bạn xuất hiện trong bảng này, hãy thực hiện thay đổi như sau:

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

Mã có một số thay đổi nhỏ:

  • 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ô 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ề 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()

Sau đây là một số ví dụ về 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 dành cho iOS

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

  • Yêu cầu 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ăng(Các) tê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 bằng việc tải mô hình từ xa 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 học của bạn xuất hiện trong bảng này, hãy thực hiện thay đổi như sau:

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

Mã có một số thay đổi nhỏ:

  • 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ô 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.

Sau đâ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)

Sau đây là một số ví dụ về phương thức Objective-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];