【发布时间】:2019-09-09 12:40:15
【问题描述】:
张量b 和c 的requires_grad 是True。但是张量d 的requires_grad 是False。我很好奇为什么会发生这种变化,因为所有 requires_grad 的输入都是 True。
但是,张量 e 的 requires_grad 是 True。我仍然可以在e 上做backward()。但是这种方式有错误吗?
我正在使用 Python3.7 和 Pytorch1.1。
import torch
import torch.nn as nn
net = nn.Conv2d(1, 1, 3, padding=1)
a = torch.randn(1, 1, 10, 10)
b = net(a)
c = net(b)
d = torch.gt(b, c)
e = b - c
e[e > 0] = 1.0
e[e < 0] = 0.0
【问题讨论】: