When using padding and stride in convolutional layers, the key metric to watch is output size and accuracy. Padding controls how the edges of input data are handled, affecting output size and detail preservation. Stride controls how much the filter moves, affecting output size and feature detection. The right balance keeps important features while maintaining good accuracy.
Padding and stride in TensorFlow - Model Metrics & Evaluation
Input size: 5x5
Filter size: 3x3
Padding: 1 (same padding)
Stride: 1
Output size calculation:
Output = ((Input - Filter + 2*Padding) / Stride) + 1
= ((5 - 3 + 2*1) / 1) + 1 = 5
If stride = 2:
Output = floor(((5 - 3 + 2*1) / 2)) + 1 = 3
This shows how padding and stride change output size.
Think of padding and stride like zooming in on a photo:
- Padding adds a border so you don't lose edges, like keeping the full photo frame.
- Stride is how big your steps are when scanning the photo.
If stride is too big, you skip details (low recall). If padding is too small, you lose edges (low precision). The tradeoff is to keep enough detail (high recall) without too much noise (high precision).
Good: Output size matches expected dimensions, model accuracy is high, and features are well captured.
Bad: Output size too small or too large, model accuracy drops, or important features are missed due to too large stride or no padding.
- Using no padding causes output size to shrink, losing edge information.
- Too large stride skips important features, hurting model learning.
- Incorrect output size calculation leads to shape mismatch errors.
- Ignoring padding and stride effects can cause overfitting or underfitting.
Your convolutional model has 98% accuracy but the output feature map is very small due to stride 3 and no padding. Is this good?
Answer: No. The large stride and no padding shrink the output too much, likely missing important features. Despite high accuracy, the model may not generalize well. Adjust padding and stride to preserve features.