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 đóng 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 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ì 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.

APICó điều gì 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 của Mô hình tuỳ chỉnh. Xoá API gắn nhãn hình ảnh hiện có của AutoML Vision Edge.

Nếu bạn hiện là người dùng Bộ công cụ học máy và đ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?

Điều này giúp đơn giản hoá các API 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. 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 ra, 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, ngoài tính năng Gắn nhãn hình ảnh mà chúng tôi hiện hỗ trợ. Ngoài ra, API mô hình tuỳ chỉnh hỗ trợ cả mô hình có bản đồ nhãn được nhúng trong siêu dữ liệu và mô hình có tệp kê khai và nhãn riêng biệt.

Tôi nhận được những 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ả tính năng Gắn nhãn hình ảnh và Phát hiện và theo dõi đối tượng, cũng như có thể sử dụng các mô hình có bản đồ nhãn được nhúng trong siêu dữ liệu của mô hình.

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

Bước 1: Cập nhật nội dung nhập 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 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
AutoML gắn nhãn hình ảnh mà không cần tải mô hình từ xa com.google.mlkit:image-labeling-automl:16.2.1 com.google.mlkit:image-labeling-custom:16.0.0-beta5
Tính năng gắn nhãn hình ảnh bằng AutoML có tính năng tải mô hình từ xa 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 chỉ định:

Lớp cũLớp 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

Bạn chỉ cần thay đổi mã ở mức tối thiểu:

  • Giờ đây, bạn có thể khởi chạy LocalModel 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 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:

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

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

  • 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 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 mới của nhóm
AutoML gắn nhãn hình ảnh mà không cần tải mô hình từ xa GoogleMLKit/ImageLabelingAutoML GoogleMLKit/ImageLabelingCustom
Tính năng gắn nhãn hình ảnh bằng AutoML có tính năng tải mô hình từ xa 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 chỉ định:

Lớp cũLớp mới
AutoMLImageLabelerLocalModel LocalModel
AutoMLImageLabelerRemoteModel CustomRemoteModel
AutoMLImageLabelerOptions CustomImageLabelerOptions
Lớp cũLớp mới
MLKAutoMLImageLabelerLocalModel MLKLocalModel
MLKAutoMLImageLabelerRemoteModel MLKCustomRemoteModel
MLKAutoMLImageLabelerOptions MLKCustomImageLabelerOptions

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

Bạn chỉ cần thay đổi mã ở mức tối thiểu:

  • Giờ đây, bạn có thể khởi chạy LocalModel 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 Firebase và khởi chạy CustomRemoteModel bằng FirebaseModelSource.

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

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

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