位置:- 正文

AttributeError: cannot assign module before Module.__init__() call

编辑:rootadmin
AttributeError: cannot assign module before Module.__init__() call

推荐整理分享AttributeError: cannot assign module before Module.__init__() call,希望有所帮助,仅作参考,欢迎阅读内容。

AttributeError: cannot assign module before Module.__init__() call

文章相关热门搜索词:,内容如对您有帮助,希望把文章链接给更多的朋友!

诸神缄默不语-个人CSDN博文目录

运行环境,报错信息和查找到的错误内容: Linux系统 Python 3.8(使用anaconda管理的虚拟环境) PyTorch 1.11+cudatoolkit 10.2(通过anaconda下载)

这个问题是出现在自定义PyTorch模型(torch.nn.Module)子类的运行过程中,在__init__()函数中报错。 我的错误原因是super(类名,self).__init__()忘写最后一个括号了。将括号加上后,就能正常运行了。 这个错误的原因就在于还没有调用Module.__init__()就开始定义子模型了,如self.classifier=nn.Linear(input_dim,output_dim)等。参考异常解决(二)-- AttributeError: cannot assign module before Module.__init__() call_奋斗の博客的博客-CSDN博客,也可能是因为直接没写super()命令而造成的。加上之后就可以正常运行。

本文链接地址:https://www.jiuchutong.com/zhishi/300118.html 转载请保留说明!
下一篇链接:https://www.jiuchutong.com/zhishi/300119.html
免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

鄂ICP备2023003026号

友情链接: 武汉网站建设 电脑维修 湖南楚通运网络