Skip to content

Conversation

@amyeroberts
Copy link
Contributor

What does this PR do?

Adds a warning in the image processor if the user is passing in images that have already had their pixel values rescale between 0 and 1 and do_rescale=True. Additionally adds information in the docstring.

This has caused some confusion and error reports recently, when users have been passing in images that have already been partially transformed.

Related issues: #25195, #24857, #23096

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

@amyeroberts amyeroberts changed the title Check if pixel values between 0-255 and add doc clarification ImageProcessor - check if input pixel values between 0-255 Aug 23, 2023
@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Aug 23, 2023

The documentation is not available anymore as the PR was closed or merged.

Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

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

Thanks, left a few nits on the doc!

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess we can also update the doc here

Copy link
Collaborator

Choose a reason for hiding this comment

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

same here I guess

Copy link
Collaborator

Choose a reason for hiding this comment

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

here too!

Copy link
Collaborator

Choose a reason for hiding this comment

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

And here

"""Preprocesses a single image."""
# All transformations expect numpy arrays.
image = to_numpy_array(image)
if _is_scaled_image(image) and do_rescale:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you think it makes sense to also set do_rescale = False ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't want to do anything "magic" and surprise the user.

Checking whether the pixels are correct isn't a perfect test, and it'd be modifying the processor behaviour under an assumption.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do was updated but forward does not have do_rescale and check not used

Copy link
Collaborator

Choose a reason for hiding this comment

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

doc needs to be udpated to?

Copy link
Collaborator

Choose a reason for hiding this comment

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

docstring can be updated to

Copy link
Collaborator

Choose a reason for hiding this comment

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

Only doc was updated, but no do_rescale exists

Copy link
Collaborator

Choose a reason for hiding this comment

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

doc can be updated!

Copy link
Contributor

@rafaelpadilla rafaelpadilla left a comment

Choose a reason for hiding this comment

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

Nice work! 🙂

Copy link
Contributor

@rafaelpadilla rafaelpadilla left a comment

Choose a reason for hiding this comment

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

Thank you!

@amyeroberts
Copy link
Contributor Author

@rafaelpadilla @ArthurZucker Thanks bot for your detailed reviews! I've added the suggested updated: making the function name consistent with others _is_scaled_image -> is_scaled_image and any missing doc updates.

@amyeroberts amyeroberts merged commit 1b2381c into huggingface:main Aug 24, 2023
@amyeroberts amyeroberts deleted the check-if-should-rescale branch August 24, 2023 16:24
parambharat pushed a commit to parambharat/transformers that referenced this pull request Sep 26, 2023
…ce#25688)

* Check if pixel values between 0-255 and add doc clarification

* Add missing docstrings

* _is_scale_image -> is_scaled_image

* Spelling is hard

* Tidy up
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 this pull request may close these issues.

4 participants