【发布时间】:2020-08-18 14:29:39
【问题描述】:
import torch.nn as nn
import torch.nn.functional as F
## TODO: Define the NN architecture
class Net(nn.Module):
def __init__(self):
super(Net, self).__init__()
# linear layer (784 -> 1 hidden node)
self.fc1 = nn.Linear(28 * 28, 512)
self.fc2 = nn.Linear(512 * 512)
self.fc3 = nn.Linear(512 * 10)
def forward(self, x):
# flatten image input
x = x.view(-1, 28 * 28)
# add hidden layer, with relu activation function
x = F.relu(self.fc1(x))
x = F.relu(self.fc2(x))
x = F.relu(self.fc3(x))
return x
# initialize the NN
model = Net()
print(model)
当我运行它时,它会抛出这个错误。为什么?
TypeError: __ init __() 缺少 1 个必需的位置参数:'out_features'
【问题讨论】:
标签: pytorch mnist conv-neural-network