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: Pad images up to the largest image in a batch and create a corresponding `pixel_mask`.
  
  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.
  
  Args:
      pixel_values_list (`List[torch.Tensor]`):
          List of images (pixel values) to be padded. Each image should be a tensor of shape `(channels, height,
          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 annotations.
  
      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 `(labels, height, width)` to be fed to a model
        (when `annotations` are provided).
      - **class_labels** -- Optional list of class labels of shape `(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: ["Pad","images","up","to","the","largest","image","in","a","batch","and","create","a","corresponding","`","pixel_mask","`",".","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",".","Args",":","pixel_values_list","(","`","List","[","torch.Tensor","]","`",")",":","List","of","images","(","pixel","values",")","to","be","padded",".","Each","image","should","be","a","tensor","of","shape","`","(","channels",",","height",",","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","annotations",".","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","`","(","labels",",","height",",","width",")","`","to","be","fed","to","a","model","(","when","`","annotations","`","are","provided",")",".","-","*","*","class_labels","*","*","--","Optional","list","of","class","labels","of","shape","`","(","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 encode_inputs(
      self,
      pixel_values_list: List["np.ndarray"],
      segmentation_maps: ImageInput = None,
      pad_and_return_pixel_mask: bool = True,
      instance_id_to_semantic_id: Optional[
          Union[List[Dict[int, int]], Dict[int, int]]
      ] = None,
      return_tensors: Optional[Union[str, TensorType]] = None,
  ):
      """
      Pad images up to the largest image in a batch and create a corresponding `pixel_mask`.
  
      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.
  
      Args:
          pixel_values_list (`List[torch.Tensor]`):
              List of images (pixel values) to be padded. Each image should be a tensor of shape `(channels, height,
              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 annotations.
  
          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 `(labels, height, width)` to be fed to a model
            (when `annotations` are provided).
          - **class_labels** -- Optional list of class labels of shape `(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]`.
      """
  
      max_size = self._max_by_axis(
          [list(image.shape) for image in pixel_values_list]
      )
  
      annotations = None
      if segmentation_maps is not None:
          segmentation_maps = map(np.array, segmentation_maps)
          converted_segmentation_maps = []
  
          for i, segmentation_map in enumerate(segmentation_maps):
              # Use instance2class_id mapping per image
              if isinstance(instance_id_to_semantic_id, List):
                  converted_segmentation_map = (
                      self.convert_segmentation_map_to_binary_masks(
                          segmentation_map,
                          instance_id_to_semantic_id[i],
                      )
                  )
              else:
                  converted_segmentation_map = (
                      self.convert_segmentation_map_to_binary_masks(
                          segmentation_map, instance_id_to_semantic_id
                      )
                  )
              converted_segmentation_maps.append(
                  converted_segmentation_map
              )
  
          annotations = []
          for mask, classes in converted_segmentation_maps:
              annotations.append({"masks": mask, "classes": classes})
  
      channels, height, width = max_size
      pixel_values = []
      pixel_mask = []
      mask_labels = []
      class_labels = []
      for idx, image in enumerate(pixel_values_list):
          # create padded image
          padded_image = np.zeros(
              (channels, height, width), dtype=np.float32
          )
          padded_image[
              : image.shape[0], : image.shape[1], : image.shape[2]
          ] = np.copy(image)
          image = padded_image
          pixel_values.append(image)
          # if we have a target, pad it
          if annotations:
              annotation = annotations[idx]
              masks = annotation["masks"]
              # pad mask with `ignore_index`
              masks = np.pad(
                  masks,
                  (
                      (0, 0),
                      (0, height - masks.shape[1]),
                      (0, width - masks.shape[2]),
                  ),
                  constant_values=self.ignore_index,
              )
              annotation["masks"] = masks
          # create pixel mask
          mask = np.zeros((height, width), dtype=np.int64)
          mask[: image.shape[1], : image.shape[2]] = True
          pixel_mask.append(mask)
  
      # return as BatchFeature
      data = {"pixel_values": pixel_values, "pixel_mask": pixel_mask}
      encoded_inputs = BatchFeature(
          data=data, tensor_type=return_tensors
      )
      # we cannot batch them since they don't share a common class size
      if annotations:
          for label in annotations:
              mask_labels.append(torch.from_numpy(label["masks"]))
              class_labels.append(torch.from_numpy(label["classes"]))
  
          encoded_inputs["mask_labels"] = mask_labels
          encoded_inputs["class_labels"] = class_labels
  
      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 6 for calling the MaskFormerFeatureExtractor obj's underlying member method code with example usage: obj.encode_inputs(pixel_values_list, segmentation_maps, pad_and_return_pixel_mask, instance_id_to_semantic_id, return_tensors) and returns: encoded_inputs