.pth转.onnx出现问题解决。(记录,仅供参考)

1.RuntimeError: Exporting the operator _convolution_mode to ONNX opset version 9 is not supported.

        表示导出.onnx模型时模块 _convolution_mode 是ONNX版本9不支持的op,尝试切换版本无果,那就对卷积模块进行操作。 

        尝试后发现是nn.Conv2d()中 padding=‘same’ 的问题,修改为(1,0)或者 1 ,问题解决,原因不明,有大佬看见可告知在评论区,感谢。

2.RuntimeError: Calculated padded input size per channel: (3 x 3). Kernel size: (5 x 5)。

        这个问题是由于 torch.onnx.export 中的 opset_version 设置错误,需要设置到 11 以上的版本即可解决(我设置的 opset_version=13)。

        

本文记录自己遇到问题以及解决方案。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据引用\[1\]中的信息,load_state_dict()方法返回的是_IncompatibleKeys对象,而不是模型本身。因此,在使用赋值等号时,model并不是你想要的那个模型,所以没有to、eval等属性。 根据引用\[2\]中的信息,将.pth模型换为onnx的代码示例中,使用了torch.load()方法加载了.pth模型,并将其赋值给了model变量。然后使用torch.onnx.export()方法将模型导出onnx格式。这种方式可以正确地将.pth模型换为onnx格式。 根据引用\[3\]中的信息,如果你想加载保存的网络模型,可以直接使用torch.load()方法加载模型文件,并将其赋值给model变量。然后调用model.eval()方法将模型设置为评估模式。 综上所述,出现错误AttributeError: 'dict' object has no attribute 'eval'的原因是你使用了错误的方式加载模型。正确的方式是使用torch.load()方法加载模型文件,并调用model.eval()方法将模型设置为评估模式。 #### 引用[.reference_title] - *1* [(完全解决)AttributeError: ‘_IncompatibleKeys‘ object has no attribute ‘to‘/‘eval](https://blog.csdn.net/qq_43391414/article/details/124074124)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Pytorch模型ONNX](https://blog.csdn.net/yangpan011/article/details/125848508)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [pytorch载入模型时出现错误AttributeError Generator object has no attribute copy](https://blog.csdn.net/LLLLUFFY/article/details/106561536)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值