pub struct Yolo26Loss {
pub grid: AnchorGrid,
pub assigner: TaskAlignedAssigner,
pub assigner_o2o: TaskAlignedAssigner,
pub nc: usize,
pub cap: Capability,
/* private fields */
}Expand description
CUDA training loss for YOLO26: computes d_boxes and d_scores.
Fields§
§grid: AnchorGridAnchor grid (points + strides) for the model’s input resolution.
assigner: TaskAlignedAssignerOne2many assigner (top_k=10) — used during compute_grads and the o2m head of compute_grads_dual.
assigner_o2o: TaskAlignedAssignerOne2one assigner (top_k=1) — used for the o2o head of compute_grads_dual.
nc: usizeNumber of detection classes.
cap: CapabilityTarget GPU compute capability for compiled kernels.
Implementations§
Source§impl Yolo26Loss
impl Yolo26Loss
Sourcepub fn new(img_h: usize, img_w: usize, nc: usize, cap: Capability) -> Self
pub fn new(img_h: usize, img_w: usize, nc: usize, cap: Capability) -> Self
Builds the loss state for a model trained at img_h × img_w with nc classes.
Sourcepub fn compute_grads(
&self,
device: &CudaDevice<'_>,
boxes: &[f32],
scores: &[f32],
gt_boxes_b: &[Vec<[f32; 4]>],
gt_cls_b: &[Vec<usize>],
) -> Result<(Vec<f32>, Vec<f32>)>
pub fn compute_grads( &self, device: &CudaDevice<'_>, boxes: &[f32], scores: &[f32], gt_boxes_b: &[Vec<[f32; 4]>], gt_cls_b: &[Vec<usize>], ) -> Result<(Vec<f32>, Vec<f32>)>
Compute loss gradients for one batch (one2many head only).
boxes – raw LTRB predictions [B, 4*A] (host f32, channels-first)
scores – class logits [B, nc*A] (host f32, channels-first)
Returns (d_boxes [B,4*A], d_scores [B,nc*A]) as host f32.
Sourcepub fn compute_grads_dual(
&self,
device: &CudaDevice<'_>,
boxes_o2m: &[f32],
scores_o2m: &[f32],
boxes_o2o: &[f32],
scores_o2o: &[f32],
gt_boxes_b: &[Vec<[f32; 4]>],
gt_cls_b: &[Vec<usize>],
w_o2m: f32,
w_o2o: f32,
) -> Result<(Vec<f32>, Vec<f32>, Vec<f32>, Vec<f32>)>
pub fn compute_grads_dual( &self, device: &CudaDevice<'_>, boxes_o2m: &[f32], scores_o2m: &[f32], boxes_o2o: &[f32], scores_o2o: &[f32], gt_boxes_b: &[Vec<[f32; 4]>], gt_cls_b: &[Vec<usize>], w_o2m: f32, w_o2o: f32, ) -> Result<(Vec<f32>, Vec<f32>, Vec<f32>, Vec<f32>)>
Compute dual-head loss gradients for consistent assignment training.
Runs TAL assignment independently for both heads using their respective
assigners (top_k=10 for o2m, top_k=1 for o2o), then scales the resulting
gradients by w_o2m and w_o2o respectively.
§Loss weight schedule (ultralytics-style)
w_o2m = 1.0(constant throughout training)w_o2o = step / total_steps(ramps 0→1 linearly; caller controls the schedule)
Returns (d_boxes_o2m, d_scores_o2m, d_boxes_o2o, d_scores_o2o).