Foundations to Frontier
Tests
E. Deep Learning › E10 Segmentation Architectures

PSPNet

PSPNet (Zhao and colleagues, CVPR 2017) adds global context to a dilated ResNet with a pyramid pooling module: the final feature map is average-pooled into 1 × 1, 2 × 2, 3 × 3 and 6 × 6 bins, each reduced by a 1 × 1 convolution, upsampled and concatenated with the original features. It fixed context errors such as a boat labelled as a car and won the ImageNet scene parsing challenge in 2016. This page covers the pyramid pooling module, adaptive pooling and the auxiliary loss. In the exercises you implement PyTorch-exact adaptive pooling and the module's sizes, then show on constructed scenes that each task needs context at its own scale (2 × 2 bins for regional labels, the global bin for image-level labels) and that the full pyramid serves both.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Look at the whole scene

A small patch of an image can be ambiguous: a grey shape could be a car or a boat. Looking at the surroundings settles it: if the scene is water, it is a boat. PSPNet gives every pixel a summary of the image at several scales: one average over the whole image, then averages over halves, thirds and sixths. Each pixel’s prediction can use the summary of the region it sits in.

Segmentation lab
1×12×23×36×6
Each grid averages the feature map over 1, 4, 9 and 36 bins; the pooled maps are upsampled and concatenated with the original features, giving every pixel context from the whole image down to a sixth of it.
Segmentation labels every pixel. Coarse score maps lose boundaries when upsampled; skip connections from finer layers (FCN, U-Net) and dilated convolutions (DeepLab) recover detail. Judge masks by IoU or Dice, not pixel accuracy, which background inflates.
Why engineers care

Scene context reduces confusions between look-alike classes (road and pavement, mountain and hill) in driving and aerial imagery.

📝 Quick check (Level 0)
0/3 answered
  1. 1. PSPNet adds…
  2. 2. The coarsest pyramid level averages…
  3. 3. A boat mislabelled as a car is…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Pyramid pooling module (PPM): average-pool the final feature map (2048 channels, 60 × 60 for a 473 crop at OS 8) into 1 × 1, 2 × 2, 3 × 3 and 6 × 6 bins.
    • That is 1 + 4 + 9 + 36 = 50 pooled values per channel.
    • Each branch is reduced by a 1 × 1 convolution to 2048/4 = 512 channels.
    • It is then upsampled bilinearly to 60 × 60.
    • Concatenating with the input gives 2048 + 4·512 = 4096 channels, followed by a 3 × 3 convolution and the classifier.
  • Bin sizes: on a 60 × 60 map, bins are 60, 30, 20 and 10 pixels wide.
  • Adaptive pooling: when the size does not divide, PyTorch’s bin i spans ⌊i·n/b⌋ to ⌈(i+1)·n/b⌉, so bins overlap. For n = 10 and b = 3: [0, 4), [3, 7), [6, 10).
  • Auxiliary loss: a second classifier on stage-4 features adds 0.4 times its loss during training only. For main 1.2 and auxiliary 1.5, the total is 1.8.
📝 Quick check (Level 1)
0/3 answered
  1. 1. PPM output channels with a 2048-channel input:
  2. 2. Pooled values per channel for bins 1, 2, 3, 6:
  3. 3. Auxiliary loss weight:

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

PSPNet in code

Exercise 1.

  • Adaptive average pooling with PyTorch’s bin edges reproduced adaptive_avg_pool2d exactly, including the overlapping bins of a 7 × 7 map.
  • The module’s output had 4096 channels.

Practice.

  • The PPM is a few lines with nn.AdaptiveAvgPool2d(b).
  • BatchNorm in the 1 × 1 branch fails on the 1 × 1 bin with batch size 1. Use larger batches or GroupNorm, or train with synchronised BatchNorm as the authors did.
  • The four branch convolutions (with BN) have 4,198,400 parameters for 2048 input channels.
  • The pyramid shares ideas with ASPP (E10-5): both gather multi-scale context, by pooling (PSPNet) or by dilation (DeepLab). DeepLabv3’s image-pooling branch is PSPNet’s 1 × 1 level.
class PPM(nn.Module):
    def __init__(self, c=2048, bins=(1, 2, 3, 6)):
        super().__init__()
        self.branches = nn.ModuleList(nn.Sequential(nn.AdaptiveAvgPool2d(b), nn.Conv2d(c, c // 4, 1, bias=False),
                                                    nn.BatchNorm2d(c // 4), nn.ReLU()) for b in bins)
    def forward(self, x):
        size = x.shape[-2:]
        return torch.cat([x] + [F.interpolate(br(x), size, mode="bilinear", align_corners=False) for br in self.branches], 1)
🐍 Exercise 1: pyramid pooling
Implement PyTorch's adaptive bin edges, adaptive average pooling and the module's output channels.
📝 Quick check (Level 2)
0/3 answered
  1. 1. PyTorch layer for pyramid bins:
  2. 2. A BatchNorm risk in the 1 × 1 branch:
  3. 3. DeepLabv3's image pooling equals PSPNet's…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Why context needs pooling.

  • A deep network’s theoretical receptive field can cover the whole image.
  • The PSPNet authors note (citing Zhou et al.) that the empirical receptive field is much smaller, so far-away evidence barely influences a pixel’s prediction.
  • Global average pooling gives every position direct access to image-level statistics.
  • Pooling over sub-regions keeps some layout: the 2 × 2 level knows what is in each quadrant.

Why a pyramid.

  • One global vector mixes all regions: a scene that is half sea and half land averages to neither.
  • Finer bins describe regions but miss the whole.
  • Concatenating several scales lets the classifier pick the scale each decision needs.
  • Exercise 2 constructs both cases and shows the full pyramid matches the best single scale on each.

Auxiliary supervision. The extra classifier on stage 4 helps optimise the deep dilated ResNet. It is discarded at test time, like GoogLeNet’s auxiliary heads (E8-6).

📝 Quick check (Level 3)
0/3 answered
  1. 1. The empirical receptive field is…
  2. 2. One global vector cannot…
  3. 3. The auxiliary classifier is used…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

Which scale of context matters?

History.

  • H. Zhao, J. Shi, X. Qi, X. Wang and J. Jia introduced PSPNet (CVPR 2017). It won the ImageNet scene parsing challenge in 2016 and led PASCAL VOC 2012 and Cityscapes at publication.
  • Spatial pyramid pooling for CNNs came earlier, from K. He et al. (SPP-net, 2014; see E9-3).
  • W. Liu et al.’s ParseNet (2015) added a global context vector.

Exercise 2. The images are constructed 24 × 24 scenes:

  • each quadrant is sea or land, with water drawn in 3 × 3 blocks (70% for sea, 30% for land);
  • one 3 × 3 object of identical appearance sits in a random quadrant.

Object pixels get one of two labels:

  • regional: whether the object’s own quadrant is sea;
  • global: whether the whole image is mostly water.

Features are the local 5 × 5 water mean plus pooled water at chosen bin sizes. A logistic regression is trained on 300 scenes and tested on 300 more (seed 0):

features regional label global label
local only 0.753 0.640
+ 1 × 1 bin 0.778 1.000
+ 2 × 2 bins 0.948 0.683
+ 6 × 6 bins 0.754 0.637
+ 1, 2, 3, 6 (pyramid) 0.949 0.997
  • Each label needs its own scale.
    • The regional label needs the 2 × 2 bins (0.95; the global bin gives 0.78).
    • The global label needs the 1 × 1 bin (1.0 by construction, since the label is defined by that average; the 2 × 2 bins give 0.68).
  • Fine bins alone help little here. 6 × 6 bins (4 pixels wide) are barely wider than the local window.
  • The pyramid matches the best single scale on both tasks, which is PSPNet’s argument for concatenating several.
  • This is a constructed demonstration. Real scenes mix scales, and the paper’s ablation found average pooling over 1, 2, 3, 6 with dimension reduction worked best on ADE20K.
🐍 Exercise 2 (research): which scale of context matters?
Label object pixels by their quadrant's or image's scene, and compare local, single-scale and pyramid-pooled features.

PSPNet in AI, robotics and aerospace

  • Scene parsing: context modules (PPM, ASPP, attention) are standard in driving and indoor robotics segmentation.
  • UPerNet: PSPNet’s PPM sits on top of an FPN in UPerNet, a common decoder for transformer backbones such as Swin.
  • Aerial imagery: global context separates look-alike classes, such as water against shadow.

References

  1. H. Zhao, J. Shi, X. Qi, X. Wang, J. Jia (2017). “Pyramid scene parsing network.” Proc. CVPR.
  2. K. He, X. Zhang, S. Ren, J. Sun (2014). “Spatial pyramid pooling in deep convolutional networks for visual recognition.” Proc. ECCV.
  3. W. Liu, A. Rabinovich, A. C. Berg (2015). “ParseNet: looking wider to see better.” arXiv:1506.04579.
  4. T. Xiao, Y. Liu, B. Zhou, Y. Jiang, J. Sun (2018). “Unified perceptual parsing for scene understanding.” Proc. ECCV.