pth转onnx遇见的坑
RuntimeError: Exporting the operator affine_grid_generator to ONNX opset version 9 is not supported. Please feel free to request support or submit a pull request on PyTorch GitHub.
解决办法:
原torch.onnx.export
torch.onnx.export(STN, input, onnx_path, verbose=True, input_names=input_names, output_names=output_names) # 指定模型的输入,以及onnx的输出路径
改为:
torch.onnx.export(STN, input, onnx_path, export_params=True, verbose=True, operator_export_type=torch.onnx.OperatorExportTypes.ONNX_ATEN_FALLBACK)
参考: https://www.wangt.cc/2020/10/runtimeerror-exporting-the-operator-max_unpool2d-to-onnx

本文解决了将PyTorch模型从.pth格式转换为ONNX格式过程中遇到的问题,具体为affine_grid_generator操作符不支持导出到ONNX opset版本9的情况。通过设置torch.onnx.export参数中的operator_export_type为ONNX_ATEN_FALLBACK,成功实现模型转换。

被折叠的 条评论
为什么被折叠?



