class_docstr: Constructs a FLAVA 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:
      do_resize (`bool`, *optional*, defaults to `True`):
          Whether to resize the input to a certain `size`.
      size (`int`, *optional*, defaults to 224):
          Resize the input to the given size. Only has an effect if `do_resize` is set to `True`.
      resample (`int`, *optional*, defaults to `PIL.Image.Resampling.BICUBIC`):
          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_center_crop (`bool`, *optional*, defaults to `True`):
          Whether to crop the input at the center. If the input size is smaller than `crop_size` along any edge, the
          image is padded with 0's and then center cropped.
      crop_size (`int`, *optional*, defaults to 224):
          Desired output size when applying center-cropping. Only has an effect if `do_center_crop` is set to `True`.
      do_normalize (`bool`, *optional*, defaults to `True`):
          Whether or not to normalize the input with `image_mean` and `image_std`.
      image_mean (`Tuple[float, float, float]`, *optional*, defaults to `[0.485, 0.456, 0.406]`):
          The sequence of means for each channel, to be used when normalizing images.
      image_std (`Tuple[float, float, float]`, *optional*, defaults to `[0.229, 0.224, 0.225]`):
          The sequence of standard deviations for each channel, to be used when normalizing images.
      input_size_patches (`int`, *optional*, defaults to 14):
          Number of patches in the image in height and width direction. 14x14 = 196 total patches.
      total_mask_patches (`int`, *optional*, defaults to 75):
          Total number of patches that should be masked.
      mask_group_min_patches (`int`, *optional*, defaults to 16):
          Minimum number of patches that should be masked.
      mask_group_max_patches (`int`, *optional*, defaults to None):
          Maximum number of patches that should be masked.
      mask_group_min_aspect_ratio (`float`, *optional*, defaults to 0.3):
          Minimum aspect ratio of the mask window.
      mask_group_max_aspect_ratio (`float`, *optional*, defaults to None):
          Maximum aspect ratio of the mask window
      codebook_do_resize (`bool`, *optional*, defaults to `True`):
          Whether to resize the input for codebook to a certain `codebook_size`.
      codebook_size (`int`, *optional*, defaults to 224):
          Resize the input for codebook to the given size. Only has an effect if `codebook_do_resize` is set to
          `True`.
      codebook_resample (`int`, *optional*, defaults to `PIL.Image.Resampling.BICUBIC`):
          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`.
      codebook_do_center_crop (`bool`, *optional*, defaults to `True`):
          Whether to crop the input for codebook at the center. If the input size is smaller than
          `codebook_crop_size` along any edge, the image is padded with 0's and then center cropped.
      codebook_crop_size (`int`, *optional*, defaults to 224):
          Desired output size for codebook input when applying center-cropping. Only has an effect if
          `codebook_do_center_crop` is set to `True`.
      codebook_do_normalize (`bool`, *optional*, defaults to `True`):
          Whether or not to normalize the input for codebook with `codebook_image_mean` and `codebook_image_std`.
      codebook_image_mean (`Tuple[float, float, float]`, *optional*, defaults to `[0, 0, 0]`):
          The sequence of means for each channel, to be used when normalizing images for codebook.
      codebook_image_std (`Tuple[float, float, float]`, *optional*, defaults to `[0.5, 0.5, 0.5]`):
          The sequence of standard deviations for each channel, to be used when normalizing images for codebook.
code: def __init__(
      self,
      do_resize: bool = True,
      size: Union[int, Tuple[int, int]] = 224,
      resample: int = PILImageResampling.BICUBIC,
      do_center_crop: bool = True,
      crop_size: Union[int, Tuple[int, int]] = 224,
      do_normalize: bool = True,
      image_mean: Tuple[float, float, float] = FLAVA_IMAGE_MEAN,
      image_std: Tuple[float, float, float] = FLAVA_IMAGE_STD,
      # Mask related params
      input_size_patches: int = 14,
      total_mask_patches: int = 75,
      mask_group_min_patches: int = 16,
      mask_group_max_patches: Optional[int] = None,
      mask_group_min_aspect_ratio: float = 0.3,
      mask_group_max_aspect_ratio: Optional[float] = None,
      # Codebook related params
      codebook_do_resize: bool = True,
      codebook_size: bool = 112,
      codebook_resample: int = PILImageResampling.LANCZOS,
      codebook_do_center_crop: bool = True,
      codebook_crop_size: int = 112,
      codebook_do_map_pixels: bool = True,
      codebook_do_normalize: bool = True,
      codebook_image_mean: Tuple[
          float, float, float
      ] = FLAVA_CODEBOOK_MEAN,
      codebook_image_std: Tuple[
          float, float, float
      ] = FLAVA_CODEBOOK_STD,
      **kwargs: Any,
  ):
      super().__init__(**kwargs)
      self.do_resize = do_resize
      self.size = size
      self.resample = resample
      self.do_center_crop = do_center_crop
      self.crop_size = crop_size
      self.do_normalize = do_normalize
      self.image_mean = image_mean
      self.image_std = image_std
  
      self.input_size_patches = input_size_patches
      self.total_mask_patches = total_mask_patches
      self.mask_group_min_patches = mask_group_min_patches
      self.mask_group_max_patches = mask_group_max_patches
      self.mask_group_min_aspect_ratio = mask_group_min_aspect_ratio
      self.mask_group_max_aspect_ratio = mask_group_max_aspect_ratio
  
      self.codebook_do_resize = codebook_do_resize
      self.codebook_size = codebook_size
      self.codebook_resample = codebook_resample
      self.codebook_do_center_crop = codebook_do_center_crop
      self.codebook_crop_size = codebook_crop_size
      self.codebook_do_map_pixels = codebook_do_map_pixels
      self.codebook_do_normalize = codebook_do_normalize
      self.codebook_image_mean = codebook_image_mean
      self.codebook_image_std = codebook_image_std
  
imports: import math
  import random
  from functools import lru_cache
  from typing import Any, List, Optional, 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, is_torch_tensor
  from ...utils import TensorType, logging
label_desc: Use image node_id 1 to create a new FlavaFeatureExtractor object from inherited base classes: FeatureExtractionMixin, ImageFeatureExtractionMixin with example: obj = FlavaFeatureExtractor(do_resize, size, resample, do_center_crop, crop_size, do_normalize, image_mean, image_std, input_size_patches, total_mask_patches, mask_group_min_patches, mask_group_max_patches, mask_group_min_aspect_ratio, mask_group_max_aspect_ratio, codebook_do_resize, codebook_size, codebook_resample, codebook_do_center_crop, codebook_crop_size, codebook_do_map_pixels, codebook_do_normalize, codebook_image_mean, codebook_image_std)