Repository navigation
feat: strength ranges for the five elementwise TAs, and bounds for the unsharp mask - #148
Hendrik-code wants to merge 2 commits into
Conversation
…e unsharp mask
Log1p, Sqrt, Sin, Exp and Sigmoid min-max scale each sample to [0, 1],
apply a fixed function and, with retain_stats, restore mean and std. Only
the function's curvature on [0, 1] survives that, and it is small: the share
of output variance a linear map of the input cannot explain is 0.8%, 4.0%,
0.5%, 1.6% and 0.1% on a uniform input, and 0.5%, 1.9-3.0%, 0.2%, 1.0% and
0.04% measured on real spine MR and CT patches. A gamma of 0.7 or 1.5 is
already 1.2-2.0%. At the paper config's p=0.1 each, 41% of samples get at
least one of the five and are effectively unchanged by it.
Each now takes an optional range that draws a stronger member of its family
per sample (once with same_on_batch):
* RandomLog1pGPU(scale_range) log(1 + k*x)
* RandomSqrtGPU(exponent_range) x**g
* RandomSinGPU(frequency_range) sin(2*pi*f*x + phi), phi ~ U(0, 2*pi)
* RandomExpGPU(rate_range) exp(k*x)
* RandomSigmoidGPU(slope_range, center_quantile_range)
sigmoid(k*(x - c)), c the sample's q-quantile
The sigmoid centre is a quantile because the min-max scaling is set by the
extremes: with a bright tail the bulk of the tissue sits in the bottom fifth
of [0, 1], where a fixed centre would saturate it.
RandomUnsharpMaskGPU drew its per-axis sigma from U(0, sigma) onto a fixed
3-wide kernel and its amount from U(0, unsharp_amount), which measured at
0.01-0.9% nonlinear share and a gradient-magnitude correlation of 0.996 with
the input. It now takes `sigma_min`, `amount_min` and `kernel_size` (None
sizes the kernel 2*ceil(3*sigma)+1).
Every default is the old transform: the leaves fall through to the fixed
function and draw nothing, and the unsharp draws reduce to `rand * x` exactly.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
exp(k*x) is convex at the bright end, so once retain_stats restores mean and std the brightest voxels land far out. Measured on 128^3 spine patches (Dixon in-phase / CT): largest |z| 5.6 / 8.4 at k=1, 9.3 / 11.8 at k=2.5, 21 / 19 at k=5. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Results: Dataset803 and Dataset804, fold 0Equivalent to the paper config within ±0.01 on both datasets, in-domain and out-of-domain. The five elementwise TAs and the unsharp mask now visibly change the image, but the model does not change. Setup.
Trained ranges, narrower than first proposed after measuring outliers on real batches:
At these ranges each function's nonlinear share is 3.5% to 22%, against 0.04% to 3% at the defaults. TA strength minus paper (replicate), paired mean and 95% CI:
All four cells are equivalent (TOST p < 0.001). Against the published run, the deltas are −0.002, −0.005, −0.001 and +0.003, all equivalent. Cohort means: 803 in / out 0.899 / 0.841 (paper replicate 0.901 / 0.844). 804 in / out 0.902 / 0.781 (paper replicate 0.903 / 0.781). The largest per-cohort deltas are on Dataset803: myelom-ct −0.009 [−0.010, −0.008] and spinegan-ct −0.005. Every other cohort is within ±0.004. In training. About 53 s/epoch on an A40, no non-finite losses in either run. The stronger ranges give a heavier tail of extreme values: 3 to 4 of 60 batches have a value beyond 15σ, against 0 to 1 of 60 for the paper config. It had no visible effect on training. The five functions fire on about 41% of batches together, and each draws its own strength. Bottom line: a null result. The defaults are bit-identical, so merging the options is harmless. There is no reason to change the paper config's ranges. |
What
Optional strength ranges for the five elementwise TAs, and lower bounds plus a kernel size for the unsharp mask. Every default is the old transform.
RandomLog1pGPUscale_rangelog(1 + k·x)RandomSqrtGPUexponent_rangex**gRandomSinGPUfrequency_rangesin(2π·f·x + φ), φ ~ U(0, 2π)RandomExpGPUrate_rangeexp(k·x)RandomSigmoidGPUslope_range,center_quantile_rangesigmoid(k·(x − c)), c = the sample's q-quantileRandomUnsharpMaskGPUsigma_min,amount_min,kernel_sizekernel_size: null→ 2⌈3σ⌉+1Draws are per sample, or once per batch with
same_on_batch.Why
Each elementwise TA min-max scales a sample to
[0, 1], applies a fixed function and, withretain_stats, restores mean and std. Only the function's curvature on[0, 1]survives. The table gives the share of output variance a linear map of the input cannot explain (1 − r²).A gamma of 0.7 or 1.5 is already 1.2-2.0%. At
p: 0.1each (the paper config), 41% of samples get at least one of the five and are effectively unchanged by it.The unsharp mask measured 0.01-0.9% with a gradient-magnitude correlation of 0.996 to its input. It draws σ from U(0, σ) onto a fixed 3-wide kernel, which truncates σ above about 0.5, and draws its amount from zero up.
[0, 1].Behaviour
_RandomFunctionBaseGPU(func=...).rand * xexactly (* (x − 0.0) + 0.0).all_augmentations.jsonregenerated.Tests
unit_tests/test_function_strength.py:same_on_batch;Full suite:
486 passed, 13 skipped.mypy smauglab/clean, pre-commit passes.🤖 Generated with Claude Code