has_triton_matching_cost() -> booldetrium.ops.matching_cost
Decoupled, modular, Triton-fused DETR matching cost computation with PyTorch fallback. Separates matching cost construction (`[H_tot * B, N, M]`) from the exact GPU Hungarian solver (`batched_hungarian_cuda`), enabling effortless customization of classification, box-regression, IoU-family, or arbitrary user-defined cost terms without touching CUDA Hungarian solver internals, while avoiding PyTorch eager's multi-kernel HBM traffic.
triton_detr_cost_matrix(boxes_all: torch.Tensor, logits_cls: Optional[torch.Tensor], logits_enc: Optional[torch.Tensor], tgt_boxes: torch.Tensor, tgt_labels: torch.Tensor, gt_mask: torch.Tensor, *, cls_cost_type: str='focal', bbox_cost_type: str='l1', iou_cost_type: str='giou', alpha: float=0.25, gamma: float=2.0, w_bbox: float=5.0, w_cls: float=2.0, w_giou: float=2.0, smooth_l1_beta: float=1.0, enc_class_agnostic: bool=False, zero_masked: bool=False) -> torch.TensorCompute DETR matching cost matrix `C` of shape `[H_tot * B, N, M]` in a single Triton kernel. Decoupled from the Hungarian solver: outputs a standard contiguous `[P, N, M]` float32 tensor directly consumable by `batched_hungarian_cuda(C, gt_mask_flat)` or any custom post-processing.
| 名称 | 类型 | 默认值 |
|---|---|---|
boxes_all | torch.Tensor | — |
logits_cls | Optional[torch.Tensor] | — |
logits_enc | Optional[torch.Tensor] | — |
tgt_boxes | torch.Tensor | — |
tgt_labels | torch.Tensor | — |
gt_mask | torch.Tensor | — |
cls_cost_type | str | 'focal' |
bbox_cost_type | str | 'l1' |
iou_cost_type | str | 'giou' |
alpha | float | 0.25 |
gamma | float | 2.0 |
w_bbox | float | 5.0 |
w_cls | float | 2.0 |
w_giou | float | 2.0 |
smooth_l1_beta | float | 1.0 |
enc_class_agnostic | bool | False |
zero_masked | bool | False |
pytorch_detr_cost_matrix(boxes_all: torch.Tensor, logits_cls: Optional[torch.Tensor], logits_enc: Optional[torch.Tensor], tgt_boxes: torch.Tensor, tgt_labels: torch.Tensor, gt_mask: torch.Tensor, *, cls_cost_type: str='focal', bbox_cost_type: str='l1', iou_cost_type: str='giou', alpha: float=0.25, gamma: float=2.0, w_bbox: float=5.0, w_cls: float=2.0, w_giou: float=2.0, smooth_l1_beta: float=1.0, enc_class_agnostic: bool=False, zero_masked: bool=False) -> torch.TensorPure PyTorch reference implementation matching `triton_detr_cost_matrix` exactly. Used automatically on CPU, when Triton is unavailable, or when `cost_mode='eager'`.
| 名称 | 类型 | 默认值 |
|---|---|---|
boxes_all | torch.Tensor | — |
logits_cls | Optional[torch.Tensor] | — |
logits_enc | Optional[torch.Tensor] | — |
tgt_boxes | torch.Tensor | — |
tgt_labels | torch.Tensor | — |
gt_mask | torch.Tensor | — |
cls_cost_type | str | 'focal' |
bbox_cost_type | str | 'l1' |
iou_cost_type | str | 'giou' |
alpha | float | 0.25 |
gamma | float | 2.0 |
w_bbox | float | 5.0 |
w_cls | float | 2.0 |
w_giou | float | 2.0 |
smooth_l1_beta | float | 1.0 |
enc_class_agnostic | bool | False |
zero_masked | bool | False |
compute_detr_cost_matrix(boxes_all: torch.Tensor, logits_cls: Optional[torch.Tensor], logits_enc: Optional[torch.Tensor], tgt_boxes: torch.Tensor, tgt_labels: torch.Tensor, gt_mask: torch.Tensor, *, cls_cost_type: str='focal', bbox_cost_type: str='l1', iou_cost_type: str='giou', alpha: float=0.25, gamma: float=2.0, w_bbox: float=5.0, w_cls: float=2.0, w_giou: float=2.0, smooth_l1_beta: float=1.0, enc_class_agnostic: bool=False, zero_masked: bool=False, use_triton: bool=True, extra_cost_fn: Optional[Callable]=None) -> torch.TensorUnified decoupled DETR cost-matrix builder (`[H_tot * B, N, M]`). Dispatches to the single-kernel Triton implementation on CUDA when available and `use_triton=True`, falling back transparently to exact PyTorch otherwise. If `extra_cost_fn` is provided, it is invoked with `(boxes_all, logits_cls, logits_enc, tgt_boxes, tgt_labels, gt_mask, enc_class_agnostic)` and its `[P, N, M]` result is added to the returned cost matrix.
| 名称 | 类型 | 默认值 |
|---|---|---|
boxes_all | torch.Tensor | — |
logits_cls | Optional[torch.Tensor] | — |
logits_enc | Optional[torch.Tensor] | — |
tgt_boxes | torch.Tensor | — |
tgt_labels | torch.Tensor | — |
gt_mask | torch.Tensor | — |
cls_cost_type | str | 'focal' |
bbox_cost_type | str | 'l1' |
iou_cost_type | str | 'giou' |
alpha | float | 0.25 |
gamma | float | 2.0 |
w_bbox | float | 5.0 |
w_cls | float | 2.0 |
w_giou | float | 2.0 |
smooth_l1_beta | float | 1.0 |
enc_class_agnostic | bool | False |
zero_masked | bool | False |
use_triton | bool | True |
extra_cost_fn | Optional[Callable] | None |