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 image processor resizing #30436

Merged
merged 5 commits into from
Apr 24, 2024

Conversation

qubvel
Copy link
Member

@qubvel qubvel commented Apr 23, 2024

What does this PR do?

I observed that the YOLOS model failed with OOM while training. After some investigation, I found that square images are not properly resized by YOLOS image processor even if do_resize=True. The size parameter is not respected even if the max size of the image is larger than longest_edge.

Example to reproduce:

import torch
from transformers import YolosImageProcessor

images = torch.randint(0, 256, (1, 3, 1500, 1500), dtype=torch.uint8)
processor = YolosImageProcessor(size={"longest_edge": 1333, "shortest_edge": 800}, do_resize=True)

# Resize the image
result = processor(images=images, return_tensors="pt")
print(result["pixel_values"].shape)

# >>> torch.Size([1, 3, 1488, 1488])

I am going to

  1. submit a test that fails on square images
  2. submit a fix

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?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@qubvel qubvel changed the title [WIP] Fix YOLOS model resizing [WIP] Fix YOLOS image processor resizing Apr 23, 2024
@HuggingFaceDocBuilderDev

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.

@qubvel qubvel changed the title [WIP] Fix YOLOS image processor resizing Fix YOLOS image processor resizing Apr 23, 2024
@qubvel
Copy link
Member Author

qubvel commented Apr 23, 2024

@amyeroberts it's ready 🙂

Copy link
Collaborator

@amyeroberts amyeroberts left a comment

Choose a reason for hiding this comment

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

Beautiful - thanks for fixing and for updating the tests!

@amyeroberts amyeroberts merged commit 767e351 into huggingface:main Apr 24, 2024
18 checks passed
itazap pushed a commit that referenced this pull request May 14, 2024
* Add test for square image that fails

* Fix for square images

* Extend test cases

* Fix resizing in tests

* Style fixup
@HindIbraheem
Copy link

--

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.

None yet

4 participants