Search code examples
ioscoreml

IOS prediction app throws error to predict the .mlmodel in IOS14


I try to use my .mlmodel to predict on IOS14 using the same method as described in the apple document link below: https://developer.apple.com/documentation/coreml/integrating_a_core_ml_model_into_your_app

I get below error. I could not understand what is wrong. My two inputs and output are all set as expected and model seems converted correctly from TF2 to mlmodel. Any suggestions how to analyze and fix the issue?

/Library/Caches/com.apple.xbs/Sources/MetalImage/MetalImage-124.0.29/MPSNeuralNetwork/Filters/MPSCNNKernel.mm:752: failed assertion `[MPSCNNConvolution encode...] Error: destination may not be nil.

enter image description here


Solution

  • This is an error from Metal, which is used to run the model on the GPU. You can try running it on the CPU instead, to see if that works without errors. (If running on the CPU also gives errors, something in your model is wrong.)

    let config = MLModelConfiguration()
    config.computeUnits = .cpuOnly
    
    let model = YourModel(configuration: config)
    ...