class_docstr: Constructs a LayoutLMv3 feature extractor. This can be used to resize + normalize document images, as well as to
  apply OCR on them in order to get a list of words and normalized bounding boxes.
  
  This feature extractor inherits from [`~feature_extraction_utils.PreTrainedFeatureExtractor`] 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` or `Tuple(int)`, *optional*, defaults to 224):
          Resize the input to the given size. If a tuple is provided, it should be (width, height). If only an
          integer is provided, then the input will be resized to (size, size). 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`.
      do_normalize (`bool`, *optional*, defaults to `True`):
          Whether or not to normalize the input with mean and standard deviation.
      image_mean (`List[int]`, defaults to `[0.5, 0.5, 0.5]`):
          The sequence of means for each channel, to be used when normalizing images.
      image_std (`List[int]`, defaults to `[0.5, 0.5, 0.5]`):
          The sequence of standard deviations for each channel, to be used when normalizing images.
      apply_ocr (`bool`, *optional*, defaults to `True`):
          Whether to apply the Tesseract OCR engine to get words + normalized bounding boxes.
      ocr_lang (`str`, *optional*):
          The language, specified by its ISO code, to be used by the Tesseract OCR engine. By default, English is
          used.
      tesseract_config (`str`, *optional*):
          Any additional custom configuration flags that are forwarded to the `config` parameter when calling
          Tesseract. For example: '--psm 6'.
  
          <Tip>
  
          LayoutLMv3FeatureExtractor uses Google's Tesseract OCR engine under the hood.
  
          </Tip>
docstr: Main method to prepare for the model one or several image(s).
  
  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.
      return_tensors (`str` or [`~utils.TensorType`], *optional*, defaults to `'np'`):
          If set, will return tensors of a particular framework. Acceptable values are:
  
          - `'tf'`: Return TensorFlow `tf.constant` objects.
          - `'pt'`: Return PyTorch `torch.Tensor` objects.
          - `'np'`: Return NumPy `np.ndarray` objects.
          - `'jax'`: Return JAX `jnp.ndarray` objects.
  
  Returns:
      [`BatchFeature`]: A [`BatchFeature`] with the following fields:
  
      - **pixel_values** -- Pixel values to be fed to a model, of shape (batch_size, num_channels, height,
        width).
      - **words** -- Optional words as identified by Tesseract OCR (only when [`LayoutLMv3FeatureExtractor`] was
        initialized with `apply_ocr` set to `True`).
      - **boxes** -- Optional bounding boxes as identified by Tesseract OCR, normalized based on the image size
        (only when [`LayoutLMv3FeatureExtractor`] was initialized with `apply_ocr` set to `True`).
  
  Examples:
  
  ```python
  >>> from transformers import LayoutLMv3FeatureExtractor
  >>> from PIL import Image
  
  >>> # Document can be a png, jpg, etc. PDFs must be converted to images.
  >>> image = Image.open(name_of_your_document).convert("RGB")
  
  >>> # option 1: with apply_ocr=True (default)
  >>> feature_extractor = LayoutLMv3FeatureExtractor()
  >>> encoding = feature_extractor(image, return_tensors="pt")
  >>> print(encoding.keys())
  >>> # dict_keys(['pixel_values', 'words', 'boxes'])
  
  >>> # option 2: with apply_ocr=False
  >>> feature_extractor = LayoutLMv3FeatureExtractor(apply_ocr=False)
  >>> encoding = feature_extractor(image, return_tensors="pt")
  >>> print(encoding.keys())
  >>> # dict_keys(['pixel_values'])
  ```
docstr_tok: ["Main","method","to","prepare","for","the","model","one","or","several","image","(","s",")",".","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",".","return_tensors","(","`","str","`","or","[","`","~utils.TensorType","`","]",",","*","optional","*",",","defaults","to","`","'np","'","`",")",":","If","set",",","will","return","tensors","of","a","particular","framework",".","Acceptable","values","are",":","-","`","'tf","'","`",":","Return","TensorFlow","`","tf.constant","`","objects",".","-","`","'pt","'","`",":","Return","PyTorch","`","torch.Tensor","`","objects",".","-","`","'np","'","`",":","Return","NumPy","`","np.ndarray","`","objects",".","-","`","'jax","'","`",":","Return","JAX","`","jnp.ndarray","`","objects",".","Returns",":","[","`","BatchFeature","`","]",":","A","[","`","BatchFeature","`","]","with","the","following","fields",":","-","*","*","pixel_values","*","*","--","Pixel","values","to","be","fed","to","a","model",",","of","shape","(","batch_size",",","num_channels",",","height",",","width",")",".","-","*","*","words","*","*","--","Optional","words","as","identified","by","Tesseract","OCR","(","only","when","[","`","LayoutLMv3FeatureExtractor","`","]","was","initialized","with","`","apply_ocr","`","set","to","`","True","`",")",".","-","*","*","boxes","*","*","--","Optional","bounding","boxes","as","identified","by","Tesseract","OCR",",","normalized","based","on","the","image","size","(","only","when","[","`","LayoutLMv3FeatureExtractor","`","]","was","initialized","with","`","apply_ocr","`","set","to","`","True","`",")",".","Examples",":","``","`","python",">",">",">","from","transformers","import","LayoutLMv3FeatureExtractor",">",">",">","from","PIL","import","Image",">",">",">","#","Document","can","be","a","png",",","jpg",",","etc",".","PDFs","must","be","converted","to","images",".",">",">",">","image","=","Image.open","(","name_of_your_document",")",".convert","(","``","RGB","''",")",">",">",">","#","option","1",":","with","apply_ocr=True","(","default",")",">",">",">","feature_extractor","=","LayoutLMv3FeatureExtractor","(",")",">",">",">","encoding","=","feature_extractor","(","image",",","return_tensors=","''","pt","''",")",">",">",">","print","(","encoding.keys","(",")",")",">",">",">","#","dict_keys","(","[","'pixel_values","'",",","'words","'",",","'boxes","'","]",")",">",">",">","#","option","2",":","with","apply_ocr=False",">",">",">","feature_extractor","=","LayoutLMv3FeatureExtractor","(","apply_ocr=False",")",">",">",">","encoding","=","feature_extractor","(","image",",","return_tensors=","''","pt","''",")",">",">",">","print","(","encoding.keys","(",")",")",">",">",">","#","dict_keys","(","[","'pixel_values","'","]",")","``","`"]
code: def __call__(
      self,
      images: ImageInput,
      return_tensors: Optional[Union[str, TensorType]] = None,
      **kwargs,
  ) -> BatchFeature:
      """
      Main method to prepare for the model one or several image(s).
  
      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.
          return_tensors (`str` or [`~utils.TensorType`], *optional*, defaults to `'np'`):
              If set, will return tensors of a particular framework. Acceptable values are:
  
              - `'tf'`: Return TensorFlow `tf.constant` objects.
              - `'pt'`: Return PyTorch `torch.Tensor` objects.
              - `'np'`: Return NumPy `np.ndarray` objects.
              - `'jax'`: Return JAX `jnp.ndarray` objects.
  
      Returns:
          [`BatchFeature`]: A [`BatchFeature`] with the following fields:
  
          - **pixel_values** -- Pixel values to be fed to a model, of shape (batch_size, num_channels, height,
            width).
          - **words** -- Optional words as identified by Tesseract OCR (only when [`LayoutLMv3FeatureExtractor`] was
            initialized with `apply_ocr` set to `True`).
          - **boxes** -- Optional bounding boxes as identified by Tesseract OCR, normalized based on the image size
            (only when [`LayoutLMv3FeatureExtractor`] was initialized with `apply_ocr` set to `True`).
  
      Examples:
  
      ```python
      >>> from transformers import LayoutLMv3FeatureExtractor
      >>> from PIL import Image
  
      >>> # Document can be a png, jpg, etc. PDFs must be converted to images.
      >>> image = Image.open(name_of_your_document).convert("RGB")
  
      >>> # option 1: with apply_ocr=True (default)
      >>> feature_extractor = LayoutLMv3FeatureExtractor()
      >>> encoding = feature_extractor(image, return_tensors="pt")
      >>> print(encoding.keys())
      >>> # dict_keys(['pixel_values', 'words', 'boxes'])
  
      >>> # option 2: with apply_ocr=False
      >>> feature_extractor = LayoutLMv3FeatureExtractor(apply_ocr=False)
      >>> encoding = feature_extractor(image, return_tensors="pt")
      >>> print(encoding.keys())
      >>> # dict_keys(['pixel_values'])
      ```"""
  
      # Input type checking for clearer error
      valid_images = 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), "
              f"but is of type {type(images)}."
          )
  
      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]
  
      # Tesseract OCR to get words + normalized bounding boxes
      if self.apply_ocr:
          requires_backends(self, "pytesseract")
          words_batch = []
          boxes_batch = []
          for image in images:
              words, boxes = apply_tesseract(
                  self.to_pil_image(image),
                  self.ocr_lang,
                  self.tesseract_config,
              )
              words_batch.append(words)
              boxes_batch.append(boxes)
  
      # transformations (resizing + normalization)
      if self.do_resize and self.size is not None:
          images = [
              self.resize(
                  image=image, size=self.size, resample=self.resample
              )
              for image in images
          ]
      if self.do_normalize:
          images = [
              self.normalize(
                  image=image, mean=self.image_mean, std=self.image_std
              )
              for image in images
          ]
  
      # return as BatchFeature
      data = {"pixel_values": images}
      encoded_inputs = BatchFeature(
          data=data, tensor_type=return_tensors
      )
  
      if self.apply_ocr:
          encoded_inputs["words"] = words_batch
          encoded_inputs["boxes"] = boxes_batch
  
      return encoded_inputs
  
file_path: H2O/h2o_flexgen/benchmark/third_party/transformers/src/transformers/models/layoutlmv3/feature_extraction_layoutlmv3.py
imports: from typing import List, Optional, Union
  import numpy
  from PIL import Image
  from transformers.image_utils import PILImageResampling
  from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin
  from ...image_utils import IMAGENET_STANDARD_MEAN, IMAGENET_STANDARD_STD, ImageFeatureExtractionMixin, is_torch_tensor
  from ...utils import TensorType, is_pytesseract_available, logging, requires_backends
label_desc: Use image node_id 2 for calling the LayoutLMv3FeatureExtractor obj's underlying member method code with example usage: obj.__call__(images, return_tensors) and returns: encoded_inputs