"Exception from Layer: 149" Problem with CoreML model after converting from PyTorch

188 Views Asked by At

I trained a YOLOv3-SPP model using PyTorch. I then saved it as an ONNX model and then converted it to CoreML using onnx-coreml. When I try to make a prediction using the model I get this error:

    YOLOv3-CoreML[13481:1004975] [espresso] [Espresso::handle_ex_plan] exception=Espresso exception: "Invalid state": reshape mismatching size: 13 13 24 1 1 -> 6 10 8 3 1 [Exception from Layer: 149: 300]
2020-03-16 13:46:05.248612-0500 YOLOv3-CoreML[13481:1004975] [coreml] Error computing NN outputs -1

This is the code I am using to make the prediction:

 if let prediction = try? model.prediction(input_1: image) {
      print("Output: \(prediction)")
    }

I did some digging to find layer #149. I used this script to find its name:

import coremltools
import numpy as np

mlmodel = coremltools.models.MLModel("model.mlmodel")
spec = mlmodel._spec

print(spec.neuralNetwork.layers[149]) 

I found its name to be "308". So I opened the model up in Netron and got this:

enter image description here

The layer in question is circled in red. How can I get my CoreML model to work properly?

0

There are 0 best solutions below