已解决Runtime Error: one of the variables needed for gradient computation has been modified by an inpla
解决 Error for The of by an has
2023-09-27 14:27:32 时间
已解决Runtime Error: one of the variables needed for gradient computation has been modified by an inplace operation
报错问题
粉丝群里面的一个小伙伴敲代码时发生了报错(当时他心里瞬间凉了一大截,跑来找我求助,然后顺利帮助他解决了,顺便记录一下希望可以帮助到更多遇到这个bug不会解决的小伙伴),报错信息如下:
Runtime Error: one of the variables needed for gradient computation has been modified by an inplace operation
解决方法
解决方法如下
optimizerD.step()对logits_fake进行了修改。直接将其挪到倒数第二行即可,修改后代码为:
for epoch in range(1, epochs + 1):
for idx, (lr, hr) in enumerate(traindata_loader):
lrs = lr.to(device)
hrs = hr.to(device)
# update the discriminator
netD.zero_grad()
logits_fake = netD(netG(lrs).detach())
logits_real = netD(hrs)
# Label smoothing
real = (torch.rand(logits_real.size()) * 0.25 + 0.85).clone().detach().to(device)
fake = (torch.rand(logits_fake.size()) * 0.15).clone().detach().to(device)
d_loss = bce(logits_real, real) + bce(logits_fake, fake)
d_loss.backward(retain_graph=True)
# update the generator
netG.zero_grad()
g_loss = contentLoss(netG(lrs), hrs) + adversarialLoss(logits_fake)
g_loss.backward()
optimizerD.step()
optimizerG.step()
福利
每周会送6本技术书籍包邮到家
由于博主时间精力有限,每天私信人数太多,没办法每个粉丝都及时回复
大家可以进社区裙或者添加博主微信
点击下方链接即可
http://t.csdn.cn/6kInJ
相关文章
- ERROR: No matching distribution found for torch==1.2.0 解决方法
- 提高Stable Diffusion十倍计算速度以及解决内存崩溃问题
- awt组件中文乱码Intellij解决
- Syntax error: "(" unexpected shell里面的报错解决
- springboot+mybatis出现A component required a bean of type 'XXX' that could not be found错误解决
- 解决.net core3.1使用docker部署在Ubuntu上连接sqlserver报error:35的问题
- 解决com.alibaba.fastjson.JSONException: write javaBean error问题以及解决Spring Boot加入Shiro导致spring aop失效的问题
- 服务器报错 http error 503.the service is unavailable怎么解决
- 解决Python OpenCV 读取视频并抽帧出现error while decoding的问题
- Visual studio debug—Process with an Id of 5616 is not running的解决方法
- C++解决error C4996报错
- 链表解决银行储存系统---技术支持
- 已解决SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes in position 2-3: truncated
- 已解决RuntimeError: CUDA error: device-side assert triggered
- 已解决java Internal error in the mapping processor java.lang.NullPointerException异常的正确解决方法,亲测有效!!!
- 已解决:Android Studio Error:Connection timed out: connect
- 【错误记录】Mac 中 Python 报错 ( ERROR: Could not build wheels for numpy which use PEP 517 | 问题未解决 | 问题记录 )
- android studio导jar包找不到类的解决方法
- lightdb for postgresql ERROR: invalid byte sequence for encoding "UTF8": 0xc92c解决方法
- 在k8s中安装flannel的故障解决: Failed to create SubnetManager: error retrieving pod spec for : the server does not allow access to the requested resource
- ubuntu下 mysql安装以后无法登陆的的解决方法((ERROR 1698 (28000): Access denied for user 'root'@'localhost'))