Torch.onnx export model IndexError: vector::_M_range_check: __n (which is 18446744073709551615)

I’m trying to convert my pytorch model into onnx, my code is as below:

dummy_input = Variable(torch.randn(1, 3, 256, 256))
torch.onnx.export(model_G, dummy_input, “test.onnx”)

And terminal says:

Traceback (most recent call last):
File “Pkl2Onnx.py”, line 49, in
torch.onnx.export(model_G, dummy_input, “test.onnx”)
File “/home/liuchang/.local/lib/python2.7/site-packages/torch/onnx/init.py”, line 25, in export
return utils.export(*args, **kwargs)
File “/home/liuchang/.local/lib/python2.7/site-packages/torch/onnx/utils.py”, line 84, in export
_export(model, args, f, export_params, verbose, training, input_names, output_names)
File “/home/liuchang/.local/lib/python2.7/site-packages/torch/onnx/utils.py”, line 153, in _export
proto, export_map = trace.export(list(_unique_state_dict(model).values()),_onnx_opset_version, defer_weight_export)
IndexError: vector::_M_range_check: __n (which is 18446744073709551615) >= this->size() (which is 173)

Has anyone met this problem before?

1 Like

Waiting for solutions

Were you able to resolve this? I suppose there’s a need to fix something in network architecture, but I’m not sure exactly what should it be.

I think you should post your model_G code here.

I am also facing a similar issue during tensorrt inference.

I0723 05:07:35.746679 1 libtorch_backend.cc:805] vector::_M_range_check: __n (which is 18446744073709551615) >= this->size() (which is 3)

Any help is appreciated.

Could you post an executable code snippet so that we could debug it?