我跑是从keras来在iPhone上经常6.预测失败,出现错误Error computing NN outputs
的mlmodel。有谁知道可能是什么原因,如果有什么我能做些什么呢?
do {
return try model.prediction(input1: input)
} catch let err {
fatalError(err.localizedDescription) // Error computing NN outputs error
}
编辑:我试过apple's sample project所以现在看来,这是专门针对我们的任何项目或模型类型的一个在后台工作。
最后,这是足以让我们设置usesCPUOnly
标志。使用在后台GPU似乎禁止的iOS。苹果实际上在他们的documentation写了一篇关于这一点。要指定这个标志,我们不能使用生成的模型类了,但只好打电话给原coreml类来代替。不过,我可以想像这种变化在未来的版本。该片段下面是从所生成的模型类采取,但与指定的加入MLPredictionOptions
。
let options = MLPredictionOptions()
options.usesCPUOnly = true // Can't use GPU in the background
// Copied from from the generated model class
let input = model_input(input: mlMultiArray)
let output = try generatedModel.model.prediction(from: input, options: options)
let result = model_output(output: output.featureValue(for: "output")!.multiArrayValue!).output
我得到了同样的错误,我自己在类似“看似随机的”倍。调试的位追查成立,它是由应用程序引起的,有时想,当它被发送到后台,再或者崩溃时重新加载到前台冻结加载其coreml模型。
该消息被Error computing NN outputs error
之前由:
Execution of the command buffer was aborted due to an error during execution. Insufficient Permission (to submit GPU work from background) (IOAF code 6)
我并不需要(或希望)当应用程序在后台使用的模型,所以我发现,当应用程序正要进/出的背景,设置一个标志,并试图调用模型之前使用保护声明。
applicationWillResignActive
的AppDelegate.swift文件内,并且例如设置一个布尔标志appInBackground = true
。更多信息请参阅本:Detect iOS app entering backgroundapplicationDidBecomeActive
前景,并重置标志appInBackground = false
guard appInBackground == false else { return } // new line to add
guard let model = try? VNCoreMLModel(for modelName.model) else { fatalError("could not load model") // original line to load model
我怀疑这是最完美的解决方案,但它为我工作。
我还没有建立,为什么加载背景模型的尝试只会有时会发生。
在您链接到苹果的例子,它看起来像他们的应用程序永远只要求在响应用户输入的模式,所以它永远不会尝试在后台时加载模型。因此,在我的情况的差异......,可能你的呢?