Calibrating segmentation networks with margin-based label smoothing

Adrian Galdran, Balamurali Murugesan, Bingyuan Liu, Ismail Ben Ayed, Jose Dolz

TL;DR

Existing calibration losses like label smoothing and focal loss implicitly enforce strict equality constraints on logit distances, constantly pushing predictions toward an uninformative uniform distribution. By reframing network calibration through constrained optimization, the authors propose Margin-based Label Smoothing (MbLS), which relaxes this requirement into an inequality constraint with a controllable margin. This simple ReLU-based penalty significantly improves both segmentation accuracy and calibration across diverse medical imaging benchmarks.

What Problem Does This Paper Address?

Modern deep neural networks excel at visual tasks like medical image segmentation, but standard training with cross-entropy loss causes severe overconfidence (miscalibration). Cross-entropy drives the pre-softmax activation (logit) of the ground-truth class to be drastically larger than all other logits, pushing softmax outputs to the extreme corners of the probability simplex.

While techniques like Label Smoothing (LS), Focal Loss (FL), and Explicit Confidence Penalty (ECP) have shown promise in general classification, their effectiveness in dense medical segmentation remains underexplored. More fundamentally, the authors identify a structural flaw in these methods: they implicitly penalize any non-zero logit distance, constantly pushing logit differences all the way to zero via constant gradients. This creates tension between calibration and discriminative segmentation accuracy.

Methods

The authors analyze calibration through a constrained-optimization framework:

  • Logit Distance Formulation: Let the vector of logit distances between the winning class and class $k$ be $d(l) = (\max_j(l_j) - l_k)_{1 \le k \le K}$.
  • Unifying Existing Losses: The paper demonstrates that LS, FL, and ECP function as soft penalties for the hard equality constraint $d(l) = 0$ (or equivalently, $d(l) \le 0$). This constant pull penalizes the network even when it makes appropriately confident, correct predictions.
  • Margin-based Label Smoothing (MbLS): Instead of forcing logits to be equal ($d(l) = 0$), the authors introduce an inequality constraint with a strictly positive margin vector $\mathbf{m} > 0$: $$\min \mathcal{L}_{\text{CE}} \quad \text{s.t.} \quad d(l) \le \mathbf{m}, \quad \mathbf{m} > 0$$
  • Unconstrained ReLU Objective: This is approximated using a non-linear ReLU penalty: $$\min \mathcal{L}_{\text{CE}} + \lambda \sum_k \max\left(0, \, \max_j(l_j) - l_k - m\right)$$ When logit distances are below margin $m$, the gradient is zero, allowing confident discriminative learning. The penalty only activates when logit distances exceed $m$. In practice, $\lambda$ is fixed to $0.1$, requiring only the margin $m$ to be tuned over validation sets.
       Linear Penalty (LS / FL / ECP)               Margin-based Penalty (MbLS)
 Penalty                                      Penalty
   ^      /                                     ^             /
   |     /                                      |            /
   |    /                                       |           /
   |   /                                        |__________/
   +----------> Logit distance                  +-----+----> Logit distance
                                                      m
 Derivative (Constant gradient)               Derivative (Zero gradient below m)
   ^                                            ^
   |                                            |           +---------
   |-----------                                 |           |
   +----------> Logit distance                  +-----+-----+--> Logit distance
                                                      m

Datasets

The authors evaluate MbLS on five diverse, public multi-class segmentation benchmarks:

  1. ACDC (Automated Cardiac Diagnosis Challenge): 100 patient cardiac MRI exams (LV, RV, myocardium, background).
  2. BRATS (Brain Tumor Segmentation Challenge): 484 multi-modal MRI scans (FLAIR, T1, T1-contrast, T2) segmenting tumor core, enhancing tumor, and whole tumor.
  3. MRBrainS18: Paired T1, T2, and T1-IR brain MRI volumes segmenting Gray Matter, White Matter, and CSF.
  4. FLARE (Fast and Low GPU memory Abdominal oRgan sEgmentation): 360 abdominal CT volumes segmenting liver, kidneys, spleen, and pancreas.
  5. PROMISE (PROMISE12 Challenge): Transversal T2-weighted prostate MRI scans across multiple centers and vendors.

Key Insights and Ideas

  • Theoretical Unification: Label smoothing can be decomposed into $\mathcal{L}_{\text{CE}}$ plus the KL divergence between a uniform distribution and softmax probabilities ($D_{\text{KL}}(u \parallel s)$), which bounds the average logit distance from above and below. Hence, LS (and similarly FL and ECP) essentially optimizes a linear penalty for logit equality ($d(l) = 0$).
  • The "Constant Gradient" Trap: In linear logit penalty formulations, the derivative with respect to logit distance is a strictly positive constant. It continuously drags network predictions toward the uninformative uniform prediction ($s_k = 1/K$), hurting segmentation discriminability.
  • Compound Losses Degrade Calibration: While combining Cross-Entropy and Dice loss ($\mathcal{L}_{\text{CE}} + \mathcal{L}_{\text{DSC}}$) is standard practice in medical imaging, it produces poor calibration—ranking worst or second-to-worst across benchmarks in ECE and CECE.
  • Logit Clustered Boundaries: MbLS maintains compact distances between the winning logit and competing non-target classes while leaving the non-target logits clustered together, mimicking a uniform background distribution without degrading edge sharpness.

Key Results

  • Discriminative & Calibration Superiority: Across all benchmarks, MbLS ranked first overall in a multi-metric sum-rank scheme (global score of 38, compared to 62 for ECP, 80 for FL, 86 for CE, and 94 for CE+DSC).
  • ACDC: MbLS achieved a mean DSC of 0.875 (vs. 0.841 for CE, 0.827 for CE+DSC) and reduced Expected Calibration Error (ECE) to 0.061 (vs. 0.079 for CE, 0.137 for CE+DSC).
  • PROMISE: MbLS reduced ECE from 0.411 (CE) and 0.430 (CE+DSC) down to 0.232, while achieving the highest mean DSC (0.583).
  • Post-Hoc Calibration Synergy: MbLS is orthogonal to post-processing methods. When paired with Local Temperature Scaling (LTS), calibration improved even further (e.g., ACDC ECE dropping to 0.041).
  • Robustness to Domain Shift: When test images were corrupted with increasing Gaussian noise ($\sigma \in [0, 0.05]$), MbLS retained higher DSC and lower Classwise ECE (CECE) than competing methods on PROMISE and MRBrainS.
  • Architecture Agnostic: The performance gains held consistently when swapping the standard U-Net backbone for AttUNet, TransUNet, or UNet++ on the FLARE dataset.
  • Hyperparameter Stability: MbLS performance proved substantially less sensitive across margin selections ($m \in \{5, 8, 10\}$) than baseline methods were to their respective balancing weights ($\alpha, \gamma \in \{0.1, 0.2, 0.3\}$).

Limitations and Future Work

  • Hyperparameter Tuning: Although significantly more stable than prior methods, the margin $m$ must still be tuned on an independent validation set.
  • Simplified Constraint Solver: The optimization uses a simple, unconstrained ReLU penalty with a heuristic fixed weight ($\lambda = 0.1$). Incorporating explicit Lagrangian dual optimization or adaptive multiplier updates was left unexplored.
  • Extending Beyond Medical Imaging: Experiments were exclusively conducted on multi-class medical segmentation; evaluating the inequality margin formulation on large-scale natural image segmentation (e.g., Cityscapes, ADE20K) remains future work.

Summary updated

BibTeX
@article{galdran2023calibrating,
  author = {Adrian Galdran and Balamurali Murugesan and Bingyuan Liu and Ismail Ben Ayed and Jose Dolz},
  title = {{Calibrating segmentation networks with margin-based label smoothing}},
  journal = {Medical Image Analysis},
  year = {2023},
  url = {https://openreview.net/forum?id=EX8g9dgfea},
}
Figure