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

owlvit/2 dynamic input resolution. #34764

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bastrob
Copy link
Contributor

@bastrob bastrob commented Nov 17, 2024

What does this PR do?

Towards #30579
Hey, this is a draft, Im wondering how can we manage the variables impacted by the dynamic input change in the OwlViTForObjectDetection class (self.sqrt_num_patches, self.box_bias) ?
Is there a better way to handle this ?

The interpolate_pos_encoding allows new input size respecting height==width strictly ?
In that case I should ensure this.
If not, I think sqrt_num_patches needs to be decomposed too (_h, _w), some examples where it might throws exc:
https://github.com/bastrob/transformers/blob/30f3c2d56729974ec0d1d9e2fc4fd633ab697eb2/src/transformers/models/owlvit/modeling_owlvit.py#L1355
https://github.com/bastrob/transformers/blob/30f3c2d56729974ec0d1d9e2fc4fd633ab697eb2/src/transformers/models/owlvit/modeling_owlvit.py#L1459
https://github.com/bastrob/transformers/blob/30f3c2d56729974ec0d1d9e2fc4fd633ab697eb2/src/transformers/models/owlvit/modeling_owlvit.py#L1719

Before submitting

Who can review?

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

Copy link
Member

@qubvel qubvel left a comment

Choose a reason for hiding this comment

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

Hi @bastrob! Thanks for opening PR!

It would be great to enable any image resolution, but If you will not find a way to manage height != width images we can limit it to a square input image size. We just have to make sure the proper error is raised.

Comment on lines +1476 to +1479
_, _, height, width = pixel_values.shape
# height must eq width.
self.sqrt_num_patches = height // self.config.vision_config.patch_size
self.box_bias = self.compute_box_bias(self.sqrt_num_patches)
Copy link
Member

Choose a reason for hiding this comment

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

I assume we can always use this code path without if/else

Comment on lines +1521 to +1525
_, _, height, width = pixel_values.shape
# height must eq width.
self.sqrt_num_patches = height // self.config.vision_config.patch_size
self.box_bias = self.compute_box_bias(self.sqrt_num_patches)
else:
Copy link
Member

Choose a reason for hiding this comment

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

Same here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants