Open2
onnxのinputの構造を取得するワンライナー
python3 -c 'import onnx;model=onnx.load("deeplab_edgetpu_default_argmax_xs.onnx");print([[d.dim_value for d in _input.type.tensor_type.shape.dim] for _input in model.graph.input])'
[[0, 3, 512, 512]]
発展形
import onnx
model=onnx.load("deeplab_edgetpu_default_argmax_xs.onnx")
inputs=[[d.dim_value for d in _input.type.tensor_type.shape.dim] for _input in model.graph.input]
print(inputs)
for input, input_shape in zip(model.graph.input, inputs):
shape_string = ""
for idx, shape in enumerate(input_shape):
if idx==0 and shape==0:
shape=1
shape_string = f'{shape_string}{shape},'
print(f'"{input.name}":{shape_string.rstrip(",")}')