apple / apple/coremltools

image input + rangeDim doesn't work!

Open
#1,276 4 comments 0 reactions 0 assignees View on GitHub
bug Flexible Shape PyTorch (traced)
Dominant language
Python
Stars
5.4k
Forks
850
Avg merge
4d 5h
Merged PRs (30d)
10

Description

https://github.com/xuebinqin/U-2-Net
I want to support flexible input, output(with image type, not multiarray) but it doesn't work.

## Trace
ValueError: Unable to map torch_upsample_bilinear to core upsample

## To Reproduce

net = U2NETP(3,1)
net.load_state_dict(torch.load('u2netp.pth', map_location='cpu'))
net.cpu()
net.eval()

example_input = torch.rand(1, 3, 320, 320) * 255
input_shape = ct.Shape(shape=(1, 3, ct.RangeDim(1, 320, default=320), ct.RangeDim(1, 320, default=320)))

traced_model = torch.jit.trace(net, example_input)
model = ct.convert(traced_model, inputs=[ct.ImageType( shape= input_shape)], convert_to='neuralnetwork')

Here are used python model and code.
[u2netp.pth.zip](https://github.com/apple/coremltools/files/6882291/u2netp.pth.zip)
[model.zip](https://github.com/apple/coremltools/files/6882295/model.zip)

## System environment
- coremltools version (e.g., 3.0b5): https://gitlab.com/zach_nation/coremltools/-/pipelines/339060573, 4.1, 5.0b1, 5.0b2
- OS (e.g., MacOS, Linux): Mac OS
- macOS version (if applicable): Monterey, Big Sur
- XCode version (if applicable): Xcode 13, 12
- How you install python (anaconda, virtualenv, system): system
- python version (e.g. 3.7): 3.8

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the provided U2NETP example with the traced model, ct.ImageType, ct.Shape, and ct.RangeDim inputs. Investigate the conversion path that reports “Unable to map torch_upsample_bilinear to core upsample,” using the linked model archives. Done means conversion succeeds with flexible image dimensions and produces the requested image-type output rather than a multiarray.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.