There are several issues with your code. Currently your code is equivalent to:
class MLP(nn.Module):
def forward(self, x):
pass
Here are the issues:
Your initializer is named __init__
.
forward
should return a value, here x
.
Replace nn.nn.Sequential
with nn.Sequential
.
class MLP(nn.Module):
def __init__(self):
super (MLP, self).__init__()
self.model = nn.Sequential(
nn.Linear(784, 200),
nn.LeakyReLU(inplace=True),
nn.Linear(200, 200),
nn.LeakyReLU(inplace=True),
nn.Linear(200, 10),
nn.LeakyReLU(inplace=True))
def forward(self,x):
x = self.model(x)
return x
device= torch.device('cuda:0')
net = MLP().to(device)
optimizer = torch.optim.SGD(net.parameters(), lr=learning_rate)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…