Instance segmentation examples
Author: qubvel
Pull request: yes

# What does this PR do?

Add examples that demonstrate how to train MaskFormer and Mask2Former for instance segmentation with Trainer or Accelerate.

Fixes #30335 
(processing void segmentation maps, I can make a separate PR, but for now its included)

At the moment kind of blocked by:
 - #30799 (not that critical, could be merged as is, as a workaround, I pass both values `reduce_labels` and `do_reduce_labels`)
 - #30943 (critical for instance segmentation, because masks are heavy and quickly occupy all RAM)

## Before submitting
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#create-a-pull-request),
      Pull Request section?
- [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 @NielsRogge 


Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_31084). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@qubvel Hi, Pavel, I really like this PR. However, wasn't there any issue of slowing down in the postprocessing evaluation outputs?

@qubvel Hi pavel, One more question. How about adding DETR in this script since this is also returns instance output?
https://github.com/huggingface/transformers/blob/573565e35a5cc68f6cfb6337f5a93753ab16c65b/src/transformers/models/detr/image_processing_detr.py#L1774

> @qubvel Hi pavel, One more question. How about adding DETR in this script since this also returns instance output?

Hi @SangbumChoi it would be nice to have DETR also, but it's not straightforward since DETR's image processor has a different input annotation format and DETR ModelOutput has different fields. It will require adding some conversion logic and I guess the example will be overcomplicated. I tried to keep it simple, but still not completely happy with the amount of code written and how much one should know to be able to modify it and adapt it for a particular use-case.

> it would be nice to have DETR also, but it's not straightforward since DETR's image processor has a different input annotation format and DETR ModelOutput has different fields. It will require adding some conversion logic and I guess the example will be overcomplicated. I tried to keep it simple, but still not completely happy with the amount of code written and how much one should know to be able to modify it and adapt it for a particular use-case.

Exactly, I also try to make the logic simple as much as possible but unfortunately DETR has different annotation input :(
In the future, We can make seperate script for DETR only and just get link in here.

Ok, I addressed most of the comments, thank you all for the reviews 🤗 

I am going to merge this:
 - At the moment, the problem with memory leaks is not critical because it occurs only with persistent DataLoader workers, which I believe is not a common case.
 - Support for other architectures (DETR, Conditional DETR) and dataset formats can be added as a follow-up.