torch.nn 中的线性 class 是如何工作的?
How does the Linear class in torch.nn work?
class LR(nn.Module):
def __init__(self, input_size, output_size):
super().__init__()
self.linear = Linear(input_size, output_size)
def forward(self, x):
pred = self.linear(x)
return pred
在上面的代码中,'forward'方法有参数x。在该方法中,'pred' 被赋值为 'self.linear(x)'。那么这个 x 被传递给什么,因为 self.linear 不接受任何参数。
你可以参考这篇官方文档link。注意 m
是用随机数组 input
.
调用的
X代表x轴,是告诉程序往哪边走的变量。我认为它是一个属于“移动动画方向计划”的计划。
class LR(nn.Module):
def __init__(self, input_size, output_size):
super().__init__()
self.linear = Linear(input_size, output_size)
def forward(self, x):
pred = self.linear(x)
return pred
在上面的代码中,'forward'方法有参数x。在该方法中,'pred' 被赋值为 'self.linear(x)'。那么这个 x 被传递给什么,因为 self.linear 不接受任何参数。
你可以参考这篇官方文档link。注意 m
是用随机数组 input
.
X代表x轴,是告诉程序往哪边走的变量。我认为它是一个属于“移动动画方向计划”的计划。