🔴 🔴 🔴  Added `segmentation maps` support for DPT image processor
Author: simonreise
Pull request: yes
Labels: name: Vision

name: Processing

# Added `segmentation maps` support for DPT image processor

Most of image processors for vision models that support semantic segmentation task accept `images` and `segmentation_maps` as inputs, but for some reason DPT image processor does not process segmentation maps, only images. This PR can make code that one uses for training or evaluation of semantic segmentation models more reusable, as now DPT image processor can process segmentation maps as most of other image processors do.

I also added `do_reduce_labels` arg because other image processors that support segmentation masks use it.

I added two new tests: one that tests segmentation_masks support and one that tests if do_reduce_labels work as expected.

Most of the code is adapted from BEIT image processor.


## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#create-a-pull-request),
      Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
- [x] Did you make sure to update the documentation with your changes? Here are the [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [x] Did you write any new necessary tests?


## Who can review?

@amyeroberts, @qubvel

<!-- Your PR will be replied to more quickly if you can figure out the right person to tag with @

 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.

Models:

- text models: @ArthurZucker
- vision models: @amyeroberts, @qubvel
- speech models: @ylacombe, @eustlb
- graph models: @clefourrier

Library:

- flax: @sanchit-gandhi
- generate: @zucchini-nlp (visual-language models) or @gante (all others)
- pipelines: @Rocketknight1
- tensorflow: @gante and @Rocketknight1
- tokenizers: @ArthurZucker
- trainer: @muellerzr and @SunMarc
- chat templates: @Rocketknight1

Integrations:

- deepspeed: HF Trainer/Accelerate: @muellerzr
- ray/raytune: @richardliaw, @amogkam
- Big Model Inference: @SunMarc
- quantization (bitsandbytes, autogpt): @SunMarc @MekkCyber

Documentation: @stevhliu

HF projects:

- accelerate: [different repo](https://github.com/huggingface/accelerate)
- datasets: [different repo](https://github.com/huggingface/datasets)
- diffusers: [different repo](https://github.com/huggingface/diffusers)
- rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)

Maintained examples (not research project or legacy):

- Flax: @sanchit-gandhi
- PyTorch: See Models above and tag the person corresponding to the modality of the example.
- TensorFlow: @Rocketknight1

 -->


Comments:
cc @molbap as well in case bandwidth permits

Could you please re-review the pull request? In the last commit I made all the changes you asked for: wrapped segmentation map preprocessing code to separate functions, added comments and renamed a variable in tests. Do I need to make any other changes to the code?

hey @simonreise , will review in a moment, we were all at a team gathering last week hence the inactivity. On my radar!

@molbap you are fobidden to work for this week 🤣 go and rest, @yonigozlan will have a look! 🤗 

friendly ping @yonigozlan 

Thanks, but the `# Copied from` statement must be placed above the function definition. You can refer to other parts of the library to see how it's done.
This is not just for information purposes; it enables the `make fix-copies` CLI command to propagate any modifications in the original function to its copied versions.

After making the required changes, you can ensure everything is in order by running the `make fixup` command.

Thanks for iterating! you just have to rebase on main and check that the tests are still passing, then LGTM!

Everything looks good to me, pinging @ArthurZucker for a final review.
There's a potential breaking change @ArthurZucker, see [this comment ](https://github.com/huggingface/transformers/pull/34345/files#r1889587930)

There was a merge conflict that appeared after #35439 was merged into main. So I also changed the order of `do_rescale` and `is_scaled_image` in the code