1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| class Classifier(nn.Module): def __init__(self): super(Classifier, self).__init__()
self.cnn_layers = nn.Sequential( nn.Conv2d(3, 64, 3, 1, 1), nn.BatchNorm2d(64), nn.ReLU(), nn.MaxPool2d(2, 2, 0),
nn.Conv2d(64, 128, 3, 1, 1), nn.BatchNorm2d(128), nn.ReLU(), nn.MaxPool2d(2, 2, 0),
nn.Conv2d(128, 256, 3, 1, 1), nn.BatchNorm2d(256), nn.ReLU(), nn.MaxPool2d(2, 2, 0), nn.Conv2d(256, 512, 3, 1, 1), nn.BatchNorm2d(512), nn.ReLU(), nn.MaxPool2d(2, 2, 0), nn.Conv2d(512, 1024, 3, 1, 1), nn.BatchNorm2d(1024), nn.ReLU(), nn.MaxPool2d(2, 2, 0), ) self.fc_layers = nn.Sequential( nn.Linear(1024 * 4 * 4, 1024), nn.ReLU(), nn.Dropout(0.5), nn.Linear(1024, 512), nn.ReLU(), nn.Dropout(0.5), nn.Linear(512, 11) )
def forward(self, x): x = self.cnn_layers(x) x = x.flatten(1) x = self.fc_layers(x) return x
|