【发布时间】:2020-04-12 08:04:16
【问题描述】:
当我尝试使用 Firebase 中的 MLModelInterpreter 在我的 Xcode 项目中加载 tflite-File 时,在 Launchsreen 完全可见后出现以下错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[FIRInstanceIDCheckinPreferences preferencesFromKeychainContents:]: unrecognized selector sent to class 0x10235ca58
我的代码基于 Firebase 的教程,因此我很惊讶它不起作用。代码如下:
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)
}
}
经过一些调试,我隐约猜测错误是由这行代码引起的:
interpreter = ModelInterpreter.modelInterpreter(localModel: localModel)
其他信息
在上述问题之前,我遇到了另一个问题:在构建项目时,编译器显示此错误:
/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
以下是我所做的总结:
- 我清理了 buildingfolder
- 重新安装所有 pod:
pod deintegrate和pod install - 将 No Common Blocks 设置为 no
- 删除所有 -ObjC,如 this Link 所述。
我的 Podfile 是:
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
如果有人可以提供帮助,我将不胜感激
编辑
如果有人有其他解决方案可以将 tflite 文件(或 h5 文件:查看我以前的问题)加载到 Xcode 项目中,这也会有所帮助
@保罗·伯斯特里安
【问题讨论】:
-
首先你明白
unrecognised selector异常是什么意思吗? -
首先感谢您的即时回复。我没有详细了解它,但我了解选择器是过去的遗物,来自Objective-C。它根据选择器选择要在对象上执行的函数。 (Information) 这些信息如何帮助解决我的问题?
-
选择器是方法的另一个名称。异常的意思是您试图在没有该方法的对象上调用该方法。换句话说,您使用了错误的对象。
-
This 可能是问题所在。
-
@trojanfoe 谢谢,我去看看
标签: ios swift xcode firebase compiler-errors