apple / apple/coremltools

Error when converting pytorch model: NotImplementedError: Image output 'colorOutput' has symbolic dimensions in its shape

Open
#1,870 10 comments 1 reaction 0 assignees View on GitHub
bug triaged
Dominant language
Python
Stars
5.4k
Forks
850
Avg merge
4d 5h
Merged PRs (30d)
10

Description

#

# Problem
I am trying to convert a super resolution model to mlmodel. I want get a mlmodel which has a flexiable image type, and its output is also image tpye. (why should it be flexiable? because for whatever w*h images, it should output 2*(w*h) image, not just for fixed
image input like (1,3,256,256))

The code is as follows:
```
torch_model = model

shape = (1, 3, 256, 256)
shape2 = (1, 3, 257, 257)
input_shape = ct.Shape(shape=(1,
3,
ct.RangeDim(lower_bound=25, upper_bound=1080, default=256),
ct.RangeDim(lower_bound=25, upper_bound=1080, default=256)))
pam_model_traced = torch.jit.trace(torch_model,torch.rand(*shape)) #trace

# convert t0 mlmodel

pam_model_ml_flexable = ct.convert(
pam_model_traced,
inputs=[ct.ImageType(name="colorImage",shape=input_shape,color_layout=ct.colorlayout.RGB,)],
outputs=[ct.ImageType(name="colorOutput",color_layout=ct.colorlayout.RGB,)]
)

# pam_model_ml_flexable = ct.convert(
# pam_model_traced,
# inputs=[ct.TensorType(name="colorImage",shape=input_shape)],
# outputs=[ct.TensorType(name="colorOutput")]
# )
print(pam_model_ml_flexable.get_spec().description)
```
and it got an error:
"NotImplementedError: Image output 'colorOutput' has symbolic dimensions in its shape"

So, what is the reason?
Hope someone can tell me the reason.
Thanks a lot!

Contributor guide

Open the contributing guide

Research direction

Start by tracing the ct.convert call using the RangeDim input_shape and ImageType output, then inspect how symbolic dimensions are handled for image outputs. Compare the ImageType and TensorType cases shown in the issue. Done means documenting the reason for the failure or providing a supported conversion path for flexible image input and output shapes.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.