AttributeError: '_IncompatibleKeys' object has no attribute 'eval'

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()
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容