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

Fix image segmentation tool bug #23897

Merged

Conversation

amyeroberts
Copy link
Collaborator

What does this PR do?

Currently tools using the ImageSegmentation tool fail because the parameters for the image processor are overridden with the input image dimensions. This results in incompatible input dimensions being passed to the model.

This PR removes this logic in the encode method and removes the resizing in the tests which only happened for the segmentation tool and hid the issue.

Fixes #23328

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
Copy link
Collaborator Author

@sgugger @LysandreJik The fix is pretty simple, but in the spirit of Chesterton's fence, I wasn't sure/couldn't remember the reason for the self.pre_processor.image_processor.size = ... logic so wanted to ask you both in case this is breaking assumptions elsewhere.

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented May 31, 2023

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

Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

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

LGTM but let's wait for @LysandreJik as he wrote this tool :-)

@LysandreJik
Copy link
Member

This seems reasonable! I had run into issues where I couldn't segment images with different sizes when implementing it.

I have tried with different flavors of the following

image

and it seems to work well even without specifying the size.

Your change looks good to me @amyeroberts; are you aware of sizes that may not work with this model?

@amyeroberts
Copy link
Collaborator Author

@LysandreJik It should all be OK if the image processor matches the model: there shouldn't be any sizes that don't work because the image processor will resize as needed.

In terms of sizes that won't work:

  • We can't input images with either height or width smaller that the model's patch size - 16 by default
  • Images which (image_height // patch_size) * (image_width // patch_size) > max_sequence_length
  • Non-square images where (image_height // patch_size) != (image_width // patch_size). Just looking high-level at the model, I think it could be reworked to accept non-square images but haven't dug into it deeply.

Copy link
Member

@LysandreJik LysandreJik 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!

@LysandreJik LysandreJik merged commit e6122c3 into huggingface:main Jun 15, 2023
@amyeroberts amyeroberts deleted the fix-image-segmentation-tool-bug branch June 15, 2023 12:21
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.

Problem with Huggingface Agent
4 participants