-
Notifications
You must be signed in to change notification settings - Fork 31.7k
Add Swin2SR ImageProcessorFast #37169
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
Add Swin2SR ImageProcessorFast #37169
Conversation
|
Hi 👋, thank you for opening this pull request! The pull request is converted to draft by default. The CI will be paused while the PR is in draft mode. When it is ready for review, please click the |
yonigozlan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @thisisiron , thanks for working on this! A few things to fix, otherwise LGTM
src/transformers/models/swin2sr/image_processing_swin2sr_fast.py
Outdated
Show resolved
Hide resolved
src/transformers/models/swin2sr/image_processing_swin2sr_fast.py
Outdated
Show resolved
Hide resolved
yonigozlan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed a few things in my first review. Also since there is very little processing happening here, the fast processors doesn't look faster than the slow on cpu, so we might need to modify or skip test_fast_is_faster_than_slow
| def test_slow_fast_equivalence(self): | ||
| image_inputs = self.image_processor_tester.prepare_image_inputs(equal_resolution=False, torchify=True)[0] | ||
|
|
||
| image_processor_slow = self.image_processing_class(**self.image_processor_dict, crop_to_patches=True) | ||
| image_processor_fast = self.fast_image_processing_class(**self.image_processor_dict, crop_to_patches=True) | ||
|
|
||
| encoded_slow = image_processor_slow(image_inputs, return_tensors="pt").pixel_values | ||
| encoded_fast = image_processor_fast(image_inputs, return_tensors="pt").pixel_values | ||
|
|
||
| self.assertTrue(torch.allclose(encoded_slow, encoded_fast, atol=1e-1)) | ||
|
|
||
| def test_slow_fast_equivalence_batched(self): | ||
| image_inputs = self.image_processor_tester.prepare_image_inputs(equal_resolution=True, torchify=True) | ||
|
|
||
| image_processor_slow = self.image_processing_class(**self.image_processor_dict, crop_to_patches=True) | ||
| image_processor_fast = self.fast_image_processing_class(**self.image_processor_dict, crop_to_patches=True) | ||
|
|
||
| encoded_slow = image_processor_slow(image_inputs, return_tensors="pt").pixel_values | ||
| encoded_fast = image_processor_fast(image_inputs, return_tensors="pt").pixel_values | ||
|
|
||
| self.assertTrue(torch.allclose(encoded_slow, encoded_fast, atol=1e-1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why this is overidden?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test_slow_fast_equivalence is unnecessary, but I added test_slow_fast_equivalence_batched because it can handle cases in batch when the image sizes are the same. And crop_to_patches=True will be removed.
| for image_processing_class in self.image_processor_list: | ||
| image_processing = image_processing_class(**self.image_processor_dict) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be done for all tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ran the following command:
RUN_SLOW=1 python -m pytest tests/models/swin2sr/test_image_processing_swin2sr.py
The log below shows the result of executing the above command.
configfile: pyproject.toml
plugins: timeout-2.3.1, hypothesis-6.124.2, anyio-4.8.0, asyncio-0.23.8, rich-0.2.0, xdist-3.6.1
asyncio: mode=strict
collected 18 items
tests/models/swin2sr/test_image_processing_swin2sr.py::Swin2SRImageProcessingTest::test_call_numpy PASSED [ 5%]
tests/models/swin2sr/test_image_processing_swin2sr.py::Swin2SRImageProcessingTest::test_call_numpy_4_channels PASSED [ 11%]
tests/models/swin2sr/test_image_processing_swin2sr.py::Swin2SRImageProcessingTest::test_call_pil PASSED [ 16%]
tests/models/swin2sr/test_image_processing_swin2sr.py::Swin2SRImageProcessingTest::test_call_pytorch PASSED [ 22%]
tests/models/swin2sr/test_image_processing_swin2sr.py::Swin2SRImageProcessingTest::test_can_compile_fast_image_processor PASSED [ 27%]
tests/models/swin2sr/test_image_processing_swin2sr.py::Swin2SRImageProcessingTest::test_cast_dtype_device PASSED [ 33%]
tests/models/swin2sr/test_image_processing_swin2sr.py::Swin2SRImageProcessingTest::test_fast_is_faster_than_slow PASSED [ 38%]
tests/models/swin2sr/test_image_processing_swin2sr.py::Swin2SRImageProcessingTest::test_image_processor_from_and_save_pretrained PASSED [ 44%]
tests/models/swin2sr/test_image_processing_swin2sr.py::Swin2SRImageProcessingTest::test_image_processor_preprocess_arguments PASSED [ 50%]
tests/models/swin2sr/test_image_processing_swin2sr.py::Swin2SRImageProcessingTest::test_image_processor_properties PASSED [ 55%]
tests/models/swin2sr/test_image_processing_swin2sr.py::Swin2SRImageProcessingTest::test_image_processor_save_load_with_autoimageprocessor PASSED [ 61%]
tests/models/swin2sr/test_image_processing_swin2sr.py::Swin2SRImageProcessingTest::test_image_processor_to_json_file PASSED [ 66%]
tests/models/swin2sr/test_image_processing_swin2sr.py::Swin2SRImageProcessingTest::test_image_processor_to_json_string PASSED [ 72%]
tests/models/swin2sr/test_image_processing_swin2sr.py::Swin2SRImageProcessingTest::test_init_without_params PASSED [ 77%]
tests/models/swin2sr/test_image_processing_swin2sr.py::Swin2SRImageProcessingTest::test_save_load_fast_slow PASSED [ 83%]
tests/models/swin2sr/test_image_processing_swin2sr.py::Swin2SRImageProcessingTest::test_save_load_fast_slow_auto PASSED [ 88%]
tests/models/swin2sr/test_image_processing_swin2sr.py::Swin2SRImageProcessingTest::test_slow_fast_equivalence PASSED [ 94%]
tests/models/swin2sr/test_image_processing_swin2sr.py::Swin2SRImageProcessingTest::test_slow_fast_equivalence_batched PASSED [100%]
============================================================================================================ 18 passed in 6.78s ============================================================================================================
@yonigozlan, Then would it be better to skip it? |
c853267 to
664fb0c
Compare
|
|
@yonigozlan, I’ve added the skip to the test. |
yonigozlan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great thanks for contributing! LGTM :)
|
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. |
* Add fast image processor support for Swin2SR * Add Swin2SR tests of fast image processing * Update docs and remove unnecessary test func * Fix docstring formatting * Skip fast vs slow processing test --------- Co-authored-by: Yoni Gozlan <[email protected]>
What does this PR do?
#36978
Add fast image processor for Swin2SR
cc @yonigozlan