fix: apply SynthSeg's probability per sample, not per batch - #109
Open
Hendrik-code wants to merge 1 commit into
Open
Hendrik-code wants to merge 1 commit into
Hendrik-code wants to merge 1 commit into
Conversation
`SynthSegTransformsGPU.forward` drew a single `torch.rand(())` and returned the batch untouched if it lost, so `probability=0.5` meant "half of all batches are entirely synthetic" rather than "half of all samples are". The network saw all-synthetic and all-real batches instead of a mix of both in each -- a different training signal, and out of step with the per-sample convention every other transform here follows. The generator now runs on the selected rows only and the result is spliced back, so the unselected samples come out bit-identical rather than merely unchanged in expectation. Scope: this class is the standalone driver and carries no registry entry, so no shipped config reaches it. The registered RandomSynthSegGPU gets its per-sample behaviour from kornia and is untouched. Co-Authored-By: Claude Opus 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.
The defect
One draw for the whole batch.
probability=0.5therefore meant "half of all batches are entirely synthetic", not "half of all samples are" — the network saw all-synthetic and all-real batches rather than a mix of both in each. That is a different training signal, and it is out of step with the per-sample convention every other transform in the package follows.Measured
At
B=8,probability=0.5, synthesised rows per batch over five seeds:Scope
SynthSegTransformsGPUis the standalone driver and carries no registry entry, so no shipped config reaches it —transform_params_paper-synthseg.jsonuses the registeredRandomSynthSegGPU, whose per-samplepcomes from kornia and is untouched here. Nothing in the package calls this class outside its own smoke test.The fix
Draw a per-sample mask, run the generator on the selected rows only, and splice the result back. The unselected samples come out bit-identical rather than merely unchanged in expectation, and the all-selected case still returns the generator's output directly.
Tests
unit_tests/test_synthseg_probability.py: a middling probability must split the batch; 1.0 synthesises everything and 0.0 nothing; unselected rows keep both their image and their labels bit-identical; shape and finiteness hold.Verified failing before the fix and passing after. Full suite unchanged against baseline;
ruff check .clean.🤖 Generated with Claude Code