I have the following classification model (dogs vs cats):

def GetModel():
        oModel = nn.Sequential(
        nn.Identity(), #-- does nothing
        nn.Conv2d(3,   16,  3, bias=False, stride=2), nn.BatchNorm2d(16),  nn.ReLU(), nn.Dropout2d(0.1),
        nn.Conv2d(16,  32,  3, bias=False, stride=2), nn.BatchNorm2d(32),  nn.ReLU(), nn.Dropout2d(0.1),
        nn.Conv2d(32,  64,  3, bias=False, stride=2), nn.BatchNorm2d(64),  nn.ReLU(), nn.Dropout2d(0.1),        
        nn.Conv2d(64,  128,  3, bias=False, stride=2), nn.BatchNorm2d(128),  nn.ReLU(), nn.Dropout2d(0.1),        
        nn.Conv2d(128,  256,  3, bias=False, stride=2), nn.BatchNorm2d(256),  nn.ReLU(), nn.Dropout2d(0.1),        
        nn.Flatten          (),     
        nn.Linear           (256, 64),
        nn.Linear           (64, 2),        
    return oModel

I trained the model and visualize the feature maps (the conv2d layers) for a new input image:

Input image

feature maps: enter image description here

  1. What can we learn from the feature maps ?
  2. Can we say the last 2 Conv2D layers (layer3 & layer4) are not useful ? (because they are very noisy) ?
  3. Can we deduce what number of Conv2D layers that are sufficient ?

1 Answer 1


It is not a question of "noise", but rather granularity. Typically, first few Conv layers learn low-level features (e.g. corners, edges, …etc.), and as you go deeper, the network learns more high-level features (e.g. nose, eye, …etc.). I think you are more interested in Saliency maps, which reflect the importance of regions in the image in influencing the decision (i.e. the output of the model). This is meant to reflect how humans focus on certain aspects of images.

To deduce the number of optimal conv layers, you would need to use cross-validation. For example, you could try removing one layer at a time and see how the performance is affected. Typically, you would need choose the simplest model with highest empirical performance.

On a side note, I suggest you use, or at least get inspiration from, existing CNN architectures when designing your own CNN. There is virtually infinite ways to put your layers together, it's kind of like legos but with continuous numbers. This would save you time putting together a good-performing model faster.

  • $\begingroup$ How can we see that: "Conv layers learn low-level features (e.g. corners, edges, …etc.), and as you go deeper, the network learns more high-level features (e.g. nose, eye, …etc.)". How can I see the learned features at each CNN layer ? $\endgroup$ Jun 14, 2022 at 5:27
  • $\begingroup$ That's simply how CNNs work. Convolution is a fancy word for filtering. So you are basically filtering and pooling over and over. You can see this if you inspect the filtering outputs. You can check this demo poloclub.github.io/cnn-explainer. Another cool demo. cs.stanford.edu/people/karpathy/convnetjs/demo/mnist.html. You can find a more detailed article on this here towardsdatascience.com/… $\endgroup$ Jun 14, 2022 at 8:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.