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 optimize ONNX model node #2408

Merged
merged 1 commit into from
Dec 15, 2023
Merged
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
29 changes: 29 additions & 0 deletions backend/src/packages/chaiNNer_onnx/onnx/utility/optimize_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from __future__ import annotations

import onnx

from nodes.impl.onnx.model import OnnxModel, load_onnx_model
from nodes.impl.onnx.utils import safely_optimize_onnx_model
from nodes.properties.inputs import OnnxModelInput
from nodes.properties.outputs import OnnxModelOutput

from .. import utility_group


@utility_group.register(
schema_id="chainner:onnx:optimize_model",
name="Optimize Model",
description="Optimize the give model. Optimizations may or may not improve performance.",
icon="MdSpeed",
inputs=[
OnnxModelInput(),
],
outputs=[
OnnxModelOutput(),
],
)
def optimize_model_node(model: OnnxModel) -> OnnxModel:
model_proto = onnx.load_from_string(model.bytes)
model_proto = safely_optimize_onnx_model(model_proto)
model_bytes = model_proto.SerializeToString()
return load_onnx_model(model_bytes)