การย้ายข้อมูลสำหรับ iOS

สิ่งที่ต้องดำเนินการก่อน

ก่อนที่จะเริ่มย้ายข้อมูลโค้ด โปรดตรวจสอบว่าคุณมีคุณสมบัติตรงตามข้อกำหนดต่อไปนี้

  • ML Kit รองรับ Xcode 13.2.1 หรือใหม่กว่า
  • ML Kit รองรับ iOS เวอร์ชัน 10 หรือใหม่กว่า
  • ML Kit ไม่รองรับสถาปัตยกรรม 32 บิต (i386 และ armv7) ML Kit รองรับสถาปัตยกรรม 64 บิต (x86_64 และ arm64)
  • คลัง ML Kit ให้บริการเป็น CocoaPod เท่านั้น คุณไม่สามารถรวมเฟรมเวิร์กและ CocoaPods เข้าด้วยกันได้ ดังนั้นคุณต้องย้ายข้อมูลเพื่อใช้ CocoaPod ก่อนจึงจะใช้ไลบรารีนี้ได้

อัปเดต CocoaPods

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

APIชื่อพ็อดเก่าชื่อพ็อดใหม่
การสแกนบาร์โค้ด Firebase/MLVision
Firebase/MLVisionBarcodeModel
GoogleMLKit/การสแกนบาร์โค้ด
การตรวจจับใบหน้า Firebase/MLVision
Firebase/MLVisionFaceModel
GoogleMLKit/FaceDetection
การติดป้ายกำกับรูปภาพ Firebase/MLVision
Firebase/MLVisionLabelModel
GoogleMLKit/ImageLabeling
การตรวจจับและติดตามวัตถุ Firebase/MLVisionObjectDetection GoogleMLKit/การตรวจจับข้อโต้แย้ง
การรู้จำข้อความ Firebase/MLVision
Firebase/MLVisionTextModel
GoogleMLKit/การรู้จำข้อความ
การติดป้ายกำกับรูปภาพ AutoML (โมเดลแบบกลุ่ม) Firebase/MLVisionAutoML GoogleMLKit/ImageLabelingCustom
การติดป้ายกำกับรูปภาพ AutoML (การดาวน์โหลดโมเดลจาก Firebase) Firebase/MLVisionAutoML GoogleMLKit/ImageLabelingCustom
GoogleMLKit/LinkFirebase
รหัสภาษา Firebase/MLNaturalLanguage
Firebase/MLNLLanguageID
GoogleMLKit/รหัสภาษา
ฟีเจอร์ช่วยตอบ Firebase/MLNaturalLanguage
Firebase/MLNLSmartฉบับ
GoogleMLKit/Smartรีพลาย
แปลภาษา Firebase/MLNaturalLanguage
Firebase/MLNLtranslate
GoogleMLKit/แปลภาษา

อัปเดตชื่อของคลาส ค่าแจกแจง และประเภท

โดยทั่วไป คลาส , enum และ ประเภท จำเป็นต้องเปลี่ยนชื่อดังนี้:

  • Swift: นำคำนำหน้า Vision ออกจากชื่อคลาสและ enum
  • Objective-C: แทนที่ทั้งชื่อคลาส FIRVision และ FIR และคำนำหน้า enum ด้วย MLK

กฎทั่วไปนี้จะไม่ใช้กับชื่อคลาสและประเภทบางรายการ

Swift

ชั้นเรียนหรือประเภทเดิมชั้นเรียนหรือประเภทใหม่
AutoMLLocalModel LocalModel
AutoMLRemoteModel CustomRemoteModel
VisionBarcodeDetectionCallback BarcodeScanningCallback
VisionBarcodeDetector BarcodeScanner
VisionBarcodeDetectorOptions BarcodeScannerOptions
VisionImage VisionImage (ไม่มีการเปลี่ยนแปลง)
VisionPoint VisionPoint (ไม่มีการเปลี่ยนแปลง)
VisionOnDeviceAutoMLImageLabelerOptions CustomImageLabelerOptions
VisionOnDeviceImageLabelerOptions ImageLabelerOptions

Objective-C

ชั้นเรียนหรือประเภทเดิมชั้นเรียนหรือประเภทใหม่
FIRAutoMLLocalModel MLKLocalModel
FIRAutoMLRemoteModel MLKCustomRemoteModel
FIRVisionBarcodeDetectionCallback MLKBarcodeScanningCallback
FIRVisionBarcodeDetector MLKBarcodeScanner
FIRVisionBarcodeDetectorOptions MLKBarcodeScannerOptions
FIRVisionImage MLKVisionImage
FIRVisionOnDeviceAutoMLImageLabelerOptions MLKCustomImageLabelerOptions
FIRVisionOnDeviceImageLabelerOptions MLKImageLabelerOptions
FIRVisionPoint MLKVisionPoint

Objective-C

อัปเดตชื่อวิธีการ

อัปเดตชื่อวิธีการตามกฎเหล่านี้

  • ไม่มีคลาสจุดแรกเข้าของโดเมน (Vision, NaturalLanguage) แล้ว ชั้นเรียนเหล่านี้มีการแทนที่ด้วยชั้นเรียนเฉพาะงาน แทนที่การเรียกใช้วิธีการต่างๆ จากโรงงานเพื่อรับตัวตรวจจับด้วยการเรียกใช้เมธอดจากโรงงานของตัวตรวจจับแต่ละรายการโดยตรง

  • นำชั้นเรียน VisionImageMetadata พร้อมกับ enum ของ VisionDetectorImageOrientation ออกแล้ว ใช้พร็อพเพอร์ตี้ orientation ของ VisionImage เพื่อระบุการวางแนวในการแสดงของรูปภาพ

  • เปลี่ยนชื่อเมธอด onDeviceTextRecognizer ที่ได้รับอินสแตนซ์ TextRecognizer ใหม่เป็น textRecognizer แล้ว

  • นำพร็อพเพอร์ตี้ความเชื่อมั่นออกจากคลาสผลลัพธ์การจดจำข้อความ ซึ่งรวมถึง TextElement, TextLine และ TextBlock แล้ว

  • ระบบผสานรวมเมธอด onDeviceImageLabeler และ onDeviceImageLabeler(options:) เพื่อรับอินสแตนซ์ ImageLabeler ใหม่และเปลี่ยนชื่อเป็น imageLabeler(options:) แล้ว

  • นำเมธอด objectDetector ในการรับอินสแตนซ์ ObjectDetector ใหม่ออกแล้ว โปรดใช้ objectDetector(options:) แทน

  • นำพร็อพเพอร์ตี้ type ออกจาก ImageLabeler และนำพร็อพเพอร์ตี้ entityID ออกจากคลาสผลการค้นหาการติดป้ายกำกับรูปภาพ ImageLabel แล้ว

  • API การสแกนบาร์โค้ด detect(in _:, completion:) ได้เปลี่ยนชื่อเป็น process(_:, completion:) เพื่อให้สอดคล้องกับ Vision API อื่นๆ

  • ตอนนี้ Natural Language API จะใช้คำว่า "แท็กภาษา" (ตามที่กำหนดโดยมาตรฐาน BCP-47) แทน "รหัสภาษา"

  • ตอนนี้ TranslateLanguage ใช้ชื่อที่อ่านได้ (เช่น .english) เป็นค่าคงที่แทนแท็กภาษา ( เช่น .en)

ต่อไปนี้คือตัวอย่างของเมธอด Swift ทั้งเก่าและใหม่

เก่า

let options = VisionOnDeviceImageLabelerOptions()
options.confidenceThreshold = 0.75
let labeler = Vision.vision().onDeviceImageLabeler(options: options)

let detector = Vision.vision().faceDetector(options: options)

let localModel = AutoMLLocalModel(manifestPath: "automl/manifest.json")
let options = VisionOnDeviceAutoMLImageLabelerOptions(localModel: localModel)
options.confidenceThreshold = 0.75
let labeler = vision.onDeviceAutoMLImageLabeler(options: options)

let detector = Vision.vision().objectDetector()
    

ใหม่

let options = ImageLabelerOptions()
options.confidenceThreshold = NSNumber(value:0.75)
let labeler = ImageLabeler.imageLabeler(options: options)

let detector = FaceDetector.faceDetector(options: options)

let localModel = LocalModel(manifestPath: "automl/manifest.json")
let options = CustomImageLabelerOptions(localModel: localModel)
options.confidenceThreshold = NSNumber(value:0.75)
let labeler = ImageLabeler.imageLabeler(options: options)

let detector = ObjectDetector.objectDetector(options: ObjectDetectorOptions())
    

ต่อไปนี้คือตัวอย่างของวิธีการ Objective-C ทั้งแบบเก่าและแบบใหม่

เก่า

FIRVisionOnDeviceImageLabelerOptions *options = 
    [[FIRVisionOnDeviceImageLabelerOptions alloc] init];
options.confidenceThreshold = 0.75;
FIRVisionImageLabeler *labeler = 
    [[FIRVision vision] onDeviceImageLabelerWithOptions:options];

FIRVisionFaceDetector *detector =
    [[FIRVision vision] faceDetectorWithOptions: options];

FIRAutoMLLocalModel *localModel =
    [[FIRAutoMLLocalModel alloc] initWithManifestPath:@"automl/manifest.json"];
FIRVisionOnDeviceAutoMLImageLabelerOptions *options =
    [[FIRVisionOnDeviceAutoMLImageLabelerOptions alloc]
        initWithLocalModel: localModel];
options.confidenceThreshold = 0.75
FIRVisionImageLabeler *labeler =
    [[FIRVision vision] onDeviceAutoMLImageLabelerWithOptions:options];

FIRVisionObjectDetector *detector =
    [[FIRVision vision] objectDetector];
    

ใหม่

MLKImageLabelerOptions *options =
    [[MLKImageLabelerOptions alloc] init];
options.confidenceThreshold = @(0.75);
MLKImageLabeler *labeler =
    [MLKImageLabeler imageLabelerWithOptions:options];

MLKFaceDetector *detector =
    [MLKFaceDetector faceDetectorWithOptions:options];

MLKLocalModel *localModel =
    [[MLKLocalModel alloc]
        initWithManifestPath:@"automl/manifest.json"];
MLKCustomImageLabelerOptions *options =
    [[MLKCustomImageLabelerOptions alloc] initWithLocalModel:localModel];
options.confidenceThreshold = @(0.75)
MLKImageLabeler *labeler =
    [MLKImageLabeler imageLabelerWithOptions:options];

MLKObjectDetectorOptions *options = [[MLKObjectDetectorOptions alloc] init];
MLKObjectDetector *detector = [MLKObjectDetector objectDetectorWithOptions:options];
    

การเปลี่ยนแปลงเฉพาะ API

การตรวจจับและติดตามวัตถุ

หากแอปใช้การจัดประเภทออบเจ็กต์ โปรดทราบว่า SDK ใหม่ได้เปลี่ยนวิธีแสดงหมวดหมู่การจัดประเภทสำหรับออบเจ็กต์ที่ตรวจพบ

VisionObjectCategory ใน VisionObject จะแสดงผลเป็น text ในออบเจ็กต์ ObjectLabel แทนจำนวนเต็ม หมวดหมู่สตริงที่เป็นไปได้ทั้งหมดจะรวมอยู่ใน enum DetectedObjectLabel

โปรดทราบว่าเราได้นำหมวดหมู่ .unknown ออกแล้ว เมื่อความมั่นใจในการจัดประเภทออบเจ็กต์ต่ำ ตัวแยกประเภทจะไม่แสดงป้ายกำกับใดๆ เลย

ต่อไปนี้คือตัวอย่างของโค้ด Swift เก่าและใหม่

เก่า

if (object.classificationCategory == .food) {
    ...
}

ใหม่

if let label = object.labels.first {
  if (label.text == DetectedObjectLabel.food.rawValue) {
    ...
  }
}
// or
if let label = object.labels.first {
  if (label.index == DetectedObjectLabelIndex.food.rawValue) {
    ...
  }
}

ต่อไปนี้คือตัวอย่างของโค้ด Objective-C ทั้งเก่าและใหม่

เก่า

if (object.classificationCategory == FIRVisionObjectCategoryFood) {
    ...
}

ใหม่

if ([object.labels[0].text isEqualToString:MLKDetectedObjectLabelFood]) {
  ...
}
// or
if ([object.labels[0].index == MLKDetectedObjectLabelIndexFood]) {
  ...
}

นำทรัพยากร Dependency ของ Firebase ออก (ไม่บังคับ)

ขั้นตอนนี้จะใช้เมื่อตรงกับเงื่อนไขเหล่านี้เท่านั้น

  • Firebase ML Kit เป็นคอมโพเนนต์ Firebase เพียงอย่างเดียวที่คุณใช้
  • คุณใช้ API ในอุปกรณ์เท่านั้น
  • คุณไม่ได้ใช้การแสดงโมเดล

ในกรณีนี้ คุณสามารถนำทรัพยากร Dependency ของ Firebase ออกหลังการย้ายข้อมูลได้ โปรดทำตามขั้นตอนต่อไปนี้

  • นำไฟล์การกำหนดค่า Firebase ออกโดยลบไฟล์ GoogleService-Info.plist จากไดเรกทอรีของแอปและโปรเจ็กต์ Xcode
  • นำ CocoaPod ของ Firebase เช่น pod 'Firebase/Analytics' ออกจาก Podfile
  • นำการเริ่มต้น FirebaseApp เช่น FirebaseApp.configure() ออกจากโค้ด
  • ลบแอป Firebase ที่คอนโซล Firebase ตามinstructionsในเว็บไซต์การสนับสนุนของ Firebase

การรับความช่วยเหลือ

หากพบปัญหา โปรดไปที่หน้าชุมชนซึ่งระบุช่องที่สามารถติดต่อเราได้