---
kind: concept
slug: shape-prior-regularization
title: Shape-prior regularization
summary: >-
  Penalise a network's outputs for being implausible by comparing low-dimensional codes of predicted and true masks or images, learned by an autoencoder or predictor. The term is used only during training, so inference cost is unchanged. Variants differ in output type (label maps or intensity images). Choose by what the network outputs and whether you can afford a two-stage training schedule.
tags: [medical-imaging, segmentation, super-resolution, regularization]
papers: ["1705.08302"]
related: [denoising-autoencoder, semantic-segmentation, image-super-resolution]
status: draft
updated_at: 2026-10-19
---

## Overview

A pixel-wise loss such as cross-entropy or a smooth ℓ1 loss does not see the
shape of the whole output. A prediction can score well per pixel and still be
an anatomically impossible shape [arxiv:1705.08302 §1]. A shape-prior
regularizer adds a second term to the training loss. That term maps the
prediction and the ground truth into a learned low-dimensional code and
penalises their distance [arxiv:1705.08302 §2.2]. The code is learned from the
data, so no explicit shape model has to be specified by hand.

Every variant shares three parts: a pixel-wise reconstruction loss, a code
distance between prediction and target, and a small weight on that distance.
The variants differ in what is coded. For label maps, an autoencoder learned
on the masks provides the code [arxiv:1705.08302 §2.2]. For intensity images,
a predictor trained to match the autoencoder's codes provides it
[arxiv:1705.08302 §2.4]. The code is used only as a training signal, so the
deployed network is the same as the baseline [arxiv:1705.08302 §2.4].

## Variants

### Label-map shape term (ACNN-Seg)

A convolutional autoencoder is trained on ground-truth label maps. Its encoder
maps the predicted class probabilities and the true labels to 64-value codes.
The segmentation network is trained with cross-entropy plus the squared code
distance, plus weight decay on the convolution filters [arxiv:1705.08302 §2.2]
[arxiv:1705.08302 eq. 1]. The reported gain over the sub-pixel 3D baseline on
cardiac MR is endocardial Dice .939 against .923 and myocardial Dice .811
against .773 [arxiv:1705.08302 tab. 1]. Card: [Anatomically Constrained Neural Networks (ACNN)](/papers/1705.08302).

### Intensity-image shape term (ACNN-SR)

Super-resolution outputs are intensity images, which the label-map autoencoder
cannot encode. A predictor maps an intensity volume to the same 64-value code
space. The predictor is trained in two stages: first the autoencoder on masks,
then the predictor to match the autoencoder's codes. Then both are trained
jointly with the super-resolution network [arxiv:1705.08302 §2.4]. The
super-resolution network is trained with a smooth ℓ1 reconstruction loss plus
the squared code distance [arxiv:1705.08302 §2.3] [arxiv:1705.08302 eq. 2].
The reported SSIM is .796 against .784 for 3D-UNet and .783 for SR-CNN on the
same test set, and the reported inference time is 0.06 s against 0.29 s for
SR-CNN [arxiv:1705.08302 tab. 3]. The same learned codes were also used for a
classification test on cardiac MR: with both the ED and ES phases, T-L codes
reached 91.6 % accuracy against 86.6 % for 64-value PCA codes of the label maps
[arxiv:1705.08302 §3.6].

## When to use which

| Situation | Use | Why |
|---|---|---|
| Output is a label or probability map (segmentation) | Label-map shape term | The autoencoder is trained on masks the task already has [arxiv:1705.08302 §2.2]. |
| Output is an intensity image (super-resolution, reconstruction) | Intensity-image shape term with predictor | The predictor provides a code for images, which the mask autoencoder cannot [arxiv:1705.08302 §2.4]. |
| Latency at inference matters | Either variant | The shape term is training-only, so inference is unchanged [arxiv:1705.08302 §2.4]. |
| Training budget or schedule is tight | Weigh the cost before choosing | The method needs a separately trained autoencoder, and for SR a predictor and two-stage training [arxiv:1705.08302 §2.4]. |
| Data that differs from the paper's cohort (healthy adults, cardiac only) | Not covered | The paper uses 900 segmentation and 1000 super-resolution training volumes from healthy subjects [arxiv:1705.08302 §3.1] [arxiv:1705.08302 §3.3]. Results on other anatomy or populations are not reported. |

Pick the variant from the output type first. The paper's evidence is all from
cardiac imaging, on three datasets, and the reported gains are small (a few
Dice points in the segmentation table). In the ultrasound table the Dice gain
has p ≈ 0.05, which the text calls not significant [arxiv:1705.08302 tab. 2]
[arxiv:1705.08302 §3.4].

## Implementation sketch

Common core: the pixel-wise loss, plus λ1 times the squared distance between
the codes of prediction and target, plus λ2 / 2 times the squared weights.
The two variants differ in how the code is computed, as the two pseudocode
blocks below show. Eq. 1 updates only the segmentation weights, which implies
a frozen encoder. The paper does not state this in words
[arxiv:1705.08302 §2.2] [arxiv:1705.08302 eq. 1].

```pseudocode
# Label-map variant (ACNN-Seg)  [arxiv:1705.08302 §2.2] [eq. 1]
def seg_loss(images, labels, seg_net, ae_encoder, lam1, lam2):
    # Per-class probability maps on the output grid  [§2.1]
    probs = seg_net(images)
    # Pixel-wise loss; mean or sum over voxels is not stated  [§2.1]
    ce = cross_entropy(probs, labels)
    # Codes of prediction and target from the frozen encoder  [§2.2]
    shape = squared_distance(ae_encoder(probs), ae_encoder(labels))
    # Weight decay on convolution filter weights  [§2.2]
    return ce + lam1 * shape + (lam2 / 2) * conv_weight_norm(seg_net)
```

```pseudocode
# Intensity-image variant (ACNN-SR)  [arxiv:1705.08302 §2.3] [§2.4] [eq. 2]
def sr_loss(lr_images, hr_targets, sr_net, predictor, lam1, lam2):
    # Super-resolved volume from LR-grid features  [§2.3]
    sr = sr_net(lr_images)
    # Smooth L1 (Huber) reconstruction, threshold 1  [§2.3] [eq. 2]
    recon = smooth_l1(sr - hr_targets, threshold=1.0)
    # Codes of synthesised and true volumes from the predictor  [§2.4]
    # Whether predictor weights also update is not stated
    shape = squared_distance(predictor(sr), predictor(hr_targets))
    # Weight decay on convolution filter weights  [§2.4]
    return recon + lam1 * shape + (lam2 / 2) * conv_weight_norm(sr_net)
```

The reported values for λ1 and λ2 are 0.01 and 5 × 10⁻⁶, with a fixed
learning rate of 0.001. The optimiser variant and schedule are not stated
[arxiv:1705.08302 supp. Implementation Details]. The code dimension is 64
[arxiv:1705.08302 tab. 5]. The label-map autoencoder's code layer has no
non-linearity [arxiv:1705.08302 supp. Network Structure].

## Contradictions

None known. The paper reports that a joint update of the two stages converged
better than alternating updates, and does not compare them further
[arxiv:1705.08302 §2.4] [arxiv:1705.08302 §3.2].

## Papers

- [Anatomically Constrained Neural Networks (ACNN)](/papers/1705.08302): introduces the code-distance shape term for cardiac segmentation and MR super-resolution, with a training-only autoencoder and predictor.
