📘
Multi-Scale Feature Pyramid
Build a multi-scale feature pyramid from an image using PyTorch.
Feature pyramids enable detection of objects at different scales. Each level of the pyramid is a downsampled version of the previous level.
Construction:
- Start with original image at level 0
- Each subsequent level: apply Gaussian blur then downsample by factor 2
- Typically 4-6 levels depending on image size
Gaussian blur before downsampling prevents aliasing (Nyquist criterion).
The pyramid enables coarse-to-fine processing:
- Top levels (small): Detect large structures
- Bottom levels (large): Detect fine details
Used in SIFT, HOG, and modern CNNs (FPN - Feature Pyramid Networks).
Example:
Input:
image = 8×8 array num_levels = 3
Output:
[tensor(8,8), tensor(4,4), tensor(2,2)]
Reasoning:
Level 0: Original 8×8 image
Level 1:
- Apply 3×3 Gaussian blur to 8×8
- Downsample to 4×4 (take every other pixel)
Level 2:
- Apply 3×3 Gaussian blur to 4×4
- Downsample to 2×2
Each level captures features at different scales:
- Level 0: Fine details (edges, textures)
- Level 2: Coarse structures (blobs, regions)
Constraints:
- image: 2D grayscale array (H, W)
- num_levels: Number of pyramid levels
- Return: List of tensors, each half the size of previous
- Use 3×3 Gaussian kernel with sigma=1.0 for blur
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.