



"""simple docstring"""







from typing import Dict, List, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import center_crop, normalize, rescale, resize, to_channel_dimension_format
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


if is_vision_available():
     import PIL


lowercase__		:    Optional[Any]				   =     logging.get_logger(__name__)







class 				UpperCamelCase__       (     lowercase_  ):




      """simple docstring"""




      _SCREAMING_SNAKE_CASE      =					["""pixel_values"""]



      def __init__(				self    :				Optional[int]   ,      SCREAMING_SNAKE_CASE_    :				bool = True   ,      SCREAMING_SNAKE_CASE_    :				Dict[str, int] = None   ,      SCREAMING_SNAKE_CASE_    :				PILImageResampling = PIL.Image.BICUBIC   ,      SCREAMING_SNAKE_CASE_    :				bool = True   ,      SCREAMING_SNAKE_CASE_    :				Dict[str, int] = None   ,      SCREAMING_SNAKE_CASE_    :				Union[int, float] = 1 / 2_5_5   ,      SCREAMING_SNAKE_CASE_    :				bool = True   ,      SCREAMING_SNAKE_CASE_    :				bool = True   ,      SCREAMING_SNAKE_CASE_    :				Optional[Union[float, List[float]]] = None   ,      SCREAMING_SNAKE_CASE_    :				Optional[Union[float, List[float]]] = None   ,      **SCREAMING_SNAKE_CASE_    :				str   ,      ):
        super().__init__(**SCREAMING_SNAKE_CASE_	)
        lowerCAmelCase_       :    Optional[int]								=			size if size is not None else {'height': 2_5_6, 'width': 2_5_6}
        lowerCAmelCase_       :    int								=			get_size_dict(SCREAMING_SNAKE_CASE_	)
        lowerCAmelCase_       :    List[Any]								=			crop_size if crop_size is not None else {'height': 2_2_4, 'width': 2_2_4}
        lowerCAmelCase_       :    Dict								=			get_size_dict(SCREAMING_SNAKE_CASE_   ,      param_name='crop_size'	)

        lowerCAmelCase_       :    Optional[Any]								=			do_resize
        lowerCAmelCase_       :    str								=			size
        lowerCAmelCase_       :    Dict								=			resample
        lowerCAmelCase_       :    Optional[Any]								=			do_center_crop
        lowerCAmelCase_       :    Optional[int]								=			crop_size
        lowerCAmelCase_       :    Any								=			do_rescale
        lowerCAmelCase_       :    Tuple								=			rescale_factor
        lowerCAmelCase_       :    Any								=			do_normalize
        lowerCAmelCase_       :    Dict								=			image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
        lowerCAmelCase_       :    Union[str, Any]								=			image_std if image_std is not None else IMAGENET_STANDARD_STD



      def 					SCREAMING_SNAKE_CASE__			(				self    :				Any   ,      SCREAMING_SNAKE_CASE_    :				np.ndarray   ,      SCREAMING_SNAKE_CASE_    :				Dict[str, int]   ,      SCREAMING_SNAKE_CASE_    :				PILImageResampling = PIL.Image.BICUBIC   ,      SCREAMING_SNAKE_CASE_    :				Optional[Union[str, ChannelDimension]] = None   ,      **SCREAMING_SNAKE_CASE_    :				int   ,      ):
        lowerCAmelCase_       :    Any								=			get_size_dict(SCREAMING_SNAKE_CASE_	)
        if "height" not in size or "width" not in size:
          raise ValueError(F"The size dictionary must have keys 'height' and 'width'. Got {size.keys()}"	)
        return resize(
            SCREAMING_SNAKE_CASE_   ,      size=(size['height'], size['width'])   ,      resample=SCREAMING_SNAKE_CASE_   ,      data_format=SCREAMING_SNAKE_CASE_   ,      **SCREAMING_SNAKE_CASE_	)



      def 					SCREAMING_SNAKE_CASE__			(				self    :				int   ,      SCREAMING_SNAKE_CASE_    :				np.ndarray   ,      SCREAMING_SNAKE_CASE_    :				Dict[str, int]   ,      SCREAMING_SNAKE_CASE_    :				Optional[Union[str, ChannelDimension]] = None   ,      **SCREAMING_SNAKE_CASE_    :				Union[str, Any]   ,      ):
        lowerCAmelCase_       :    List[str]								=			get_size_dict(SCREAMING_SNAKE_CASE_	)
        if "height" not in size or "width" not in size:
          raise ValueError(F"The size dictionary must have keys 'height' and 'width'. Got {size.keys()}"	)
        return center_crop(SCREAMING_SNAKE_CASE_   ,      size=(size['height'], size['width'])   ,      data_format=SCREAMING_SNAKE_CASE_   ,      **SCREAMING_SNAKE_CASE_	)



      def 					SCREAMING_SNAKE_CASE__			(				self    :				str   ,      SCREAMING_SNAKE_CASE_    :				np.ndarray   ,      SCREAMING_SNAKE_CASE_    :				Union[int, float]   ,      SCREAMING_SNAKE_CASE_    :				Optional[Union[str, ChannelDimension]] = None   ,      **SCREAMING_SNAKE_CASE_    :				Optional[int]   ,      ):
        return rescale(SCREAMING_SNAKE_CASE_   ,      scale=SCREAMING_SNAKE_CASE_   ,      data_format=SCREAMING_SNAKE_CASE_   ,      **SCREAMING_SNAKE_CASE_	)



      def 					SCREAMING_SNAKE_CASE__			(				self    :				Any   ,      SCREAMING_SNAKE_CASE_    :				np.ndarray   ,      SCREAMING_SNAKE_CASE_    :				Union[float, List[float]]   ,      SCREAMING_SNAKE_CASE_    :				Union[float, List[float]]   ,      SCREAMING_SNAKE_CASE_    :				Optional[Union[str, ChannelDimension]] = None   ,      **SCREAMING_SNAKE_CASE_    :				Optional[Any]   ,      ):
        return normalize(SCREAMING_SNAKE_CASE_   ,      mean=SCREAMING_SNAKE_CASE_   ,      std=SCREAMING_SNAKE_CASE_   ,      data_format=SCREAMING_SNAKE_CASE_   ,      **SCREAMING_SNAKE_CASE_	)





      def 					SCREAMING_SNAKE_CASE__			(				self    :				Dict   ,      SCREAMING_SNAKE_CASE_    :				ImageInput   ,      SCREAMING_SNAKE_CASE_    :				bool = None   ,      SCREAMING_SNAKE_CASE_    :				Dict[str, int] = None   ,      SCREAMING_SNAKE_CASE_    :				Any=None   ,      SCREAMING_SNAKE_CASE_    :				bool = None   ,      SCREAMING_SNAKE_CASE_    :				Dict[str, int] = None   ,      SCREAMING_SNAKE_CASE_    :				bool = None   ,      SCREAMING_SNAKE_CASE_    :				float = None   ,      SCREAMING_SNAKE_CASE_    :				bool = None   ,      SCREAMING_SNAKE_CASE_    :				Optional[Union[float, List[float]]] = None   ,      SCREAMING_SNAKE_CASE_    :				Optional[Union[float, List[float]]] = None   ,      SCREAMING_SNAKE_CASE_    :				Optional[Union[str, TensorType]] = None   ,      SCREAMING_SNAKE_CASE_    :				ChannelDimension = ChannelDimension.FIRST   ,      **SCREAMING_SNAKE_CASE_    :				Tuple   ,      ):
        lowerCAmelCase_       :    Tuple								=			do_resize if do_resize is not None else self.do_resize
        lowerCAmelCase_       :    Optional[Any]								=			resample if resample is not None else self.resample
        lowerCAmelCase_       :    int								=			do_center_crop if do_center_crop is not None else self.do_center_crop
        lowerCAmelCase_       :    Any								=			do_rescale if do_rescale is not None else self.do_rescale
        lowerCAmelCase_       :    Optional[int]								=			rescale_factor if rescale_factor is not None else self.rescale_factor
        lowerCAmelCase_       :    Optional[Any]								=			do_normalize if do_normalize is not None else self.do_normalize
        lowerCAmelCase_       :    Union[str, Any]								=			image_mean if image_mean is not None else self.image_mean
        lowerCAmelCase_       :    Dict								=			image_std if image_std is not None else self.image_std

        lowerCAmelCase_       :    Optional[int]								=			size if size is not None else self.size
        lowerCAmelCase_       :    Tuple								=			get_size_dict(SCREAMING_SNAKE_CASE_	)
        lowerCAmelCase_       :    Dict								=			crop_size if crop_size is not None else self.crop_size
        lowerCAmelCase_       :    List[Any]								=			get_size_dict(SCREAMING_SNAKE_CASE_   ,      param_name='crop_size'	)

        lowerCAmelCase_       :    int								=			make_list_of_images(SCREAMING_SNAKE_CASE_	)

        if not valid_images(SCREAMING_SNAKE_CASE_	):
          raise ValueError(
              'Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, '
              'torch.Tensor, tf.Tensor or jax.ndarray.'	)

        if do_resize and size is None or resample is None:
          raise ValueError('Size and resample must be specified if do_resize is True.'	)

        if do_center_crop and crop_size is None:
          raise ValueError('Crop size must be specified if do_center_crop is True.'	)

        if do_rescale and rescale_factor is None:
          raise ValueError('Rescale factor must be specified if do_rescale is True.'	)

        if do_normalize and (image_mean is None or image_std is None):
          raise ValueError('Image mean and std must be specified if do_normalize is True.'	)

        # All transformations expect numpy arrays.
        lowerCAmelCase_       :    Optional[int]								=			[to_numpy_array(SCREAMING_SNAKE_CASE_	) for image in images]

        if do_resize:
          lowerCAmelCase_       :    Any								=			[self.resize(image=SCREAMING_SNAKE_CASE_   ,      size=SCREAMING_SNAKE_CASE_   ,      resample=SCREAMING_SNAKE_CASE_	) for image in images]

        if do_center_crop:
          lowerCAmelCase_       :    Dict								=			[self.center_crop(image=SCREAMING_SNAKE_CASE_   ,      size=SCREAMING_SNAKE_CASE_	) for image in images]

        if do_rescale:
          lowerCAmelCase_       :    List[str]								=			[self.rescale(image=SCREAMING_SNAKE_CASE_   ,      scale=SCREAMING_SNAKE_CASE_	) for image in images]

        if do_normalize:
          lowerCAmelCase_       :    Union[str, Any]								=			[self.normalize(image=SCREAMING_SNAKE_CASE_   ,      mean=SCREAMING_SNAKE_CASE_   ,      std=SCREAMING_SNAKE_CASE_	) for image in images]

        lowerCAmelCase_       :    List[str]								=			[to_channel_dimension_format(SCREAMING_SNAKE_CASE_   ,      SCREAMING_SNAKE_CASE_	) for image in images]

        lowerCAmelCase_       :    List[Any]								=			{'pixel_values': images}
        return BatchFeature(data=SCREAMING_SNAKE_CASE_   ,      tensor_type=SCREAMING_SNAKE_CASE_	)










"""simple docstring"""







from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_sentencepiece_available,
    is_speech_available,
    is_torch_available,
)


lowercase__		:    Optional[int]				   =     {
    """configuration_trocr""": ["""TROCR_PRETRAINED_CONFIG_ARCHIVE_MAP""", """TrOCRConfig"""],
    """processing_trocr""": ["""TrOCRProcessor"""],
}


try:
     if not is_torch_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     lowercase__		:    Dict				   =     [
         """TROCR_PRETRAINED_MODEL_ARCHIVE_LIST""",
         """TrOCRForCausalLM""",
         """TrOCRPreTrainedModel""",
     ]


if TYPE_CHECKING:
     from .configuration_trocr import TROCR_PRETRAINED_CONFIG_ARCHIVE_MAP, TrOCRConfig
     from .processing_trocr import TrOCRProcessor

     try:
          if not is_torch_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_trocr import TROCR_PRETRAINED_MODEL_ARCHIVE_LIST, TrOCRForCausalLM, TrOCRPreTrainedModel

else:
     import sys

     lowercase__		:    int				   =     _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)





