code: def main():
      args = parser.parse_args()
      onnx_model = onnx.load(args.model)
      num_original_nodes, original_graph_str = traverse_graph(
          onnx_model.graph
      )
  
      # Optimizer passes to perform
      passes = [
          #'eliminate_deadend',
          "eliminate_identity",
          "eliminate_nop_dropout",
          "eliminate_nop_pad",
          "eliminate_nop_transpose",
          "eliminate_unused_initializer",
          "extract_constant_to_initializer",
          "fuse_add_bias_into_conv",
          "fuse_bn_into_conv",
          "fuse_consecutive_concats",
          "fuse_consecutive_reduce_unsqueeze",
          "fuse_consecutive_squeezes",
          "fuse_consecutive_transposes",
          #'fuse_matmul_add_bias_into_gemm',
          "fuse_pad_into_conv",
          #'fuse_transpose_into_gemm',
          #'lift_lexical_references',
      ]
  
      # Apply the optimization on the original serialized model
      # WARNING I've had issues with optimizer in recent versions of PyTorch / ONNX causing
      # 'duplicate definition of name' errors, see: https://github.com/onnx/onnx/issues/2401
      # It may be better to rely on onnxruntime optimizations, see onnx_validate.py script.
      warnings.warn(
          "I've had issues with optimizer in recent versions of PyTorch / ONNX."
          "Try onnxruntime optimization if this doesn't work."
      )
      optimized_model = optimizer.optimize(onnx_model, passes)
  
      num_optimized_nodes, optimzied_graph_str = traverse_graph(
          optimized_model.graph
      )
      print(
          "==> The model after optimization:\n{}\n".format(
              optimzied_graph_str
          )
      )
      print(
          "==> The optimized model has {} nodes, the original had {}.".format(
              num_optimized_nodes, num_original_nodes
          )
      )
  
      # Save the ONNX model
      onnx.save(optimized_model, args.output)
  
imports: import argparse
  import warnings
  import onnx
  from onnx import optimizer
label_desc: Use image node_id 2 for calling a global function with example usage: main() without return types