0
0
PyTorchml~20 mins

Why CNNs detect spatial patterns in PyTorch - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Spatial Pattern Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why do CNNs use filters?

Why do convolutional neural networks (CNNs) use filters (also called kernels) when processing images?

AFilters scan the image to detect local patterns like edges or textures by focusing on small regions.
BFilters randomly change pixel values to increase image diversity.
CFilters convert images into text descriptions for easier processing.
DFilters remove all colors to simplify the image into black and white.
Attempts:
2 left
💡 Hint

Think about how looking at small parts of a picture helps you recognize shapes.

Predict Output
intermediate
2:00remaining
Output shape after convolution

Given a grayscale image tensor of shape (1, 1, 28, 28) and a convolution layer with 6 filters of size 3x3, stride 1, and padding 0, what is the output shape after applying the convolution?

PyTorch
import torch
import torch.nn as nn

image = torch.randn(1, 1, 28, 28)  # batch=1, channels=1, height=28, width=28
conv = nn.Conv2d(in_channels=1, out_channels=6, kernel_size=3, stride=1, padding=0)
output = conv(image)
print(output.shape)
Atorch.Size([1, 6, 26, 26])
Btorch.Size([1, 6, 28, 28])
Ctorch.Size([1, 1, 26, 26])
Dtorch.Size([6, 1, 28, 28])
Attempts:
2 left
💡 Hint

Output size = (Input size - Kernel size + 2 * Padding) / Stride + 1

Model Choice
advanced
2:00remaining
Choosing CNN for spatial pattern detection

You want to build a model to recognize handwritten digits from images. Which model type is best suited to detect spatial patterns like edges and curves?

AA linear regression model that predicts digits directly from pixel values.
BA simple feedforward neural network with fully connected layers only.
CA convolutional neural network (CNN) because it captures local spatial features using filters.
DA recurrent neural network (RNN) designed for sequential data like text.
Attempts:
2 left
💡 Hint

Think about which model type is designed to understand images by looking at small parts.

Hyperparameter
advanced
2:00remaining
Effect of kernel size on spatial pattern detection

How does increasing the kernel size in a CNN layer affect the spatial patterns the model can detect?

ALarger kernels always improve model accuracy without any drawbacks.
BLarger kernels capture bigger spatial patterns but reduce the output size more.
CLarger kernels ignore spatial patterns and treat the image as a flat vector.
DLarger kernels decrease the number of filters in the layer automatically.
Attempts:
2 left
💡 Hint

Think about how a bigger window sees more of the image at once.

Metrics
expert
2:00remaining
Interpreting CNN training loss and accuracy

During CNN training on image data, you observe the training loss steadily decreases but the validation accuracy stops improving and fluctuates. What does this indicate?

AThe training data is corrupted and causing unstable validation results.
BThe model is underfitting and needs more training epochs.
CThe model has perfect generalization and no further tuning is needed.
DThe model is overfitting the training data and not generalizing well to new data.
Attempts:
2 left
💡 Hint

Think about what it means when training improves but validation does not.