-
Notifications
You must be signed in to change notification settings - Fork 27k
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
[DETR
] Update the processing to adapt masks & bboxes to reflect padding
#28363
[DETR
] Update the processing to adapt masks & bboxes to reflect padding
#28363
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
…ding (huggingface#28363) * Update the processing so bbox coords are adjusted for padding * Just pad masks * Tidy up, add tests * Better tests * Fix yolos and mark as slow for pycocotols * Fix yolos - return_tensors * Clarify padding and normalization behaviour
…ding (#28363) * Update the processing so bbox coords are adjusted for padding * Just pad masks * Tidy up, add tests * Better tests * Fix yolos and mark as slow for pycocotols * Fix yolos - return_tensors * Clarify padding and normalization behaviour
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=False
then no action is needed. The output bboxes are not in relative format.do_normalize=True
the relative coordinates of the bbox needs to be updated to account for the additional pixels when padding.This PR:
do_convert_annotations
which 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_annotations
logic 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=False
this 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.