You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

自定义PyTorch模型转ONNX遇RuntimeError问题及解决方法

PyTorch转ONNX遇index_put不支持问题的解决方法

在Jetson设备上尝试将自定义PyTorch模型转换为TensorRT并运行时,导出.pt模型为ONNX格式触发如下错误:

RuntimeError: Unsupported: ONNX export of index_put in opset 9. Please try opset version 11.

触发错误的代码如下:

import torch.onnx
# 标准ImageNet输入 - 3通道,224x224
# 输入值不影响网络结构导出,也可以使用真实输入
dummy_input = torch.randn(1, 3, 224, 224)
# 执行导出
# torch.onnx.export(model, dummy_input, "best.onnx")

通过在torch.onnx.export()函数中添加opset_version=11参数即可解决该问题,修改后的代码如下:

import torch.onnx
# 标准ImageNet输入 - 3通道,224x224
# 输入值不影响网络结构导出,也可以使用真实输入
dummy_input = torch.randn(1, 3, 224, 224)
# 执行导出
torch.onnx.export(model, dummy_input, "best.onnx", opset_version=11)

内容的提问来源于stack exchange,提问作者Chafik Boulealam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 20:55:22