簡體   English   中英

預訓練的 model 錯誤? 'collections.OrderedDict' object 沒有屬性 'eval'

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

我正在使用預訓練的 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()))

這使:

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

謝謝你們的意見。我解決了。 所以我使用了我的 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM