CNN model validity check? need your technical suggestion

class TinyCNN(nn.Module):
def init(self):
super(TinyCNN, self).init()
# Convolutional layer with very few channels and 5x5 kernel size
self.conv1 = nn.Conv2d(in_channels=1, out_channels=4, kernel_size=5, padding=2) # Padding = (filter_size-1)/2
self.bn1 = nn.BatchNorm2d(num_features=4)
# Max pooling reduces size to 14x14
self.pool = nn.MaxPool2d(kernel_size=2, stride=2)

    # Calculate the size of the flattened features after pooling
    # Assuming the input size is 28x28, after one conv and one pool layer, the feature map will be 14x14
    feature_size = 4 * 14 * 14  #784

    # Fully connected layer with very few units
    self.fc1 = nn.Linear(in_features=feature_size, out_features=10)
    # Using LeakyReLU as the activation function
    self.leaky_relu = nn.LeakyReLU()

def forward(self, x):
    x = self.pool(self.leaky_relu(self.bn1(self.conv1(x))))
    x = x.view(x.size(0), -1)  # Flatten
    x = self.fc1(x)
    return F.log_softmax(x, dim=1)
1 Like

Two comments:

  • What is your question?
  • If you’re going to post code on the forum, please enclose it in the ‘preformatted text’ tag. Otherwise your code is very difficult to read.
1 Like