Repository navigation
Add convert_segmentation_map_to_binary_masks_sorted function for hand… - #40446
Closed
Ahmed-G-ElTaher wants to merge 3 commits into
Closed
Ahmed-G-ElTaher wants to merge 3 commits into
Ahmed-G-ElTaher wants to merge 3 commits into
Conversation
…ling overlapping annotations This commit adds a new function that extends the base mask conversion functionality with area-based sorting capability. Key improvements: - Sorts segmentation masks by area (largest first) to handle overlapping annotations - Maintains compatibility with existing convert_segmentation_map_to_binary_masks API - Includes comprehensive tests covering basic functionality, edge cases, instance mapping, and area ordering - Provides detailed documentation with examples demonstrating usage for overlapping object scenarios The area-based sorting is particularly useful for Mask2Former models when processing images with overlapping object annotations, ensuring consistent mask ordering for training and inference.
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: mask2former |
Member
Collaborator
|
Thanks for the PR, and sorry it didn't make it in! This branch is based on v4, and v5 is very different, so rather than rebasing we'd love to invite you to open a new PR against
Closing this one in the meantime, thanks again! |
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.
Pull Request: Add Support for Handling Overlapping Annotations in Mask2Former
Problem
The current image processing pipeline for Mask2Former doesn't handle overlapping annotations correctly. When annotations overlap, the processing order is arbitrary, causing larger objects to sometimes be overwritten by smaller ones. This can lead to information loss and incorrect segmentation masks.
Solution
This PR introduces a new function,
convert_segmentation_map_to_binary_masks_sorted, that addresses this issue by processing object instances in descending order of their area. This ensures that smaller objects consistently appear on top of larger objects, preserving all annotation information in overlapping regions.The implementation draws inspiration from the approach used in the
coco2masksfunction, which sorts annotations by area before processing them. This enhancement is particularly beneficial for datasets with significant object overlaps.Changes
A new function
convert_segmentation_map_to_binary_masks_sortedhas been added with the following features:sort_by_areaparameter (default:True).This new function can serve as a direct replacement for the existing conversion function, providing improved handling of overlapping regions.
Testing
Performance Impact
While the area calculation introduces a minor computational overhead, its impact is negligible within the overall processing pipeline. This step occurs during preprocessing rather than during model inference.