dbsystel / yolov5-coreml-tools

Scripts for exporting YOLOv5 models to CoreML and benchmarking it.
Apache License 2.0
64 stars 9 forks source link

raw_coordinates not in outputs #12

Open martinazapletalova opened 2 months ago

martinazapletalova commented 2 months ago

Hi, I'm trying to use your code in the colab notebook to add postprocessing to coreML yolo model. But I'm running into issue:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
[<ipython-input-18-e52d81475349>](https://q3bkdlr8ah-496ff2e9c6d22116-0-colab.googleusercontent.com/outputframe.html?vrz=colab_20240506-060112_RC00_630977236#) in <cell line: 1>()
----> 1 builder.set_output(output_names=["raw_confidence", "raw_coordinates"], output_dims=[
      2                     (25200, numberOfClassLabels), (25200, 4)])

[/usr/local/lib/python3.10/dist-packages/coremltools/models/neural_network/builder.py](https://q3bkdlr8ah-496ff2e9c6d22116-0-colab.googleusercontent.com/outputframe.html?vrz=colab_20240506-060112_RC00_630977236#) in set_output(self, output_names, output_dims)
    522         spec = self.spec
    523         for idx, dim in enumerate(output_dims):
--> 524             spec.description.output[idx].type.multiArrayType.ClearField("shape")
    525             spec.description.output[idx].type.multiArrayType.shape.extend(dim)
    526             spec.description.output[

IndexError: list index (1) out of range

in step:

    builder.set_output(output_names=["raw_confidence", "raw_coordinates"], output_dims=[
                       (25200, numberOfClassLabels), (25200, 4)])

I've checked builder.spec.description.output and I can see only this:

 [name: "raw_confidence"
type {
  multiArrayType {
    shape: 25200
    shape: 80
    dataType: DOUBLE
  }
}
]

even though the layer with concat_coordinates is there b/c I'm gettingValueError: Layer with name "concat_coordinates" has already been added. Please use a unique name.

martinazapletalova commented 2 months ago

At the end I've found solution in your medium article in comments that I have to add:

builder.spec.description.output.add() before

builder.set_output(output_names=["raw_confidence", "raw_coordinates"], output_dims=[
                       (25200, numberOfClassLabels), (25200, 4)])

but now I have different problem when predicting: Error compiling model: "compiler error: Error reading protobuf spec. validator error: Layer 'concat_confidence' of type 980 has 1 inputs but expects at least 2.