属性错误: 'collections.OrderedDict'对象没有属性'modules'



我正在尝试使用以下代码将pt文件导出到onnx:

import torch import torchvision
dummy_input = torch.randn(10, 3, 224, 224, device="cuda") model = torch.load('base_40m_textvec.pt')
input_names = [ "actual_input_1" ] + [ "learned_%d" % i for i in range(16) ] output_names = [ "output1" ]
torch.onnx.export(model, dummy_input, "base_40m_textvec.onnx", verbose=True, input_names=input_names, output_names=output_names)

但是,我一直得到这个错误:

AttributeError: 'collections.OrderedDict' object has no attribute 'modules'

我试着在互联网上搜索这个错误,我得到了

的结果
object has no attribute 'eval'
object has no attribute 'parameters'
object has no attribute 'value_counts'

object has no attribute 'modules'

无这是我第一次尝试将某些东西转换为onnx,所以我不知道为什么它不工作。任何帮助吗?

您加载的检查点'base_40m_textvec.pt'可能是OrderedDict而不是torch.nn.Module

最新更新