Fix segmentation preprocessing to pixel-centre sampling - #21797
Merged
TurboGit merged 1 commit intoAug 10, 2026
Conversation
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.
Follow-up to #21764
That PR fixed the mask side, but
_preprocess_image()still samples aty / scale, so the encoder sees the image shifted by0.5/scale - 0.5source pixels and bakes that into every mask. It is a uniform shift, so it does not cancel anywhere: 1.5 px at 4000 → 1024, 2.4 px at 6000 → 1024, 5.4 px at 6000 → 512.With both ends on the same convention the round trip is exact. The
MAX(..., 0.0f)keeps(int)a floor andfy >= 0, same as in_crop_resize_mask; I swept the usual sizes and found no index outside the source and no weight outside[0, 1).SEG_CACHE_VERSIONgoes to 2 because the cache stores encoder outputs, which are now different numbers. Its key (imgid, distort hash, model) cannot notice a code change, so otherwise previously opened images would keep serving embeddings from the old sampling. Cost is one re-encode per cached image.