Week 09 · Segmentation and boundary errors

Train a pixel classifier, then inspect where a good overlap score hides errors.

← Week 8 · Subject contents · Week 10 →

Train a pixel classifier, then inspect where a good overlap score hides errors.

Work through the problem

A segmentation model predicts a class for each pixel. A 1×1 convolution can learn a logistic pixel classifier, sharing its intensity threshold across positions. It cannot examine neighbours, so dim boundary pixels may be classified as background.

IoU measures overlap. If a 6×6 square is eroded to its central 4×4 pixels, IoU is 16/36. Boundary recall is zero if all 20 original boundary pixels are lost. Compare an intensity model on bright training masks and dimmer evaluation edges.

Dim boundaries change a predicted mask. Panels from left to right: Gold, Observed intensity, Predicted.

Dim boundaries change a predicted mask.

Run the Python lab

import torch
from torch import nn
torch.set_num_threads(1)
torch.manual_seed(6)
gold = torch.zeros(1,1,12,12)
gold[:,:,3:9,3:9]=1
inner = torch.zeros_like(gold)
inner[:,:,4:8,4:8]=1
boundary = gold.bool() & ~inner.bool()
x = gold.repeat(32,1,1,1)*.8 + .09*torch.randn(32,1,12,12)
model = nn.Conv2d(1,1,1)
opt = torch.optim.Adam(model.parameters(),lr=.12)
for _ in range(110):
    opt.zero_grad()
    nn.functional.binary_cross_entropy_with_logits(model(x),gold.expand_as(x)).backward()
    opt.step()
test = .8*inner+.28*boundary.float()
mask = model(test)>0
intersection = (mask & gold.bool()).sum()
union = (mask | gold.bool()).sum()
print("IoU",round((intersection/union).item(),3),"boundary recall",round(mask[boundary].float().mean().item(),3))
print("False negatives",int((~mask & gold.bool()).sum()))
assert mask[inner.bool()].all()

Output from the lab

IoU 0.444 boundary recall 0.0
False negatives 20

Practice

  1. Why can pixel accuracy hide a missed mask?

Check your reasoning

  1. Most pixels may be background. Predicting background everywhere can score high accuracy while foreground recall is zero.

← Week 8 · Subject contents · Week 10 →

Further reading · Szeliski · Computer Vision: Algorithms and Applications