Onnx graphsurgeon add node op with optional inputs

Hi, i’m looking to use graphsurgeon to add a Resize node to an onnx model

this op allows for 3 optional inputs, but I only want to use one (‘sizes’, along with the required input ‘x’). How do I go about doing this in onnx graphsurgeon?

Request you to share the ONNX model and the script if not shared already so that we can assist you better.
Alongside you can try few things:

  1. validating your model with the below snippet


import sys
import onnx
filename = yourONNXmodel
model = onnx.load(filename)
2) Try running your model with trtexec command.
In case you are still facing issue, request you to share the trtexec “”–verbose"" log for further debugging

Creating the model:

    model_path = 'model.onnx'
    shape = (1, 224, 224, 3)
    x0 = gs.Variable(name="x0", dtype=np.float32, shape=shape)
    new_shape = (1, 3, 224, 224)
    Y = gs.Variable(name="Y", dtype=np.float32, shape=new_shape)
   nodes = [
            op="Transpose", inputs=[x0], outputs=[Y], attrs={"perm": [0, 3, 1, 2]}

    graph = gs.Graph(nodes=nodes, inputs=[x0], outputs=[Y])
    model = gs.export_onnx(graph)
    print("checking for errors...")
    check = onnx.checker.check_model(model)
    onnx.save(model, model_path)

Modifying the model attempt:

    graph = gs.import_onnx(onnx.load(model_path))
    first_t = [node for node in graph.nodes if node.op == "Transpose"][0]
    resize_out = gs.Variable("resize_out", dtype=np.float32)
    sizes = np.asarray([1, 3, 512, 512])
    size_tensor = gs.Constant(name="resize_sizes", values=sizes)
    resize = gs.Node(
        inputs=[first_t.outputs[0], [], [], size_tensor], #What to do here  <----------

I’m unsure of what to do for the creation of the gs.Node(op=“Resize”) . Resize takes up to four inputs (3 optional), but I only want to use the first and last ones. If I only give two inputs, then it returns “Node (resize_op) has input size 2 not in range [min=3, max=4].”

I found the solution: it’s using gs.Variable.empty() where in the positions for the unused optional parameters
and you need to set the graph opset to 13 (other values may work, 11 does not)