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 of annotator time. Image-level tags saying dog or no dog cost almost nothing and already exist in search logs and alt text. The gap between cheap tags and expensive boxes blocks datasets that could be ten times larger.
Weakly supervised learning bridges it with localization from classification. A classifier trained on tags alone still has to look at the right pixels to decide, and class activation maps expose where it looked. Multi-instance rules then turn bag-level tags into pixel decisions. Programmatic labeling with hand-written rules rather than heatmaps lives in weak supervision, and box craft with full labels lives in object detection. This page covers heatmap boxes only.
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 reach for 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 while missing full bodies.
How It Actually Works
Train a classifier on image tags with global average pooling before the final layer, which preserves spatial maps instead of flattening them away. A class activation map, CAM, weights each feature plane by its class weight, , where is feature plane and is its weight for class , then upsamples to image size. Thresholding at keeps the hot pixels, connected components clean the 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. The largest connected component holds of those pixels and spans columns to and rows to , giving box in heatmap cells. The box area is cells, comfortably holding its hot pixels. Scaling by to a image gives . One tag became one box with no hand drawing.
Code
Threshold plus tight box on an toy heatmap with a hot block at rows to , columns to :
W = 8vals = [0.1] * (W * W)for r in range(2, 5): for c in range(3, 7): vals[r * W + c] = 0.9
hot = [i for i, x in enumerate(vals) if x >= 0.5]xs = [i % W for i in hot]ys = [i // W for i in hot]print(len(hot), (min(xs), min(ys), max(xs), max(ys)))# -> 12 (3, 2, 6, 4)hot cells with tight box , exactly the planted block. The same gate-and-box routine scales to the map in the worked example.
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 that score well on classification but fail detection IoU on a labeled probe. Expand coverage with erasing or multi-map fusion during training, and judge boxes by IoU on a small fully labeled set, never by classification accuracy alone.
Thresholding speckle into confetti boxes
A single global threshold on a noisy heatmap keeps scattered hot pixels far from the object, and boxing every component sprays false positives. The symptom is many tiny high-confidence boxes around background texture. Keep only the largest connected component, or merge components closer than a few cells, before drawing the box.
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 , largest cluster boxed as .
- Largest-component cleanup removes speckle before boxing.
- Expect part-focus on faces over bodies, and verify against true boxes on a small probe set.