
DETR Hungarian matching and set-prediction loss (Geron Ch 16, grdetr)
Source:R/geron_ml_native.R
morie_geron_detr_hungarian_matching.RdCost C(i,j) = -p_i(c_j) + lam_bbox ||b_i - b_j||_1 - lam_giou GIoU,
minimised exactly by the Jonker-Volgenant shortest-augmenting-path
assignment. matching pairs are 0-based (pred, gt), as in Python.
Usage
morie_geron_detr_hungarian_matching(
pred_boxes,
pred_classes,
gt_boxes,
gt_classes,
lam_bbox = 5,
lam_giou = 2,
box_format = "xyxy",
no_object_class = NULL,
eos_coef = 0.1,
class_is_logits = TRUE
)Arguments
- pred_boxes, gt_boxes
Box matrices (N, 4) / (M, 4).
- pred_classes
Logits or probabilities (N, C).
- gt_classes
0-based ground-truth classes.
- lam_bbox, lam_giou
Non-negative cost weights.
- box_format
"xyxy" or "cxcywh".
- no_object_class
Optional 0-based no-object index.
- eos_coef
No-object down-weight.
- class_is_logits
Softmax needed.
Value
List with matching, cost_matrix, total_cost, loss,
loss_class, loss_bbox, loss_giou, loss_no_object,
matched_giou, matched_l1, unmatched_predictions.
Examples
pb <- matrix(c(0, 0, 1, 1, 10, 10, 11, 11, 0, 0, 2, 2), 3, 4,
byrow = TRUE)
pc <- matrix(c(10, 0, 0, 10, 1, 1), 3, 2, byrow = TRUE)
gb <- matrix(c(0, 0, 1, 1, 10, 10, 11, 11), 2, 4, byrow = TRUE)
morie_geron_detr_hungarian_matching(pb, pc, gb, c(0, 1), no_object_class = 1)
#> $matching
#> $matching[[1]]
#> [1] 0 0
#>
#> $matching[[2]]
#> [1] 1 1
#>
#>
#> $cost_matrix
#> [,1] [,2]
#> [1,] -2.999955 201.966897
#> [2,] 201.966897 -2.999955
#> [3,] 9.000000 191.417355
#>
#> $total_cost
#> [1] -5.999909
#>
#> $loss
#> [1] 0.06940552
#>
#> $loss_class
#> [1] 9.07978e-05
#>
#> $loss_bbox
#> [1] 0
#>
#> $loss_giou
#> [1] 0
#>
#> $loss_no_object
#> [1] 0.06931472
#>
#> $matched_giou
#> [1] 1 1
#>
#> $matched_l1
#> [1] 0 0
#>
#> $unmatched_predictions
#> [1] 2
#>
#> $estimate
#> [1] 0.06940552
#>
#> $n
#> [1] 2
#>
#> $method
#> [1] "DETR Hungarian matching and set-prediction loss"
#>