apple / apple/coremltools

Errors when doing inference with compiled model.

Open
#2,049 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
5.4k
Forks
850
Avg merge
4d 5h
Merged PRs (30d)
10

Description

## 🐞Describing the bug
- Errors running a model with image input and grayscale image output
passing the same shapes in (but using numpy array as runtime input) e.g. passing a (1, 3, 512, 512) image in and expecting a (1, 1, 512, 512) grayscale image out.

II tried both mlprogram and neuralnetwork when compiling MODNet but keep getting these errors

## Stack Trace
-
```

/usr/local/lib/python3.11/site-packages/coremltools/models/model.py:154: RuntimeWarning: You will not be able to run predict() on this Core ML model. Underlying exception message was: Error compiling model: "compiler error: Encountered an error while compiling a neural network model: validator error: Model image output 'pred_matte' has a different shape than its corresponding return value to main.".
_warnings.warn(
Traceback (most recent call last):
File "/Users/leepenkman/code/MODNet/onnx/inference_coreml.py", line 102, in
result = model.predict({"img": im})
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/coremltools/models/model.py", line 632, in predict
raise self._framework_error
File "/usr/local/lib/python3.11/site-packages/coremltools/models/model.py", line 152, in _get_proxy_and_spec
return _MLModelProxy(filename, compute_units.name), specification, None
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Error compiling model: "compiler error: Encountered an error while compiling a neural network model: validator error: Model image output 'pred_matte' has a different shape than its corresponding return value to main.".
# Paste Python code snippet here, complete with any required import statements.
```
model conversion succeeded but then when i go to do inference on the model i get these errors.

## System environment (please complete the following information):
- coremltools version:
- OS (e.g. MacOS version or Linux type): happening on MacOS/latest pytorch/coremltools
- Any other relevant version information (e.g. PyTorch or TensorFlow version):

any pointers would be really appreciated

Contributor guide

Open the contributing guide

Research direction

Start with onnx/inference_coreml.py at line 102 and inspect the model.predict call using the converted model and image input. Reproduce the compiler validation error for the `pred_matte` image output, checking the declared output shape against the return value and recording the relevant PyTorch, coremltools, and macOS versions.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.