pytorch高版本(如1.7.0)RuntimeError: Legacy autograd function with non-static forward method is deprecate
就一个前向推理,也报错了。。。
代码:
from torchvision import models
model = models.vgg19(pretrained=True)
output = model(input.cuda())
报错:
RuntimeError: Legacy autograd function with non-static forward method is deprecated.
完整报错:
Traceback (most recent call last):File "/home/user1/pjs/frvt_pytorch/batch_run/2branch_alter_1update_2pfc_MMD_ori_auto/recognition/arcface_torch/tools/visualize.py", line 373, in <module>gb = gb_model(input, index=target_index)File "/home/user1/pjs/frvt_pytorch/batch_run/2branch_alter_1update_2pfc_MMD_ori_auto/recognition/arcface_torch/tools/visualize.py", line 192, in __call__output = self.forward(input.cuda())File "/home/user1/pjs/frvt_pytorch/batch_run/2branch_alter_1update_2pfc_MMD_ori_auto/recognition/arcface_torch/tools/visualize.py", line 188, in forwardreturn self.model(input)File "/home/user1/miniconda3/envs/py377/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_implresult = self.forward(*input, **kwargs)File "/home/user1/miniconda3/envs/py377/lib/python3.7/site-packages/torchvision/models/vgg.py", line 43, in forwardx = self.features(x)File "/home/user1/miniconda3/envs/py377/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_implresult = self.forward(*input, **kwargs)File "/home/user1/miniconda3/envs/py377/lib/python3.7/site-packages/torch/nn/modules/container.py", line 117, in forwardinput = module(input)File "/home/user1/miniconda3/envs/py377/lib/python3.7/site-packages/torch/autograd/function.py", line 160, in __call__"Legacy autograd function with non-static forward method is deprecated. "
RuntimeError: Legacy autograd function with non-static forward method is deprecated. Please use new-style autograd function with static forward method. (Example: https://pytorch.org/docs/stable/autograd.html#torch.autograd.Function)Process finished with exit code 1
原因:高版本pytorch代码要求写法不一样,产生了兼容性问题吧。
解决:网上的各种说加 staticmethod、集成torch.autograd.Function,apply调用等等都不管用
这里的解决是:
推理过程中涉及到 model(input)形式的都改为model.forward(input)形式,加一个forward
代码改成:
from torchvision import models
model = models.vgg19(pretrained=True)
output = model.forward(input.cuda())
另外:/home/xxx/miniconda3/envs/py377/lib/python3.7/site-packages/torch/nn/modules/container.py
中的 117 行:
input = module(input)
也改为:
input = module.forward(input)
参考:https://www.pythonheidong.com/blog/article/764153/6219b3a9423dea894603/
pytorch高版本(如1.7.0)RuntimeError: Legacy autograd function with non-static forward method is deprecate相关推荐
- Pytorch版本过高产生的RuntimeError: Legacy autograd function with non-static forward method is deprecated.
前言 在尝试用ECO Lite做视频分类的时候,使用了作者的Pytorch实现,然而Pytorch实现是基于Pytorch0.4的,我自己的Pytorch版本是1.4,所以在跑模型的时候出现了一些问题 ...
- RuntimeError: Legacy autograd function with non-static forward method is deprecated.
显卡RTX3080 cuda 11.1 cudnn 8.0.5 python3.6.4 在使用pytorch1.0训练densefusion模型时报错,改用pytorch1.7,然后报上面的错误 Tr ...
- Pytorch的自定义拓展:torch.nn.Module和torch.autograd.Function
参考链接:pytorch的自定义拓展之(一)--torch.nn.Module和torch.autograd.Function_LoveMIss-Y的博客-CSDN博客_pytorch自定义backw ...
- 【无标题】cannot import name ‘container_abcs‘ from ‘torch._six‘错误的解决方法(pytorch高版本1.9后)
在1.8版本之后container_abcs就已经被移除了.所以导入方式不同会出现这样的错误:cannot import name 'container_abcs' from 'torch._six' ...
- 程序从高版本降到2.0,数据集报错 TypedTableBase
错误 命名空间"System.Data"中不存在类型或命名空间名称"TypedTableBase"(是缺少程序集引用吗?) 解决: 该错误出现在自动生成的XX ...
- 高版本Android,鸿蒙2.0,debug安装解析失败
安装到android高版本,鸿蒙2.0以上,提示安装包解析错误,检查application是否加入了以下两行: android:appComponentFactory="" too ...
- fckeditor漏洞_三十,文件上传漏洞、编辑器漏洞和IIS高版本漏洞及防御
一.编辑器漏洞 1.编辑器 编辑器属于第三方软件,它的作用是方便网站管理员上传或编辑网站上的内容,类似我们电脑上的Word文档. 编辑器通常分为两种情况: (1) 不需要后台验证,可以直接在前台访问且 ...
- Pytorch使用autograd.Function自定义拓展神经网络
我们知道CNN这类人工神经网络都基于BP算法进行优化,因此需要误差关于权重是连续可导的,这是可以运用BP算法的前提条件:也有一些网络不满足这个条件. 1.可导 对于可连续求导的神经网络构建时采用nn. ...
- 最新翻译的官方PyTorch简易入门教程(PyTorch1.0版本)
"PyTorch 深度学习:60分钟快速入门"为PyTorch官网教程,网上已经有部分翻译作品,随着PyTorch1.0版本的公布,这个教程有较大的代码改动,本人对教程进行重新翻译 ...
- c++排查线程hang住_Kafka学习笔记之kafka高版本Client连接0.9Server引发的血案排查 - 时光飞逝,逝者如斯...
0x00 概述 kafka server虽然原则上是兼容详细的client,但只是高版本的Server端兼容低版本的Client端: 在有高版本Client端连接时,会导致低版本Server集群会ha ...
最新文章
- .net 怎么循环得到数组里的值_提升ML.NET模型的准确性
- Java实现批量修改文件名,重命名
- 作为一名Java程序员,这些Spring知识点面试官常考
- Sqlite使用技巧集锦
- MySQL使用Amoeba作为Proxy时的注意事项
- 记一次性能优化,限制tcp_timewait数量,快速回收和重用
- 2014多校第一场A题 || HDU 4861 Couple doubi
- hikaricp 连接池分析_数据库连接池终于搞对了,这次直接从100ms优化到3ms!
- vs2012打包和部署程序成可安装安装包文件(InstallShield
- 聊聊高并发(五)理解缓存一致性协议以及对并发编程的影响
- 方立勋_30天掌握JavaWeb_EL表达式功能详解
- FullCalendar 七:FullCalendar应用——整合农历节气和节日
- idea如何打开pom引用依赖_idea 怎么引入在pom.xml的jar
- 使用Spark Shell开发运行Spark程序
- Spring Boot项目中使用 TrueLicense 生成和验证License(服务器许可)
- Codeforces Round #442 (Div. 2) 877E - Danil and a Part-time Job dfs序+线段树
- ABC + DEF = GHI //递归思想的充分体现(重难点)
- 还在为表单搭建而烦恼吗?免费低代码平台足够解忧~
- 图像修复经典算法--Criminisi算法
- ctf.show misc入门 21~40
热门文章
- 将实际环节都拆成了理论公式后,做好抽奖活动其实不难!
- Opencv学习四图像操作(反差色处理)
- ada:世界上第一位程序员
- 今日,华为重磅发布6大创新产品及服务!
- 高通MSM8953点屏记录
- 【Day42 文献精读】A Bayesian Model of Perceived Head-Centered Velocity during Smooth Pursuit Eye Movement
- C++(35)——判断一个数能否同时被3和5整除
- UVALive4987(dp+贪心)
- 计算机网络--哈工大网课--MOOC中国大学 慕课 答案
- c语言汉诺塔课设计报告,汉诺塔游戏的设计