이 가이드에서는 iOS용 Firebase ML Kit에서 이전하는 방법을 설명합니다.
기본 요건
코드를 이전하기 전에 다음 요구사항을 충족하는지 확인하세요.
- 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 업데이트
앱의 Podfile에서 ML Kit iOS cocoapods의 종속 항목을 업데이트합니다.
| 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/MLVisionAutoML | GoogleMLKit/ImageLabelingCustom 커스텀 모델을 호스팅하고 다운로드하려면 모델을 Cloud Storage로 이동하고 앱에 다운로드 로직을 추가하여 로컬 모델로 로드하세요. 자세한 내용은 Firebase ML에서 Cloud Storage로의 이전 가이드를 참고하세요. |
| 언어 ID | Firebase/MLNaturalLanguage Firebase/MLNLLanguageID |
GoogleMLKit/LanguageID |
| 스마트 답장 | Firebase/MLNaturalLanguage Firebase/MLNLSmartReply |
GoogleMLKit/SmartReply |
| 번역 | Firebase/MLNaturalLanguage Firebase/MLNLTranslate |
GoogleMLKit/Translate |
클래스, enum, 유형 이름 업데이트
일반적으로 클래스, enum, 유형의 이름을 다음과 같이 변경해야 합니다.
- Swift: 클래스 이름과 enum에서
Vision접두사 삭제 - Objective-C:
FIRVision및FIR클래스 이름과 enum 접두사를 모두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)가 더 이상 존재하지 않습니다. 작업별 클래스로 대체되었습니다. 감지기를 가져오기 위한 다양한 팩토리 메서드 호출을 각 감지기의 팩토리 메서드에 대한 직접 호출로 대체합니다.VisionDetectorImageOrientation열거형과 함께VisionImageMetadata클래스가 삭제되었습니다.VisionImage의orientation속성을 사용하여 이미지의 표시 방향을 지정합니다.새
TextRecognizer인스턴스를 가져오는onDeviceTextRecognizer메서드 이름이textRecognizer로 변경되었습니다.TextElement,TextLine,TextBlock를 비롯한 텍스트 인식 결과 클래스에서 신뢰도 속성이 삭제되었습니다.새
ImageLabeler인스턴스를 가져오는onDeviceImageLabeler및onDeviceImageLabeler(options:)메서드가 병합되어imageLabeler(options:)로 이름이 변경되었습니다.새
ObjectDetector인스턴스를 가져오는objectDetector메서드가 삭제되었습니다. 대신objectDetector(options:)를 사용하세요.type속성이ImageLabeler에서 삭제되었고entityID속성이 이미지 라벨 지정 결과 클래스인ImageLabel에서 삭제되었습니다.바코드 스캔 API
detect(in _:, completion:)의 이름이 다른 비전 API와의 일관성을 위해process(_:, completion:)으로 변경되었습니다.이제 Natural Language API에서 '언어 코드' 대신 BCP-47 표준에 정의된 '언어 태그'라는 용어를 사용합니다.
이제
TranslateLanguage은 언어 태그 (예:.en) 대신 상수에 읽기 쉬운 이름 (예:.english)을 사용합니다.
다음은 이전 및 새로운 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에서는 감지된 객체의 분류 카테고리를 반환하는 방식이 변경되었습니다.
VisionObject의 VisionObjectCategory이 정수 대신 ObjectLabel 객체의 text로 반환됩니다. 가능한 모든 문자열 카테고리는 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]) {
...
}Firebase 종속 항목 삭제
마이그레이션 후 Firebase 종속 항목을 삭제합니다. 다음 단계를 따르세요.
- 앱의 디렉터리와 Xcode 프로젝트에서
GoogleService-Info.plist파일을 삭제하여 Firebase 구성 파일을 삭제합니다. - Podfile에서
pod 'Firebase/Analytics'와 같은 Firebase cocoapod을 삭제합니다. - 코드에서
FirebaseApp.configure()와 같은 FirebaseApp 초기화를 삭제합니다. - Firebase 지원 사이트의 안내에 따라 Firebase Console에서 Firebase 앱을 삭제합니다.
도움말 보기
문제가 발생하면 Google에 문의할 수 있는 채널이 설명된 커뮤니티 페이지를 확인하세요.