New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ONNX export failed: Couldn't export Python operator CorrSampler #33
Comments
CorrSampler is an optional faster implementation of the correlation sampler, enabled using Sorry if my question doesn't make sense, I am not so familiar with ONNX. |
thank you for your reply! RuntimeError: Exporting the operator |
It looks like ONNX is not yet compatible with |
This is correct (strictly, the ONNX opset-v16 offers this operation but PyTorch doesn't reflect it yet).
I recommend to use contrib-op provided by Microsoft. This enables you to export a model with from torch.onnx import register_custom_op_symbolic
import torch.onnx.symbolic_helper as sym_help
def grid_sampler(g, input, grid, mode, padding_mode, align_corners):
# mode
# 'bilinear' : onnx::Constant[value={0}]
# 'nearest' : onnx::Constant[value={1}]
# 'bicubic' : onnx::Constant[value={2}]
# padding_mode
# 'zeros' : onnx::Constant[value={0}]
# 'border' : onnx::Constant[value={1}]
# 'reflection' : onnx::Constant[value={2}]
mode = sym_help._maybe_get_const(mode, "i")
padding_mode = sym_help._maybe_get_const(padding_mode, "i")
mode_str = ['bilinear', 'nearest', 'bicubic'][mode]
padding_mode_str = ['zeros', 'border', 'reflection'][padding_mode]
align_corners = int(sym_help._maybe_get_const(align_corners, "b"))
return g.op("com.microsoft::GridSample", input, grid,
mode_s=mode_str,
padding_mode_s=padding_mode_str,
align_corners_i=align_corners)
# Register contrib GridSample operation as a counterpart for F.grid_sample
register_custom_op_symbolic('::grid_sampler', grid_sampler, 1)
torch.onnx.export(
... # a model with F.grid_sample
) See my gist for a simple usage ;) |
Hi, did you convert the pth model to onnx format? Could you kindly share your script if you do? Thanks. |
When I converted the ONNX model, I encountered that the CorrSampler could not be converted. Can you provide some suggestions?
Looking forward to your reply!
The text was updated successfully, but these errors were encountered: