AttributeError: Can‘t get attribute ‘Net‘ on module ‘__main__‘
在使用pytorch深度学习框架的时候,我们加载预先训练好的完整pkl模型时,如果报错:
AttributeError: Can't get attribute 'Net' on module '__main__'
此时我们应该在主函数内加载一个当时训练时的类,用于初始化神经网络,如下:
# 加入:初始化
class Net(nn.Module):def __init__(self, hidden_layers=64):super(Net, self).__init__()# hidden_layers = 128self.fc1 = nn.Linear(8, hidden_layers)self.fc2 = nn.Linear(hidden_layers, hidden_layers)self.fc_mu = nn.Linear(hidden_layers, 1)def forward(self, x):x = F.relu(self.fc1(x))x = F.relu(self.fc2(x))mu = 5*torch.sigmoid(self.fc_mu(x))return mu
# 加入:实例化
r_net = Net(hidden_layers=64)
# 加载预先训练模型的参数
r_net = torch.load('./model.pkl')
此时r_net就可以正常使用了
AttributeError: Can‘t get attribute ‘Net‘ on module ‘__main__‘相关推荐
- Python多进程 AttributeError: Can't get attribute 'worker' on module '__main__' from
被调用函数要放到 if main 的外面 虽说 if main 是从入口开始运行 实际情况应该是 外面的部分 先编译?
- 解决YOLO v5的AttributeError: Can‘t get attribute SPPF on module models. common的问题
** 目录 一.问题描述 二.解决方法 三.参考来源 一.问题描述 在运行YOLOv5的detect.py程序时候,出现了以下错误提示AttributeError: Can't get attribu ...
- AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from ‘D:\\ModelTest\\yolov5-5
记录一下这个错误: AttributeError: Can't get attribute 'SPPF' on <module 'models.common' from 'D:\\ModelTe ...
- 运行yolov5-5.0出现AttributeError: Can‘t get attribute ‘SPPF‘ 正确解决方法
运行yolov5旧版本代码(比如5.0版本)出现错误 AttributeError: Can't get attribute 'SPPF' on <module 'models.common' ...
- AttributeError: Cant get attribute SPPF on module models
运行YOLOV5出现报错AttributeError: Can't get attribute 'SPPF' 问题 AttributeError: Can't get attribute 'SPPF' ...
- 解决pytouch导入模型报错:AttributeError: Can‘t get attribute ‘XXX‘ on <module ‘__main__‘ from XXX>
解决方法 看到这个报错的文件位置:<module '__main__' from XXX,只需要把自定义的那个模型的类,即Can't get attribute 'XXX'这里的XXX,直接把这 ...
- Can't get attribute '_rebuild_tensor_v2' on module 'torch._utils'
Can't get attribute '_rebuild_tensor_v2' on <module 'torch._utils' pip uninstall torch 会把0.1.2版本也 ...
- Cesi运行报错AttributeError: can‘t set attribute
环境说明: Centos 7 + Python3.6 + Cesi 2.7.1 按照官网说明运行,服务启动正常,在登录界面输入密码后提示密码错误. 打开浏览器开发者工具,查看对应的登录POST请求,提 ...
- 解决:AttributeError: can't set attribute
报错代码如下: File "./ga_web/lib/meta_data.py", line 94, in instance_list_ip_portreturn [x.get(' ...
最新文章
- 手把手教你如何扩展GridView之自带CheckBox
- postman 请求 页面出现 Could not get any response 解决方法
- 矩形法求定积分的原理和实现
- 吴恩达机器学习 -- 逻辑回归(Logistic Regression)
- 转:聊聊开发中幂等性问题(*)
- linux/window 下 solr5.1 tomcat7.x 环境搭建即简单功能测试
- 项目管理学习总结(16)——如何突破技术管理
- 世界读书日,给你们送大福利!
- 设置TeeChart的提示文本
- Hive内部表外部表转化分析(装)
- 手机上怎么去掉a 标签中的img点击时的阴影?
- 小白如何上手产品经理
- 面对恐惧和压力,你是怎么做的?
- 【错误集】 MonkeyPatchWarning: Monkey-patching ssl after ssl has already been imported may lead to errors
- JavaScript指定长度和进制的UUID
- 如何找到google主题的壁纸
- singleSpa记录
- 嵌入式软件开发工程师求职要求
- java 自动生成条形码_JAVA生成商品条形码
- 2021全球与中国自动导引车市场现状及未来发展趋势