'coremltools: output has no shape and cannot be used in pipeline -- how to fix it?

When I convert tensorflow.keras models to CoreML using coremltools, my models end up having no output shape. I.e., if model is my coremltools.models.MLModel instance, model.get_spec().description.output[0] results in

name: "output"
shortDescription: "model output"
type {
multiArrayType {
dataType: FLOAT32
}
}

so I have a multiArray with no specified output shape. This is fine and I can use it in my Xcode project. However, if I'm using coremltols.models.pipeline.Pipeline to combine two instances of coremltools.models.Model, I get the following message displayed when opening the model with Xcode:

validator error: Pipeline: the input 'input' of model '...' does not match the type previously specified by the pipeline input or the output of a previous model. For the second case, make sure the input and previous model's output has the matching name and shape.

I checked that name and dataType coincide so the only thing I can think of is that the missing output shape is the issue. Unfortunately, I could not find a way to make coreml output the model's output shape.

Any ideas on this? Maybe there is some misuse of mine of the pipeline class?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source