คำแนะนำในการย้ายข้อมูล AutoML Vision Edge ของ ML Kit

คุณสามารถส่งโมเดลการจัดประเภทรูปภาพที่ฝึกโดย AutoML ไปยัง Custom Model API ได้ คุณยังคงรวมโมเดลไว้ในแอปหรือโฮสต์โมเดลในคอนโซล Firebase เป็นโมเดลที่กำหนดเองได้ ระบบได้นำ AutoML Image Labeling API ออกจาก ML Kit แล้วเนื่องจาก Custom Model Image Labeling API ได้เข้ามาแทนที่อย่างสมบูรณ์

APIสิ่งที่เปลี่ยนแปลง
AutoML Vision Edge Image Labeling API Custom Model Image Labeling API ได้เข้ามาแทนที่อย่างสมบูรณ์ ระบบได้นำ AutoML Vision Edge Image Labeling API ที่มีอยู่ ออกแล้ว

หากคุณใช้ AutoML Vision Edge API ให้ทำตามวิธีการย้ายข้อมูลสำหรับ Android และ iOS

คำถามที่พบบ่อย

เหตุใดจึงมีการเปลี่ยนแปลงนี้

การเปลี่ยนแปลงนี้ช่วยลดความซับซ้อนของ ML Kit API และทำให้การผสานรวม ML Kit เข้ากับแอปง่ายขึ้น การเปลี่ยนแปลงนี้จะช่วยให้คุณใช้โมเดลที่ฝึกโดย AutoML ได้ในลักษณะเดียวกับโมเดลที่กำหนดเอง นอกจากนี้ยังช่วยให้คุณใช้โมเดลที่ฝึกโดย AutoML สำหรับ Object Detection และ Object Tracking นอกเหนือจาก Image Labeling ที่เรารองรับ ยิ่งไปกว่านั้น Custom Model API ยังรองรับทั้งโมเดลที่มี Label Map ฝังอยู่ในข้อมูลเมตา และโมเดลที่มีไฟล์ Manifest และไฟล์ป้ายกำกับแยกกัน

การย้ายข้อมูลไปใช้ SDK ใหม่มีประโยชน์อย่างไร

  • ฟีเจอร์ใหม่: ความสามารถในการใช้โมเดลที่ฝึกโดย AutoML สำหรับทั้ง Image Labeling และ Object Detection รวมถึง Object Tracking และความสามารถในการใช้โมเดลที่มี Label Map ฝังอยู่ในข้อมูลเมตา

คำแนะนำในการย้ายข้อมูลสำหรับ Android

ขั้นตอนที่ 1: อัปเดตการนำเข้า Gradle

อัปเดตทรัพยากร Dependency สำหรับ ML Kit Android Library ในไฟล์ Gradle ของโมดูล (ระดับแอป) (โดยมากจะเป็นไฟล์ app/build.gradle.kts) ตามตารางต่อไปนี้

ฟีเจอร์อาร์ติแฟกต์เดิมอาร์ติแฟกต์ใหม่
Image Labeling AutoML โดยไม่ต้องดาวน์โหลดโมเดลจากระยะไกล com.google.mlkit:image-labeling-automl:16.2.1 com.google.mlkit:image-labeling-custom:16.0.0-beta5
Image Labeling AutoML พร้อมการดาวน์โหลดโมเดลจากระยะไกล 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
หากต้องการโฮสต์และดาวน์โหลดโมเดลที่กำหนดเอง ให้ย้ายโมเดลไปยัง Cloud Storage และ เพิ่มตรรกะการดาวน์โหลดในแอปเพื่อโหลดโมเดลโดยใช้ LocalModel ดูรายละเอียดได้ที่ [คำแนะนำในการย้ายข้อมูลจาก Firebase ML ไปยัง Cloud Storage][migrate-storage]

ขั้นตอนที่ 2: อัปเดตชื่อคลาส

หากชั้นเรียนของคุณปรากฏในตารางนี้ ให้ทำการเปลี่ยนแปลงตามที่ระบุ

ชั้นเรียนเดิมชั้นเรียนใหม่
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.LocalModel
แอปของคุณต้องมีตรรกะในการดาวน์โหลดโมเดลที่โฮสต์จากระยะไกลและ เริ่มต้นโมเดลโดยใช้ LocalModel
com.google.mlkit.vision.label.automl.AutoMLImageLabelerOptions com.google.mlkit.vision.label.custom.CustomImageLabelerOptions

ขั้นตอนที่ 3: อัปเดตชื่อเมธอด

มีการเปลี่ยนแปลงโค้ดเพียงเล็กน้อย ดังนี้

  • ตอนนี้คุณสามารถเริ่มต้น LocalModel ด้วยเส้นทางโมเดล (หากโมเดลมีข้อมูลเมตาที่มี Label Map) หรือเส้นทาง Manifest ของโมเดล (หาก Manifest, โมเดล และป้ายกำกับอยู่ในไฟล์แยกกัน)
  • เพิ่มตรรกะลงในแอปเพื่อดาวน์โหลดโมเดลที่โฮสต์จากระยะไกลไปยังพื้นที่เก็บข้อมูลในเครื่องและโหลดโมเดลโดยใช้ LocalModel

ตัวอย่างเมธอด Kotlin เดิมและเมธอด Kotlin ใหม่

เดิม

val localModel = AutoMLImageLabelerLocalModel.Builder()
    .setAssetFilePath("automl/manifest.json")
    // or .setAbsoluteFilePath(absolute 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()

ใหม่

// Similar process for both local and remotely-hosted models (that have been downloaded)
val localModel = LocalModel.Builder()
    .setAssetManifestFilePath("automl/manifest.json")
    // or .setAbsoluteManifestFilePath(absolute path to manifest file)
    .build()

val optionsWithLocalModel = CustomImageLabelerOptions.Builder(localModel)
    .setConfidenceThreshold(0.5f)
    .build()

ตัวอย่างเมธอด Java เดิมและเมธอด Java ใหม่

เดิม

AutoMLImageLabelerLocalModel localModel =
    new AutoMLImageLabelerLocalModel.Builder()
        .setAssetFilePath("automl/manifest.json")
        // or .setAbsoluteFilePath(absolute 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();

ใหม่

// Similar process for local models and remotely-hosted models (that have been downloaded)
LocalModel localModel =
    new LocalModel.Builder()
        .setAssetManifestFilePath("automl/manifest.json")
        // or .setAbsoluteManifestFilePath(absolute path to manifest file)
        .build();
CustomImageLabelerOptions optionsWithLocalModel =
    new CustomImageLabelerOptions.Builder(localModel)
        .setConfidenceThreshold(0.5f)
        .build();

คำแนะนำในการย้ายข้อมูลสำหรับ iOS

ข้อกำหนดเบื้องต้น

  • ต้องใช้ Xcode 13.2.1 ขึ้นไป

ขั้นตอนที่ 1: อัปเดต Cocoapods

อัปเดตทรัพยากร Dependency สำหรับ ML Kit iOS Cocoapods ใน Podfile ของแอป

ฟีเจอร์ชื่อ Pod เดิมชื่อ Pod ใหม่
Image Labeling AutoML โดยไม่ต้องดาวน์โหลดโมเดลจากระยะไกล GoogleMLKit/ImageLabelingAutoML GoogleMLKit/ImageLabelingCustom
Image Labeling AutoML พร้อมการดาวน์โหลดโมเดลจากระยะไกล GoogleMLKit/ImageLabelingAutoML
GoogleMLKit/LinkFirebase
GoogleMLKit/ImageLabelingCustom
หากต้องการโฮสต์และดาวน์โหลดโมเดลที่กำหนดเอง ให้ย้ายโมเดลไปยัง Cloud Storage และ เพิ่มตรรกะการดาวน์โหลดในแอปเพื่อโหลดโมเดลเป็นโมเดลในเครื่อง ดูรายละเอียดได้ที่ [คำแนะนำในการย้ายข้อมูลจาก Firebase ML ไปยัง Cloud Storage][migrate-storage]

ขั้นตอนที่ 2: อัปเดตชื่อคลาส

หากชั้นเรียนของคุณปรากฏในตารางนี้ ให้ทำการเปลี่ยนแปลงตามที่ระบุ

Swift

ชั้นเรียนเดิมชั้นเรียนใหม่
AutoMLImageLabelerLocalModel LocalModel
AutoMLImageLabelerRemoteModel LocalModel
หากต้องการโฮสต์และดาวน์โหลดโมเดลที่กำหนดเอง ให้ย้ายโมเดลไปยัง Cloud Storage และ เพิ่มตรรกะการดาวน์โหลดในแอปเพื่อโหลดโมเดลเป็นโมเดลในเครื่อง ดูรายละเอียดได้ที่ [คำแนะนำในการย้ายข้อมูลจาก Firebase ML ไปยัง Cloud Storage][migrate-storage]
AutoMLImageLabelerOptions CustomImageLabelerOptions

Objective-C

ชั้นเรียนเดิมชั้นเรียนใหม่
MLKAutoMLImageLabelerLocalModel MLKLocalModel
MLKAutoMLImageLabelerRemoteModel MLKLocalModel
หากต้องการโฮสต์และดาวน์โหลดโมเดลที่กำหนดเอง ให้ย้ายโมเดลไปยัง Cloud Storage และ เพิ่มตรรกะการดาวน์โหลดในแอปเพื่อโหลดโมเดลเป็นโมเดลในเครื่อง ดูรายละเอียดได้ที่ [คำแนะนำในการย้ายข้อมูลจาก Firebase ML ไปยัง Cloud Storage][migrate-storage]
MLKAutoMLImageLabelerOptions MLKCustomImageLabelerOptions

ขั้นตอนที่ 3: อัปเดตชื่อเมธอด

มีการเปลี่ยนแปลงโค้ดเพียงเล็กน้อย ดังนี้

  • ตอนนี้คุณสามารถเริ่มต้น LocalModel ด้วยเส้นทางโมเดล (หากโมเดลมีข้อมูลเมตาที่มี Label Map) หรือเส้นทาง Manifest ของโมเดล (หาก Manifest, โมเดล และป้ายกำกับอยู่ในไฟล์แยกกัน)
  • เพิ่มตรรกะลงในแอปเพื่อดาวน์โหลดโมเดลที่โฮสต์จากระยะไกลไปยังพื้นที่เก็บข้อมูลในเครื่องและโหลดโมเดลโดยใช้ LocalModel

ตัวอย่างเมธอด Swift เดิมและเมธอด Swift ใหม่

เดิม

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

ใหม่

// Similar process for local models and remotely-hosted models (that have been downloaded)
guard let localModel = LocalModel(manifestPath: "automl/manifest.json") else { return }
let optionsWithLocalModel = CustomImageLabelerOptions(localModel: localModel)

ตัวอย่างเมธอด Objective-C เดิมและเมธอด Objective-C ใหม่

เดิม

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

ใหม่

// Similar process for local models and remotely-hosted models (that have been downloaded)
MLKLocalModel *localModel =
    [[MLKLocalModel alloc] initWithManifestPath:"automl/manifest.json"];
MLKCustomImageLabelerOptions *optionsWithLocalModel =
    [[MLKCustomImageLabelerOptions alloc] initWithLocalModel:localModel];