在后台运行coreml时发生错误:计算NN输出错误时出错 [英] Error when running coreml in the background: Error computing NN outputs error

查看:72
本文介绍了在后台运行coreml时发生错误:计算NN输出错误时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行来自iPhone 6上的keras的mlmodel.预测经常失败,并出现错误计算NN输出错误.有人知道原因是什么吗,如果我能做些什么呢?

I'm running an mlmodel that is coming from keras on an iPhone 6. The predictions often fails with the error Error computing NN outputs. Does anyone know what could be the cause and if there is anything I can do about it?

do {
    return try model.prediction(input1: input)
} catch let err {
    fatalError(err.localizedDescription) // Error computing NN outputs error
}

编辑:我尝试了苹果公司的示例项目,那个是在后台运行的,所以它似乎特定于我们的项目或模型类型.

I tried apple's sample project and that one works in the background so it seems it's specific to either our project or model type.

推荐答案

最后,对于我们来说,设置 usesCPUOnly 标志就足够了.在iOS中似乎禁止在后台使用GPU.苹果实际上也在他们的文档中对此进行了写道..为了指定这个标志,我们不能再使用生成的模型类,而不得不调用原始的coreml类.我可以想象在将来的版本中这种变化.以下代码段摘自生成的模型类,但指定了添加的 MLPredictionOptions .

In the end it was enough for us to set the usesCPUOnly flag. Using the GPU in the background seems prohibited in iOS. Apple actually wrote about this in their documentation as well. To specify this flag we couldn't use the generated model class anymore but had to call the raw coreml classes instead. I can imagine this changing in a future version however. The snippet below is taken from the generated model class, but with the added MLPredictionOptions specified.

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时发生错误:计算NN输出错误时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆