Repository navigation
fix: remove the padding again in predict_instance_mask(pad_size=n) - #78
Open
Hendrik-code wants to merge 3 commits into
Open
Hendrik-code wants to merge 3 commits into
Hendrik-code wants to merge 3 commits into
Conversation
`whole_vert_nii_uncropped.apply_pad(-pad_size)` is not an in-place call and its result was dropped, so any `pad_size > 0` returned a mask `2 * pad_size` voxels larger per axis than the one handed in -- while the docstring promised the padding was "removed afterwards". `predict_instance_mask` is part of the public API (`spineps.predict_instance_mask`); the pipeline itself always passes the default 0, which is why this never surfaced. The padding was also applied before the rescale to the model resolution, so even a rebound `apply_pad(-pad_size)` would have removed the wrong number of voxels whenever the input zoom differs from the model's. Padding now happens after the rescale, which makes the removal its exact inverse. `pad_size=0` -- every call in the pipeline -- is bit-for-bit unchanged (the golden regression digests still match). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Problem
NII.apply_padhasinplace=False, so the padding added at the top ofpredict_instance_maskwas neverremoved. On the shared test fixture:
The docstring says the padding is "removed afterwards".
predict_instance_maskis exported asspineps.predict_instance_mask, so a caller using the documented parameter gets a mask that does notline up with their input. The pipeline itself always passes the default
0, which is why this was nevernoticed.
A second defect sat behind it: the padding was applied before the rescale to the model resolution, so
pad_sizeinput voxels become a different number of voxels in the grid the un-pad operates on. Even acorrectly rebound
apply_pad(-pad_size)would have removed the wrong amount whenever the input zoomdiffers from the model's.
Fix
resolution.
pad_size=0-- every call inside the pipeline -- is bit-for-bit unchanged: the existingtest_regression_goldendigests still match.Tests
unit_tests/test_instance_pad_size.py:pad_size=4returns the same shape, affine and voxel content aspad_size=0, and the same holds for a model whose resolution forces a rescale. All 3 fail onmain.Full suite: 226 passed, ruff clean.
🤖 Generated with Claude Code