Skip to content

Handling Overlapping Annotations in Mask2Former by A Small Trick #38054

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Ahmed-G-ElTaher
Copy link

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 coco2masks function, 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_sorted has been added with the following features:

  • Accepts an optional sort_by_area parameter (default: True).
  • Calculates the area of each instance when sorting is enabled.
  • Processes instances in descending order of their area.

This new function can serve as a direct replacement for the existing conversion function, providing improved handling of overlapping regions.

Testing

  • Tested with sample COCO annotations containing overlapping objects.
  • Verified that all objects are correctly represented in the output masks.
  • Confirmed compatibility with existing Mask2Former models.

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.

Copy link
Contributor

github-actions bot commented May 9, 2025

Hi 👋, thank you for opening this pull request! The pull request is converted to draft by default. The CI will be paused while the PR is in draft mode. When it is ready for review, please click the Ready for review button (at the bottom of the PR page). This will assign reviewers and trigger CI.

@github-actions github-actions bot marked this pull request as draft May 9, 2025 21:12
@Ahmed-G-ElTaher Ahmed-G-ElTaher marked this pull request as ready for review May 9, 2025 21:16
@github-actions github-actions bot requested a review from qubvel May 9, 2025 21:16
@Ahmed-G-ElTaher
Copy link
Author

@NielsRogge can you review the pull request please.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant