0
0
PyTorchml~20 mins

Feature map visualization in PyTorch - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Feature Map Visualization Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output shape of feature maps after convolution
Consider a PyTorch convolutional layer defined as conv = nn.Conv2d(in_channels=3, out_channels=16, kernel_size=3, stride=1, padding=1). If the input tensor has shape (1, 3, 64, 64), what will be the shape of the output feature map after applying conv?
PyTorch
import torch
import torch.nn as nn
conv = nn.Conv2d(in_channels=3, out_channels=16, kernel_size=3, stride=1, padding=1)
input_tensor = torch.randn(1, 3, 64, 64)
output = conv(input_tensor)
print(output.shape)
Atorch.Size([1, 16, 62, 62])
Btorch.Size([1, 3, 64, 64])
Ctorch.Size([1, 16, 64, 64])
Dtorch.Size([1, 16, 66, 66])
Attempts:
2 left
💡 Hint
Remember that padding=1 keeps the spatial size same when kernel_size=3 and stride=1.
🧠 Conceptual
intermediate
1:30remaining
Purpose of feature map visualization in CNNs
Why do we visualize feature maps in convolutional neural networks (CNNs)?
ATo understand what patterns or features the network is detecting at different layers
BTo reduce the size of the dataset before training
CTo increase the number of parameters in the model
DTo convert images into grayscale
Attempts:
2 left
💡 Hint
Think about what feature maps represent inside a CNN.
Metrics
advanced
1:30remaining
Interpreting feature map activation statistics
After visualizing feature maps from a CNN layer, you notice most activations are near zero except a few very high values. What does this indicate about the layer's behavior?
AThe input images are all black
BThe layer is overfitting the training data
CThe layer has a bug causing all zeros
DThe layer is sparsely activating, focusing on specific features
Attempts:
2 left
💡 Hint
Sparse activations mean only some neurons respond strongly.
🔧 Debug
advanced
2:00remaining
Why does feature map visualization show a blank image?
You wrote code to visualize feature maps from a CNN layer but the output images are all black. Which of the following is the most likely cause?
PyTorch
import matplotlib.pyplot as plt
import torch

# feature_maps is a tensor of shape (1, 16, 64, 64)
feature_maps = torch.randn(1, 16, 64, 64) * 0.01

plt.imshow(feature_maps[0, 0].detach().numpy())
plt.show()
AThe feature map values are too small and not normalized for visualization
BMatplotlib cannot plot tensors directly
CThe tensor shape is incorrect for visualization
DThe feature maps are empty tensors
Attempts:
2 left
💡 Hint
Check the range of values before plotting images.
Model Choice
expert
2:30remaining
Choosing a layer for meaningful feature map visualization
You want to visualize feature maps that show clear edges and textures from an image classification CNN. Which layer is best to choose?
AThe final fully connected layer
BAn early convolutional layer close to the input
CA batch normalization layer
DThe output softmax layer
Attempts:
2 left
💡 Hint
Early layers detect simple features like edges.