Weakly Supervised Learning
Weakly supervised learning draws boxes and masks from image-level tags using heatmaps and multi-instance rules instead of hand-drawn outlines.
Why Does This Exist?
Drawing boxes around every dog in a million images costs months. Image-level tags saying dog or no dog cost almost nothing and already exist in search logs. The gap between cheap tags and expensive boxes blocks datasets that could be ten times larger.
Weakly supervised learning bridges it with localisation from classification. Class activation maps expose where the classifier looked, and multi-instance rules turn bag-level tags into pixel decisions. Programmatic labeling practice lives in weak supervision, which covers Snorkel-style rules rather than heatmaps. Detection craft lives in object detection.
Think of It Like This
Finding a hot pan by hovering hands
You cannot see which burner is on, but hovering hands feel heat rising strongest over one spot. You mark that hot zone and grab the handle beside it.
The classifier is the hovering hand, the heatmap is felt warmth, and the threshold picks the hot zone. The analogy stops at precision: hands find heat, not object edges, and heatmaps hug discriminative parts like faces over full bodies.
How It Actually Works
Train a classifier on image tags with global average pooling before the final layer, which preserves spatial maps. A class activation map weights each feature plane by its class weight and upsamples to image size. Thresholding at keeps hot pixels, connected components clean speckle, and the tight box around the largest component becomes the pseudo-box. Multi-instance learning frames it formally: an image is a bag, regions are instances, and a positive bag holds at least one positive instance.
Worked example
Heatmap pixels for class dog. Threshold keeps hot pixels clustered over the torso and head. Largest component spans columns to and rows to , giving box in heatmap cells, scaled by to in a image. One tag became one box with no hand drawing.
Code
Threshold plus tight box from a heatmap.
def hot_box(vals: list[float], width: int = 64, tau: float = 0.5) -> tuple[int, tuple[int, int, int, int]]: """Count hot cells and tight box over a flat heatmap.""" hot = [i for i, v in enumerate(vals) if v >= tau] # heat gate xs = [i % width for i in hot] ys = [i // width for i in hot] return len(hot), (min(xs), min(ys), max(xs), max(ys))
print(hot_box([0.9] * 1200 + [0.1] * 2896)) # -> (1200, (0, 0, 63, 18))Watch Out For
Boxes that hug faces instead of bodies
Classifiers discriminate by parts: dog faces over torsos, bird heads over wings. The symptom is tight boxes around heads scoring well on classification but failing detection IoU.
Expand with erasing or multi-map fusion during training. Check box IoU on a small fully labeled probe, never classification accuracy alone.
The Quick Version
- Weak supervision turns image tags into boxes and masks via heatmaps and bag rules.
- CAM weights feature planes by class weights and upsamples to full resolution.
- Worked numbers: of pixels kept at , box .
- Largest-component cleanup removes speckle before boxing.
- Expect part-focus and verify against true boxes on a small probe set.