Skip to content

fix: correct off-by-one error in windowed DINOv2 early stopping#523

Open
lixiaolei1982 wants to merge 1 commit intoroboflow:developfrom
lixiaolei1982:fix/windowed-dinov2-early-stopping-off-by-one
Open

fix: correct off-by-one error in windowed DINOv2 early stopping#523
lixiaolei1982 wants to merge 1 commit intoroboflow:developfrom
lixiaolei1982:fix/windowed-dinov2-early-stopping-off-by-one

Conversation

@lixiaolei1982
Copy link
Contributor

Fixed an off-by-one error in the early stopping logic of WindowedDinov2WithRegistersEncoder.forward().

Bug: The condition if i > int(self.config.out_features[-1][5:]): incorrectly compares a 0-based layer index (i) with a 1-based stage number.

Fix: Changed to if i > int(self.config.out_features[-1][5:]) - 1: to properly convert the stage number to a 0-based index before comparison.

Example:
If out_features[-1] = "stage8", stage number = 8
Corresponding layer index = 7 (0-based)
Old condition: i > 8 → never true for i in [0, 11]
New condition: i > 7 → stops when i reaches 8

Impact: The encoder now correctly stops after processing the last required transformer layer, improving computational efficiency.

- Changed if i > int(self.config.out_features[-1][5:]): to
  if i > int(self.config.out_features[-1][5:]) - 1:
- Properly compares 0-based layer indices with 1-based stage numbers
- Encoder now correctly stops after processing last required layer
- Improves computational efficiency for partial feature extraction
@Borda Borda self-requested a review January 12, 2026 20:32
@Borda Borda added the bug Something isn't working label Jan 22, 2026
@Borda Borda requested a review from isaacrob as a code owner February 11, 2026 15:57
@Borda Borda force-pushed the develop branch 4 times, most recently from 60b16c1 to 523f9df Compare February 14, 2026 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working has conflicts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants