栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

pytorch加载模型报错TypeError: ‘collections.OrderedDict‘ object is not callable

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

pytorch加载模型报错TypeError: ‘collections.OrderedDict‘ object is not callable

# 导入模型
print("model loading")

path_model = "./static/model/resnet_.pt"
model=resnet()
model = model.load_state_dict(torch.load(path_model),False)
# model = model_loaded.load_state_dict(torch.load(path_model))

print("finish")

加载模型状态,首先要初始化模型状态,再加载状态
实际上,torch.load是加载state_dict而不是模型本身。

load_state_dict 的 strict 参数默认是 True :

表示预训练模型的层和自己定义的网络结构层严格对应相等(如层名和维度)
所以当我们修改了网络结构后,如果strict为True的时候就会报错

加载模型状态
https://blog.csdn.net/weixin_45727931/article/details/121516285)
strict参数
https://blog.csdn.net/weixin_45084253/article/details/123609392

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/889626.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号