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 image post-processing for OWLv2 #30686

Merged
merged 9 commits into from May 9, 2024

Conversation

jla524
Copy link
Contributor

@jla524 jla524 commented May 7, 2024

What does this PR do?

Fixes #30131 (issue)

Who can review?

@NielsRogge @nisyad-ms

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.

Thanks for updating our example, @jla524!

This is something which should really be handled within the image processor of the model itself, specifically the rescaling of the box dimensions

@jla524 jla524 changed the title Add a note about OWLv2 example Fix post processing for the OWLv2 image processor May 7, 2024
@jla524 jla524 changed the title Fix post processing for the OWLv2 image processor Fix image post-processing for OWLv2 May 7, 2024
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.

Looks great - thanks for taking the time to update the example as well!

Technically this is a breaking change. However, as many users have highlighted this confusing behaviour and it should always have been done in the post-processing method, I think it's OK to add directly.

Final request is to add a test here so that we check the images and boxes are rescaled as expected in the post processing method. Once that's done I think we're good to merge!

@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.

@jla524
Copy link
Contributor Author

jla524 commented May 8, 2024

Looks great - thanks for taking the time to update the example as well!

Technically this is a breaking change. However, as many users have highlighted this confusing behaviour and it should always have been done in the post-processing method, I think it's OK to add directly.

Final request is to add a test here so that we check the images and boxes are rescaled as expected in the post processing method. Once that's done I think we're good to merge!

Added a test for the resize. I'm not sure if this is the right approach. Let me know what you think!

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.

Looks great - thanks for iterating on this!

For the test, have you visualized the bounding boxes to confirm they are sensible? It would be good to check this + bboxes on the examples to make sure everything is a-ok before merge. Otherwise looks good to go!

tests/models/owlv2/test_image_processor_owlv2.py Outdated Show resolved Hide resolved
Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>
@jla524
Copy link
Contributor Author

jla524 commented May 9, 2024

Looks great - thanks for iterating on this!

For the test, have you visualized the bounding boxes to confirm they are sensible? It would be good to check this + bboxes on the examples to make sure everything is a-ok before merge. Otherwise looks good to go!

Yes, the boxes look reasonable. One thing to note is that the box on the right is slightly out of bound. The box has a x_max of 642.32, whereas the image itself is 640 pixels.

image

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.

Thanks for fixing, adding tests and verifying the outputs!

@amyeroberts amyeroberts merged commit 218f441 into huggingface:main May 9, 2024
18 checks passed
zucchini-nlp pushed a commit to zucchini-nlp/transformers that referenced this pull request May 10, 2024
* feat: add note about owlv2

* fix: post processing coordinates

* remove: workaround document

* fix: extra quotes

* update: owlv2 docstrings

* fix: copies check

* feat: add unit test for resize

* Update tests/models/owlv2/test_image_processor_owlv2.py

Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>

---------

Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>
@ydshieh
Copy link
Collaborator

ydshieh commented May 13, 2024

Hi @jla524 Thank you for the fix.

Our doctesting for this model now has one failure. See below.

python3 -m pytest -v --make-reports doc_tests_gpu_docs_source_en_model_doc_owlv2.md --doctest-modules docs/source/en/model/doc/owlv2.md failures:
owlv2.md -sv --doctest-continue-on-failure --doctest-glob="*.md"

(on a T4 GPU machine)

I think it's expected? Would you like to take a look to confirm and open a pull request to update docs/source/en/model/doc/owlv2.md if that is the way to go?

Expected:
    Detected a photo of a cat with confidence 0.614 at location [341.67, 17.54, 642.32, 278.51]
    Detected a photo of a cat with confidence 0.665 at location [6.75, 38.97, 326.62, 354.85]
Got:
    Detected a photo of a cat with confidence 0.614 at location [341.67, 23.39, 642.32, 371.35]
    Detected a photo of a cat with confidence 0.665 at location [6.75, 51.96, 326.62, 473.13]

@jla524 jla524 deleted the fix_owlv2_example branch May 14, 2024 01:45
@jla524
Copy link
Contributor Author

jla524 commented May 14, 2024

@ydshieh Yes, I'll send in a PR to fix this.

@jla524 jla524 mentioned this pull request May 14, 2024
itazap pushed a commit that referenced this pull request May 14, 2024
* feat: add note about owlv2

* fix: post processing coordinates

* remove: workaround document

* fix: extra quotes

* update: owlv2 docstrings

* fix: copies check

* feat: add unit test for resize

* Update tests/models/owlv2/test_image_processor_owlv2.py

Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>

---------

Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>
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.

[Bug] Owlv2 Zero-Shot Object Detection
4 participants