美文网首页
AttributeError: '_IncompatibleKe

AttributeError: '_IncompatibleKe

作者: 1037号森林里一段干木头 | 来源:发表于2021-12-14 15:07 被阅读0次

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()

相关文章

网友评论

      本文标题:AttributeError: '_IncompatibleKe

      本文链接:https://www.haomeiwen.com/subject/ocaefrtx.html