---
title: Masked Duplicate Suppressor in DETR
url: https://www.emergentmind.com/topics/masked-duplicate-suppressor-mds
type: topic
---

# Masked Duplicate Suppressor in DETR

Searching arXiv for the target paper and closely related DETR one-to-many variants to ground citations.
Masked Duplicate Suppressor (MDS) is an asymmetric, confidence-aware self-attention module introduced in MDS-DETR to convert dense one-to-many query predictions into duplicate-free detections within a single decoder layer. It is designed for DETR-style object detection, where conventional one-to-one Hungarian matching provides end-to-end set prediction but is associated with slow convergence and limited recall because at most one query is matched to each ground-truth object. MDS addresses the complementary requirement—retaining the optimization advantages of one-to-many supervision while preserving duplicate-free end-to-end inference—by imposing confidence-based causal masking, appending true positive tokens, and using a symmetric relative position bias in the final one-to-one layer of the decoder [2605.23507].

## 1. DETR background and the problem MDS targets

Standard DETR and Deformable-DETR use a set prediction formulation with one-to-one Hungarian matching between predicted queries and ground-truth objects. Given object queries
\[
Q^{(0)} = \{\mathbf{q}^{(0)}_1, \dots, \mathbf{q}^{(0)}_n\},
\]
the decoder produces refined queries \(Q^{(L)}\), and each query \(\mathbf{q}^{(l)}_i\) predicts class logits \(\mathbf{s}^{(l)}_i \in \mathbb{R}^C\) and a box \(\mathbf{b}^{(l)}_i \in \mathbb{R}^4\). The one-to-one objective can be written as
\[
\mathcal{L}_{\mathrm{one2one}} = \sum_{i=1}^{n} \left[
\mathcal{L}_{\mathrm{cls}}(\mathbf{s}_i,\bar{\mathbf{s}}_{\sigma(i)})
+
\mathcal{L}_{\mathrm{bbox}}(\mathbf{b}_i,\bar{\mathbf{b}}_{\sigma(i)})
\right],
\]
where \(\sigma(\cdot)\) denotes the Hungarian assignment.

This formulation yields duplicate-free predictions by construction, because only one query may match each ground truth. Its limitations are equally direct: few positive queries, slow convergence, and weaker recall. Prior DETR variants therefore introduced one-to-many supervision, allowing each ground-truth object to match multiple queries. The paper situates Hybrid-DETR, MS-DETR, DAC-DETR, Rank-DETR, Relation-DETR, and MR.DETR in this lineage, noting that they generally implement one-to-many matching through auxiliary decoders or auxiliary branches. These approaches improve optimization but increase training cost, add extra queries, and rely on decoder components that are discarded at inference [2605.23507].

MDS is formulated as a response to a specific architectural question: whether one-to-many benefits can be obtained inside a single decoder, without auxiliary branches, while still ending with duplicate-free, fully end-to-end predictions.

## 2. Placement of MDS within MDS-DETR

MDS is not a standalone detector; it is the defining module of the final decoder layer in MDS-DETR. The decoder is reorganized into two parts. Early layers are supervised with one-to-many matching, while the last layer is supervised with one-to-one matching. In the six-layer configuration described in the paper, layers 1–5 are standard Deformable-DETR-style decoder layers with one-to-many supervision, and layer 6 is a special one-to-one layer containing MDS followed by an FFN [2605.23507].

A central design decision is that the final one-to-one layer removes cross-attention. Its role is therefore not additional image-conditioned box refinement, but selection among the candidate queries produced by the one-to-many layers. The early layers act as dense candidate generators; the last layer uses MDS to identify true positives and suppress duplicates. The paper explicitly characterizes this as an internal, learned analog of NMS.

Relative to Deformable-DETR++, the architecture retains the same number of queries as the baseline—300 or 900 depending on the setting—and introduces no auxiliary decoders, no hybrid branches, and no extra decoder weights. The early decoder layers use the reversed order of cross-attention and self-attention following MS-DETR, which the paper reports as giving \(+0.1\) mAP. The final layer contains only masked self-attention and an FFN, with no cross-attention [2605.23507].

This organization is significant because it locates duplicate suppression inside the main prediction path rather than in a discarded auxiliary branch or in post-hoc NMS. The same decoder, including MDS, is used during both training and inference, and no NMS is applied at inference.

## 3. Attention asymmetry, confidence-based causal masking, and true positive tokens

The core technical claim of MDS is that duplicate suppression requires asymmetry. Standard self-attention in DETR is permutation-equivariant; if two queries are identical, symmetric self-attention produces identical outputs, so the duplicates remain duplicates. MDS injects asymmetry by sorting queries according to confidence and enforcing a causal direction in confidence rank [2605.23507].

Let the inputs to the final layer be queries \(Q^{(l-1)}\), class scores \(S^{(l-1)}\), and boxes \(B^{(l-1)}\). Query confidence is defined as
\[
S^{(l-1)}_{\text{max},i} = \max_c [\mathbf{s}^{(l-1)}_i]_c.
\]
Queries are sorted in descending order of \(S^{(l-1)}_{\text{max},i}\). On this sorted sequence, MDS applies the causal mask
\[
\hat{M}_{ij} =
\begin{cases}
1, & \text{if } i > j, \\
0, & \text{otherwise}.
\end{cases}
\]
Thus a lower-confidence query can attend only to higher-confidence queries. The diagonal is also masked, so self-attention to the same query is disallowed. The paper’s ablation reports that allowing the diagonal to remain unmasked drops mAP by \(1.7\), indicating that strict masking is critical [2605.23507].

The intended behavior is explicit. If several one-to-many queries correspond to the same object, the highest-confidence one is likely to be the true positive, while the others are duplicates. Since lower-confidence duplicates can attend upward in confidence rank, they are updated toward suppression. Conversely, a higher-confidence query is protected from being influenced by lower-confidence duplicates.

A complication arises for a genuine true positive that has no same-context higher-confidence neighbor. Its causal attention window would otherwise contain only unrelated queries. To address this, MDS appends \(n_t\) learned true positive tokens to the key/value set. These are always visible to all queries and function as attention sinks. The paper reports that true positive queries tend to attend to these tokens, while lower-confidence similar boxes attend to higher-confidence queries and are suppressed. The default choice is \(n_t = 10\); an ablation shows that \(5\) or \(15\) also work well, whereas \(1\) token underperforms due to insufficient expressivity [2605.23507].

The paper also incorporates geometry through a relative position bias. The relative box encoding is
\[
\mathbf{e}_{ij}= \left[
\log\left(\frac{|\Delta x|}{w_i}+1\right),
\log\left(\frac{|\Delta y|}{h_i}+1\right),
\log\left(\frac{w_i}{w_j}\right),
\log\left(\frac{h_i}{h_j}\right)
\right].
\]
Because this encoding is non-commutative, the authors propose the symmetric bias
\[
R_{ij} =
\frac{1}{2}
\left[
\mathrm{MLP}\big(\mathrm{SinEnc}(\mathbf{e}_{ij})\big)
+
\mathrm{MLP}\big(\mathrm{SinEnc}(\mathbf{e}_{ji})\big)
\right],
\]
which ensures \(R_{ij}=R_{ji}\). The paper states that the asymmetric scale terms are harmful, especially for small objects, and that the symmetric formulation improves suppression behavior. It also notes that \(R_{ij}\) is not clamped with ReLU, so it may be negative and can therefore down-weight distant pairs [2605.23507].

## 4. Supervision, matching, losses, and implementation details

The one-to-many layers in MDS-DETR use the DETA-style matcher. For a prediction \((\mathbf{s}_i,\mathbf{b}_i)\) and ground truth \((\bar{\mathbf{s}}_j,\bar{\mathbf{b}}_j)\), the matching score is
\[
\mathrm{MatchScore}_{ij}
=
\alpha \cdot \mathbf{s}_i^\top \bar{\mathbf{s}}_j
+
(1-\alpha)\cdot \mathrm{IoU}(\mathbf{b}_i,\bar{\mathbf{b}}_j).
\]
For each ground truth, the top-\(K\) queries are selected by \(\mathrm{MatchScore}_{ij}\), and predictions below threshold \(\tau\) are discarded by swipe-out. The reported hyperparameters are \(K=6\), \(\tau=0.4\), and \(\alpha=0.3\), following DETA, MS-DETR, and MR.DETR configurations [2605.23507].

Losses consist of Varifocal loss for classification, with \(\alpha=0.75\) and \(\gamma=2\), together with \(\mathcal{L}_{gIoU}\) and \(\mathcal{L}_{l1}\) for box regression. The one-to-one supervision applied to the final MDS layer and two-stage encoder proposals uses the ratio
\[
\mathcal{L}_{cls} : \mathcal{L}_{gIoU} : \mathcal{L}_{l1} = 1 : 5 : 2,
\]
whereas one-to-many supervision on earlier layers uses
\[
\mathcal{L}_{cls} : \mathcal{L}_{gIoU} : \mathcal{L}_{l1} = 0.5 : 5 : 2.
\]
The classification term is therefore intentionally down-weighted in the one-to-many layers so that training remains centered on one-to-one predictions while the earlier layers primarily provide box coverage [2605.23507].

The implementation base is Deformable-DETR++ in its two-stage variant. Main experiments use an ImageNet-pretrained ResNet-50 backbone, with additional experiments on Swin-L. The training setup uses COCO 2017, AdamW, learning rate \(2\times 10^{-4}\), weight decay \(1\times 10^{-4}\), and batch size 16 on \(8\times\) RTX 4090. In the 12-epoch schedule, the learning rate is decayed by \(0.1\) at epoch 11; in the 24-epoch schedule, it is decayed at epoch 20 [2605.23507].

The paper also reports several implementation ablations. Relative position bias alone yields \(49.8\) mAP, outperforming absolute positional embeddings alone (\(49.4\)) and the combination of both (\(49.7\)). Removing dropout improves performance from \(49.0\) to \(49.8\) mAP. Look Forward Twice has negligible effect. Mixed Query Selection, which often helps DETR, reduces performance to \(49.3\) mAP; the authors hypothesize that its static rank-like embeddings conflict with MDS’s dynamic confidence-based ranking [2605.23507].

## 5. Empirical behavior, efficiency, and interpretability

Under a 12-epoch training schedule on MS COCO with a ResNet-50 backbone, MDS-DETR achieves a \(+2.8\) mAP improvement over Deformable-DETR with only a \(5\%\) increase in training time, and outperforms MR.DETR by \(+0.3\) mAP while being \(20\%\) faster in training [2605.23507]. In the paper’s ResNet-50, 300-query comparison, Deformable-DETR++ attains \(47.0\) mAP, Hybrid-DETR \(48.7\), MS-DETR \(48.8\), MR.DETR \(49.5\), and MDS-DETR \(49.8\). In the 900-query, 12-epoch setting, MDS-DETR reaches \(51.1\) mAP, exceeding MR.DETR at \(50.7\), DINO at \(49.9\), and MS-DETR at \(50.0\), while Hybrid-MDS-DETR reaches \(51.2\). In the 24-epoch, 900-query setting, MDS-DETR achieves \(52.3\) mAP, outperforming MR.DETR (\(51.4\)) and Relation-DINO (\(52.1\)) [2605.23507].

The reported training-cost comparison with ResNet-50 and 300 queries shows \(7534\) MB memory and \(40\) min/epoch for Deformable-DETR++, versus \(8252\) MB and \(42\) min/epoch for MDS-DETR. Hybrid-DETR uses \(11200\) MB and \(57\) min/epoch; MS-DETR uses \(8326\) MB and \(49\) min/epoch; MR.DETR uses \(8920\) MB and \(53\) min/epoch. The paper interprets the additional cost of MDS-DETR as arising from MDS computations and extra supervision rather than from extra decoder stacks [2605.23507].

Qualitative analysis is presented as an argument for interpretability. Attention maps for the top 20 one-to-many queries plus 10 true positive tokens show that true positive queries attend predominantly to true positive tokens, whereas lower-confidence queries with similar boxes focus on higher-confidence queries and are suppressed. A further plot of learned relative position bias against IoU indicates that the bias increases with IoU, so overlapping boxes receive stronger attention; different heads learn different slopes and patterns, which the paper describes as different suppression strategies [2605.23507].

Layer-wise NMS ablations reinforce the same point. Raw outputs from one-to-many layers 1–5 have low mAP without NMS, approximately \(11\)–\(15\), but rise to approximately \(47.5\)–\(49.7\) with NMS. The final one-to-one layer with MDS reaches \(49.8\) without NMS, and NMS slightly reduces this to \(49.6\). This indicates that the last layer is already duplicate-free and that external NMS is unnecessary for final predictions [2605.23507].

## 6. Relation to prior DETR variants, common misconceptions, and stated limitations

MDS is closely related to the one-to-many DETR literature, but its mechanism differs from prior variants in where duplicate suppression occurs. MS-DETR uses one-to-many supervision throughout the decoder without a dedicated duplicate suppressor. MR.DETR uses one main decoder and two auxiliary decoders, together with an instruction token controlling one-to-many versus one-to-one behavior. Relation-DETR and Relation-DINO encode pairwise IoU and relative rank into attention weights but still rely on hybrid branches and auxiliary decoders. By contrast, MDS-DETR keeps one decoder and places suppression directly inside the final one-to-one layer [2605.23507].

A common misconception is to treat MDS as equivalent to post-hoc NMS. The paper argues against that equivalence on three grounds. First, MDS is integrated into self-attention and used during both training and inference. Second, its behavior is learned through one-to-one supervision rather than specified by a fixed IoU threshold. Third, the suppression process is inspectable through confidence ordering, causal masking, and relative geometry. This suggests that MDS is better understood as a learned, differentiable, NMS-like operation rather than as a direct replacement of heuristic NMS by the same rule set.

The paper also identifies several limitations. Integrating MDS with DINO-like techniques is non-trivial: Mixed Query Selection degrades performance, and query denoising as used in DN-DETR or DINO is not directly incorporated. Stacking multiple MDS-based one-to-one layers does not help; with \(5/1\) one-to-many/one-to-one layers the model reaches \(49.8\) mAP, whereas \(5/2\) and \(5/3\) both yield \(49.7\), which the paper attributes to over-suppression. MDS also assumes that one-to-many layers produce reasonably calibrated confidences, since the causal mask depends on ranking by confidence. Finally, the paper notes that asymmetric relative geometry is harmful for small objects and proposes the symmetric bias partly to mitigate this issue [2605.23507].

Beyond object detection, the paper reports an instance segmentation extension obtained by adding a mask head. In that setting, MDS-DETR improves both box and mask mAP over MR.DETR with no extra decoders. The authors further suggest that applying MDS to other transformer-based tasks, including universal segmentation and tracking, could be promising.

Source: https://www.emergentmind.com/topics/masked-duplicate-suppressor-mds