Repository navigation
feat: z-score the SynthSeg synthesis on request with zscore_output - #146
Hendrik-code wants to merge 1 commit into
Conversation
With SynthSeg's default `normalise=True` the synthesis is min-max scaled to [0, 1]. The real training patches it is mixed with are z-scored, so the synthetic samples reach every later transform at about a fifth of the spread of a real one: measured 0.16-0.20 against 0.86-0.91 on two Dixon datasets. Transforms that work in absolute units then act on them at several times their strength on real samples. RandomGaussianNoiseGPU draws its std from U(0, std), and with the paper config's std 1.0 the synthesis was buried under noise in 16 of 20 firings in a measured sample (label boundaries no longer stood out from the background gradient). `zscore_output=True` standardises each synthesised sample over its patch before it replaces the image. It draws no random numbers, so the same seed gives the same synthesis up to that rescale. Default False keeps the [0, 1] output and every shipped config's seeded result. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Results: Dataset803 and Dataset804, fold 0Z-scoring the synthesis improves the SynthSeg config on Dataset804 (+0.019 in-domain, +0.014 out-of-domain) and changes nothing measurable on Dataset803. It does not bring SynthSeg up to the paper config: in-domain stays about 0.03 below it on both datasets. Setup.
The two SynthSeg arms differ only in Z-scored minus paper-synthseg, paired mean and 95% CI:
Dataset803 is equivalent on both scopes (TOST p < 0.001). Dataset804 is better on both: the whole interval clears +0.01. Three Dataset803 runs of the SynthSeg config (folds 0 to 2) spread up to 0.007 in cohort means, so the 804 gain is beyond run-to-run noise. Where the 804 gain comes from: the CT and SPIDER cohorts (myelom-ct +0.019, spider-T1w +0.020, spider-T2w +0.015, spinegan-ct +0.009). The three Dixon cohorts (24 scans each) move −0.007 to +0.007. Out-of-domain, all three classes gain: vertebra +0.016, IVD +0.017, spinal canal +0.010. Against the paper config, paired mean:
Cohort means, unweighted across cohorts:
In training. About 74 s/epoch on an A40, no non-finite losses in either run. In the pre-flight, SynthSeg fired in 20 of 20 batches. Bottom line: worth merging, and worth turning on in the SynthSeg configs. It removes a scale mismatch at no cost and gains on the CT-trained model. On its own, it does not make SynthSeg competitive with the paper config in-domain. |
What
RandomSynthSegGPUtakeszscore_output(defaultFalse). When set, each synthesised sample is standardised over its patch before it replaces the image:Why
With SynthSeg's default
normalise=Truethe synthesis is min-max scaled to[0, 1], while the real patches beside it are z-scored. Measured on the 128³ training patches of four SpineGAN datasets (two cases each, five draws): the image std after SynthSeg is 0.16-0.20, against 0.86-0.91 for the Dixon in-phase and fat inputs.Every later transform that works in absolute units then acts on the synthetic samples at several times its strength on the real ones. The visible case is
RandomGaussianNoiseGPU, whose std is drawn fromU(0, std): at the paper config'sstd: 1.0, the noise std exceeds the image's in about 80% of firings on a SynthSeg sample. In the measured sample, 16 of 20 noise firings after SynthSeg left the label boundaries indistinguishable from the background gradient (mean |∇I| on label boundaries ÷ mean |∇I| over the slice fell from 1.8-2.8 to 1.0-1.3). That affects the publishedSynthSeg (post)configuration (transform_params_paper-synthseg.json), where noise is on atp: 0.1and SynthSeg atp: 1.0.Behaviour
False: shipped configs and their seeded outputs are unchanged.all_augmentations.jsonregenerated (smauglab matrix --write).Tests
unit_tests/test_synthseg_zscore_output.py:[0, 1];Full suite:
477 passed, 13 skipped.mypy smauglab/clean, pre-commit passes.🤖 Generated with Claude Code