RT-DETRv4: Painlessly Furthering Real-Time Object Detection with Vision Foundation Models
Copyright (c) 2025 The RT-DETRv4 Authors. All Rights Reserved.
---------------------------------------------------------------------------------
Modified from DEIM: DETR with Improved Matching for Fast Convergence
Copyright (c) 2024 The DEIM Authors. All Rights Reserved.
class RTv4Criterion(nn.Module)
This class computes the loss for RT-DETRv4.
| 名称 | 类型 | 默认值 |
|---|
matcher | — | — |
weight_dict | — | — |
losses | — | — |
alpha | — | 0.2 |
gamma | — | 2.0 |
num_classes | — | 80 |
reg_max | — | 32 |
boxes_weight_format | — | None |
share_matched_indices | — | False |
mal_alpha | — | None |
use_uni_set | — | True |
distill_adaptive_params | — | None |
dn_losses | — | None |
loss_distillation(self, outputs, targets, indices, num_boxes, **kwargs)
| 名称 | 类型 | 默认值 |
|---|
outputs | — | — |
targets | — | — |
indices | — | — |
num_boxes | — | — |
kwargs | — | — |
loss_labels_focal(self, outputs, targets, indices, num_boxes)
| 名称 | 类型 | 默认值 |
|---|
outputs | — | — |
targets | — | — |
indices | — | — |
num_boxes | — | — |
loss_labels_vfl(self, outputs, targets, indices, num_boxes, values=None)
| 名称 | 类型 | 默认值 |
|---|
outputs | — | — |
targets | — | — |
indices | — | — |
num_boxes | — | — |
values | — | None |
loss_labels_mal(self, outputs, targets, indices, num_boxes, values=None)
| 名称 | 类型 | 默认值 |
|---|
outputs | — | — |
targets | — | — |
indices | — | — |
num_boxes | — | — |
values | — | None |
loss_boxes(self, outputs, targets, indices, num_boxes, boxes_weight=None)
Compute the losses related to the bounding boxes, the L1 regression loss and the GIoU loss
targets dicts must contain the key "boxes" containing a tensor of dim [nb_target_boxes, 4]
The target boxes are expected in format (center_x, center_y, w, h), normalized by the image size.
| 名称 | 类型 | 默认值 |
|---|
outputs | — | — |
targets | — | — |
indices | — | — |
num_boxes | — | — |
boxes_weight | — | None |
loss_local(self, outputs, targets, indices, num_boxes, T=5)
Compute Fine-Grained Localization (FGL) Loss
and Decoupled Distillation Focal (DDF) Loss.
| 名称 | 类型 | 默认值 |
|---|
outputs | — | — |
targets | — | — |
indices | — | — |
num_boxes | — | — |
T | — | 5 |
get_loss(self, loss, outputs, targets, indices, num_boxes, **kwargs)
| 名称 | 类型 | 默认值 |
|---|
loss | — | — |
outputs | — | — |
targets | — | — |
indices | — | — |
num_boxes | — | — |
kwargs | — | — |
forward(self, outputs, targets, **kwargs)
This performs the loss computation.
Parameters:
outputs: dict of tensors, see the output specification of the model for the format
targets: list of dicts, such that len(targets) == batch_size.
The expected keys in each dict depends on the losses applied, see each loss' doc
| 名称 | 类型 | 默认值 |
|---|
outputs | — | — |
targets | — | — |
kwargs | — | — |
get_loss_meta_info(self, loss, outputs, targets, indices)
| 名称 | 类型 | 默认值 |
|---|
loss | — | — |
outputs | — | — |
targets | — | — |
indices | — | — |
get_cdn_matched_indices(dn_meta, targets)
get_cdn_matched_indices
| 名称 | 类型 | 默认值 |
|---|
dn_meta | — | — |
targets | — | — |
feature_loss_function(self, fea, target_fea)
unimodal_distribution_focal_loss(self, pred, label, weight_right, weight_left, weight=None, reduction='sum', avg_factor=None)
| 名称 | 类型 | 默认值 |
|---|
pred | — | — |
label | — | — |
weight_right | — | — |
weight_left | — | — |
weight | — | None |
reduction | — | 'sum' |
avg_factor | — | None |
get_gradual_steps(self, outputs)