pytorch读取权重文件后出现
File "test.py", line 61, in main
resNet50.eval()
AttributeError: '_IncompatibleKeys' object has no attribute 'eval'
- 代码
#保存的权重文件
resNet50 = resnet.resnet50()
resNet50 = resNet50.load_state_dict(torch.load(resNet_path)['state_dict'])
resNet50.eval()
- 修改
这里的模型不能用“=”来赋值,第一行代码导入模型的结构文件,下面应该直接在此模型上调用load_state_dict函数加载权重文件
#保存的权重文件
resNet50 = resnet.resnet50()
resNet50.load_state_dict(torch.load(resNet_path)['state_dict'])
resNet50.eval()