question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ONNX shape inference does not infer shapes

See original GitHub issue

Bug Report

Describe the bug

onnx.shape_inference.infer_shapes does not correctly infer shape of each layer.

System information

  • OS Platform and Distribution: Windows 10
  • ONNX version: 1.7.0
  • Python version: 3.7.4

Reproduction instructions

  • Describe the code to reproduce the behavior.
model = onnx.load("models/conv_dummy.onnx")
onnx.checker.check_model(model)
inferred_model = onnx.shape_inference.infer_shapes(model)
print(inferred_model.graph.value_info)

output:

[name: "9"
type {
  tensor_type {
    elem_type: 1
  }
}
, name: "10"
type {
  tensor_type {
    elem_type: 1
  }
}
, name: "11"
type {
  tensor_type {
    elem_type: 1
  }
}
, name: "12"
type {
  tensor_type {
    elem_type: 1
  }
}
, name: "13"
type {
  tensor_type {
    elem_type: 1
  }
}
, name: "14"
type {
  tensor_type {
    elem_type: 1
  }
}
]

Model file: models.zip

Expected behavior

Expected each entry in model.graph.value_info to have tensor shape field which tells me the shape of that layer.

Notes

Model was exported from PyTorch using torch.onnx.export

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:24 (13 by maintainers)

github_iconTop GitHub Comments

4reactions
dtch1997commented, Jul 22, 2020

Good workaround. Adding a line add_value_info_for_constants(model) before shape inference runs correctly.

0reactions
jcwchencommented, Nov 11, 2021

Actually the utilities here come from protobuf since it’s a model proto. Perhaps you can raise this concern there. Thank you for the suggestion.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ONNX shape inference does not infer shapes #4357 - GitHub
Describe the bug onnx.shape_inference.infer_shapes does not correctly infer shape of each layer. System information
Read more >
onnx-tool - PyPI
A tool for ONNX model's shape inference and MACs counting.
Read more >
Source code for polygraphy.backend.onnx.loader
If the provided model is already a graph, the graph is not exported to ONNX. ... InferShapes(BaseLoader): """ Functor that runs shape inference...
Read more >
How to extract layer shape and type from ONNX / PyTorch?
If the model is sequential then you can infer the architecture of the network from its layers directly. For any model that is...
Read more >
utils/add_nms.py · muttalib1326/Punjabi_Character_Detection ...
LOGGER.info(f"Shape inference could not be performed at this ... "This version of ONNX GraphSurgeon does not support folding shapes, ".
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found