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

คู่มือนี้จะอธิบายวิธีย้ายข้อมูลออกจาก ML Kit สำหรับ Firebase สำหรับ iOS

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

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

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

อัปเดต Cocoapods

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

APIชื่อ Pod เดิมชื่อ Pod ใหม่
การสแกนบาร์โค้ด Firebase/MLVision
Firebase/MLVisionBarcodeModel
GoogleMLKit/BarcodeScanning
การตรวจจับใบหน้า Firebase/MLVision
Firebase/MLVisionFaceModel
GoogleMLKit/FaceDetection
การติดป้ายกำกับรูปภาพ Firebase/MLVision
Firebase/MLVisionLabelModel
GoogleMLKit/ImageLabeling
การตรวจจับออบเจ็กต์และการติดตาม Firebase/MLVisionObjectDetection GoogleMLKit/ObjectDetection
การจดจำข้อความ Firebase/MLVision
Firebase/MLVisionTextModel
GoogleMLKit/TextRecognition
การติดป้ายกำกับรูปภาพด้วย AutoML (โมเดลที่รวมไว้) Firebase/MLVisionAutoML GoogleMLKit/ImageLabelingCustom
การติดป้ายกำกับรูปภาพด้วย AutoML (โมเดลที่ดาวน์โหลด) Firebase/MLVisionAutoML GoogleMLKit/ImageLabelingCustom

หากต้องการโฮสต์และดาวน์โหลดโมเดลที่กำหนดเอง ให้ย้ายโมเดลไปยัง Cloud Storage และเพิ่ม ตรรกะการดาวน์โหลดในแอปเพื่อโหลดโมเดลเหล่านั้นเป็นโมเดลในเครื่อง ดูรายละเอียดได้ที่ ดู คำแนะนำในการย้ายข้อมูลจาก Firebase ML ไปยัง Cloud Storage
รหัสภาษา Firebase/MLNaturalLanguage
Firebase/MLNLLanguageID
GoogleMLKit/LanguageID
ฟีเจอร์ช่วยตอบ Firebase/MLNaturalLanguage
Firebase/MLNLSmartReply
GoogleMLKit/SmartReply
แปลภาษา Firebase/MLNaturalLanguage
Firebase/MLNLTranslate
GoogleMLKit/Translate

อัปเดตชื่อคลาส, Enum และประเภท

โดยทั่วไปแล้ว คุณต้องเปลี่ยนชื่อคลาส, Enum และประเภทดังนี้

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

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

Swift

คลาสหรือประเภทเดิมคลาสหรือประเภทใหม่
AutoMLLocalModel LocalModel
AutoMLRemoteModel LocalModel

ต้องดาวน์โหลดด้วยตนเอง โมเดลระยะไกลที่โฮสต์โดย Firebase ไม่ได้รับการสนับสนุนอีกต่อไป ดูรายละเอียดได้ที่ คำแนะนำในการย้ายข้อมูลจาก Firebase ML ไปยัง Cloud Storage
VisionBarcodeDetectionCallback BarcodeScanningCallback
VisionBarcodeDetector BarcodeScanner
VisionBarcodeDetectorOptions BarcodeScannerOptions
VisionImage VisionImage (ไม่มีการเปลี่ยนแปลง)
VisionPoint VisionPoint (ไม่มีการเปลี่ยนแปลง)
VisionOnDeviceAutoMLImageLabelerOptions CustomImageLabelerOptions
VisionOnDeviceImageLabelerOptions ImageLabelerOptions

Objective-C

คลาสหรือประเภทเดิมคลาสหรือประเภทใหม่
FIRAutoMLLocalModel MLKLocalModel
FIRAutoMLRemoteModel MLKLocalModel

ต้องดาวน์โหลดด้วยตนเอง โมเดลระยะไกลที่โฮสต์โดย Firebase ไม่ได้รับการสนับสนุนอีกต่อไป ดูรายละเอียดได้ที่ คำแนะนำในการย้ายข้อมูลจาก Firebase ML ไปยัง Cloud Storage
FIRVisionBarcodeDetectionCallback MLKBarcodeScanningCallback
FIRVisionBarcodeDetector MLKBarcodeScanner
FIRVisionBarcodeDetectorOptions MLKBarcodeScannerOptions
FIRVisionImage MLKVisionImage
FIRVisionPoint MLKVisionPoint
FIRVisionOnDeviceAutoMLImageLabelerOptions MLKCustomImageLabelerOptions
FIRVisionOnDeviceImageLabelerOptions MLKImageLabelerOptions

อัปเดตชื่อเมธอด

อัปเดตชื่อเมธอดตามกฎต่อไปนี้

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

  • คลาส 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 ออก

นำทรัพยากร Dependency ของ Firebase ออกหลังจากการย้ายข้อมูล โดยทำตามขั้นตอนต่อไปนี้

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

ขอความช่วยเหลือ

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