当前位置:网站首页>Pytorch: a pit about the implementation of gradreverselayer
Pytorch: a pit about the implementation of gradreverselayer
2022-04-23 12:54:00 【Qing San】
I've been working on one recently domain adaptation Project , Yes gradreverselayer:`class GradReverse(Function):
def forward(ctx, x, alpha, **kwargs:None):
ctx.alpha = alpha
return x.view_as(x)
def backward(ctx, grad_output):
output = grad_output * -ctx.alpha
return output, None
There seems to be no problem , But keep reporting the wrong :

I haven't done it for a long time , So I made a stupid decision , I added one :
src_domain_loss=torch.tensor(src_domain_loss, requires_grad=True)
As a result, the error disappeared , I happily used this silly * The code took two months , Results the experimental results have been unsatisfactory , Until today, check the training gradient , It is found that the gradient is always zero !!!

Speechless , It must be the pot of this code , But without it, an error will be reported , I searched every corner of the Internet , No solution has been found , And paid people to consult ( cry ).
result , A flash of light , I found something missing in the code of gradient flip layer :
class GradReverse(Function):
@staticmethod
def forward(ctx, x, alpha, **kwargs:None):
ctx.alpha = alpha
return x.view_as(x)
@staticmethod
def backward(ctx, grad_output):
output = grad_output * -ctx.alpha
return output, None`
Have you found it? ?@staticmethod!!! I always thought this was a comment , Delete... Directly , Great speechless event , cause sb. to die of anger !!!
In fact, this is declaring a static method !
I hope you will take a warning .( cry )
版权声明
本文为[Qing San]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230616251505.html
边栏推荐
- 解决disagrees about version of symbol device_create
- SSM framework series - data source configuration day2-1
- No idle servers? Import OVF image to quickly experience smartx super fusion community version
- 教你快速开发一个 狼人杀微信小程序(附源码)
- 将新增和编辑的数据同步更新到列表
- Idea的src子文件下无法创建servlet
- Realize several "Postures" in which a box is horizontally and vertically centered in the parent box
- 航芯技术分享 | ACM32 MCU安全特性概述
- Calculate the past date and days online, and calculate the number of live days
- 【每日一题】棋盘问题
猜你喜欢

8 websites that should be known for product development to enhance work experience

Aviation core technology sharing | overview of safety characteristics of acm32 MCU

Dialogue with Bruce, author of PostgreSQL: "changing careers" is to better move forward

22. Bracket generation

31. 下一个排列

拥抱机器视觉新蓝海,冀为好望开启数字经济发展新“冀”遇

使用Source Insight查看编辑源代码

网站首页文件被攻击篡改的形式有哪些

【vulnhub靶场】-dc2

产品开发都应该知道的8个网站,增强工作体验
随机推荐
Uni app native app local packaging integrated Aurora push (jg-jpush) detailed tutorial
Zigbee之CC2530最小系统及寄存器配置(1)
Trier les principales utilisations de l'Agent IP réseau
22. 括号生成
Recommended website for drawing result map
Kubernetes 入门教程
4.DRF 权限&访问频率&过滤&排序
Resolve disagrees about version of symbol device_ create
unity常见的问题(一)
Plato Farm-以柏拉图为目标的农场元宇宙游戏
World Book Day: I'd like to recommend these books
Servlet监听器&过滤器介绍
mysql中 innoDB执行过程分析
STM32 project transplantation: transplantation between chip projects of different models: Ze to C8
After the data of El table is updated, the data in the page is not updated this$ Forceupdate() has no effect
BaseRecyclerViewAdapterHelper 实现下拉刷新和上拉加载
Zero trust in network information security
进程虚拟地址空间区域划分
php生成json处理中文
Ad20 supplementary note 3 - shortcut key + continuous update