Papers
Topics
Authors
Recent
Search
2000 character limit reached

Differentiable clDice: Topology-Aware Segmentation Loss

Updated 12 January 2026
  • Differentiable clDice is a loss function that preserves topology by comparing soft skeletons of predicted and ground truth masks using differentiable morphological operations.
  • It integrates with deep learning models through iterative soft-skeletonization and efficient gradient computation, ensuring connectivity in segmentation tasks.
  • Empirical evaluations show improved connectivity metrics in tubular structure segmentation, while extensions like cbDice address geometric sensitivity limitations.

Differentiable clDice, also known as soft-clDice, is a topology-preserving loss function specifically designed for training neural networks to segment tubular or network-like structures, such as blood vessels, neurons, or roads, in 2D and 3D images. Unlike conventional overlap-based losses, differentiable clDice penalizes topological errors by comparing skeletonized versions of the predicted and ground truth masks, ensuring preservation of connectivity and homotopy equivalence. The formulation employs differentiable morphological operators that allow integration into end-to-end deep learning pipelines, providing efficient gradient computation for training (Shit et al., 2020).

1. Mathematical Formulation and Skeletonization

The central construct in differentiable clDice is the comparison of soft skeletons extracted from the prediction P∈[0,1]ΩP \in [0, 1]^\Omega and the ground truth %%%%1%%%%, with Ω\Omega denoting the spatial domain (image grid or volume). The soft-clDice metric is based on two terms: topology precision (Tprec\mathrm{Tprec}) and topology sensitivity (Tsens\mathrm{Tsens}),

  • Tprec=∑x∈ΩS~(P)x Gx∑x∈ΩS~(P)x\mathrm{Tprec} = \frac{\sum_{x \in \Omega} \widetilde{S}(P)_x \, G_x}{\sum_{x \in \Omega} \widetilde{S}(P)_x},
  • Tsens=∑x∈ΩS~(G)x Px∑x∈ΩS~(G)x\mathrm{Tsens} = \frac{\sum_{x \in \Omega} \widetilde{S}(G)_x \, P_x}{\sum_{x \in \Omega} \widetilde{S}(G)_x},

where S~\widetilde{S} denotes the differentiable skeletonization operator. The differentiable clDice loss is then given by

$\mathrm{soft\mathchar`-clDice}(P, G) = \frac{2 \cdot \mathrm{Tprec} \cdot \mathrm{Tsens}}{\mathrm{Tprec} + \mathrm{Tsens}}$

The soft skeletonization operator S~\widetilde{S} is implemented using iterative min- and max-pooling operations simulating morphological erosion and dilation, followed by open operations and ReLU thresholding. This operation preserves differentiability at every stage, making the entire loss function suitable for gradient-based optimization (Shit et al., 2020).

2. Differentiability and Backpropagation

Differentiable clDice is constructed using sums, products, and rational functions of the network's output, and all skeletonization steps are composed of neighborhood-wise pooling and point-wise functions. The gradients of the loss with respect to network predictions can be analytically written using the chain rule. For loss $\mathcal{L}_c = 1 - \mathrm{soft\mathchar`-clDice}$:

  • For topology precision a=Tpreca = \mathrm{Tprec} and sensitivity b=Tsensb = \mathrm{Tsens},

∂Lc∂a=−2b2(a+b)2 ,∂Lc∂b=−2a2(a+b)2\frac{\partial \mathcal{L}_c}{\partial a} = -\frac{2b^2}{(a+b)^2} \ ,\quad \frac{\partial \mathcal{L}_c}{\partial b} = -\frac{2a^2}{(a+b)^2}

Downstream differentiation with respect to PP or the output of skeletonization is recursively obtained by chaining these partials with those for the skeletonization and linear mask terms, all of which are differentiable (Shit et al., 2020). This allows implementation in modern deep learning frameworks via automatic differentiation.

3. Theoretical Guarantees and Complexity

In the limiting case where predictions and ground truth are binary (P,G∈{0,1}P, G \in \{0,1\}), it is shown that

clDice(P,G)=1  ⟺  S(G)⊂P and S(P)⊂G,\mathrm{clDice}(P,G) = 1 \iff S(G) \subset P \ \text{and} \ S(P) \subset G,

where S(â‹…)S(\cdot) denotes the morphological skeleton. Under mild topological conditions (foreground and background both being homotopy-equivalent to 1D graphs), this criterion guarantees homotopy equivalence between PP and GG, i.e., their underlying graphs are topologically identical up to continuous deformation (Shit et al., 2020).

The operational complexity of soft-skeletonization is O(K∣Ω∣)O(K|\Omega|), where KK is the maximum number of skeletonization iterations (typically matching the maximum tubular radius in pixels or voxels), and ∣Ω∣|\Omega| is the number of voxels. This is computationally efficient: typically K=10K=10–$25$, yielding <10%<10\% overhead relative to a standard Dice loss. By contrast, persistent homology–based losses are O(∣Ω∣3)\mathcal{O}(|\Omega|^3) (Shit et al., 2020).

4. Implementation Details and Training Integration

The soft-clDice loss function is realized as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
def soft_skeleton(I, K):
    S = 0
    cur = I
    for j in range(K+1):
        opened = soft_dilate(soft_erode(cur))
        delta  = relu(cur - opened)
        S      = S + (1 - S) * delta
        cur    = soft_erode(cur)
    return S

def soft_cldice(P, G, K, eps):
    S_P = soft_skeleton(P, K)
    S_G = soft_skeleton(G, K)
    A   = sum(S_P * G)
    B   = sum(S_P)
    C   = sum(S_G * P)
    D   = sum(S_G)
    a   = (A+eps)/(B+eps)
    b   = (C+eps)/(D+eps)
    return 2*a*b/(a+b+1e-12)

def loss_fn(P, G, alpha):
    dsc = 2*sum(P*G)/(sum(P)+sum(G)+eps)
    cl  = soft_cldice(P,G,K=20,eps=1e-6)
    return (1-alpha)*(1-dsc) + alpha*(1-cl)

All operations are vectorized, leveraging GPU acceleration, and require hyperparameter tuning:

  • KK (skeleton iterations): K≳K \gtrsim maximum tube radius in pixels
  • α\alpha (blend between Dice and clDice): α∈[0.1,0.5]\alpha \in [0.1, 0.5]
  • ϵ\epsilon (numerical stability): typically 10−610^{-6} to 10−310^{-3}

Combining soft-clDice with volumetric losses (e.g., Dice) stabilizes training. Pure soft-clDice loss (α=1\alpha=1) can result in slower convergence, especially under high prediction noise (Shit et al., 2020).

5. Comparative Performance and Limitations

Empirical evaluations on five public benchmarks covering 2D and 3D vascular, road, and neuron segmentation demonstrate that soft-clDice:

  • Improves connectivity-related metrics, e.g., StreetMoverDistance (↓\downarrow15–20%), Opt-Junction F1 (↑\uparrow5–10%)
  • Reduces Betti numbers errors (∣Δβ1∣|\Delta \beta_1|, ∣Δβ0∣|\Delta \beta_0| drop by 20–50%)
  • Increases topology-aware clDice by 2–6 points absolute and volumetric Dice by 1–2 points
  • Recovers small network branches and avoids introducing spurious bridges

The approach notably produces segmentations with more accurate network topology and fewer isolated or missing branches (Shit et al., 2020). However, clDice, by design, is insensitive to boundary shifts within the vessel radius and treats all skeleton points equally, which introduces sensitivity to skeleton parallel translations and may confer a bias toward larger-diameter structures. This leads to limitations in precise geometric quantification, such as diameter imbalance or insensitivity to subtle boundary errors—motivating recent extensions that introduce boundary and diameter weighting (Shi et al., 2024).

6. Extensions and Relation to Other Metrics

The centerline-boundary Dice (cbDice) and the more general cl-X-Dice family were developed to address the geometric and diameter sensitivity shortcomings of clDice. These introduce distance or inverse-radius weighting to the skeleton and mask overlaps, thereby extending clDice to be translation- and diameter-aware (Shi et al., 2024). Such modifications retain the core topological guarantees of clDice while adding sensitivity to geometric detail and uniform treatment over varying vessel radii.

A comparison of related loss functions appears below:

Loss Function Topology Preservation Boundary/Geometric Sensitivity Diameter Balance
Dice No Yes No (area-biased)
clDice (soft-clDice) Yes No (insensitive within radius) No (skeleton-biased)
cbDice/cl-X-Dice Yes Yes Yes

Soft-clDice thus occupies a central position within topology-aware segmentation losses, balancing computational efficiency with provable topological correctness, and forms the basis for more finely resolved boundary- and structure-aware losses (Shit et al., 2020, Shi et al., 2024).

Definition Search Book Streamline Icon: https://streamlinehq.com
References (2)

Topic to Video (Beta)

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Differentiable clDice.