Pytorch 中如何使用 self() 来生成预测?
pytorch 237
原文标题 :How is self() used in Pytorch to generate predictions?
class MNIST_model(nn.Module):
def __init__(self):
super().__init__()
self.linear = nn.Linear(input_size, num_classes)
def forward(self, xb):
xb = xb.reshape(-1, 28 * 28)
out = self.linear(xb)
return out
def training_step(self, batch):
images, labels = batch
out = self(images)
loss = F.cross_entropy(out, labels)
return loss
我在关注 Freecodecamp 教程。在 training_step 方法中,教程中说 = self(images) 用于 Generate Predictions 。
我无法理解如何使用 self 来获得预测。