pytorch錯誤解決:Missing key(s) in state_dict: Unexpected key(s) in state_dict:

在進行模型測試時報錯:

Missing key(s) in state_dict: xxxxxxxxxx

Unexpected key(s) in state_dict:xxxxxxxxxx

 

報錯原因:

在模型訓練時有加上:【可以加速訓練速度】

model = nn.DataParallel(model)

#cudnn.benchmark = True

但是在模型測試推斷時,在模型參數被加載到模型前沒有加這句話,故報出上面的錯誤。

 

解決:

在模型參數被加載到模型前加下面的語句:

model = nn.DataParallel(model)

#cudnn.benchmark = True

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章