Bounding boxes describe an object's location, and intersection over union measures overlap. A detector must also learn to move an inaccurate box toward its target. What numerical signal tells it how wrong the location is, especially before the boxes touch?
Box regression predicts continuous coordinates. A training loss compares those coordinates or their geometry with an annotated box. Start with one prediction already paired with one target; deciding which prediction belongs to which target comes later.
Four numbers in image coordinates
Use : horizontal center, vertical center, width, and height. Divide horizontal pixel coordinates and widths by image width, and vertical coordinates and heights by image height. Each component is dimensionless. For example, a box centered at pixel (120, 100) with size (80, 40) in a 400-by-200 image becomes .
These are absolute normalized box parameters, not offsets from an anchor. Other detector families can regress anchor-relative offsets. Here widths and heights are strictly positive, and the explorer keeps corners inside the image.
The simplest discrepancy is the sum of four absolute differences:
For the target and prediction , only the horizontal center is wrong, so . This is a sum, not the mean of the four coordinates. A positive error supplies a direction toward the target through the loss derivative; at zero error, the absolute value has a kink.
From coordinates to overlap
To compute areas, convert each box to corners:
The intersection has width , with the analogous expression for height. Multiply them to get intersection area . Union area is , so . Areas here are fractions of the image area; IoU is a ratio with no units.
A loss directly rewards overlap. But if two boxes remain separated under small coordinate changes, their intersection stays zero. The loss stays at one, and its local derivative is zero. It cannot distinguish a small gap from a large gap in this region.
Let the enclosure expose empty space
Generalized IoU adds the smallest axis-aligned rectangle enclosing both boxes:
The correction measures enclosure area not covered by either box. It can provide a changing loss when overlap is zero, as introduced in the GIoU paper by Rezatofighi and colleagues. GIoU can be negative; its loss can exceed one.
Move the predicted center and size below. Compare Disjoint with Overlap, then select Contained and shift its center slightly. The values are calculated from authored boxes, not measured detector outputs.
Authored analytic geometry, rounded to three decimals. Areas are fractions of image area. Target (cx, cy, w, h) = (0.3, 0.5, 0.2, 0.2). All changes are manual.
In the disjoint preset, both boxes have area . Their union is and their enclosing rectangle has area . Thus , , and . Moving the prediction left shrinks the enclosure before the boxes overlap.
In the overlap preset, shifting the prediction's center to gives intersection and union , so IoU is . Here the boxes jointly fill the enclosure, so GIoU also equals .
GIoU has limits too
Containment is a useful counterexample. A centered prediction of width and height lies inside the target of width and height . Its area is and the target's area is , giving IoU . The enclosure equals the union, so the GIoU correction is zero: GIoU is also .
Translate that small box while it remains fully contained. Neither its area nor the union changes, so both losses stay constant even though its center moves. GIoU is not a universal cure for unhelpful derivatives. Coordinate L1 still detects that center error. Minima, maxima, and absolute values also make these objectives piecewise smooth rather than differentiable everywhere.
The optional slope readout approximates a derivative by evaluating each loss at and , then dividing the difference by , with . It is not an automatic gradient. At exact alignment or another kink, a symmetric finite difference can be zero even when moving either way increases the loss.
Put the losses back into a detector
Original DETR combines coordinate and geometric supervision for matched boxes:
Its official box utility uses the order and converts to corners for GIoU. The official criterion sums coordinate errors for matched pairs and normalizes losses by the number of target boxes. The expression above describes one pair; classification supervision and weighting remain separate parts of training.
An evaluation rule such as “count a detection as localized when IoU is at least 0.5” is a discrete scoring decision. It is not the continuous box training loss, and training assignment is not evaluation matching. See object detection metrics for that distinction.
Next, set prediction and bipartite matching shows how a detector pairs an unordered set of predictions with targets before applying these losses. Then modern object detection places the box head, matching, and classification into the complete pipeline.
Related concepts
Learn how DETR assigns unordered object targets to prediction slots, why greedy choices can fail, and how matching differs from training loss and evaluation.
Convert between xyxy, xywh and center-size boxes, normalize coordinates correctly, and avoid mistakes when resizing, clipping or flipping detection labels.
Follow a query from a spatial reference through learned offsets, bilinear feature sampling and weighted aggregation, with exact non-square coordinate arithmetic.
Calculate box intersection and union, explore how position and size change IoU, and distinguish overlap used for evaluation, NMS and localization losses.
Understanding end-to-end object detection with transformers, from DETR's object queries to bipartite matching and attention-based localization
Understand object detection from image features to boxes, classes and scores. Compare one-stage and two-stage pipelines, training and duplicate handling.
