maskformer sample code error
Author: Tungway1990
Pull request: no

### System Info

- `transformers` version: 4.24.0
- Platform: Windows-10-10.0.19045-SP0
- Python version: 3.9.12
- Huggingface_hub version: 0.10.1
- PyTorch version (GPU?): 1.12.0 (True)

### Who can help?

@sgugger @patil-suraj

Try running the sample code in maskformer [https://huggingface.co/docs/transformers/v4.24.0/en/model_doc/maskformer](url)
```python
output = feature_extractor.post_process_instance_segmentation(outputs)
```
has a NoneType error.



### Information

- [x] The official example scripts
- [ ] My own modified scripts

### Tasks

- [x] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

```python
from transformers import MaskFormerFeatureExtractor, MaskFormerForInstanceSegmentation
from PIL import Image
import requests

url = "http://images.cocodataset.org/val2017/000000039769.jpg"
image = Image.open(requests.get(url, stream=True).raw)
feature_extractor = MaskFormerFeatureExtractor.from_pretrained("facebook/maskformer-swin-base-ade")
inputs = feature_extractor(images=image, return_tensors="pt")

model = MaskFormerForInstanceSegmentation.from_pretrained("facebook/maskformer-swin-base-ade")
outputs = model(**inputs)
# model predicts class_queries_logits of shape `(batch_size, num_queries)`
# and masks_queries_logits of shape `(batch_size, num_queries, height, width)`
class_queries_logits = outputs.class_queries_logits
masks_queries_logits = outputs.masks_queries_logits

# you can pass them to feature_extractor for postprocessing
output = feature_extractor.post_process_semantic_segmentation(outputs)
output = feature_extractor.post_process_instance_segmentation(outputs)
output = feature_extractor.post_process_panoptic_segmentation(outputs)
```

Error Message:
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [5], in <cell line: 1>()
----> 1 output = feature_extractor.post_process_instance_segmentation(outputs)

File ~\anaconda3\lib\site-packages\transformers\models\maskformer\feature_extraction_maskformer.py:794, in MaskFormerFeatureExtractor.post_process_instance_segmentation(self, outputs, threshold, mask_threshold, overlap_mask_area_threshold, target_sizes, return_coco_annotation)
    792 # Get segmentation map and segment information of batch item
    793 target_size = target_sizes[i] if target_sizes is not None else None
--> 794 segmentation, segments = compute_segments(
    795     mask_probs_item,
    796     pred_scores_item,
    797     pred_labels_item,
    798     mask_threshold,
    799     overlap_mask_area_threshold,
    800     target_size,
    801 )
    803 # Return segmentation map in run-length encoding (RLE) format
    804 if return_coco_annotation:

File ~\anaconda3\lib\site-packages\transformers\models\maskformer\feature_extraction_maskformer.py:163, in compute_segments(mask_probs, pred_scores, pred_labels, mask_threshold, overlap_mask_area_threshold, label_ids_to_fuse, target_size)
    161 for k in range(pred_labels.shape[0]):
    162     pred_class = pred_labels[k].item()
--> 163     should_fuse = pred_class in label_ids_to_fuse
    165     # Check if mask exists and large enough to be a segment
    166     mask_exists, mask_k = check_segment_validity(
    167         mask_labels, mask_probs, k, mask_threshold, overlap_mask_area_threshold
    168     )

TypeError: argument of type 'NoneType' is not iterable

### Expected behavior

Checking logic shall add if label_ids_to_fuse is None like below. 
```python
if label_ids_to_fuse is None:
    should_fuse = False
elif pred_class in label_ids_to_fuse:
    should_fuse = True 
else:
    should_fuse = False
```

Comments:
cc @alaradirik and @NielsRogge 

Hi @Tungway1990, thanks for pointing this out! You are right, the ` label_ids_to_fuse` argument is only used for panoptic segmentation and the logic should take None values into account.

We'll open a PR to fix this shortly. cc @sgugger @NielsRogge 

We should actually update that code example, as that particular checkpoint was fine-tuned on ADE20K Semantic Segmentation. Hence, it doesn't make sense to postprocess the outputs for instance or panoptic segmentation.

Thanks for pointing out!

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.