在使用pytorch編寫代碼時,出現了"TypeError: ‘_IncompatibleKeys’ object is not callable",報錯原因如下:
model = model.load_state_dict(torch.load('model.pt'))
model.load_state_dict(torch.load(‘model.pt’))返回結果不是model類型,正確寫法是:
model.load_state_dict(torch.load(PATH))
調用model.load_state_dict之後即可加載成功,不用單獨再賦變量。