fix(seg): filter unlabeled images and fix mask-loss DDP graph disconnect#323
Open
imagra93 wants to merge 2 commits into
Open
fix(seg): filter unlabeled images and fix mask-loss DDP graph disconnect#323imagra93 wants to merge 2 commits into
imagra93 wants to merge 2 commits into
Conversation
Contributor
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
Contributor
|
I'm concerned that this PR is dropping the unlabelled images basically (often called background images)d, but background images are useful in order to avoid the model to detect false positives when there isn't an object in the image. |
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
DDP segmentation training (
static_graph=True) crashes when the dataset contains unlabeled images. Two independent code paths contribute:Disconnected gradient in
loss_masks— when a rank's batch haszero Hungarian matches, the factored mask-head branch returns
torch.tensor([], device=device). This tensor has nograd_fn, sospatial_features,query_features, andbiasare silently droppedfrom the backward graph on that rank, violating
static_graph=True.Unlabeled images in the dataloader — images with no annotation
file inflate the dataset and can produce all-unlabeled batches on some
ranks, making the no-match case structurally inevitable.
Fixes #291
Solution
libreyolo/models/rfdetr/loss.pyReturn zero losses routed through the mask-head tensors instead of a
disconnected empty tensor:
Every mask-head parameter participates in backward (with zero gradient),
satisfying DDP's reducer regardless of batch content.
libreyolo/data/dataset.pyNew filter_empty_annotations: bool = False parameter on YOLODataset.
When True, zero-annotation images are dropped at construction time. A
warning is logged (main process only) with the count of dropped images.
Raises ValueError if the entire dataset is unlabeled.
libreyolo/training/trainer.pyfilter_empty_annotations=load_segments passed to all three
YOLODataset construction sites, enabling the filter automatically for
every segmentation training path.