在進行模型測試時報錯:
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