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

center_crop outputs wrong sized array if provided with odd-numbered dimensions smaller than requested crop size #30922

Closed
2 of 4 tasks
mattlbeck opened this issue May 20, 2024 · 1 comment · Fixed by #30934

Comments

@mattlbeck
Copy link
Contributor

System Info

transformers 4.40.1, python 3.12

Who can help?

@amyeroberts

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • My own task or dataset (give details below)

Reproduction

from transformers.image_transforms import center_crop
import numpy as np
small_even = np.ones((3,4,4))
small_odd = np.ones((3,3,3))
big_even = np.ones((3,10,10))
big_odd = np.ones((3,11,11))
print([center_crop(x, (8,8)).shape for x in [small_even, big_even, big_odd, small_odd]])

Result:

[(3, 8, 8), (3, 8, 8), (3, 8, 8), (3, 7, 7)]

Expected behavior

All arrays should be cropped to the requested size of (8,8). However, odd-numbered dimensions that are smaller than the crop size and require padding result in an unexpected off-by-one output size.

@mattlbeck
Copy link
Contributor Author

I believe the issue is more accurately caused by odd-numbered difference between original size and new size. Rounding up rather than down when calculating the padding fixes the above test cases.

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 a pull request may close this issue.

1 participant