在TSN代码中, segmentconsensus是一个自定义函数, 所以要写一下它对应的梯度运算


# tj : https://blog.csdn.net/tsq292978891/article/details/79364140
class SegmentConsensus(torch.autograd.Function):@staticmethoddef forward(ctx, input_tensor, consensus_type, dim):ctx.consensus_type = consensus_typectx.dim = dimctx.shape = input_tensor.size()if consensus_type == 'avg':output = input_tensor.mean(dim=dim, keepdim=True)elif consensus_type == 'identity':output = input_tensorelse:output = Nonereturn output@staticmethoddef backward(ctx, grad_output):if ctx.consensus_type == 'avg':grad_in = grad_output.expand(ctx.shape) / float(ctx.shape[ctx.dim])elif ctx.consensus_type == 'identity':grad_in = grad_outputelse:grad_in = Nonereturn grad_in, None, None# tj : 常数要返回 None

# tj : https://blog.csdn.net/tsq292978891/article/details/79364140
class ConsensusModule(torch.nn.Module):def __init__(self, consensus_type, dim=1):super(ConsensusModule, self).__init__()self.consensus_type = consensus_type if consensus_type != 'rnn' else 'identity'self.dim = dimdef forward(self, input):return SegmentConsensus.apply(input, self.consensus_type, self.dim)

自定义autograd function相关推荐

  1. Pytorch使用autograd.Function自定义拓展神经网络

    我们知道CNN这类人工神经网络都基于BP算法进行优化,因此需要误差关于权重是连续可导的,这是可以运用BP算法的前提条件:也有一些网络不满足这个条件. 1.可导 对于可连续求导的神经网络构建时采用nn. ...

  2. Pytorch的自定义拓展:torch.nn.Module和torch.autograd.Function

    参考链接:pytorch的自定义拓展之(一)--torch.nn.Module和torch.autograd.Function_LoveMIss-Y的博客-CSDN博客_pytorch自定义backw ...

  3. 使用torch.autograd.function解决dist.all_gather不能反向传播问题

    1. 问题来源 最近在用mmcv复现Partial FC模型,看到源码中,有单独写的前向反向传播,甚是疑惑- 源码: # Features all-gather total_features = to ...

  4. Please use new-style autograd function with static forward method

    Please use new-style autograd function with static forward method Legacy autograd function with non- ...

  5. Legacy autograd function with non-static forward method is deprecated. Please use new-style autograd

    Legacy autograd function with non-static forward method is deprecated. Please use new-style autograd ...

  6. 数据库系列之mysql 自定义函数function,函数和存储过程的区别

    mysql 自定义函数function,函数和存储过程的区别 https://blog.csdn.net/u010365819/article/details/80470448 https://blo ...

  7. Pytorch版本过高产生的RuntimeError: Legacy autograd function with non-static forward method is deprecated.

    前言 在尝试用ECO Lite做视频分类的时候,使用了作者的Pytorch实现,然而Pytorch实现是基于Pytorch0.4的,我自己的Pytorch版本是1.4,所以在跑模型的时候出现了一些问题 ...

  8. Legacy autograd function with non-static forward method is deprecated

    Legacy autograd function with non-static forward method is deprecated 在网络s3fd_atss_sapd 测试时发现这个问题, d ...

  9. 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 ...

最新文章

  1. 从ACT-R探讨认知智能
  2. java集合框架图(二)
  3. putty登陆sourceforge.net(设置登录)
  4. html中radio值的获取、赋值、注册事件示例详解
  5. linux或者shell进入vi命令
  6. python实现指纹识别毕业论文_指纹识别系统大学本科毕业论文
  7. PHP 与 Perl 对照表
  8. 第三章 第一部分 不定积分例题
  9. 力扣812.最大三角形面积
  10. 社会生存的75条忠告----胜读十年书【转】
  11. 那些很重要,但是不常用的技术,websocket
  12. 摩擦力特点用计算机绘制出,AGC液压缸模拟工况摩擦力特性测试方法研究
  13. eclipse New菜单项的显示问题
  14. 多算法综合的文本挖掘系统
  15. jenkins 全局工具配置
  16. 参数估计(一)--置信区间
  17. laravel 开源文档管理系统
  18. 淘客返利机器人,淘宝,拼多多,京东三合一查券返利机器人搭建教程
  19. 详述break、return、continue的区别
  20. pythonword编辑报告模板_使用Python制作WORD报告

热门文章

  1. QSerialport多线程方法
  2. Sapera帮助文档
  3. LESS----CSS预处理语言
  4. UWP 颜色选择器(ColorPicker) 和 自定义的Flyout(AdvancedFlyout)
  5. 前端清单之Vue.js篇
  6. 4、Windows2008 R2安装Vcenter5.0
  7. spring集成quartz框架
  8. linux操作移动了根目录下的/lib和/lib64之后系统使用除了cd之外的任何命令都提示...
  9. ASMSupport教程4.7 生成关系运算符
  10. 通讯http,TCP/IP与socket之间的区别