class Neural(nn.Module):
def init(self):
super(Neural, self).__init__()
self.ConvNet = nn.Sequential((nn.Conv2d(in_channels=1,
out_channels=5,
kernel_size=3,
stride=1,
padding=1),
nn.ReLU(inplace=True),
nn.Conv2d(in_channels=5,
out_channels=10,
kernel_size=3,
stride=1,
padding=1),
nn.MaxPool2d(2, 2),
nn.ReLU(inplace=True),
))
- List item
Declare all the layers for classification
self.classifier = nn.Sequential(
nn.Linear(14 * 14 * 10, 128),
nn.ReLU(inplace=True),
nn.Linear(128, 128),
nn.ReLU(inplace=True),
nn.Linear(128, 10))
def forward(self, x):
# Apply the feature extractor in the input
x = self.ConvNet(x)
# Squeeze the three spatial dimensions in one
x = x.view(-1, 14* 14* 10)
# Classify the images
x = self.classifier(x)
return x
criterion = nn.CrossEntropyLoss()
model= Neural()
optimizer = optim.SGD(model.parameters(), lr=0.03, momentum=0.1)
TypeError Traceback (most recent call last)
in
1 criterion = nn.CrossEntropyLoss()
----> 2 model= Neural()
3 optimizer = optim.SGD(model.parameters(), lr=0.03, momentum=0.1)
in init(self)
4 super(Neural, self).init()
5
----> 6 self.ConvNet = nn.Sequential((nn.Conv2d(in_channels=1,
7 out_channels=5,
8 kernel_size=3,
~\Anaconda3\envs\pytorch\lib\site-packages\torch\nn\modules\container.py in init(self, *args)
67 else:
68 for idx, module in enumerate(args):
—> 69 self.add_module(str(idx), module)
70
71 def _get_item_by_idx(self, iterator, idx) → T:
~\Anaconda3\envs\pytorch\lib\site-packages\torch\nn\modules\module.py in add_module(self, name, module)
370 “”"
371 if not isinstance(module, Module) and module is not None:
→ 372 raise TypeError("{} is not a Module subclass".format(
373 torch.typename(module)))
374 elif not isinstance(name, torch._six.string_classes):
TypeError: tuple is not a Module subclass