DETRSetLoss<T>

Models & Types · AiDotNet.ComputerVision.Detection.Losses

DETR-family set prediction loss with exact Hungarian assignment.

Inheritance: LossFunctionBase<T> → DETRSetLoss<T>

How It Works

Foreground queries are assigned with a weighted sum of a classification cost, center-format L1 distance and negative GIoU. The matched boxes receive L1 and GIoU losses normalized by the total foreground target count across the local batch. Every query receives classification supervision, including unmatched queries and empty images.

Three classification forms are supported (ClassificationLoss): DETR’s softmax cross-entropy with a down-weighted no-object class (Carion et al. 2020); the sigmoid focal loss of DINO (Zhang et al. 2022), normalized by the target count; and RT-DETR’s IoU-aware varifocal loss (Zhao et al. 2023; Zhang et al. 2021), whose matched class target is the IoU of the matched predicted box. Sigmoid heads are matched with the focal classification cost of Deformable DETR’s reference matcher.

Only the supplied final prediction heads are supervised; intermediate decoder, query-selection and denoising losses are not fabricated. More targets than queries in an image are rejected rather than silently dropped.

Constructors

Constructor Summary
DETRSetLoss(int numClasses, DetrSetLossOptions options) Creates a DETR-family objective with explicit classification form and weights.
DETRSetLoss(int numClasses, double classWeight, double boxL1Weight, double boxGIoUWeight) Creates a DETR objective with the standard final-head loss weights.

Properties

Property Summary
SetPredictionClassificationLoss ClassificationLoss { get; } The classification form this objective trains.

Methods

Method Summary
T CalculateLoss(Tensor<T> classLogits, Tensor<T> boxes, DetectionTrainingBatch<T> targets) Evaluates the actual class and normalized cxcywh heads against typed targets.
T CalculateLoss(Tensor<T> predicted, Tensor<T> targets) Evaluates structured predictions against -1-padded DETR targets.
T CalculateLoss(Vector<T> predicted, Vector<T> actual) Evaluates structured predictions against -1-padded DETR targets.
Tensor<T> ComputeTapeLoss(Tensor<T> classLogits, Tensor<T> boxes, DetectionTrainingBatch<T> targets) Builds differentiable final-head classification, L1 and GIoU losses after discrete assignment.
Tensor<T> ComputeTapeLoss(Tensor<T> classLogits, Tensor<T> boxes, DetectionTrainingBatch<T> targets, int[][] assignments) The set loss for a FIXED assignment: target j of image i is matched to query assignments[i][j], and every other query is background.
Tensor<T> ComputeTapeLoss(Tensor<T> predicted, Tensor<T> target)