py123d_detection.torch.models.common.loss¶
The set-prediction loss both detectors train against.
A detection head emits a fixed number of queries, 900 in the shipped configs, and a frame holds a
handful of objects. HungarianMatcher decides which query is responsible for which box, by
solving the assignment that minimises a cost of focal classification plus L1 on the normalised box.
SetCriterion then scores that assignment: focal loss over all queries, with the unmatched
ones as background, and L1 over the matched ones only.
The matching is what makes the loss order-invariant, and also what makes it easy to get subtly
wrong. A matcher that pairs the wrong query with the wrong box still produces a loss that falls,
just to a worse place, so tests/test_loss.py pins the matching itself rather than only the
number that comes out.
Every decoder layer is supervised, not just the last. The intermediate losses are keyed d0.,
d1., … and the final one carries no prefix, which is the convention the PETR and BEVFormer
configs use.
Under DDP the box count the loss normalises by is all-reduced across ranks, so each rank divides by the same number and the gradients agree. That reduction has to happen before any per-dataset split of the batch, because a split that differs between ranks would leave them reducing over a different number of groups and the job would hang instead of failing.
Classes
|
|
|