[英]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.