






'''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 convert_to_rgb, normalize, rescale, resize, to_channel_dimension_format
from ...image_utils import (
    OPENAI_CLIP_MEAN,
    OPENAI_CLIP_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


_A			:    Union[str, Any]					  =logging.get_logger(__name__)

class _lowercase			(       _lowercase	):
							a          = ["""pixel_values"""]




							def __init__(							self:       int    ,							UpperCamelCase__:       bool = True    ,							UpperCamelCase__:       Dict[str, int] = None    ,							UpperCamelCase__:       PILImageResampling = PILImageResampling.BICUBIC    ,							UpperCamelCase__:       bool = True    ,							UpperCamelCase__:       Union[int, float] = 1 / 255    ,							UpperCamelCase__:       bool = True    ,							UpperCamelCase__:       Optional[Union[float, List[float]]] = None    ,							UpperCamelCase__:       Optional[Union[float, List[float]]] = None    ,							UpperCamelCase__:       bool = True    ,							**UpperCamelCase__:       Any    ,							):
														super().__init__(**UpperCamelCase__  )
														lowerCamelCase__      :			Dict 						= size if size is not None else {"""height""": 384, """width""": 384}
														lowerCamelCase__      :			Tuple 						= get_size_dict(UpperCamelCase__    ,							default_to_square=UpperCamelCase__  )

														lowerCamelCase__      :			Union[str, Any] 						= do_resize
														lowerCamelCase__      :			int 						= size
														lowerCamelCase__      :			List[str] 						= resample
														lowerCamelCase__      :			Optional[Any] 						= do_rescale
														lowerCamelCase__      :			Dict 						= rescale_factor
														lowerCamelCase__      :			Optional[Any] 						= do_normalize
														lowerCamelCase__      :			str 						= image_mean if image_mean is not None else OPENAI_CLIP_MEAN
														lowerCamelCase__      :			str 						= image_std if image_std is not None else OPENAI_CLIP_STD
														lowerCamelCase__      :			Optional[Any] 						= do_convert_rgb




							def 	lowerCamelCase_       (							self:       List[Any]    ,							UpperCamelCase__:       np.ndarray    ,							UpperCamelCase__:       Dict[str, int]    ,							UpperCamelCase__:       PILImageResampling = PILImageResampling.BICUBIC    ,							UpperCamelCase__:       Optional[Union[str, ChannelDimension]] = None    ,							**UpperCamelCase__:       Union[str, Any]    ,							):
														lowerCamelCase__      :			Dict 						= get_size_dict(UpperCamelCase__    ,							default_to_square=UpperCamelCase__  )
														if "height" not in size or "width" not in size:
																					raise ValueError(F'''The `size` dictionary must contain the keys `height` and `width`. Got {size.keys()}'''  )
														lowerCamelCase__      :			Tuple 						= (size["""height"""], size["""width"""])
														return resize(UpperCamelCase__    ,							size=UpperCamelCase__    ,							resample=UpperCamelCase__    ,							data_format=UpperCamelCase__    ,							**UpperCamelCase__  )




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




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




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

														lowerCamelCase__      :			str 						= size if size is not None else self.size
														lowerCamelCase__      :			Tuple 						= get_size_dict(UpperCamelCase__    ,							default_to_square=UpperCamelCase__  )

														lowerCamelCase__      :			str 						= make_list_of_images(UpperCamelCase__  )

														if not valid_images(UpperCamelCase__  ):
																					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_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."""  )

														# PIL RGBA images are converted to RGB
														if do_convert_rgb:
																					lowerCamelCase__      :			int 						= [convert_to_rgb(UpperCamelCase__  ) for image in images]

														# All transformations expect numpy arrays.
														lowerCamelCase__      :			Dict 						= [to_numpy_array(UpperCamelCase__  ) for image in images]

														if do_resize:
																					lowerCamelCase__      :			List[Any] 						= [self.resize(image=UpperCamelCase__    ,							size=UpperCamelCase__    ,							resample=UpperCamelCase__  ) for image in images]

														if do_rescale:
																					lowerCamelCase__      :			Optional[Any] 						= [self.rescale(image=UpperCamelCase__    ,							scale=UpperCamelCase__  ) for image in images]

														if do_normalize:
																					lowerCamelCase__      :			Optional[Any] 						= [self.normalize(image=UpperCamelCase__    ,							mean=UpperCamelCase__    ,							std=UpperCamelCase__  ) for image in images]

														lowerCamelCase__      :			List[Any] 						= [to_channel_dimension_format(UpperCamelCase__    ,							UpperCamelCase__  ) for image in images]

														lowerCamelCase__      :			Optional[Any] 						= BatchFeature(data={"""pixel_values""": images}    ,							tensor_type=UpperCamelCase__  )

														return encoded_outputs









'''simple docstring'''







from typing import TYPE_CHECKING

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


_A			:    Any					  ={
    '''configuration_trocr''': ['''TROCR_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''TrOCRConfig'''],
    '''processing_trocr''': ['''TrOCRProcessor'''],
}


try:
			if not is_torch_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			_A			:    str					  =[
			    '''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

			_A			:    Dict					  =_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)

