Xamarin.iOS coreML 在后台模式下获取预测空引用错误

Xamarin.iOS coreML Get Prediction null reference error in background mode

当 iOS 应用 运行 处于后台模式时,

model.GetPrediction 方法 return 是一个空对象。当应用程序处于前台时,方法 return 可以纠正预测。还有其他人遇到过这个问题吗?

两件事:

当应用处于 Backgrounded.

时,您执行任意代码的时间非常有限
  • 您可以检查 BackgroundTimeRemaining 以确定您还剩多少时间。
  • 您必须在 BeginBackgroundTask 个动作中执行您的预测

前台应用(包括 Springboard)优先于 GPU。

  • 前台应用 GPU 处理不会中断以执行您的后台 task-based 预测。

  • 您可以通过向预测调用提供 MLPredictionOptions 来请求预测使用 CPU (UsesCpuOnly)。

Your model should be restricted to the CPU if it might run in the background or if your app has other GPU intensive tasks.

回复:https://developer.apple.com/documentation/coreml/mlpredictionoptions/2921288-usescpuonly?language=objc