Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change input size of ONNX model

I need to change the input size of an ONNX model from [1024,2048,3] to [1,1024,2048,3].

For this, I've tried using update_inputs_outputs_dims by ONNX

import onnx
from onnx.tools import update_model_dims

model = onnx.load("./0818_pspnet_1.0_713_resnet_v1/pspnet_citysc.onnx")
updated_model = update_model_dims.update_inputs_outputs_dims(model, {"inputs:0":[1,1024,2048,3]}, {"predictions:0":[1, 1025, 2049, 1]})
onnx.save(updated_model, 'pspnet_citysc_upd.onnx')

However, this is the error I end up with.

ValueError: Unable to set dimension value to 1 for axis 0 of inputs:0. Contradicts existing dimension value 1024.

The ONNX model is exported from a Tensorflow frozen graph of PSPNet. If the above approach does not work, would I need to modify the frozen graph?

Any help is greatly appreciated.

like image 724
Rani Avatar asked Oct 14 '25 16:10

Rani


1 Answers

You can use the dynamic shape fixed tool from onnxruntime

python -m onnxruntime.tools.make_dynamic_shape_fixed --dim_param batch --dim_value 1 model.onnx model.fixed.onnx
like image 124
AcidBurn Avatar answered Oct 17 '25 09:10

AcidBurn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!