Fixed VitDet for non-squre Images - #35969
Conversation
|
Hey @cjfghk5697! Thanks for opening a PR 🤗 Feel free to ping me when it's ready for review |
|
@qubvel Thanks for your response! Would you like me to provide a mock code to check the tuple case? |
qubvel
left a comment
There was a problem hiding this comment.
Thanks! Can you please add a test to tests/models/test_modeling_vitdet.py which allows passing non-square image through the model
| if isinstance(config.image_size, tuple) and isinstance(config.patch_size, tuple): | ||
| input_size = tuple(i // p for i, p in zip(config.image_size, config.patch_size)) | ||
| elif isinstance(config.image_size, tuple) and not isinstance(config.patch_size, tuple): | ||
| input_size = tuple(i // config.patch_size for i in config.image_size) | ||
| elif not isinstance(config.image_size, tuple) and isinstance(config.patch_size, tuple): | ||
| input_size = tuple(config.image_size // p for p in config.patch_size) | ||
| else: | ||
| input_size = config.image_size // config.patch_size |
There was a problem hiding this comment.
| if isinstance(config.image_size, tuple) and isinstance(config.patch_size, tuple): | |
| input_size = tuple(i // p for i, p in zip(config.image_size, config.patch_size)) | |
| elif isinstance(config.image_size, tuple) and not isinstance(config.patch_size, tuple): | |
| input_size = tuple(i // config.patch_size for i in config.image_size) | |
| elif not isinstance(config.image_size, tuple) and isinstance(config.patch_size, tuple): | |
| input_size = tuple(config.image_size // p for p in config.patch_size) | |
| else: | |
| input_size = config.image_size // config.patch_size | |
| image_size = config.image_size | |
| image_size = image_size if isinstance(image_size, (list, tuple)) else (image_size, image_size) | |
| patch_size = config.patch_size | |
| patch_size = patch_size if isinstance(patch_size, (list, tuple)) else (patch_size, patch_size) | |
| input_size = (config.image_size[0] // config.patch_size[0], config.image_size[1] // config.patch_size[1]) |
Co-authored-by: Pavel Iakubovskii <qubvel@gmail.com>
…7/transformers into issue/vitDet-nonsquare
|
@qubvel, thank you for reviewing it🤗. I've finished adding the test code. Could you please check it again? |
qubvel
left a comment
There was a problem hiding this comment.
Thanks, to ensure CI is green, please run make modified_only_fixup to reformat the code 🤗
|
@qubvel I’ve finished running |
|
hm... something goes wrong, probably you have older/newer version of ruff? Can you please check and update accordingly? |
I tried running it with |
|
It's ruff 0.5.1 in my env, it might be that you are running with no |
|
It's better to delete 3 last commits, apply a modified fixup, and then force push |
fb2998f to
713e610
Compare
|
@qubvel Sorry about that! I created a new environment and deleted some commits, which ended up modifying the fixup. Let me know if anything needs to be adjusted. |
|
@qubvel Can you review it again? |
|
Hey @cjfghk5697 can you please fix quality issues? most probably |
|
@qubvel Thank you for your help. I checked and discovered that there was an issue with my environment. I've applied the fix!🤗 |
|
Hey @cjfghk5697, with the recent modification we have a bunch of tests failed, can you please check what should be fixed? |
|
I think I got why tests failed, I hope you don't mind I've pushed the fix 🤗 |
|
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. |
|
cc @yonigozlan can you take a look |
|
@qubvel I sincerely appreciate your help in successfully wrapping up this task🤗 |
yonigozlan
left a comment
There was a problem hiding this comment.
Looks great to me @cjfghk5697 ! Thanks for making the model more flexible 🤗
|
|
||
| def test_non_square_image(self): | ||
| non_square_image_size = (32, 40) | ||
| patch_size = (2, 2) |
There was a problem hiding this comment.
I don't know too much about this model, but do we also want to test a non-square patch size?
There was a problem hiding this comment.
yeah, maybe a bit out of scope for this PR, but should also work
What does this PR do?
Fixes #35280 (issue)
The VitDet model doesn't support tuple-type inputs for image_size and patch_size. I’ve fixed it so that tuples can now be used.
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
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 @amyeroberts