I tried to Reproduce the results of Hinton’s capsuleNet, however I have stucked in the baseline CNN coding.
From the paper
The baseline is a standard CNN with three convolutional layers of 256, 256, 128 channels. Each has
5x5 kernels and stride of 1. The last convolutional layers are followed by two fully connected layers
of size 328, 192. The last fully connected layer is connected with dropout to a 10 class softmax layer
with cross entropy loss.
The following are my module code:
class BaseLineNet(nn.Module): def __init__(self): super(BaseLineNet, self).__init__() self.conv1 = nn.Conv2d(in_channels=1, out_channels=256, kernel_size=5, stride=1) self.conv2 = nn.Conv2d(in_channels=256, out_channels=256, kernel_size=5, stride=1) self.conv3 = nn.Conv2d(in_channels=256, out_channels=128, kernel_size=5, stride=1) self.fc1 = nn.Linear(328, 192) self.fc2 = nn.Linear(192, 10) def forward(self, x): x = F.relu(F.max_pool2d(self.conv1(x), 2)) x = F.relu(F.max_pool2d(self.conv2(x), 2)) x = F.relu(F.max_pool2d(self.conv3(x), 2)) x = x.view(-1, 328) x = F.relu(self.fc1(x)) x = F.dropout(x, training=self.training) x = self.fc2(x) return (F.log_softmax(x))
I got puzzled about the paper’s channels and the channels in FC layer.
when I run the code, I got an error
Calculated padded input size per channel: (4 x 4). Kernel size: (5 x 5). Kernel size can't be greater than actual input size
The Input img is [28*28] from MNIST, the error must be from my module, but I’m confused about it.
Could anyone tell me how to fix it? That will be fine!
Thanks a lot! & Have a good day