A box = centre, width, height (4 numbers), plus a class and a score (how sure the detector is).
Enough for counting, tracking, cropping each object for a second network.
Poor for long diagonal objects: a box around a diagonal rod is mostly background (in the demo’s rod: the rod fills 16 % of its box).
A mask per object can be predicted inside each box afterwards.
IoU of two boxes
The evaluation day’s overlap measure, intersection over union: \mathrm{IoU} = |A \cap B| / |A \cup B|. For two axis-aligned boxes the intersection is a box again.
A = [0, 4] \times [0, 4], B = [2, 6] \times [2, 6]: intersection [2, 4] \times [2, 4], area 4; union 16 + 16 - 4 = 28; \mathrm{IoU} = 4/28 = 0.14.
The same 4 \times 4 box shifted by one pixel to the right: 12/20 = 0.6. Shifted by one pixel right and down: 9/23 = 0.39.
For small objects one pixel matters a lot.
The math: IoU of boxes in closed form
A = [a_0, a_1] \times [b_0, b_1], B = [c_0, c_1] \times [d_0, d_1]:
w = \max(0, \min(a_1, c_1) - \max(a_0, c_0)), \quad h = \max(0, \min(b_1, d_1) - \max(b_0, d_0)),
\mathrm{IoU}(A, B) = \frac{wh}{|A| + |B| - wh}.
Scale invariant: scaling both boxes by s multiplies every area by s^2; the ratio is unchanged.
1 - \mathrm{IoU} as a training loss gives no gradient when the boxes do not overlap (w = 0 or h = 0 on a whole region): the loss is flat at 1 however far apart they are. Hence the regression losses on the box coordinates (next day).
Match predictions to true objects one to one at IoU \ge \tau (often \tau = 0.5): TP, FP, FN objects; F1 and matching accuracyTP/(TP + FP + FN).
Rank the scored detections, walk down the list: a precision–recall curve; its area is the average precision (AP). Detection benchmarks often average AP over \tau = 0.5, 0.55, \dots, 0.95.
This unit is about what happens before the evaluation: where the scored boxes come from, and how duplicates are removed.
Where do the candidates come from?
The network looks at a coarse grid over the image (e.g. every 16 pixels).
Every grid cell guesses a box and a score.
Older detectors guess relative to template boxes (anchors); objects that fit no template are never learned.
Others predict a heat map of centres; its peaks are the objects.
One micrograph can hold spots of 3 px, nuclei of 15 px and clusters of 100 px.
A CNN’s early layers are fine grids (stride 4–8), but each cell sees a small region and knows little (edges, blobs).
Its deep layers see large regions and know what is there, but on a coarse grid (stride 32): a spot is 1/100 of a cell.
The old answer, from scale space: run the detector on an image pyramid (the image at ×2, ×1, ×½). It works, but the whole network runs once per level: 4 + 1 + \tfrac14 \approx 5 passes.
A pyramid inside the network
The CNN already makes a pyramid: its maps at strides 4, 8, 16, 32 (bottom-up). Coarse maps know what is there; fine maps are sharp but know little.
Feature pyramid network (FPN; Lin et al., 2017), a top-down path: upsample the coarsest map ×2 and add the finer map, brought to the same channels by a 1×1 convolution (the lateral connection). Repeat to the finest level.
Every level is now sharp and knows what it sees. The same box head runs on every level: small objects on fine levels, large on coarse. Cost: one pass, plus a few cheap layers.
Coarse to fine, adding detail level by level: how a Laplacian pyramid is added back up. Like U-Net’s skip connections, but U-Net predicts on the finest level only, FPN on every level.
The math: the top-down path, and which level an object goes to
Backbone maps C_2, \dots, C_5 (stride 2^k); W_k a 1×1 convolution (the same linear map of the channels at every pixel); \mathrm{up} = ×2 upsampling:
The Laplacian pyramid’s reconstruction is the same recursion, g_i = l_i + \mathrm{up}(g_{i+1}), with fixed details l_i; here the “details” W_k C_k are learned. A 3×3 convolution on each P_k smooths the blocky upsampling.
An object of size s = \sqrt{wh} goes to level k = \lfloor k_0 + \log_2(s / s_0) \rfloor, clamped to 2, \dots, 5; in the original paper s_0 = 224, k_0 = 4:
s = 224: k = 4 (stride 16); s = 448: k = 5; s = 112: k = 3. Twice the size, one level coarser: the object always covers about 224/16 = 14 cells.
A 20 px nucleus: \lfloor 4 + \log_2(20/224) \rfloor = \lfloor 0.51 \rfloor = 0, clamped to k = 2 (stride 4, 5 cells).
Many single-shot detectors instead let the training choose the level (next day).
Many candidates per object
Whatever proposes the boxes, every object gets several overlapping candidates: neighbouring grid cells, neighbouring pixels of a peak, jittered guesses.
Greedy non-maximum suppression: sort by score; keep the best box; delete every remaining box with IoU > t with it; repeat with the best remaining box.
Five boxes: b_1 = [0,10]^2 (0.9), b_2 = [1,11] \times [0,10] (0.8), b_3 = [8,18] \times [0,10] (0.7), b_4 = [9,19] \times [1,11] (0.6), b_5 = [20,26]^2 (0.3). Two true cells: under b_1 and under b_3.
t
kept
0.3
b_1, b_3, b_5
duplicates gone
0.7
b_1, b_3, b_4, b_5
b_4 (IoU 0.68 with b_3) survives
0.1
b_1, b_4, b_5
b_3 (IoU 0.11 with b_1) deleted
The math: greedy NMS
Sort the candidates by score, highest first; K = \emptyset.
Take the first remaining candidate b; add it to K.
Remove every remaining candidate c with \mathrm{IoU}(b, c) > t.
Repeat from 2 until no candidate remains; output K.
At most n rounds, each comparing with up to n boxes: O(n^2) IoUs. The result depends only on the order of the scores and on t. It is not an optimisation of any global criterion; it is a rule. The same rule with polygon IoU prunes star-convex polygons (next day, StarDist).
Try it: boxes and suppression
What NMS gets wrong
In a crowd of touching cells, the box of a true neighbour overlaps the kept box by more than t: it is deleted (a missed cell). The fix “raise t” lets duplicates of the same cell survive.
One threshold cannot do both when neighbours overlap as much as duplicates do. In the demo’s palisade (neighbour IoU about 0.3): t = 0.2 loses 4 of 12 cells; t = 0.75 keeps 34 duplicates; the best, t = 0.4, still has 3 false positives.
Hence for dense cells the map-based routes of the previous unit are usually preferred over boxes.
polygons that overlap a better polygon by more than t
polygon IoU with the kept polygons
A centre heat map’s peak picking (next day) is the Hough version; box NMS is a different rule with the same name, and polygon NMS is the box rule with polygon IoU.
Summary
A box is 4 numbers + score; IoU of boxes has a closed form; poor for diagonal or long objects.
Candidates come from a grid of guesses (anchors or centre peaks: next day).
Objects of every size: a feature pyramid (top-down path with lateral 1×1 connections) gives sharp maps that know what they see at every stride; boxes are predicted at every level, small objects on fine levels.
Every object gets many candidates; greedy NMS keeps the best and deletes overlaps above t.
In crowds, one t cannot both remove duplicates and keep touching neighbours.
Scoring (matching, F1, AP) comes from the evaluation day.