class_docstr: Constructs a MaskFormer feature extractor. The feature extractor can be used to prepare image(s) and optional
  targets for the model.
  
  This feature extractor inherits from [`FeatureExtractionMixin`] which contains most of the main methods. Users
  should refer to this superclass for more information regarding those methods.
  
  Args:
      do_resize (`bool`, *optional*, defaults to `True`):
          Whether to resize the input to a certain `size`.
      size (`int`, *optional*, defaults to 800):
          Resize the input to the given size. Only has an effect if `do_resize` is set to `True`. If size is a
          sequence like `(width, height)`, output size will be matched to this. If size is an int, smaller edge of
          the image will be matched to this number. i.e, if `height > width`, then image will be rescaled to `(size *
          height / width, size)`.
      max_size (`int`, *optional*, defaults to 1333):
          The largest size an image dimension can have (otherwise it's capped). Only has an effect if `do_resize` is
          set to `True`.
      resample (`int`, *optional*, defaults to `PIL.Image.Resampling.BILINEAR`):
          An optional resampling filter. This can be one of `PIL.Image.Resampling.NEAREST`,
          `PIL.Image.Resampling.BOX`, `PIL.Image.Resampling.BILINEAR`, `PIL.Image.Resampling.HAMMING`,
          `PIL.Image.Resampling.BICUBIC` or `PIL.Image.Resampling.LANCZOS`. Only has an effect if `do_resize` is set
          to `True`.
      size_divisibility (`int`, *optional*, defaults to 32):
          Some backbones need images divisible by a certain number. If not passed, it defaults to the value used in
          Swin Transformer.
      do_normalize (`bool`, *optional*, defaults to `True`):
          Whether or not to normalize the input with mean and standard deviation.
      image_mean (`int`, *optional*, defaults to `[0.485, 0.456, 0.406]`):
          The sequence of means for each channel, to be used when normalizing images. Defaults to the ImageNet mean.
      image_std (`int`, *optional*, defaults to `[0.229, 0.224, 0.225]`):
          The sequence of standard deviations for each channel, to be used when normalizing images. Defaults to the
          ImageNet std.
      ignore_index (`int`, *optional*):
          Label to be assigned to background pixels in segmentation maps. If provided, segmentation map pixels
          denoted with 0 (background) will be replaced with `ignore_index`.
      reduce_labels (`bool`, *optional*, defaults to `False`):
          Whether or not to decrement all label values of segmentation maps by 1. Usually used for datasets where 0
          is used for background, and background itself is not included in all classes of a dataset (e.g. ADE20k).
          The background label will be replaced by `ignore_index`.
docstr: Main method to prepare for the model one or several image(s) and optional annotations. Images are by default
  padded up to the largest image in a batch, and a pixel mask is created that indicates which pixels are
  real/which are padding.
  
  MaskFormer addresses semantic segmentation with a mask classification paradigm, thus input segmentation maps
  will be converted to lists of binary masks and their respective labels. Let's see an example, assuming
  `segmentation_maps = [[2,6,7,9]]`, the output will contain `mask_labels =
  [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]` (four binary masks) and `class_labels = [2,6,7,9]`, the labels for
  each mask.
  
  <Tip warning={true}>
  
  NumPy arrays and PyTorch tensors are converted to PIL images when resizing, so the most efficient is to pass
  PIL images.
  
  </Tip>
  
  Args:
      images (`PIL.Image.Image`, `np.ndarray`, `torch.Tensor`, `List[PIL.Image.Image]`, `List[np.ndarray]`, `List[torch.Tensor]`):
          The image or batch of images to be prepared. Each image can be a PIL image, NumPy array or PyTorch
          tensor. In case of a NumPy array/PyTorch tensor, each image should be of shape (C, H, W), where C is a
          number of channels, H and W are image height and width.
  
      segmentation_maps (`PIL.Image.Image`, `np.ndarray`, `torch.Tensor`, `List[PIL.Image.Image]`, `List[np.ndarray]`, `List[torch.Tensor]`, *optional*):
          The corresponding semantic segmentation maps with the pixel-wise class id annotations or instance
          segmentation maps with pixel-wise instance id annotations. Assumed to be semantic segmentation maps if
          no `instance_id_to_semantic_id map` is provided.
  
      pad_and_return_pixel_mask (`bool`, *optional*, defaults to `True`):
          Whether or not to pad images up to the largest image in a batch and create a pixel mask.
  
          If left to the default, will return a pixel mask that is:
  
          - 1 for pixels that are real (i.e. **not masked**),
          - 0 for pixels that are padding (i.e. **masked**).
  
      instance_id_to_semantic_id (`List[Dict[int, int]]` or `Dict[int, int]`, *optional*):
          A mapping between object instance ids and class ids. If passed, `segmentation_maps` is treated as an
          instance segmentation map where each pixel represents an instance id. Can be provided as a single
          dictionary with a global / dataset-level mapping or as a list of dictionaries (one per image), to map
          instance ids in each image separately.
  
      return_tensors (`str` or [`~file_utils.TensorType`], *optional*):
          If set, will return tensors instead of NumPy arrays. If set to `'pt'`, return PyTorch `torch.Tensor`
          objects.
  
  Returns:
      [`BatchFeature`]: A [`BatchFeature`] with the following fields:
  
      - **pixel_values** -- Pixel values to be fed to a model.
      - **pixel_mask** -- Pixel mask to be fed to a model (when `pad_and_return_pixel_mask=True` or if
        `pixel_mask` is in `self.model_input_names`).
      - **mask_labels** -- Optional list of mask labels of shape `(num_class_labels, height, width)` to be fed to
        a model (when `annotations` are provided).
      - **class_labels** -- Optional list of class labels of shape `(num_class_labels)` to be fed to a model
        (when `annotations` are provided). They identify the labels of `mask_labels`, e.g. the label of
        `mask_labels[i][j]` if `class_labels[i][j]`.
docstr_tok: ["Main","method","to","prepare","for","the","model","one","or","several","image","(","s",")","and","optional","annotations",".","Images","are","by","default","padded","up","to","the","largest","image","in","a","batch",",","and","a","pixel","mask","is","created","that","indicates","which","pixels","are","real\/which","are","padding",".","MaskFormer","addresses","semantic","segmentation","with","a","mask","classification","paradigm",",","thus","input","segmentation","maps","will","be","converted","to","lists","of","binary","masks","and","their","respective","labels",".","Let","'s","see","an","example",",","assuming","`","segmentation_maps","=","[","[","2,6,7,9","]","]","`",",","the","output","will","contain","`","mask_labels","=","[","[","1,0,0,0","]",",","[","0,1,0,0","]",",","[","0,0,1,0","]",",","[","0,0,0,1","]","]","`","(","four","binary","masks",")","and","`","class_labels","=","[","2,6,7,9","]","`",",","the","labels","for","each","mask",".","<","Tip","warning=","{","true","}",">","NumPy","arrays","and","PyTorch","tensors","are","converted","to","PIL","images","when","resizing",",","so","the","most","efficient","is","to","pass","PIL","images",".","<","\/Tip",">","Args",":","images","(","`","PIL.Image.Image","`",",","`","np.ndarray","`",",","`","torch.Tensor","`",",","`","List","[","PIL.Image.Image","]","`",",","`","List","[","np.ndarray","]","`",",","`","List","[","torch.Tensor","]","`",")",":","The","image","or","batch","of","images","to","be","prepared",".","Each","image","can","be","a","PIL","image",",","NumPy","array","or","PyTorch","tensor",".","In","case","of","a","NumPy","array\/PyTorch","tensor",",","each","image","should","be","of","shape","(","C",",","H",",","W",")",",","where","C","is","a","number","of","channels",",","H","and","W","are","image","height","and","width",".","segmentation_maps","(","`","PIL.Image.Image","`",",","`","np.ndarray","`",",","`","torch.Tensor","`",",","`","List","[","PIL.Image.Image","]","`",",","`","List","[","np.ndarray","]","`",",","`","List","[","torch.Tensor","]","`",",","*","optional","*",")",":","The","corresponding","semantic","segmentation","maps","with","the","pixel-wise","class","id","annotations","or","instance","segmentation","maps","with","pixel-wise","instance","id","annotations",".","Assumed","to","be","semantic","segmentation","maps","if","no","`","instance_id_to_semantic_id","map","`","is","provided",".","pad_and_return_pixel_mask","(","`","bool","`",",","*","optional","*",",","defaults","to","`","True","`",")",":","Whether","or","not","to","pad","images","up","to","the","largest","image","in","a","batch","and","create","a","pixel","mask",".","If","left","to","the","default",",","will","return","a","pixel","mask","that","is",":","-","1","for","pixels","that","are","real","(","i.e",".","*","*","not","masked","*","*",")",",","-","0","for","pixels","that","are","padding","(","i.e",".","*","*","masked","*","*",")",".","instance_id_to_semantic_id","(","`","List","[","Dict","[","int",",","int","]","]","`","or","`","Dict","[","int",",","int","]","`",",","*","optional","*",")",":","A","mapping","between","object","instance","ids","and","class","ids",".","If","passed",",","`","segmentation_maps","`","is","treated","as","an","instance","segmentation","map","where","each","pixel","represents","an","instance","id",".","Can","be","provided","as","a","single","dictionary","with","a","global","\/","dataset-level","mapping","or","as","a","list","of","dictionaries","(","one","per","image",")",",","to","map","instance","ids","in","each","image","separately",".","return_tensors","(","`","str","`","or","[","`","~file_utils.TensorType","`","]",",","*","optional","*",")",":","If","set",",","will","return","tensors","instead","of","NumPy","arrays",".","If","set","to","`","'pt","'","`",",","return","PyTorch","`","torch.Tensor","`","objects",".","Returns",":","[","`","BatchFeature","`","]",":","A","[","`","BatchFeature","`","]","with","the","following","fields",":","-","*","*","pixel_values","*","*","--","Pixel","values","to","be","fed","to","a","model",".","-","*","*","pixel_mask","*","*","--","Pixel","mask","to","be","fed","to","a","model","(","when","`","pad_and_return_pixel_mask=True","`","or","if","`","pixel_mask","`","is","in","`","self.model_input_names","`",")",".","-","*","*","mask_labels","*","*","--","Optional","list","of","mask","labels","of","shape","`","(","num_class_labels",",","height",",","width",")","`","to","be","fed","to","a","model","(","when","`","annotations","`","are","provided",")",".","-","*","*","class_labels","*","*","--","Optional","list","of","class","labels","of","shape","`","(","num_class_labels",")","`","to","be","fed","to","a","model","(","when","`","annotations","`","are","provided",")",".","They","identify","the","labels","of","`","mask_labels","`",",","e.g",".","the","label","of","`","mask_labels","[","i","]","[","j","]","`","if","`","class_labels","[","i","]","[","j","]","`","."]
code: def __call__(
      self,
      images: ImageInput,
      segmentation_maps: ImageInput = None,
      pad_and_return_pixel_mask: Optional[bool] = True,
      instance_id_to_semantic_id: Optional[
          Union[List[Dict[int, int]], Dict[int, int]]
      ] = None,
      return_tensors: Optional[Union[str, TensorType]] = None,
      **kwargs,
  ) -> BatchFeature:
      """
      Main method to prepare for the model one or several image(s) and optional annotations. Images are by default
      padded up to the largest image in a batch, and a pixel mask is created that indicates which pixels are
      real/which are padding.
  
      MaskFormer addresses semantic segmentation with a mask classification paradigm, thus input segmentation maps
      will be converted to lists of binary masks and their respective labels. Let's see an example, assuming
      `segmentation_maps = [[2,6,7,9]]`, the output will contain `mask_labels =
      [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]` (four binary masks) and `class_labels = [2,6,7,9]`, the labels for
      each mask.
  
      <Tip warning={true}>
  
      NumPy arrays and PyTorch tensors are converted to PIL images when resizing, so the most efficient is to pass
      PIL images.
  
      </Tip>
  
      Args:
          images (`PIL.Image.Image`, `np.ndarray`, `torch.Tensor`, `List[PIL.Image.Image]`, `List[np.ndarray]`, `List[torch.Tensor]`):
              The image or batch of images to be prepared. Each image can be a PIL image, NumPy array or PyTorch
              tensor. In case of a NumPy array/PyTorch tensor, each image should be of shape (C, H, W), where C is a
              number of channels, H and W are image height and width.
  
          segmentation_maps (`PIL.Image.Image`, `np.ndarray`, `torch.Tensor`, `List[PIL.Image.Image]`, `List[np.ndarray]`, `List[torch.Tensor]`, *optional*):
              The corresponding semantic segmentation maps with the pixel-wise class id annotations or instance
              segmentation maps with pixel-wise instance id annotations. Assumed to be semantic segmentation maps if
              no `instance_id_to_semantic_id map` is provided.
  
          pad_and_return_pixel_mask (`bool`, *optional*, defaults to `True`):
              Whether or not to pad images up to the largest image in a batch and create a pixel mask.
  
              If left to the default, will return a pixel mask that is:
  
              - 1 for pixels that are real (i.e. **not masked**),
              - 0 for pixels that are padding (i.e. **masked**).
  
          instance_id_to_semantic_id (`List[Dict[int, int]]` or `Dict[int, int]`, *optional*):
              A mapping between object instance ids and class ids. If passed, `segmentation_maps` is treated as an
              instance segmentation map where each pixel represents an instance id. Can be provided as a single
              dictionary with a global / dataset-level mapping or as a list of dictionaries (one per image), to map
              instance ids in each image separately.
  
          return_tensors (`str` or [`~file_utils.TensorType`], *optional*):
              If set, will return tensors instead of NumPy arrays. If set to `'pt'`, return PyTorch `torch.Tensor`
              objects.
  
      Returns:
          [`BatchFeature`]: A [`BatchFeature`] with the following fields:
  
          - **pixel_values** -- Pixel values to be fed to a model.
          - **pixel_mask** -- Pixel mask to be fed to a model (when `pad_and_return_pixel_mask=True` or if
            `pixel_mask` is in `self.model_input_names`).
          - **mask_labels** -- Optional list of mask labels of shape `(num_class_labels, height, width)` to be fed to
            a model (when `annotations` are provided).
          - **class_labels** -- Optional list of class labels of shape `(num_class_labels)` to be fed to a model
            (when `annotations` are provided). They identify the labels of `mask_labels`, e.g. the label of
            `mask_labels[i][j]` if `class_labels[i][j]`.
      """
      # Input type checking for clearer error
  
      valid_images = False
      valid_segmentation_maps = False
  
      # Check that images has a valid type
      if isinstance(
          images, (Image.Image, np.ndarray)
      ) or is_torch_tensor(images):
          valid_images = True
      elif isinstance(images, (list, tuple)):
          if (
              len(images) == 0
              or isinstance(images[0], (Image.Image, np.ndarray))
              or is_torch_tensor(images[0])
          ):
              valid_images = True
  
      if not valid_images:
          raise ValueError(
              "Images must of type `PIL.Image.Image`, `np.ndarray` or `torch.Tensor` (single example), "
              "`List[PIL.Image.Image]`, `List[np.ndarray]` or `List[torch.Tensor]` (batch of examples)."
          )
      # Check that segmentation maps has a valid type
      if segmentation_maps is not None:
          if isinstance(
              segmentation_maps, (Image.Image, np.ndarray)
          ) or is_torch_tensor(segmentation_maps):
              valid_segmentation_maps = True
          elif isinstance(segmentation_maps, (list, tuple)):
              if (
                  len(segmentation_maps) == 0
                  or isinstance(
                      segmentation_maps[0], (Image.Image, np.ndarray)
                  )
                  or is_torch_tensor(segmentation_maps[0])
              ):
                  valid_segmentation_maps = True
  
          if not valid_segmentation_maps:
              raise ValueError(
                  "Segmentation maps must of type `PIL.Image.Image`, `np.ndarray` or `torch.Tensor` (single"
                  " example),`List[PIL.Image.Image]`, `List[np.ndarray]` or `List[torch.Tensor]` (batch of"
                  " examples)."
              )
  
      is_batched = bool(
          isinstance(images, (list, tuple))
          and (
              isinstance(images[0], (Image.Image, np.ndarray))
              or is_torch_tensor(images[0])
          )
      )
  
      if not is_batched:
          images = [images]
          if segmentation_maps is not None:
              segmentation_maps = [segmentation_maps]
  
      # transformations (resizing + normalization)
      if self.do_resize and self.size is not None:
          if segmentation_maps is not None:
              for idx, (image, target) in enumerate(
                  zip(images, segmentation_maps)
              ):
                  image, target = self._resize_with_size_divisibility(
                      image=image,
                      target=target,
                      size=self.size,
                      max_size=self.max_size,
                  )
                  images[idx] = image
                  segmentation_maps[idx] = target
          else:
              for idx, image in enumerate(images):
                  images[idx] = self._resize_with_size_divisibility(
                      image=image,
                      target=None,
                      size=self.size,
                      max_size=self.max_size,
                  )[0]
  
      if self.do_normalize:
          images = [
              self.normalize(
                  image=image, mean=self.image_mean, std=self.image_std
              )
              for image in images
          ]
      # NOTE I will be always forced to pad them them since they have to be stacked in the batch dim
      encoded_inputs = self.encode_inputs(
          images,
          segmentation_maps,
          pad_and_return_pixel_mask,
          instance_id_to_semantic_id=instance_id_to_semantic_id,
          return_tensors=return_tensors,
      )
  
      # Convert to TensorType
      tensor_type = return_tensors
      if not isinstance(tensor_type, TensorType):
          tensor_type = TensorType(tensor_type)
  
      if not tensor_type == TensorType.PYTORCH:
          raise ValueError("Only PyTorch is supported for the moment.")
      else:
          if not is_torch_available():
              raise ImportError(
                  "Unable to convert output to PyTorch tensors format, PyTorch is not installed."
              )
  
      return encoded_inputs
  
imports: from typing import TYPE_CHECKING, Dict, List, Optional, Set, Tuple, Union
  import numpy
  from PIL import Image
  from transformers.image_utils import PILImageResampling
  from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin
  from ...image_utils import ImageFeatureExtractionMixin, ImageInput, is_torch_tensor
  from ...utils import TensorType, is_torch_available, logging
label_desc: Use image node_id 3 for calling the MaskFormerFeatureExtractor obj's underlying member method code with example usage: obj.__call__(images, segmentation_maps, pad_and_return_pixel_mask, instance_id_to_semantic_id, return_tensors) and returns: encoded_inputs