Reputation: 370
When I try to use the MLModelInterpreter from Firebase to load a tflite-File in my Xcode project I'm getting the following error after the Launchsreen is fully visible:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[FIRInstanceIDCheckinPreferences preferencesFromKeychainContents:]: unrecognized selector sent to class 0x10235ca58
My code is based on the tutorial from Firebase, thus I’m surprised that it doesn’t work. Here is the code:
import Firebase
var interpreter: ModelInterpreter?
func convertTheModel(){
guard let modelPath = Bundle.main.path( forResource: "model", ofType: "tflite", inDirectory: ""
)
else {
print("not able to load model")
return
}
let localModel = CustomLocalModel(modelPath: modelPath)
interpreter = ModelInterpreter.modelInterpreter(localModel: localModel)
let ioOptions = ModelInputOutputOptions()
do {
try ioOptions.setInputFormat(index: 0, type: .float32, dimensions: [1, 22])
try ioOptions.setOutputFormat(index: 0, type: .float32, dimensions: [1, 1])
} catch let error as NSError {
print("Failed to set input or output format with error: \(error.localizedDescription)")
}
let inputs = ModelInputs()
var inputData = Data()
do {
for _ in 0 ..< 22 {
// require fixed-point values or the original bytes.
var RandomNumber = Float.random(in: 0 ..< 1)
// Append normalized values to Data object.
let elementSize = MemoryLayout.size(ofValue: RandomNumber)
var bytes = [UInt8](repeating: 0, count: elementSize)
memcpy(&bytes, &RandomNumber, elementSize)
inputData.append(&bytes, count: elementSize)
}
try inputs.addInput(inputData)
} catch let error {
print("Failed to add input: \(error)")
}
interpreter!.run(inputs: inputs, options: ioOptions) { outputs, error in
guard error == nil, let outputs = outputs else { return }
print(outputs)
}
}
After some debugging I have a vague guess that the error is caused by this line of code:
interpreter = ModelInterpreter.modelInterpreter(localModel: localModel)
Additional Information
Before the issue described above I had another issue: When building the project the compiler showed this error:
/Users/Path/Application_Name/Update/Pods/GoogleMobileVision/Detector/Frameworks/GoogleMobileVision.framework/GoogleMobileVision(VisionExtension.pbobjc_0848a2b53cac8a49ea32ab4e6cb931d4.o)
ld: 46 duplicate symbols for architecture arm64
clang: error: linker command failed with exit code
Here is a summary of what I did:
pod deintegrate
and than pod install
My Podfile is:
platform :ios, '13.0'
target 'My Project' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for My Project
pod 'Firebase/Database'
pod 'Firebase/Auth'
pod 'GoogleMobileVision/FaceDetector'
pod 'Firebase/Firestore'
pod 'Firebase/MLModelInterpreter'
end
I would appreciate if anyone can help
Edit
If anybody has an other solution to load an tflite-file (or an h5-file: check out my previous Question) into an Xcode project it would be also helpful
@ Paul Beusterien
This Is the location where I pasted the -ObjC
:
Upvotes: 5
Views: 1149
Reputation: 29582
-ObjC must be in the app's Other Linker Flags
for Firebase to work correctly. See https://github.com/firebase/firebase-ios-sdk/issues/4776 for more details about this issue.
Upvotes: 3