3

I am trying to export a pytorch text detection model to onnx format. The model uses grid_sample in the code of one module . I am unable to convert it to the onnx format because of the following error

/usr/local/lib/python3.6/dist-packages/torch/onnx/utils.py:738: UserWarning: ONNX export failed on ATen operator grid_sampler because torch.onnx.symbolic_opset9.grid_sampler does not exist**
  .format(op_name, opset_version, op_name))
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-134-0350cc891688> in <module>()
----> 1 torch.onnx.export(models_module, (dummy_input,dummy_text), "test1.onnx", verbose=True)

7 frames
/usr/local/lib/python3.6/dist-packages/torch/onnx/symbolic_registry.py in get_registered_op(opname, domain, version)
    107         else:
    108             msg += "Please open a bug to request ONNX export support for the missing operator."
--> 109         raise RuntimeError(msg)
    110     return _registry[(domain, version)][opname]

RuntimeError: Exporting the operator grid_sampler to ONNX opset version 9 is not supported. Please open a bug to request ONNX export support for the missing operator.

I am not able to resolve this error . Also the code I am writing to convert to onnx format is shown below

import torch.onnx
dummy_input = torch.autograd.Variable(torch.rand(10,1,32,100,dtype=torch.float32))
dummy_text = torch.autograd.Variable(torch.LongTensor(batch_size, batch_max_length + 1).fill_(0).to(device))     # shape is (10,26)
models_module = model.module.to(device)
torch.onnx.export(models_module, (dummy_input,dummy_text), "test1.onnx", verbose=True)
Anonymous
  • 31
  • 1
  • 3
  • As the error suggests the exportation of the grid_sample operation is not supported by ONNX. Your options are to either open a request to try and get pytorch support for this operation or try to replace the use of `grid_sampler` in your model with equivalent ONNX supported operations. – jodag Jul 23 '20 at 23:27
  • 1
    What is the alternate or equivalent operation for this? – Anonymous Jul 26 '20 at 23:19

0 Answers0