Replies: 1 comment
-
Would the ifrom onnx import ModelProto
import numpy as np
import spox.opset.ai.onnx.v18 as op
from spox import build, inline, argument, Tensor
def some_existing_model() -> ModelProto:
a = argument(Tensor(np.float32, ("N", "H", "W", "C")))
b = op.identity(a)
return build(inputs={"a": a}, outputs={"b": b})
# Wrap existing model and fix order of output axes
a = argument(Tensor(np.float32, ("N", "H", "W", "C")))
(nhwc,) = inline(some_existing_model())(a).values()
nchw = op.transpose(nhwc, perm=(0, 3, 1, 2))
model_with_reordered_axes: ModelProto = build(inputs={"a": a}, outputs={"nchw": nchw}) The individual functions are all documented in Spox's docs but feel free to ask if you have questions. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I wonder how I can change the output format of an already existing Onnx models, i.e. from [n,h,w,c] to [n,c,h,w].
Gladly also with tools of the Onnx Community?
Beta Was this translation helpful? Give feedback.
All reactions