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 = [
gs.Node(
op="Transpose", inputs=[x0], outputs=[Y], attrs={"perm": [0, 3, 1, 2]}
),
]
graph = gs.Graph(nodes=nodes, inputs=[x0], outputs=[Y])
graph.cleanup().toposort()
model = gs.export_onnx(graph)
print("checking for errors...")
check = onnx.checker.check_model(model)
print(check)
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(
op="Resize",
inputs=[first_t.outputs[0], [], [], size_tensor], #What to do here <----------
outputs=[resize_out],
attrs={},
name="resize_op",
)
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].”