[DETR] Update the processing to adapt masks & bboxes to reflect padding#28363
Merged
amyeroberts merged 7 commits intohuggingface:mainfrom Feb 13, 2024
Merged
Conversation
7482b3d to
3c819b0
Compare
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
af6fdbf to
e41cbc2
Compare
DETR] Update the processing to adapt masks to reflect padding
7d5e944 to
bb22bc6
Compare
DETR] Update the processing to adapt masks to reflect paddingDETR] Update the processing to adapt masks & bboxes to reflect padding
ydshieh
approved these changes
Feb 13, 2024
Collaborator
ydshieh
left a comment
There was a problem hiding this comment.
Thank you @amyeroberts , LGTM.
I would suggest to make the docstring in normalize_annotation more precisely: i.e. mention it also change the coordinates to relative one.
def normalize_annotation(self, annotation: Dict, image_size: Tuple[int, int]) -> Dict:
"""
Normalize the boxes in the annotation from `[top_left_x, top_left_y, bottom_right_x, bottom_right_y]` to
`[center_x, center_y, width, height]` format.
"""
return normalize_annotation(annotation, image_size=image_size)And also make the fact that padding is done in bottom-right explicitly.
Both of these could be done in follow up PRs.
4 tasks
5 tasks
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.
What does this PR do?
Fixes an issue with the processing of batches of images for DETR and DETR related models.
Previously, the annotations for the models - specifically the masks and bboxes, wouldn't be updated to account for the new image sizes if padding occurred. This PR pads the masks to match their corresponding masks.
The following images show the processing behaviour for annotations when there are two images in the batch, of different sizes.
Fixes #28153
Bounding boxes
In the previous processing logic, there were two possible scenarios:
do_normalize=Falsethen no action is needed. The output bboxes are not in relative format.do_normalize=Truethe relative coordinates of the bbox needs to be updated to account for the additional pixels when padding.This PR:
do_convert_annotationswhich enables the user to control whether the bboxes are converted independent ofdo_normalize. This is useful because 1) the normalization of bounding boxes is independent of the pixel values 2) The currentnormalize_annotationslogic both normalizes AND converts to a different bbox format ((x0, y0, x1, y1)->(center_x, center_y, width, height))do_convert_annotations=True. Ifdo_convert_annotations=Falsethis isn't necessary.Here we see the input and output images, and their bbox annotations.
On main:

On this branch:

Masks
Masks are updated so they have the same padding as their corresponding image.
Here are the input and output images and masks:
On main:

On this branch:

On main:

On this branch:

Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.