Skip to content

[Fast image processors] Improve handling of image-like inputs other than images (segmentation_maps) #39489

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

Merged

Conversation

yonigozlan
Copy link
Member

What does this PR do?

As the title says, unbloats (😉) a lot of the fast processing code for models needing to processed segmentation maps, trimaps, depth_maps etc.

@yonigozlan yonigozlan requested a review from ArthurZucker July 17, 2025 21:13
@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.

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.

Does seem to simplify a lot! Not 100% sure it BC?

Comment on lines 207 to 213
segmentation_maps_kwargs = kwargs.copy()
segmentation_maps_kwargs["do_normalize"] = False
segmentation_maps_kwargs["do_rescale"] = False
segmentation_maps_kwargs["input_data_format"] = ChannelDimension.FIRST
# Nearest interpolation is used for segmentation maps instead of BILINEAR.
segmentation_maps_kwargs["interpolation"] = pil_torch_interpolation_mapping[PILImageResampling.NEAREST]

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would pass these explicitly instead of updating them but a small nit maybe complicated

Copy link
Member Author

Choose a reason for hiding this comment

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

I would still need to remove them from the kwargs as they have the default values for image processing there, so not sure if that simplifies...

@yonigozlan
Copy link
Member Author

@ArthurZucker Should be 100% BC 🤗

Copy link
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: beit, dpt, eomt, idefics2, idefics3, llava_next, llava_onevision, mobilenet_v2, mobilevit, qwen2_vl, sam, smolvlm, vitmatte

@yonigozlan yonigozlan merged commit b3ebc76 into huggingface:main Jul 21, 2025
25 checks passed
zucchini-nlp pushed a commit to zucchini-nlp/transformers that referenced this pull request Jul 22, 2025
…han images (segmentation_maps) (huggingface#39489)

* improve handlike of other image-like inputs in fast image processors

* fix issues with _prepare_images_structure

* update sam image processor fast

* use dict update
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.

3 participants