Can not convert identity image model
- Dominant language
- Python
- Stars
- 5.4k
- Forks
- 850
- Avg merge
- 4d 5h
- Merged PRs (30d)
- 10
Description
Can not convert identity image model due to a name sanitization bug.
```python
import torch
from torch import nn
import coremltools as ct
class Model(nn.Module):
def forward(self, x):
return x
m = Model()
m.eval()
x = torch.randn([1, 3, 1024, 1024])
traced_model = torch.jit.trace(m, x)
y = traced_model(x) # This works
mlmodel = ct.convert(traced_model,
convert_to="mlprogram",
inputs=[ct.ImageType(name="imageInput",
shape=x.shape,
color_layout=ct.colorlayout.RGB,)],
outputs=[ct.ImageType(name="imageOutput",
color_layout=ct.colorlayout.RGB,)],
)
```
Produces:
```
File ~/miniconda3/envs/prod/lib/python3.8/site-packages/coremltools/converters/mil/mil/passes/name_sanitization_utils.py:102, in _sanitize_block_input_vars(block, sanitizer_vars, main_input_types, sanitize_main_input_only)
100 for input_name, var in block.inputs.items():
101 msg = "Main block's input name, '{}', is different from its corresponding var's name, '{}'."
--> 102 assert input_name == var.name, msg.format(input_name, var.name)
103 new_name = sanitizer_vars.sanitize_name(var.name)
104 new_input_dict[new_name] = var
AssertionError: Main block's input name, 'colorImage', is different from its corresponding var's name, 'colorOutput'.
```
Contributor guide
Research direction
Reproduce the conversion with the PyTorch example and inspect coremltools/converters/mil/mil/passes/name_sanitization_utils.py, especially _sanitize_block_input_vars. Trace why the main input key is colorImage while its variable is colorOutput; done means the provided ct.convert call completes without this assertion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100