class_docstr: Constructs a YOLOS feature extractor.
  
  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:
      format (`str`, *optional*, defaults to `"coco_detection"`):
          Data format of the annotations. One of "coco_detection" or "coco_panoptic".
      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`.
      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.
class_docstr_tok: ["Constructs","a","YOLOS","feature","extractor",".","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",":","format","(","`","str","`",",","*","optional","*",",","defaults","to","`","``","coco_detection","''","`",")",":","Data","format","of","the","annotations",".","One","of","``","coco_detection","''","or","``","coco_panoptic","''",".","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","`",".","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","."]
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.
  
  <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.
  
      annotations (`Dict`, `List[Dict]`, *optional*):
          The corresponding annotations in COCO format.
  
          In case [`DetrFeatureExtractor`] was initialized with `format = "coco_detection"`, the annotations for
          each image should have the following format: {'image_id': int, 'annotations': [annotation]}, with the
          annotations being a list of COCO object annotations.
  
          In case [`DetrFeatureExtractor`] was initialized with `format = "coco_panoptic"`, the annotations for
          each image should have the following format: {'image_id': int, 'file_name': str, 'segments_info':
          [segment_info]} with segments_info being a list of COCO panoptic annotations.
  
      return_segmentation_masks (`Dict`, `List[Dict]`, *optional*, defaults to `False`):
          Whether to also include instance segmentation masks as part of the labels in case `format =
          "coco_detection"`.
  
      masks_path (`pathlib.Path`, *optional*):
          Path to the directory containing the PNG files that store the class-agnostic image segmentations. Only
          relevant in case [`DetrFeatureExtractor`] was initialized with `format = "coco_panoptic"`.
  
      padding (`bool`, *optional*, defaults to `True`):
          Whether or not to pad images up to the largest image in a batch.
  
      return_tensors (`str` or [`~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.
      - **labels** -- Optional labels to be fed to a model (when `annotations` are provided)
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",".","<","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",".","annotations","(","`","Dict","`",",","`","List","[","Dict","]","`",",","*","optional","*",")",":","The","corresponding","annotations","in","COCO","format",".","In","case","[","`","DetrFeatureExtractor","`","]","was","initialized","with","`","format","=","``","coco_detection","''","`",",","the","annotations","for","each","image","should","have","the","following","format",":","{","'image_id","'",":","int",",","'annotations","'",":","[","annotation","]","}",",","with","the","annotations","being","a","list","of","COCO","object","annotations",".","In","case","[","`","DetrFeatureExtractor","`","]","was","initialized","with","`","format","=","``","coco_panoptic","''","`",",","the","annotations","for","each","image","should","have","the","following","format",":","{","'image_id","'",":","int",",","'file_name","'",":","str",",","'segments_info","'",":","[","segment_info","]","}","with","segments_info","being","a","list","of","COCO","panoptic","annotations",".","return_segmentation_masks","(","`","Dict","`",",","`","List","[","Dict","]","`",",","*","optional","*",",","defaults","to","`","False","`",")",":","Whether","to","also","include","instance","segmentation","masks","as","part","of","the","labels","in","case","`","format","=","``","coco_detection","''","`",".","masks_path","(","`","pathlib.Path","`",",","*","optional","*",")",":","Path","to","the","directory","containing","the","PNG","files","that","store","the","class-agnostic","image","segmentations",".","Only","relevant","in","case","[","`","DetrFeatureExtractor","`","]","was","initialized","with","`","format","=","``","coco_panoptic","''","`",".","padding","(","`","bool","`",",","*","optional","*",",","defaults","to","`","True","`",")",":","Whether","or","not","to","pad","images","up","to","the","largest","image","in","a","batch",".","return_tensors","(","`","str","`","or","[","`","~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",".","-","*","*","labels","*","*","--","Optional","labels","to","be","fed","to","a","model","(","when","`","annotations","`","are","provided",")"]
code: def __call__(
      self,
      images: ImageInput,
      annotations: Union[List[Dict], List[List[Dict]]] = None,
      return_segmentation_masks: Optional[bool] = False,
      masks_path: Optional[pathlib.Path] = None,
      padding: Optional[bool] = True,
      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.
  
      <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.
  
          annotations (`Dict`, `List[Dict]`, *optional*):
              The corresponding annotations in COCO format.
  
              In case [`DetrFeatureExtractor`] was initialized with `format = "coco_detection"`, the annotations for
              each image should have the following format: {'image_id': int, 'annotations': [annotation]}, with the
              annotations being a list of COCO object annotations.
  
              In case [`DetrFeatureExtractor`] was initialized with `format = "coco_panoptic"`, the annotations for
              each image should have the following format: {'image_id': int, 'file_name': str, 'segments_info':
              [segment_info]} with segments_info being a list of COCO panoptic annotations.
  
          return_segmentation_masks (`Dict`, `List[Dict]`, *optional*, defaults to `False`):
              Whether to also include instance segmentation masks as part of the labels in case `format =
              "coco_detection"`.
  
          masks_path (`pathlib.Path`, *optional*):
              Path to the directory containing the PNG files that store the class-agnostic image segmentations. Only
              relevant in case [`DetrFeatureExtractor`] was initialized with `format = "coco_panoptic"`.
  
          padding (`bool`, *optional*, defaults to `True`):
              Whether or not to pad images up to the largest image in a batch.
  
          return_tensors (`str` or [`~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.
          - **labels** -- Optional labels to be fed to a model (when `annotations` are provided)
      """
      # Input type checking for clearer error
  
      valid_images = False
      valid_annotations = False
      valid_masks_path = 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)."
          )
  
      is_batched = bool(
          isinstance(images, (list, tuple))
          and (
              isinstance(images[0], (Image.Image, np.ndarray))
              or is_torch_tensor(images[0])
          )
      )
  
      # Check that annotations has a valid type
      if annotations is not None:
          if not is_batched:
              if self.format == "coco_detection":
                  if (
                      isinstance(annotations, dict)
                      and "image_id" in annotations
                      and "annotations" in annotations
                  ):
                      if isinstance(
                          annotations["annotations"], (list, tuple)
                      ):
                          # an image can have no annotations
                          if len(
                              annotations["annotations"]
                          ) == 0 or isinstance(
                              annotations["annotations"][0], dict
                          ):
                              valid_annotations = True
              elif self.format == "coco_panoptic":
                  if (
                      isinstance(annotations, dict)
                      and "image_id" in annotations
                      and "segments_info" in annotations
                  ):
                      if isinstance(
                          annotations["segments_info"], (list, tuple)
                      ):
                          # an image can have no segments (?)
                          if len(
                              annotations["segments_info"]
                          ) == 0 or isinstance(
                              annotations["segments_info"][0], dict
                          ):
                              valid_annotations = True
          else:
              if isinstance(annotations, (list, tuple)):
                  if len(images) != len(annotations):
                      raise ValueError(
                          "There must be as many annotations as there are images"
                      )
                  if isinstance(annotations[0], Dict):
                      if self.format == "coco_detection":
                          if isinstance(
                              annotations[0]["annotations"],
                              (list, tuple),
                          ):
                              valid_annotations = True
                      elif self.format == "coco_panoptic":
                          if isinstance(
                              annotations[0]["segments_info"],
                              (list, tuple),
                          ):
                              valid_annotations = True
  
          if not valid_annotations:
              raise ValueError(
                  """
                      Annotations must of type `Dict` (single image) or `List[Dict]` (batch of images). In case of object
                      detection, each dictionary should contain the keys 'image_id' and 'annotations', with the latter
                      being a list of annotations in COCO format. In case of panoptic segmentation, each dictionary
                      should contain the keys 'file_name', 'image_id' and 'segments_info', with the latter being a list
                      of annotations in COCO format.
                      """
              )
  
      # Check that masks_path has a valid type
      if masks_path is not None:
          if self.format == "coco_panoptic":
              if isinstance(masks_path, pathlib.Path):
                  valid_masks_path = True
              if not valid_masks_path:
                  raise ValueError(
                      "The path to the directory containing the mask PNG files should be provided as a"
                      " `pathlib.Path` object."
                  )
  
      if not is_batched:
          images = [images]
          if annotations is not None:
              annotations = [annotations]
  
      # prepare (COCO annotations as a list of Dict -> DETR target as a single Dict per image)
      if annotations is not None:
          for idx, (image, target) in enumerate(
              zip(images, annotations)
          ):
              if not isinstance(image, Image.Image):
                  image = self.to_pil_image(image)
              image, target = self.prepare(
                  image, target, return_segmentation_masks, masks_path
              )
              images[idx] = image
              annotations[idx] = target
  
      # transformations (resizing + normalization)
      if self.do_resize and self.size is not None:
          if annotations is not None:
              for idx, (image, target) in enumerate(
                  zip(images, annotations)
              ):
                  image, target = self._resize(
                      image=image,
                      target=target,
                      size=self.size,
                      max_size=self.max_size,
                  )
                  images[idx] = image
                  annotations[idx] = target
          else:
              for idx, image in enumerate(images):
                  images[idx] = self._resize(
                      image=image,
                      target=None,
                      size=self.size,
                      max_size=self.max_size,
                  )[0]
  
      if self.do_normalize:
          if annotations is not None:
              for idx, (image, target) in enumerate(
                  zip(images, annotations)
              ):
                  image, target = self._normalize(
                      image=image,
                      mean=self.image_mean,
                      std=self.image_std,
                      target=target,
                  )
                  images[idx] = image
                  annotations[idx] = target
          else:
              images = [
                  self._normalize(
                      image=image,
                      mean=self.image_mean,
                      std=self.image_std,
                  )[0]
                  for image in images
              ]
  
      if padding:
          # pad images up to largest image in batch
          max_size = self._max_by_axis(
              [list(image.shape) for image in images]
          )
          c, h, w = max_size
          padded_images = []
          for image in images:
              # create padded image
              padded_image = np.zeros((c, h, w), dtype=np.float32)
              padded_image[
                  : image.shape[0], : image.shape[1], : image.shape[2]
              ] = np.copy(image)
              padded_images.append(padded_image)
          images = padded_images
  
      # return as BatchFeature
      data = {}
      data["pixel_values"] = images
      encoded_inputs = BatchFeature(
          data=data, tensor_type=return_tensors
      )
  
      if annotations is not None:
          # 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."
                  )
  
              encoded_inputs["labels"] = [
                  {k: torch.from_numpy(v) for k, v in target.items()}
                  for target in annotations
              ]
  
      return encoded_inputs
  
imports: import pathlib
  import warnings
  from typing import Dict, List, Optional, Tuple, Union
  import numpy
  from PIL import Image
  from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin
  from ...image_utils import ImageFeatureExtractionMixin, is_torch_tensor
  from ...utils import TensorType, is_torch_available, logging
label_desc: Use image node_id 9 for calling the YolosFeatureExtractor obj's underlying member method code with example usage: obj.__call__(images, annotations, return_segmentation_masks, masks_path, padding, return_tensors) and returns: encoded_inputs