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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| class Net(nn.Module): def __init__(self): super(Net, self).__init__()
self.pool = nn.MaxPool2d(2, 2)
self.batchNorm1 = nn.BatchNorm2d(64) self.batchNorm2 = nn.BatchNorm2d(128) self.batchNorm3 = nn.BatchNorm2d(256) self.batchNorm4 = nn.BatchNorm2d(512) self.batchNorm5 = nn.BatchNorm2d(512)
self.conv1_1 = nn.Conv2d(3, 64, 3, padding=1, bias=False) self.conv1_2 = nn.Conv2d(64, 64, 3, padding=1, bias=False) self.conv2_1 = nn.Conv2d(64, 128, 3, padding=1, bias=False) self.conv2_2 = nn.Conv2d(128, 128, 3, padding=1, bias=False) self.conv3_1 = nn.Conv2d(128, 256, 3, padding=1, bias=False) self.conv3_2 = nn.Conv2d(256, 256, 3, padding=1, bias=False) self.conv3_3 = nn.Conv2d(256, 256, 3, padding=1, bias=False) self.conv4_1 = nn.Conv2d(256, 512, 3, padding=1, bias=False) self.conv4_2 = nn.Conv2d(512, 512, 3, padding=1, bias=False) self.conv4_3 = nn.Conv2d(512, 512, 3, padding=1, bias=False) self.conv5_1 = nn.Conv2d(512, 512, 3, padding=1, bias=False) self.conv5_2 = nn.Conv2d(512, 512, 3, padding=1, bias=False) self.conv5_3 = nn.Conv2d(512, 512, 3, padding=1, bias=False)
self.fc1 = nn.Linear(512 * 7 * 7, 4096) self.fc2 = nn.Linear(4096, 4096) self.fc3 = nn.Linear(4096, 10) self.drop = nn.Dropout(p=0.5)
def forward(self, x): x = F.relu(self.batchNorm1(self.conv1_1(x))) x = F.relu(self.batchNorm1(self.conv1_2(x))) x = self.pool(x)
x = F.relu(self.batchNorm2(self.conv2_1(x))) x = F.relu(self.batchNorm2(self.conv2_2(x))) x = self.pool(x)
x = F.relu(self.batchNorm3(self.conv3_1(x))) x = F.relu(self.batchNorm3(self.conv3_2(x))) x = F.relu(self.batchNorm3(self.conv3_3(x))) x = self.pool(x)
x = F.relu(self.batchNorm4(self.conv4_1(x))) x = F.relu(self.batchNorm4(self.conv4_2(x))) x = F.relu(self.batchNorm4(self.conv4_3(x))) x = self.pool(x)
x = F.relu(self.batchNorm5(self.conv5_1(x))) x = F.relu(self.batchNorm5(self.conv5_2(x))) x = F.relu(self.batchNorm5(self.conv5_3(x))) x = self.pool(x)
x = x.view(-1, 512 * 7 * 7)
x = F.relu(self.fc1(x)) x = F.relu(self.fc2(x))
x = self.fc3(x) return x
net = Net()
|