fix(data): correct GaussianBlur probability semantics#342
Open
Ace3Z wants to merge 1 commit into
Open
Conversation
The `GaussianBlur` transform in `dinov3/data/transforms.py` passed `1 - p` to `torchvision.transforms.v2.RandomApply`, inverting the meaning of `p`: calling `GaussianBlur(p=1.0)` actually never blurred the image, while `GaussianBlur(p=0.0)` blurred every image. Maintainer `@mseitzer` confirmed the bug in facebookresearch#286: one global crop was never blurred at training time despite the nominal `p=1.0`, and view 2 was blurred ~90% of the time despite a nominal `p=0.1`. Remove the `1 - p` inversion so `GaussianBlur(p=X)` actually applies blur with probability `X`, matching `v2.RandomApply`'s documented semantics. The augmentation call sites in `dinov3/data/augmentations.py` were inverted in the same commit to preserve the de-facto behavior used to train released DINOv3 / DINOv2 checkpoints (per the maintainer's direction to "align the code of the augmentations with the actual behavior"). A comment documents why the nominal probabilities differ from BYOL Table 6. Add `tests/test_gaussian_blur_probability.py` with four cases that pass against the fix and fail against the previous inversion (3 of 4 fail on `origin/main`). Closes facebookresearch#286
9df8e1b to
d13bc80
Compare
Author
|
Friendly ping @patricklabatut. This is a small fix for #286 (the GaussianBlur probability inversion) that @mseitzer confirmed in the thread. It preserves the behavior of released checkpoints. Whenever you have a moment, would appreciate a review. |
Author
|
Friendly ping. @patricklabatut, would you have a moment to take a look? Small probability semantics fix in |
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.
Closes #286.
GaussianBlurindinov3/data/transforms.pywas passing1 - ptov2.RandomApply. The existing comment was wrong about howRandomApplyworks: it usespas the probability of applying the transform, not the probability of returning the original image. SoGaussianBlur(p=1.0)actually never blurred andGaussianBlur(p=0.0)always did. @mseitzer confirmed this in the issue, including the downstream effect that one global crop was never being blurred at training time.Removed the
1 - pinversion so the class does what its parameter name says. Then swapped the call site values inaugmentations.pyto preserve the actual behavior used to train released DINOv3 and DINOv2 checkpoints (as requested in the issue thread). The mapping isp=1.0->p=0.0,p=0.1->p=0.9,p=0.5unchanged. Added a one line comment so the next reader doesn't wonder why these don't match BYOL Table 6.To sanity check that behavior is preserved, I ran the full
DataAugmentationDINOpipeline on 200 random images with paired seeds and hashed all 14 crops per image, comparing against main. Zero mismatches across 2800 tensor hashes. The all-True mask the unfixed code passed is mathematically equivalent to None for the attention path, so this is a code cleanup, not a distribution change.The same bug exists in DINOv2 (
dinov2/data/transforms.py). Someone else has it on PR #411 over there.