v9.1.1
Menu

Multi-Scale Feature Pyramid

hardFREEBook OverviewFeature ExtractionCV: Introduction to Computer Vision

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:

  1. Start with original image at level 0
  2. Each subsequent level: apply Gaussian blur then downsample by factor 2
  3. 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
  • Inputs: image is an 8×88 \times 8 grid of grayscale intensities (here, all ones), and num_levels =3= 3 counts every level, including the untouched original.
  • The blur weights: with σ=1\sigma = 1, the 1-D Gaussian at offsets −1,0,1-1, 0, 1 is e−x2/2=0.6065, 1, 0.6065e^{-x^2/2} = 0.6065,\ 1,\ 0.6065. Dividing by their total 2.21312.2131 gives 0.2741, 0.4519, 0.27410.2741,\ 0.4519,\ 0.2741. The 3×33 \times 3 weight at (i,j)(i, j) is the product of the row and column weights: centre 0.45192=0.20420.4519^2 = 0.2042, edge 0.12380.1238, corner 0.07510.0751. The nine weights sum to 11.
  • Level 1: each blurred pixel is a weighted average of its 3×33 \times 3 neighbourhood, so a constant image stays 11. Halving each side then keeps one pixel from each 2×22 \times 2 block: 8×8→4×48 \times 8 \to 4 \times 4, all values 11.
  • Level 2: blurring and halving the 4×44 \times 4 level gives a 2×22 \times 2 grid of ones.
  • Output: three 2-D tensors of sizes 8×88 \times 8, 4×44 \times 4, 2×22 \times 2, finest first. Notice that because the weights sum to 11, the blur never brightens or darkens an image. It only smooths away fine detail.

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

More from CV: Introduction to Computer Vision

solution.py

Test results

Sign in to run your code against the test cases.