-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Add Image Processor Fast RT-DETR #34354
Add Image Processor Fast RT-DETR #34354
Conversation
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. |
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.
Thanks! Just a few nits - saw you were removing the kwargs validation as well, can we also do that for detr?
def prepare_coco_detection_annotation( | ||
image, | ||
target, | ||
return_segmentation_masks: bool = False, |
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.
return_segmentation_masks
is unused here, could either reuse the one from detr_fast
so we have a # Copied from statement here?
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.
Yes it's a bit weird, return_segmentation_masks
is present in several places, but rt-detr does not support segmentation. I added a copied from here, with an Ignore copy for the segmentation part (as otherwise we would need to import/copy a function that would never be used.
EDIT: actually the Ignore copy makes the CI crash, not sure why, so I left it as is for now...
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.
# Ignore copy
does not work like this 😉 forget about it in this case!
src/transformers/models/rt_detr/image_processing_rt_detr_fast.py
Outdated
Show resolved
Hide resolved
cb68014
to
2ccaaa0
Compare
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.
Thanks for working on this!
A few more nits, overall good, IMO all your graph should be placed in the documentation as well and not just on the PR description!
src/transformers/models/rt_detr/image_processing_rt_detr_fast.py
Outdated
Show resolved
Hide resolved
def prepare_coco_detection_annotation( | ||
image, | ||
target, | ||
return_segmentation_masks: bool = False, |
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.
# Ignore copy
does not work like this 😉 forget about it in this case!
src/transformers/models/rt_detr/image_processing_rt_detr_fast.py
Outdated
Show resolved
Hide resolved
src/transformers/models/rt_detr/image_processing_rt_detr_fast.py
Outdated
Show resolved
Hide resolved
src/transformers/models/rt_detr/image_processing_rt_detr_fast.py
Outdated
Show resolved
Hide resolved
src/transformers/models/rt_detr/image_processing_rt_detr_fast.py
Outdated
Show resolved
Hide resolved
src/transformers/models/rt_detr/image_processing_rt_detr_fast.py
Outdated
Show resolved
Hide resolved
src/transformers/models/rt_detr/image_processing_rt_detr_fast.py
Outdated
Show resolved
Hide resolved
b22bf32
to
2960859
Compare
@ArthurZucker Refactored DETR and RT-DETR image processor fast to loop as few times as possible over annotations and images, and added some docs! |
Does this improve the perf you saw? 😉 |
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.
Thanks for iterating with me! 🤗
Thank you!
Hmm hard to tell, maybe very slightly when on GPU, as on CPU the potential gains are overshadowed by the processing time. But at least it's cleaner that way! :) |
What does this PR do?
Adds a fast image processor for RT-DETR. Follows issue #33810.
This image processor is a result of this work on comparing different image processing method.
The diffs look bad but this PR is almost exclusively made up of
# Copied from
based on the fast image processor for DETR!Implementation
See #34063
Usage
Except for the fact that it only returns torch tensors, this fast processor is fully compatible with the current one.
It can be instantiated through AutoImageProcessor with use_fast=True, or through the Class directly:
Usage is the same as the current processor, except for the
device
kwarg:If
device
is not specified:Performance gains
batch_size=1
.batch_size=8
.Tests
Who can review?
@ArthurZucker Pinging you directly as there is almost no "new" code here.