---
title: L1-weighted Dice Focal Loss for Lesion Segmentation
url: https://www.emergentmind.com/topics/l1-weighted-dice-focal-loss-l1dfl-e6621943-8f56-447e-a3e6-aefbcf6b0908
type: topic
---

# L1-weighted Dice Focal Loss for Lesion Segmentation

L1-weighted Dice Focal Loss (L1DFL) is a supervised loss function developed for voxel-wise segmentation tasks in deep learning, with demonstrated efficacy in automated lesion segmentation in PSMA PET/CT imaging for prostate cancer. L1DFL explicitly integrates dynamic, data-adaptive weighting of voxels based on L₁ norm errors into a weighted Dice-Focal framework, refining the sensitivity of segmentation models to rare, hard-to-classify regions while controlling for the dominance of easy background voxels. The approach yields substantial improvements in quantitative clinical metrics and agreement with expert annotations on complex medical images [2504.16237][2502.02756].

## 1. Mathematical Definition

The L1-weighted Dice Focal Loss re-weights the sum of a squared-denominator Dice loss and a focal loss term by a voxel-wise, data-driven weight derived from prediction error statistics. The full computation is as follows:

1. **L₁ norm calculation** (per voxel $i$ and class $c$):
   $$
   \Delta_i(c) = |p_i(c) - g_i(c)|
   $$
   where $p_i(c)$ is the predicted probability and $g_i(c)\in\{0,1\}$ is the ground-truth label.

2. **Density estimation via binning**: Bin $\Delta_i(c)$ into non-overlapping bins of width $\kappa$ (typically $0.1$ over $[0,1]$), constructing a histogram over all voxels and classes in a batch. The density in bin $B$ is:
   $$
   \mathcal{D}(B) = \frac{1}{\lambda(B)} \sum_{i} \sum_{c\in\{0,1\}} \delta_\kappa(B, \Delta_i(c))
   $$
   with $\lambda(B)$ as the effective bin width.

3. **Weight assignment**: Each bin receives a weight inversely proportional to its density,
   $$
   w(B) = \frac{N}{\mathcal{D}(B)}
   $$
   where $N$ is the total number of (voxel, class) pairs; each voxel $i$ uses $w_i = w(B_k)$ for its assigned bin $B_k$.

4. **Loss combination**:
   - Weighted squared-denominator Dice loss:
     $$
     L_\mathrm{wDice} = 1 - \frac{2\sum_i w_i g_i p_i + \epsilon}{\sum_i w_i (g_i^2 + p_i^2) + \epsilon}
     $$
   - Focal loss (with $\alpha_c=1$ and $\gamma=2$):
     $$
     L_\mathrm{Focal} = -\frac{1}{2}\sum_{c\in\{0,1\}} \sum_i (1-p_i(c))^{\gamma}\log(p_i(c))
     $$
   - **Total L1DFL loss**:
     $$
     L_\mathrm{L1DFL} = L_\mathrm{wDice} + L_\mathrm{Focal}
     $$
   All hyperparameters, including $\kappa=0.1, \gamma=2, \alpha_c=1, \epsilon=1\mathrm{e}{-6}$, are fixed across architectures and splits [2504.16237][2502.02756].

## 2. Rationale and Theoretical Motivation

Standard Dice Loss and its derivatives operate globally, treating every voxel or class equally and are typically insensitive to the changing batch-wise distribution of errors. Focal Loss introduces class-level modulation, but not local adaptivity. L1DFL leverages the following rationale:

- PSMA PET lesion voxels are challenging—small, low-contrast, and irregular—meaning that a small number of difficult voxels can dramatically reduce segmentation fidelity.
- By estimating the batch-wise distribution of L₁-norm errors and inverting their density, L1DFL dynamically up-weights rare or hard examples (often lesion boundaries or small lesions) and down-weights abundant, easy examples (background).
- This mechanism adaptively focuses the model’s gradient updates on the specific difficult regions in each mini-batch, leading to improved detection sensitivity, boundary accuracy, and reduced false positives in high class-imbalance regimes [2504.16237][2502.02756].

## 3. Comparison with Other Losses

The table below summarizes key properties distinguishing L1DFL from alternatives:

| Loss Function         | Weighting Mechanism    | Sensitivity to Hard Voxels | Adaptive?     |
|----------------------|-----------------------|---------------------------|---------------|
| Dice Loss (DL)       | Uniform               | None                      | No            |
| Dice+Cross-Entropy   | Uniform               | None                      | No            |
| Dice Focal Loss (DFL)| Global (focal term)   | Some (via $(1-p_i)^\gamma$) | No           |
| L1DFL                | Per-bin L₁, dynamic   | High (bin count-inverse)  | Yes (per-batch)|

L1DFL outperforms DL and DFL, particularly in scenarios with small, irregular, or low-contrast lesions, by adaptively targeting high-error voxels [2502.02756][2504.16237].

## 4. Experimental Protocol

L1DFL has been validated primarily in binary lesion segmentation of [¹⁸F]DCFPyL PSMA PET/CT scans in prostate cancer. The protocol includes:

- **Dataset**: 380 scans, 684 lesions (mean volume $6.7\pm10.2$ ml), ground truth via expert PET Edge annotation.
- **Architectures**: 3D U-Net, Attention U-Net, SegResNet (with channel and normalization details as specified).
- **Preprocessing**: PET to SUV, CT windowing, isotropic 2 mm resampling; spatial augmentations.
- **Training**: 5-fold cross-validation, AdamW optimizer (initial $\mathrm{lr} = 2\mathrm{e}{-4}$), 1000 epochs with cosine annealing, MONAI + PyTorch, sliding window inference, ensemble via majority voting.
- **Evaluation**: DSC, per-lesion F1 (SUVmax voxel overlap), clinical quantification (SUVmax, SUVmean, TMTV, TLA, count, spread), statistical agreement (Lin’s CCC, TOST at $\pm20\%$, Bland-Altman, CP, TDI$_{95}$) [2504.16237][2502.02756].

## 5. Quantitative Results and Comparative Performance

Across architectures and metrics, L1DFL demonstrates the following improvements:

- **Segmentation (median DSC, test set)**:
  - SegResNet+L1DFL: 0.71 [IQR 0.52–0.81] ($+4.4\%$ over Dice or DCE), mean DSC 0.61 ± 0.28, F1=0.72, lowest FP ($\sim$0.31)
  - U-Net+L1DFL: 0.66 [0.48–0.77], mean 0.56 ± 0.29
  - Att-U-Net+L1DFL: 0.67 [0.54–0.79], mean 0.60 ± 0.28
- **Clinical metrics, Lin’s CCC (Att-U-Net+L1DFL)**: SUVmax 0.98, SUVmean 0.96, TLA 0.95, TMTV 0.89, Lesion count 0.91, Dmax 0.90
- **Equivalence (TOST, $\alpha$=0.05, $\pm$20%):** L1DFL achieves equivalence for SUVmax, SUVmean, TLA, lesion count; alternatives fail for TLA, count, or Dmax.
- **Coverage Probability (CP) & TDI$_{95}$:** L1DFL yields higher coverage and consistently lowest TDI$_{95}$, with Dice/Dice Focal up to $3\times$ higher deviations [2504.16237].
- **Cross-study observations:** L1DFL shows +13% median DSC improvement over Dice and DFL on test sets; F1 score increases by $\geq6\%$ over Dice and $\geq34\%$ over DFL [2502.02756].
- Ablation: When $\Delta$ is uniform, weighting reduces to standard Dice behavior, isolating the role of batch-adaptive L₁-based weights.

## 6. Implementation and Practical Considerations

- **Hyperparameters**: All experiments fix bin width $\Gamma=0.1$; focal parameter $\gamma=2$; class balance $\alpha=1$; smoothing $\epsilon=1\mathrm{e}{-6}$.
- **Histograms and weighting**: Implemented efficiently in PyTorch, typically using `torch.bucketize` or GPU histogram operations. Weight normalization is implicit via $w(N)=N/\mathcal{D}$.
- **Batch-wise adaptivity**: All weights and densities are recomputed every batch, maximizing adaptivity to current data statistics.
- **STL/PyTorch workflow**: Open-source at https://github.com/ObedDzik/pca_segment.git; trained on Tesla V100 16GB, batch size set per GPU capacity, and code uses MONAI sliding-window segmentation and majority voting ensemble for robustness [2504.16237][2502.02756].

## 7. Limitations and Extensions

While L1DFL demonstrates robust improvements, certain limitations are evident:

- **Lesion spread**: Performance declines in the largest anatomical spread quartile ($D_\text{max}>14$ cm), signaling challenges in extreme cases.
- **Network specificity**: Some interaction with architecture and lesion characteristics; for example, in low-spread lesions SegResNet+Dice Loss may approach L1DFL performance.
- **Hyperparameter sensitivity**: While $\Gamma$, $\gamma$, and $\alpha$ are robust for PSMA PET/CT, their transferability to other modalities or tasks is unproven; parameter retuning may be required.
- **Potential for generalization**: Extensions could include vector L₁ norms for multiclass, dynamic tuning of bin width, incorporation of spatial context, or adaptation to non-PT/PET modalities [2502.02756].
- **A plausible implication** is that L1DFL’s value is highest where class imbalance, voxel-wise difficulty heterogeneity, and rare-event detection are pronounced.

---

L1DFL establishes an interpretable and practical mechanism for adaptive per-voxel weighting in medical image segmentation networks, improving sensitivity and agreement for challenging tasks such as PSMA PET/CT lesion detection [2504.16237][2502.02756].

Source: https://www.emergentmind.com/topics/l1-weighted-dice-focal-loss-l1dfl-e6621943-8f56-447e-a3e6-aefbcf6b0908