Back to paper library
arXiv 2022CVPR 2023Object detectionPaper notes

H-DETR

The Rebellion of Silent Queries

Original paper

DETRs with Hybrid Matching

Paper authors

Ding Jia · Yuhui Yuan · Haodi He …

Show all 9 authors

Ding Jia · Yuhui Yuan · Haodi He · Xiaopei Wu · Haojun Yu · Weihong Lin · Lei Sun · Chao Zhang · Han Hu

Publication
CVPR 2023Conference
First submitted to arXiv
arXiv:2207.13080
Cite this paper · BibTeX

The citation identifies the linked source version. It cites the original paper and its authors.

@misc{objectdetectionhdetr2022,
  title = {{DETRs with Hybrid Matching}},
  author = {Ding Jia and Yuhui Yuan and Haodi He and Xiaopei Wu and Haojun Yu and Weihong Lin and Lei Sun and Chao Zhang and Han Hu},
  year = {2022},
  eprint = {2207.13080},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2207.13080}
}
On this page

In the world of DETR, most queries are assigned to classification and ordered to stay silent.

Even if they get close to the truth... sorry, there is only one truth; the rest do not count.

Problem Definition

Since DETR pioneered the introduction of Transformers into object detection, the DETR architecture quickly became a landmark standard in the vision field, as shown below:

Its core contribution lies in abandoning handcrafted components such as anchors, proposals, and NMS, reformulating the object detection problem as a "query-to-object" matching task.

This design not only simplifies the pipeline but also enhances the overall architecture's transferability and generalization, spawning a whole ecosystem widely applied in 2D detection, 3D perception, pose estimation, visual tracking, segmentation, and other tasks.

This development path also encouraged researchers to continuously optimize various modules: some redesigned the Transformer structure, such as Deformable-DETR introducing deformable attention to address small object detection and convergence speed; others explored more efficient query representations, such as DAB-DETR, while DN-DETR and DINO introduced denoising queries to improve matching stability.

However, regardless of architecture type, most learning mechanisms are still based on DETR’s foundational "one-to-one matching": each ground truth can only be assigned to a unique query, which is a key condition for removing NMS.

Yet, this one-to-one assignment strategy introduces significant bottlenecks during training.

On COCO, nearly 99% of images have fewer than 30 annotated boxes, while a Deformable-DETR configuration can generate 300 queries. Under one-to-one assignment, most unmatched queries receive background classification supervision but no positive box-regression supervision.

This means most queries receive very limited learning signals during training. Although they might still produce predictions during inference, their learning space during training is heavily constrained.

Moreover, this assignment limitation suppresses the model’s ability to explore potential positive samples.

Even if some queries align well spatially with an object, they are excluded from regression learning because that object is already "occupied" by other queries. This reduces training sample efficiency, limits queries’ spatial feature learning, and leads to slow training, poor positive sample fitting, and low resource utilization.

While existing improvements like DN-DETR or DINO-DETR attempt to supplement positive sample supervision by "adding noisy queries," their core aim is matching stability rather than training efficiency, often requiring extra noising schemes or query format adjustments and lacking generality for other tasks.

So, the question arises:

Can we, while preserving DETR’s matching advantages, unleash the potential of idle queries and expand positive sample supervision?


Solution

In DETR’s original design, each image generates a set of query vectors, which after decoder processing produce predicted boxes and classification probabilities. These predictions are matched one-to-one with ground truth, selecting the "best query describing each object," and the loss is computed accordingly.

H-DETR’s modification does not break this one-to-one mechanism but adds an auxiliary branch allowing more queries to participate in learning.

Specifically, the model trains two groups of queries simultaneously: one maintains the original one-to-one supervision logic; the other adopts a "one-to-many" supervision, where each ground truth can correspond to multiple queries. This way, those previously "wasted" queries can learn to fit positive samples by approaching ground truth boxes during training.

Main Branch: One-to-One Supervision

For the first query group Q={q1,q2,...,qn}Q = \{q_1, q_2, ..., q_n\}, the standard DETR training is applied:

  1. Queries pass through LL decoder layers, producing LL sets of predictions {P1,P2,...,PL}\{P^1, P^2, ..., P^L\}.
  2. Each layer’s predictions are matched to ground truth via Hungarian Matching, selecting the best correspondences.
  3. The loss function is:
Lone2one=∑l=1LLHungarian(Pl,G)\mathcal{L}_{\text{one2one}} = \sum_{l=1}^{L} \mathcal{L}_{\text{Hungarian}}(P^l, G)

where LHungarian\mathcal{L}_{\text{Hungarian}} is the standard DETR loss, including:

  • Classification loss
  • Bounding box L1L_1 regression loss
  • Generalized IoU loss

This branch preserves the core of DETR’s streamlined inference.


Auxiliary Branch: One-to-Many Supervision

The other branch creates more "opportunities to approach true objects" through:

  1. Generating another query set Qb={qb1,qb2,...,qbT}Q_b = \{q_b^1, q_b^2, ..., q_b^T\} for one-to-many learning.
  2. Repeating ground truth G={g1,...,gm}G = \{g_1, ..., g_m\} KK times to obtain an augmented target set:
Gb={G,G,...,G}(K times)G_b = \{G, G, ..., G\} \quad (K \text{ times})
  1. For each layer’s predictions {Pb1,...,PbL}\{P_b^1, ..., P_b^L\}, perform matching with GbG_b, calculating the loss:
Lone2many=∑l=1LLHungarian(Pbl,Gb)\mathcal{L}_{\text{one2many}} = \sum_{l=1}^{L} \mathcal{L}_{\text{Hungarian}}(P_b^l, G_b)

This branch is used only during training. In the main COCO setting, there are 300 main queries and 1,500 auxiliary queries, and the target set is repeated K=6K=6 times. Each object can therefore provide six additional positive matches beside its one main-branch match; this does not make all 1,800 queries positive.


Total Loss and Implementation Details

The overall training loss is:

L=Lone2one+λ⋅Lone2many\mathcal{L} = \mathcal{L}_{\text{one2one}} + \lambda \cdot \mathcal{L}_{\text{one2many}}

where λ\lambda balances the importance of the two branches.

To enable parallel processing of the two query groups within the computation graph, H-DETR employs masked multi-head self-attention to prevent cross-branch query interaction. The auxiliary queries and matching still add training cost: Table 6 reports 80 minutes for optimized Hybrid Branch training versus 75 minutes for a 1,800-query one-to-one baseline and 65 minutes for a 300-query baseline.

Finally, during inference, H-DETR completely ignores the one-to-many branch and only retains the main branch’s outputs. Thus, H-DETR maintains DETR’s original simplicity: no NMS required, detection completed solely via query outputs.

More Forms of Hybrid Supervision

Besides the "dual-branch" training structure, H-DETR proposes two further variants that implement dynamic switching of supervision strategies along the "temporal" and "layer" dimensions.

  • Hybrid Epoch Scheme: Implicit Stage Switching

    This variant uses only one query set Qe={q1,...,qM}Q_e = \{q_1, ..., q_M\} but changes matching strategy according to training "stage."

    • Early phase (the first ρ\rho fraction of epochs): use one-to-many matching by repeating each ground truth K~\widetilde K times to form an augmented annotation set GeG_e, matched against predictions {Pe1,...,PeL}\{P_e^1, ..., P_e^L\}. The loss is:
    Lone2many=∑l=1LLHungarian(Pel,Ge)\mathcal{L}_{\text{one2many}} = \sum_{l=1}^{L} \mathcal{L}_{\text{Hungarian}}(P_e^l, G_e)
    • Late phase (remaining 1−ρ1 - \rho epochs): switch back to one-to-one supervision with original ground truth GG, loss:
    Lone2one=∑l=1LLHungarian(Pel,G)\mathcal{L}_{\text{one2one}} = \sum_{l=1}^{L} \mathcal{L}_{\text{Hungarian}}(P_e^l, G)

    The idea is to use abundant supervision early to help queries approach ground truth quickly, then converge to the exclusivity required by one-to-one matching once the model learns basic localization.

    During inference, only the one-to-one query outputs remain, preserving DETR’s simplicity.


  • Hybrid Layer Scheme: Supervision Splitting Within Layers

    This variant also uses a single query set Q={q1,...,qN}Q = \{q_1, ..., q_N\}, but switches supervision based on the decoder layer number.

    • First L1L_1 decoder layers: apply one-to-many supervision, matching predictions {P1,...,PL1}\{P^1, ..., P^{L_1}\} to the repeated target set G‾\overline G:
    Lone2many=∑l=1L1LHungarian(Pl,G‾)\mathcal{L}_{\text{one2many}} = \sum_{l=1}^{L_1} \mathcal{L}_{\text{Hungarian}}(P^l, \overline G)
    • Last L2L_2 decoder layers: revert to one-to-one supervision with loss:
    Lone2one=∑l=L1+1L1+L2LHungarian(Pl,G)\mathcal{L}_{\text{one2one}} = \sum_{l=L_1+1}^{L_1+L_2} \mathcal{L}_{\text{Hungarian}}(P^l, G)

    This design intuitively "warms up" queries with dense supervision early, then strengthens independent prediction and inference consistency later.

    The total training loss is the sum:

    L=Lone2many+Lone2one\mathcal{L} = \mathcal{L}_{\text{one2many}} + \mathcal{L}_{\text{one2one}}

    Allowing the model to balance supervision density and inference consistency along the decoder depth.


Compared with the original dual-branch architecture, these two strategies need no separate auxiliary query branch, yet still provide additional positive sample supervision. In the reported setting each uses a single set of 1,800 queries: Hybrid Epoch uses K~=10\widetilde K=10 and ρ=2/3\rho=2/3, while Hybrid Layer uses K‾=10\overline K=10, L1=4L_1=4, and L2=2L_2=2. Unlike Hybrid Branch, both keep 1,800 queries at inference in Table 6, so their deployment cost must be compared separately. H-DETR’s core idea remains to give queries more training information without losing the one-to-one objective at inference.

Discussion

The authors first focus on examining whether H-DETR can effectively improve the detection capability of the existing DETR architecture.

Using the COCO and LVIS datasets as benchmarks, they evaluate the performance of the improved H-Deformable-DETR model across different backbones and training durations.

COCO Benchmark

According to the experimental results, H-Deformable-DETR demonstrates consistent performance gains on the COCO validation set across different backbone scales—including ResNet-50, Swin-T, and Swin-L—and training schedules of 12 or 36 epochs.

For example, with Swin-T:

  • At 12 training epochs, the AP improves from 49.3% to 50.6%.
  • At 36 training epochs, AP increases from 51.8% to 53.2%.

In the three backbone and 12/36-epoch configurations shown in Table 1, hybrid matching improves COCO AP over each matching baseline while Hybrid Branch still uses the one-to-one branch at inference.

LVIS Benchmark

Next, the LVIS results are examined. LVIS is a dataset with thousands of categories exhibiting a highly long-tailed distribution, used to validate H-DETR’s generalization ability on large-scale and low-frequency classes.

On LVIS v1.0, R50 at 24 epochs rises from 32.2 to 33.5 AP (+1.3 percentage points); Swin-L at 48 epochs rises from 47.0 to 47.9 (+0.9 percentage points). The table breaks AP down by object size, not by rare/common/frequent categories.

SOTA Benchmark

The authors also perform a system-level comparison of H-Deformable-DETR against recent representative state-of-the-art (SOTA) methods, shown in the table above.

The table reports single-scale inference, but backbones, input sizes, and schedules vary across systems. DINO-DETR and H-Deformable-DETR both use Swin-L, 1333×800 input, and 36 epochs in their compared rows.

Overall, H-Deformable-DETR achieves 59.4% AP on the COCO validation set, surpassing several strong baselines including DINO-DETR.

The 59.4% AP system also includes other enhancement techniques from DINO, so its gap over DINO-DETR cannot all be credited to hybrid matching. The more isolated hybrid-matching gain is in the matched Deformable-DETR rows above; the one-to-one inference branch still needs no NMS.

Ablation Study

Let us review the performance of different hybrid architectures; readers can refer to the original paper for further experiments.

In designing this experiment, the authors made two key settings to ensure fairness:

  1. All three strategies provide six times as many additional positive-assignment opportunities as the one-to-one baseline, or seven times the total when the original positive match is counted.
  2. All three strategies use 1,800 queries during training; Hybrid Branch keeps only 300 of them at inference.

Additionally, the table annotates different data sources as follows:

  • † symbol: The method uses 1800 queries in both training and inference.
  • ♮ symbol: The 80-minute training time is measured after combining the two branches' matching-cost and loss computations. The paper did not implement GPU Hungarian matching.

Key observations include:

  • The Hybrid Branch strategy achieves the most balanced overall performance:

    • At 36 epochs it reaches 48.0 AP, tied with Hybrid Layer; at 24 epochs Hybrid Layer reaches 47.9 versus Branch's 47.6.
    • Optimized training averages 80 minutes: about 7% more than the 1,800-query baseline's 75 minutes and about 23% more than the 300-query baseline's 65 minutes.
    • Its inference uses 268 GFLOPs and runs at 6.7 FPS. The two 1,800-query variants use 282 GFLOPs and run at 6.3 FPS in the same V100 test. This table does not report memory.
  • The Hybrid Epoch strategy averages 95 minutes of training and reaches 47.9 AP at 36 epochs. The table does not isolate how much time the matching switch itself adds.

  • The Hybrid Layer strategy also reaches 48.0 AP at 36 epochs, averages 100 minutes of training, and runs at 6.3 FPS at inference. It cannot be described as uniformly less accurate than Branch.

Conclusion

DETR’s key innovation is reframing object detection as a query matching problem, simplifying inference but causing low training efficiency.

H-DETR addresses this by introducing one-to-many supervision on the training side while retaining the one-to-one branch's inference behavior. For Hybrid Branch, the engineering appeal is no auxiliary inference branch, a measurable training cost, and a matching change that can be added to DETR variants. The reported results on several tasks support this direction; applying it to another query-based system still calls for matching its own training and inference costs.