Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing Shapes after Cleanup transformation #95

Closed
3 of 4 tasks
Harsh9650 opened this issue Jan 29, 2024 · 1 comment
Closed
3 of 4 tasks

Missing Shapes after Cleanup transformation #95

Harsh9650 opened this issue Jan 29, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Harsh9650
Copy link
Collaborator

Harsh9650 commented Jan 29, 2024

Prerequisites

Please make sure to check off these prerequisites before submitting a bug report.

  • Test that the bug appears on the current version of the main branch. Make sure to include the commit hash of the commit you checked out.
  • Check that the issue hasn't already been reported, by checking the currently open issues.
  • If there are steps to reproduce the problem, make sure to write them down below.
  • If relevant, please include the ONNX files, which were created directly before and/or after the bug.

Quick summary

cleanup transformation not fixing shape issues related the onnx graph of renet-18.

Details

Please add to the following sections to describe the bug as accurately as possible.

Steps to Reproduce

import netron
import os # netron
from IPython.display import IFrame # netron

import urllib.request
from qonnx.util.cleanup import cleanup
from qonnx.core.modelwrapper import ModelWrapper

def showInNetron(model_filename: str, localhost_url: str = None, port: int = None):
"""Shows a ONNX model file in the Jupyter Notebook using Netron.

:param model_filename: The path to the ONNX model file.
:type model_filename: str

:param localhost_url: The IP address used by the Jupyter IFrame to show the model.
 Defaults to localhost.
:type localhost_url: str, optional

:param port: The port number used by Netron and the Jupyter IFrame to show
 the ONNX model.  Defaults to 8081.
:type port: int, optional

:return: The IFrame displaying the ONNX model.
:rtype: IPython.lib.display.IFrame
"""
try:
    port = port or int(os.getenv("NETRON_PORT", default="8081"))
except ValueError:
    port = 8081
localhost_url = localhost_url or os.getenv("LOCALHOST_URL", default="localhost")
netron.start(model_filename, address=("0.0.0.0", port), browse=False)
return IFrame(src=f"http://{localhost_url}:{port}/", width="100%", height=400)

model_url = ("https://github.com/onnx/models/raw/main/validated/vision/classification/resnet/model/resnet18-v1-7.onnx?download=")
dl_file = "/tmp/resnet18-v1-7.onnx"
urllib.request.urlretrieve(model_url, dl_file)
out_file = "/tmp/resnet18-v1-7_clean.onnx"
cleanup(dl_file, out_file=out_file, override_batchsize = 1) # Batchsize for resnet18 is set to 1.
showInNetron(out_file)

Expected behavior

All tensors should have their respective shapes after cleanup.

Actual behavior

Most tensors missing shapes.

Optional

Possible fix

Transforming the model using InferShapes transformation (from qonnx.transformation.infer_shapes import InferShapes)

Additional context

Faced this problem with only the model specified above.

@Harsh9650 Harsh9650 added the bug Something isn't working label Jan 29, 2024
@maltanar
Copy link
Collaborator

maltanar commented Feb 5, 2024

Thanks @Harsh9650 for reporting this. I was able to reproduce the bug, which is now fixed and merged as part of #97. Note that override_batchsize is now renamed to override_inpsize and is more generic (i.e. it is also possible to set the spatial dimensions as well as the batch size, if required -- this is handy for e.g. fully convolutional neural networks).

@maltanar maltanar closed this as completed Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants