Repository navigation
feat: strength ranges for the five elementwise TAs, and bounds for the unsharp mask - #148
Open
Hendrik-code wants to merge 2 commits into
Open
Hendrik-code wants to merge 2 commits into
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>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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