ข้อกำหนดเบื้องต้น
ก่อนเริ่มย้ายข้อมูลโค้ด โปรดตรวจสอบว่าคุณมีคุณสมบัติตรงตามข้อกำหนดต่อไปนี้
- 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 สำหรับ ML Kit iOS Cocoapods ใน Podfile ของแอปโดยทำดังนี้
| API | ชื่อพ็อดเดิม | ชื่อพ็อดใหม่ |
|---|---|---|
| การสแกนบาร์โค้ด | 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) | Firebase/MLVisionAutoML | GoogleMLKit/ImageLabelingCustom GoogleMLKit/LinkFirebase |
| รหัสภาษา | Firebase/MLNaturalLanguage Firebase/MLNLLanguageID |
GoogleMLKit/LanguageID |
| ฟีเจอร์ช่วยตอบ | Firebase/MLNaturalLanguage Firebase/MLNLSmartReply |
GoogleMLKit/SmartReply |
| แปลภาษา | Firebase/MLNaturalLanguage Firebase/MLNLTranslate |
GoogleMLKit/Translate |
อัปเดตชื่อของคลาส 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) ไม่มีอยู่อีกต่อไป โดยระบบจะแทนที่ด้วยคลาสเฉพาะงาน แทนที่การเรียกเมธอดต่างๆ ของ Factory สำหรับรับเครื่องตรวจจับด้วย การเรียกเมธอด Factory ของเครื่องตรวจจับแต่ละรายการโดยตรงระบบได้นำคลาส
VisionImageMetadataออกแล้วพร้อมกับ enumVisionDetectorImageOrientationใช้พร็อพเพอร์ตี้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
แทนที่จะเป็นจำนวนเต็ม หมวดหมู่สตริงที่เป็นไปได้ทั้งหมดจะรวมอยู่ใน
DetectedObjectLabel enum
โปรดทราบว่าเราได้นำหมวดหมู่.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]) {
...
}นำการขึ้นต่อกันของ Firebase ออก (ไม่บังคับ)
ขั้นตอนนี้จะมีผลก็ต่อเมื่อเป็นไปตามเงื่อนไขต่อไปนี้
- คุณใช้ Firebase ML Kit เป็นคอมโพเนนต์ Firebase เพียงอย่างเดียว
- คุณใช้เฉพาะ API บนอุปกรณ์
- คุณไม่ได้ใช้การแสดงโมเดล
ในกรณีนี้ คุณสามารถนำการอ้างอิง Firebase ออกได้หลังจากการย้ายข้อมูล โปรดทำตามขั้นตอนต่อไปนี้
- นำไฟล์การกำหนดค่า Firebase ออกโดยลบไฟล์ GoogleService-Info.plist ออกจากไดเรกทอรีของแอปและโปรเจ็กต์ Xcode
- นำ Cocoapod ของ Firebase เช่น
pod 'Firebase/Analytics'ออกจาก Podfile - นำการเริ่มต้น FirebaseApp ออก เช่น
FirebaseApp.configure()จากโค้ด - ลบแอป Firebase ในคอนโซล Firebase ตามวิธีการในเว็บไซต์สนับสนุนของ Firebase
ขอความช่วยเหลือ
หากพบปัญหา โปรดไปที่หน้าชุมชน ซึ่งเราได้ระบุช่องทางต่างๆ ที่คุณใช้ติดต่อเราได้