简体   繁体   English

预训练的 model 错误? 'collections.OrderedDict' object 没有属性 'eval'

[英]pretrained model error ? 'collections.OrderedDict' object has no attribute 'eval'

I'm using the pretrained resnet50 model and I have to use in this project this model with pretrained weights我正在使用预训练的 resnet50 model 并且我必须在这个项目中使用这个带有预训练权重的 model

original_model=torch.load('model_best.pth',map_location='cpu')
    
original_model.eval()
preproc_img = torch.FloatTensor(preproc_img)
    
out = original_model(preproc_img)
    
print("\nPyTorch model prediction: \n")
print("* shape: ", out.shape)

test_class_id = torch.argmax(out, axis=1).item()
print("* class ID: {}, label: {}".format(test_class_id, test_labels[test_class_id]))
 
confidence = out[0][test_class_id]
print("* confidence: {:.4f}".format(confidence.item()))

which gives:这使:

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

thank you guys for your comments.I solved.谢谢你们的意见。我解决了。 so I used my model and load after my weights than its worked correct所以我使用了我的 model 并在我的重量之后加载而不是正常工作

model = models.resnet50(pretrained = True)
model.fc = nn.Linear(in_features=2048, out_features=2, bias=True)
weights = torch.load('model_best.pth',map_location ='cpu')
model.load_state_dict(weights)
model.eval()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “collections.OrderedDict”对象没有属性 - 'collections.OrderedDict' object has no attribute Django AttributeError: 'collections.OrderedDict' 对象没有属性 'pk' - Django AttributeError: 'collections.OrderedDict' object has no attribute 'pk' AttributeError: 'collections.OrderedDict' object 没有属性 'value_counts' - AttributeError: 'collections.OrderedDict' object has no attribute 'value_counts' 'collections.OrderedDict' 对象没有属性 'pk' - django rest 框架 - 'collections.OrderedDict' object has no attribute 'pk' - django rest framework AttributeError: 'collections.OrderedDict' object 没有属性 'train' - AttributeError: 'collections.OrderedDict' object has no attribute 'train' Django - AttributeError: 'collections.OrderedDict' 对象没有属性 'id' - Django - AttributeError: 'collections.OrderedDict' object has no attribute 'id' AttributeError: 'collections.OrderedDict' 对象没有属性 'split' - AttributeError: 'collections.OrderedDict' object has no attribute 'split' AttributeError: 'collections.OrderedDict' 对象没有属性 'iloc' - AttributeError: 'collections.OrderedDict' object has no attribute 'iloc' Django - 'collections.OrderedDict' 对象没有属性 'headers' - Django - 'collections.OrderedDict' object has no attribute 'headers' 如果不是 (target.size() == input.size()): AttributeError: 'collections.OrderedDict' object has no attribute 'size' 我收到此错误 - if not (target.size() == input.size()): AttributeError: 'collections.OrderedDict' object has no attribute 'size' I'm getting this error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM