Modiyfing A Model
Introduction
This example first generates a basic model, then modifies the resulting model in various ways.
By importing an ONNX graph into the ONNX GraphSurgeon IR, it is possible to modify virtually every aspect of the graph. We can then export the modified IR back to ONNX.
Running the example
-
Generate a model with several nodes and save it to
model.onnxby running:python3 generate.pyThe generated model computes
Y = x0 + (a * x1 + b): -
Modify the model in various ways, and save it to
modified.onnxby running:python3 modify.pyThis script does the following:
- Removes the
binput of the firstAddnode - Changes the first
Addto aLeakyRelu - Adds an
Identitynode after the firstAdd - Changes the output of the graph to be the output of the
Identitynode - Runs
cleanup()which removes thex0tensor and secondAddnode due to the previous change to the graph outputs.
The resulting graph computes
identity_out = leaky_relu(a * x1): - Removes the

