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

Add shape inference as an arg for tools/onnx-optimize.py #1960

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions tools/onnx-optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import logging

import onnx
from onnx import helper
from onnx import helper, shape_inference

from tf2onnx.graph import GraphUtil
from tf2onnx import logging, optimizer, constants
Expand Down Expand Up @@ -46,6 +46,12 @@ def load_graph(fname, target):
return g, model_proto


def model_shape_inference(onnx_model_proto):
inferred_model = shape_inference.infer_shapes(onnx_model_proto)
onnx.checker.check_model(inferred_model)
return inferred_model


def main():
args = get_args()

Expand All @@ -64,10 +70,12 @@ def main():

model_proto = helper.make_model(onnx_graph, **kwargs)

model_proto_inferred = model_shape_inference(model_proto)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change it as a optional argument.


# write onnx graph
if args.output:
with open(args.output, "wb") as f:
f.write(model_proto.SerializeToString())
f.write(model_proto_inferred.SerializeToString())


if __name__ == "__main__":
Expand Down