在学习 Pytorch 的过程中一直是使用 Jupyter notebook ,今天换到 Pycharm 中就发现了在 Pycharm 中使用 net(X) 不会输出前向计算的结果,只有使用 print(net(X)) 才会输出
import torch
from torch import nn
class MLP(nn.Module):
def __init__(self, **kwargs):
super(MLP, self).__init__(**kwargs)
self.hidden = nn.Linear(784, 256)
self.act = nn.ReLU()
self.output = nn.Linear(256, 10)
def forward(self, x):
a = self.act(self.hidden(x))
return self.output(a)
X = torch.rand(2, 784)
net = MLP()
print(net)
# print(net(X))
net(X)
如何才能使 net(X) 得到输出,因为在教程中
显示,该函数本来就能得到一个输出,如果不能输出,为什么