Hello everyone!
Hoping someone can help explain how I can calculate the input dimensionality into the first fully connected layer of the following CNN architecture I’m tinkering with… see the question marks in the code:
class AlexNet(nn.Module):
def __init__(self, num_classes=10):
super(AlexNet, self).__init__()
self.layer1 = nn.Sequential(
nn.Conv2d(1, 32, kernel_size=5, stride=1, padding=1),
nn.BatchNorm2d(32),
nn.ReLU(),
nn.MaxPool2d(kernel_size = 3, stride = 2)) #
self.layer2 = nn.Sequential(
nn.Conv2d(32, 64, kernel_size=3, padding=1),
nn.BatchNorm2d(64),
nn.ReLU(),
nn.MaxPool2d(kernel_size = 2, stride = 2))
self.layer3 = nn.Sequential(
nn.Conv2d(64, 96, kernel_size=3, padding=1),
nn.BatchNorm2d(96),
nn.ReLU())
self.layer4 = nn.Sequential(
nn.Conv2d(96, 64, kernel_size=3, padding=1),
nn.BatchNorm2d(64),
nn.ReLU())
self.layer5 = nn.Sequential(
nn.Conv2d(64, 32, kernel_size=3, padding=1),
nn.BatchNorm2d(32),
nn.ReLU(),
nn.MaxPool2d(kernel_size = 2, stride = 1))
self.fc = nn.Sequential(
nn.Dropout(0.5),
nn.Linear(?????????, 2048),
nn.ReLU())
self.fc1 = nn.Sequential(
nn.Dropout(0.5),
nn.Linear(2048, 1024),
nn.ReLU())
self.fc2= nn.Sequential(
nn.Linear(1024, d.num_classes))
If you can, please show how you arrived at the input dimensionality, because I have also tried using the formula (W - F +2P)/S + 1, but I know that this is supposed to be done recursively depending on the number of previous convolutional layers.
However, I was unable to properly apply the formula…
Thanks so much,
John