Skip to content
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

Fix yolos resizing #27663

Merged
merged 3 commits into from
Dec 20, 2023
Merged

Conversation

amyeroberts
Copy link
Collaborator

@amyeroberts amyeroberts commented Nov 22, 2023

What does this PR do?

On main - running the following produces an image outside of the limits set by "longest_edge" in an images config:

from transformers import AutoProcessor
from PIL import Image
import requests

processor = AutoProcessor.from_pretrained("Xenova/yolos-small-300") # or hustvl/yolos-small-300
url = 'https://i.imgur.com/qOp3m0N.png' # very thin image

image = Image.open(requests.get(url, stream=True).raw).convert('RGB')
output = processor(image)
# Result
# main: (3, 89, 1335)
# branch: (3, 80, 1328)
print(output['pixel_values'][0].shape) 

This logic was copied from the DETR image processing logic which comes from the original DETR repo . Note: this means the DETR models' image processors won't respect longest_edge.

Yolos' image processor has been updated to reflect the original model.

Note - this also differers from the output image size that would be obtained from using torchvisions resize. In the above example, it would be (3, 88, 1333)

Fixes #27381

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Let's add a test? 😉

@amyeroberts amyeroberts merged commit 1d77735 into huggingface:main Dec 20, 2023
18 checks passed
@amyeroberts amyeroberts deleted the fix-yolos-resize-bug branch December 20, 2023 20:55
staghado pushed a commit to staghado/transformers that referenced this pull request Jan 15, 2024
* Fix yolos resizing

* Update tests

* Add a test
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.

YolosImageProcessor violates longest_edge constraint for certain images
2 participants