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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃毃 Update image_processing_vitmatte.py #30566

Merged
merged 3 commits into from May 2, 2024

Conversation

rb-synth
Copy link
Contributor

In the previous implementation, if either dimension wasn't divisible by factor, then both would be padded even if only one needed it.

For example, for divisible factor 32, if I have an image of size (1024, 819), then I would expect a padded size of (1024, 832). However, with the current implementation, even though 1024 is divisible by 32, it will be padded by a full 32 pixels, and the output size is (1056, 832).

This PR fixes that 馃悰 by computing dimensions individually.

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 handling this!

Could you add a test?

pad_width = size_divisibility - width % size_divisibility
pad_height = 0 if height % size_divisibility == 0 else size_divisibility - height % size_divisibility
pad_width = 0 if width % size_divisibility == 0 else size_divisibility - width % size_divisibility
if pad_width + pad_height > 0:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice :)

@rb-synth
Copy link
Contributor Author

Test added! be4e44b

@amyeroberts
Copy link
Collaborator

@rb-synth Great! Last thing is to make sure the slow tests for the model still pass:

RUN_SLOW=1 pytest tests/models/vitmatte/

Once you've confirmed they're all passing (or not different from running on main) then we're good to merge!

@rb-synth
Copy link
Contributor Author

doesn't work locally for me (neither does main).

RUN_SLOW=1 pytest tests/models/vitmatte/
=================================================================================================================================== test session starts ===================================================================================================================================
platform darwin -- Python 3.9.19, pytest-8.2.0, pluggy-1.5.0
rootdir: /Users/richard.brown/Downloads/transformers
configfile: pyproject.toml
collected 121 items / 1 error                                                                                                                                                                                                                                                             

========================================================================================================================================= ERRORS ==========================================================================================================================================
________________________________________________________________________________________________________ ERROR collecting tests/models/vitmatte/test_image_processing_vitmatte.py _________________________________________________________________________________________________________
../../Documents/Code/miniconda3/envs/temp/lib/python3.9/unittest/case.py:462: in __hash__
    return hash((type(self), self._testMethodName))
E   AttributeError: 'VitMatteImageProcessingTester' object has no attribute '_testMethodName'
==================================================================================================================================== warnings summary =====================================================================================================================================
../../Documents/Code/miniconda3/envs/temp/lib/python3.9/site-packages/_pytest/config/__init__.py:1448
  /Users/richard.brown/Documents/Code/miniconda3/envs/temp/lib/python3.9/site-packages/_pytest/config/__init__.py:1448: PytestConfigWarning: Unknown config option: doctest_glob
  
    self._warn_or_fail_if_strict(f"Unknown config option: {key}\n")

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
================================================================================================================================= short test summary info =================================================================================================================================
ERROR tests/models/vitmatte/test_image_processing_vitmatte.py::VitMatteImageProcessingTester - AttributeError: 'VitMatteImageProcessingTester' object has no attribute '_testMethodName'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
=============================================================================================================================== 1 warning, 1 error in 8.19s ===============================================================================================================================

@amyeroberts
Copy link
Collaborator

@rb-synth Interesting - it looks like there's an issue with test setup / env. Running pip install -e .[testing] should install all the necessary packages for running, which sometimes cause issues like this.

Last night, we merge in a feature enabling us to run specific slow model tests on our github action runners. This is useful as sometimes there's differences which arise from hardward and environments.

To enable this for the vitmatte tests could you:

  • Rebase on main to include the latest changes
  • Push an empty commit with the message [run-slow]vitmatte

@rb-synth
Copy link
Contributor Author

rb-synth commented May 2, 2024

Have done that now

@rb-synth
Copy link
Contributor Author

rb-synth commented May 2, 2024

Also tried the testing on a different machine and it completed without any issues:

RUN_SLOW=1 pytest tests/models/vitmatte
=================================================================================================================================== test session starts ===================================================================================================================================
platform linux -- Python 3.10.14, pytest-7.4.4, pluggy-1.5.0
rootdir: /home/Documents/Code/transformers
configfile: pyproject.toml
plugins: timeout-2.3.1, xdist-3.6.1
collected 122 items                                                                                                                                                                                                                                                                       

tests/models/vitmatte/test_image_processing_vitmatte.py ............                                                                                                                                                                                                                [  9%]
tests/models/vitmatte/test_modeling_vitmatte.py .........ssssss...sssssssss...........s.......s....sss.sssssssssssssssssssssssssssss.s...s....sss..ss....ssss.                                                                                                                      [100%]

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

@amyeroberts
Copy link
Collaborator

@rb-synth Great! The slow tests on the github action runners are also all passing; and the quality checks are unrelated to this PR so we can merge.

I'm going to mark the PR title with an 馃毃 - as there's a possibility this could cause downstream changes for users who were relying on the previous behaviour. As this padding behaviour is more correct, and slow model tests are all OK, I think it's OK.

@amyeroberts amyeroberts changed the title Update image_processing_vitmatte.py 馃毃 Update image_processing_vitmatte.py May 2, 2024
@amyeroberts amyeroberts merged commit f953025 into huggingface:main May 2, 2024
19 of 21 checks passed
@rb-synth rb-synth deleted the patch-1 branch May 2, 2024 10:02
itazap pushed a commit that referenced this pull request May 14, 2024
* Update image_processing_vitmatte.py

* add test

* [run-slow]vitmatte
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.

None yet

3 participants