---
title: Distance-aware Focal Loss for HD Map Construction
url: https://www.emergentmind.com/topics/distance-aware-focal-loss-dafl
type: topic
---

# Distance-aware Focal Loss for HD Map Construction

Searching arXiv for the cited papers to ground the article in current paper metadata.
Distance-aware Focal Loss (DAFL) most directly denotes a quality-aware variant of focal loss introduced in the context of online vectorized HD map construction, where the classification target for a matched prediction is made a function of geometric localization quality rather than a fixed binary foreground label [2510.22675]. In that formulation, DAFL addresses task misalignment in DETR-like one-to-many matching by converting a per-instance localization loss into a continuous confidence target and using that target inside a focal-style classification objective, so that high classification scores are more closely aligned with well-localized map elements. The acronym is not fully uniform across the literature: one paper on federated medical image classification uses DAFL to mean Dynamic Adaptive Focal Loss and explicitly frames it as distribution-aware rather than distance-aware [2602.01633], while a light-field depth-estimation paper does not use the term DAFL but describes an uncertainty-aware focal loss with DAFL-like behavior because a distribution-distance term modulates a regression loss [2208.09688].

## 1. Definition and scope

In DAMap, DAFL is defined for online HD map construction from multi-view RGB images, where a DETR-like pipeline predicts vectorized map elements such as road boundaries, lane dividers, pedestrian crossings, and, in some experiments, centerlines [2510.22675]. The central objective is “high quality predictions,” meaning simultaneously high classification confidence and high localization accuracy. Localization quality is evaluated with Chamfer Distance under hard thresholds $\{0.2, 0.5, 1.0\}\,\text{m}$ and easy thresholds $\{0.5, 1.0, 1.5\}\,\text{m}$.

The defining departure from standard focal loss is that DAFL does not assign the same positive label to all matched queries. Instead, for each matched prediction–ground-truth pair, the label is softened according to localization quality. Good localizers receive targets near $1$, while poor localizers receive targets closer to $0$, even if they are matched positives. This makes classification scores reflect both class membership and geometric accuracy [2510.22675].

A related but distinct usage appears in federated learning for medical image classification, where DAFL stands for Dynamic Adaptive Focal Loss:
\[
\mathcal{L}_{\text{DAFL}} = - (1 + c_{f,t}) \cdot (1 - p_t)^\gamma \cdot \log(p_t).
\]
That loss introduces a dynamic imbalance coefficient based on client-level and global class-level statistics, not an explicit geometric distance term [2602.01633]. In a different domain, light-field depth estimation introduces an uncertainty-aware focal loss,
\[
UAFL = \| U \|^{\beta} \odot \| d - \hat{d} \|_1,
\]
which can be interpreted as DAFL-like because a divergence between predicted and target disparity distributions acts as a distance-aware difficulty signal [2208.09688].

## 2. Origin in HD map construction and the task-misalignment problem

The immediate motivation for DAFL in DAMap is the task misalignment that arises in DETR-like HD map detectors with one-to-many matching [2510.22675]. In that setting, each ground-truth map element is matched to multiple query predictions. Under standard focal loss, all such matched queries are trained as positives with the same label $y=1$, irrespective of whether their geometric predictions are accurate.

The paper identifies two causes of misalignment. The first is inappropriate task labels due to one-to-many matching: queries with very different localization quality receive identical classification supervision. The second is sub-optimal task features due to task-shared sampling in the decoder. DAFL addresses the first issue by changing the classification label assignment, while Task Modulated Deformable Attention addresses the second [2510.22675].

The practical implication is that, under standard focal loss, a poorly localized query matched to a ground-truth polyline can still be pushed toward a high foreground score. This weakens the correspondence between score ranking and geometric correctness. The DAMap analysis states that this harms high-quality mAP because predictions with high classification scores may have poor geometry, while some accurate polylines may be scored less favorably [2510.22675].

This same alignment concern appears in another form in light-field depth estimation. There, the authors argue that supervising only the scalar expectation of a disparity distribution with an $L_1$ loss is suboptimal because multiple distributions can share the same mean disparity. Their remedy is not called DAFL, but it similarly seeks to align the learned distribution with a more informative target rather than supervising only a reduced projection [2208.09688].

## 3. Mathematical formulation

The baseline focal loss used in DAMap is
\[
\text{FL}(p,y)=
\begin{cases}
-(1-p)^\gamma\log(p), & y = 1,\\[4pt]
-p^\gamma\log(1-p),   & y = 0,
\end{cases}
\]
where $p \in [0,1]$ is the predicted foreground probability and $y \in \{0,1\}$ is the binary label [2510.22675].

DAFL replaces the binary positive target with a continuous quality target derived from localization error. For a matched prediction–ground-truth instance $i$, the localization loss is defined as
\[
\mathcal{L}_{\rm dist} = \sum_{i=0}^{N-1} \mathbbm{1}_{\{c_i \neq \varnothing\}} \sum_{j=0}^{N_v-1} D_{\rm L1}\bigl(\hat{v}_{\hat{\pi}(i),j}, \, v_{i,\hat{\gamma}_i(j)}\bigr),
\]
and the corresponding per-instance distance can be written as
\[
\mathcal{L}_{\rm dist}^i  = \sum_{j=0}^{N_v-1} D_{\rm L1}\bigl(\hat{v}_{\hat{\pi}(i),j}, \, v_{i,\hat{\gamma}_i(j)}\bigr).
\]
Here, the loss sums $L_1$ distances over points along the vectorized map element [2510.22675].

That distance is converted into a localization confidence:
\[
P_{\rm dist}^i = e^{-\lambda \mathcal{L}_{\rm dist}^i},
\]
with $P_{\rm dist}^i \in (0,1]$. If $\mathcal{L}_{\rm dist}^i = 0$, then $P_{\rm dist}^i = 1$; as the localization loss grows, the confidence decays toward $0$ [2510.22675].

The DAFL objective is then
\[
\text{DAFL}(p,y)
 = - (y - p)^\gamma \bigl( y\log(p) + (1-y)\log(1-p) \bigr),
\]
where $y \in [0,1]$ is the soft target for the foreground class. For positive matched queries, $y=P_{\rm dist}^i$; for unmatched background queries, $y=0$ [2510.22675].

The structure combines two elements. The inner term,
\[
y\log(p) + (1-y)\log(1-p),
\]
is binary cross-entropy with a soft label. The modulation factor $(y-p)^\gamma$ focuses the loss on cases where the predicted score differs from the target quality. In this sense, distance is not inserted merely as a sample weight; it becomes the classification target itself [2510.22675].

## 4. Label assignment, one-to-many matching, and score calibration

DAFL is specifically motivated by one-to-many matching. In DAMap, each ground-truth instance can be matched to multiple query slots, for example across branches or decoder outputs. Under conventional supervision, all matched queries are treated as positives for the ground-truth category. DAFL changes only the target assignment: each matched positive is re-labeled with a localization-dependent soft target rather than a universal foreground label [2510.22675].

This yields a finer ordering among multiple positives associated with the same ground truth. A query whose predicted polyline is close to the matched ground-truth polyline obtains $y \approx 1$ and is encouraged to predict a high score. A matched query with worse geometry obtains a smaller $y$ and is correspondingly encouraged to predict a lower score. The result is that classification confidence is more closely calibrated to geometric quality [2510.22675].

The paper explicitly compares this behavior to quality-aware detection losses such as Quality Focal Loss and VarifocalNet, while emphasizing a task-specific difference: DAFL uses an exponential transform of a distance-based polyline loss instead of IoU. This avoids the need for an explicit IoU representation, which is awkward for vectorized polylines [2510.22675].

A similar conceptual pattern appears in the light-field disparity work, though the mathematical object is different. There, the “hardness” signal is the Jensen–Shannon divergence between a predicted disparity distribution and a discretized ground-truth distribution:
\[
U = JS(Y_{\text{dist}} \,\|\, \hat{Y}_{\text{dist}}),
\]
and the loss becomes
\[
UAFL(x,y) = \big( U(x,y) \big)^{\beta} \cdot |d(x,y) - \hat{d}(x,y)|.
\]
That paper argues that easy examples correspond to small divergence and hard examples to large divergence, which is DAFL-like in the sense of using a distribution-distance measure to focus learning on misaligned predictions [2208.09688].

## 5. Hybrid supervision and architectural context

In DAMap, DAFL is not applied uniformly across all decoder layers. The authors introduce a Hybrid Loss Scheme because early decoder layers often have very poor localization during the initial stage of training. If DAFL is used too early, the quality targets derived from poor regressions may become nearly zero and provide noisy supervision [2510.22675].

The hybrid classification objective is
\[
\mathcal{L}_{\rm cls} = \sum_{l=1}^{L_1}\text{FL}(p^{(l)},y^{(l)}) + \sum_{l=1}^{L_2}\text{DAFL}(p^{(l)},y^{(l)}),
\]
with $L_1 + L_2 = L$. The reported best configuration for a $6$-layer decoder uses focal loss on only the first decoder layer and DAFL on the remaining five layers [2510.22675].

Within the overall DAMap architecture, DAFL operates at the classification heads of decoder layers. The pipeline is multi-view images to a backbone, then a view-transform module to BEV features, then a transformer decoder producing classification and localization outputs. The localization branch supplies the distance signal that DAFL turns into a soft classification label [2510.22675].

The loss-side modification is complemented by Task Modulated Deformable Attention, which provides task-specific features for classification and localization rather than a single shared query feature. The paper presents TMDA as orthogonal to DAFL: better task-specific features make the distance-aware label more meaningful, but DAFL can also be used independently [2510.22675].

The federated medical-imaging usage of DAFL differs structurally. There, the loss is the sole local training objective within a synchronous federated learning protocol, and the “adaptive” component is tied to imbalance statistics rather than localization quality. The client-aware aggregation weight
\[
\omega_k = \frac{w_k}{\sum_{j=1}^{K} w_j}, \qquad
w_k = \frac{1}{c_k + \epsilon},
\]
is coupled to the same imbalance signal used in the loss, but no geometric distance or localization-derived soft label is involved [2602.01633].

## 6. Empirical behavior, related variants, and terminology

The empirical evidence reported for DAMap indicates that DAFL improves the alignment between scores and localization quality. On nuScenes with a ResNet-50 backbone and a 24-epoch MapTRv2 baseline, the ablation reports $60.4$ mAP for the baseline, $60.9$ with DAFL alone, $61.6$ with DAFL plus Hybrid Loss Scheme, and $62.8$ with DAFL plus Hybrid Loss Scheme plus Task Modulated Deformable Attention [2510.22675]. In a longer 110-epoch setting, the combination of DAFL and Hybrid Loss Scheme improves the reproduced MapTRv2 baseline from $44.9$ to $47.0$ mAP on the hard metric and from $68.3$ to $69.4$ on the easy metric [2510.22675].

The same study reports that the distance-to-quality mapping parameter is not highly sensitive within the tested range: $\lambda = 1.0$ gives $62.8$ mAP, $\lambda = 0.8$ gives $62.9$, and $\lambda = 1.2$ gives $62.5$ [2510.22675]. It also states that DAFL and the Hybrid Loss Scheme add no parameters or inference-time computation relative to the baseline, since they alter only the training loss [2510.22675].

The acronym DAFL is therefore domain-dependent. In the federated ViT paper, DAFL consistently denotes Dynamic Adaptive Focal Loss, not Distance-aware Focal Loss, and the paper explicitly states that it is “not a distance-aware loss in the sense of using explicit feature or logit distances” [2602.01633]. Its reported gains are associated with imbalanced, heterogeneous medical datasets and with a dynamic class imbalance coefficient
\[
c_{f,t} = \lambda \cdot c_k + (1 - \lambda) \cdot c_{f,i}\big|_{i=t},
\]
rather than geometric supervision [2602.01633].

The light-field depth paper adds a further terminological caution. It does not name its loss DAFL, but the paper’s own interpretation is that its uncertainty-aware focal loss has “DAFL-like characteristics,” because a Jensen–Shannon divergence between predicted and target disparity distributions increases when probability mass lies farther from the true disparity in disparity space [2208.09688]. A plausible implication is that “distance-aware focal loss” can refer either to explicit geometric quality targets, as in DAMap, or more loosely to focal-type losses modulated by a distance or divergence in an ordered output space.

Taken together, the literature supports a narrow and a broad reading. In the narrow reading, Distance-aware Focal Loss is the DAMap loss for HD map construction that transforms localization loss into a continuous classification target [2510.22675]. In the broader reading, the term can denote focal-style objectives that incorporate a notion of distance from the correct output—geometric, distributional, or ordinal—into the focusing mechanism. The papers considered here, however, make clear that these are not interchangeable formulations and should be distinguished by task, target construction, and the specific meaning of “distance.”

Source: https://www.emergentmind.com/topics/distance-aware-focal-loss-dafl