TwoStageDetectionLoss<T>

Models & Types · AiDotNet.ComputerVision.Detection.Losses

Region proposal and region-of-interest losses for Faster R-CNN and Cascade R-CNN.

For Beginners

the first loss teaches the detector where objects might be; the second teaches it what each proposed region contains and how to tighten its box.

How It Works

Region proposal network (Ren et al. 2015, Eq. 1): anchors are labeled by IoU with the objects (positive above the positive threshold or as an object’s best anchor, negative below the negative threshold, otherwise ignored), a balanced sample is drawn, the two-way object/background cross-entropy is averaged over the sample, and the smooth-L1 regression of positive anchors is weighted by lambda and divided by the number of anchor locations.

Region-of-interest head (Girshick 2015, Eq. 1-3): proposals with IoU of at least the stage threshold take their object’s class, proposals with IoU in [low, threshold) are background (class 0), a sample with a bounded foreground fraction is drawn, cross-entropy is averaged over it, and foreground boxes regress the deltas of their own class with smooth-L1, also averaged over the sample. Cascade R-CNN applies this per stage with rising thresholds to the boxes that stage actually receives (Cai and Vasconcelos 2018, Eq. 8).

Box deltas use the R-CNN parameterization the detectors here decode: t_x = (g_x - p_x) / p_w, t_y = (g_y - p_y) / p_h, t_w = log(g_w / p_w), t_h = log(g_h / p_h), with center coordinates. Assignment and sampling use detached host values; the losses are built from engine operations on the live heads.

Constructors

Constructor Summary
TwoStageDetectionLoss(int foregroundClasses, int stages, TwoStageDetectionLossOptions options) Creates the objective for a detector with the given foreground classes and detection stages.

Methods

Method Summary
Tensor<T> ComputeProposalLoss(Tensor<T> objectness, Tensor<T> deltas, IReadOnlyList<BoundingBox<T>> anchors, IReadOnlyList<double[]> gold, int anchorsPerLocation, Random random) Builds the region proposal loss for one image.
Tensor<T> ComputeStageLoss(Tensor<T> classLogits, Tensor<T> boxDeltas, Tensor<T> proposals, IReadOnlyList<double[]> gold, IReadOnlyList<int> goldClasses, int stage, Random random) Builds one detection stage’s region-of-interest loss for one image.