



'''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,
    convert_to_rgb,
    get_resize_output_image_size,
    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


_A				:    Dict     						=logging.get_logger(__name__)


if is_vision_available():
		import PIL



class 		lowerCamelCase__      (						A     ):




					'''simple docstring'''



					A_						    =						["""pixel_values"""]




					def __init__(  self				:	Tuple     ,  UpperCamelCase_				:	bool = True     ,  UpperCamelCase_				:	Dict[str, int] = None     ,  UpperCamelCase_				:	PILImageResampling = PILImageResampling.BICUBIC     ,  UpperCamelCase_				:	bool = True     ,  UpperCamelCase_				:	Dict[str, int] = None     ,  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_				:	Union[str, Any]     ,  )  ->       None:



						'''simple docstring'''





						super().__init__(**UpperCamelCase_					)
						_lowercase					:       Union[str, Any]       =		size if size is not None else {'shortest_edge': 224}
						_lowercase					:       str       =		get_size_dict(UpperCamelCase_     ,  default_to_square=UpperCamelCase_					)
						_lowercase					:       List[str]       =		crop_size if crop_size is not None else {'height': 224, 'width': 224}
						_lowercase					:       Union[str, Any]       =		get_size_dict(UpperCamelCase_     ,  default_to_square=UpperCamelCase_     ,  param_name='crop_size'					)

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




					def 						__UpperCAmelCase     (  self				:	List[Any]     ,  UpperCamelCase_				:	np.ndarray     ,  UpperCamelCase_				:	Dict[str, int]     ,  UpperCamelCase_				:	PILImageResampling = PILImageResampling.BICUBIC     ,  UpperCamelCase_				:	Optional[Union[str, ChannelDimension]] = None     ,  **UpperCamelCase_				:	int     ,  )  ->       np.ndarray:



						'''simple docstring'''





						_lowercase					:       Dict       =		get_size_dict(UpperCamelCase_     ,  default_to_square=UpperCamelCase_					)
						if "shortest_edge" not in size:
							raise ValueError(F'''The `size` parameter must contain the key `shortest_edge`. Got {size.keys()}'''					)
						_lowercase					:       Optional[Any]       =		get_resize_output_image_size(UpperCamelCase_     ,  size=size['shortest_edge']     ,  default_to_square=UpperCamelCase_					)
						return resize(UpperCamelCase_     ,  size=UpperCamelCase_     ,  resample=UpperCamelCase_     ,  data_format=UpperCamelCase_     ,  **UpperCamelCase_					)




					def 						__UpperCAmelCase     (  self				:	int     ,  UpperCamelCase_				:	np.ndarray     ,  UpperCamelCase_				:	Dict[str, int]     ,  UpperCamelCase_				:	Optional[Union[str, ChannelDimension]] = None     ,  **UpperCamelCase_				:	Optional[int]     ,  )  ->       np.ndarray:



						'''simple docstring'''





						_lowercase					:       List[Any]       =		get_size_dict(UpperCamelCase_					)
						if "height" not in size or "width" not in size:
							raise ValueError(F'''The `size` parameter must contain the keys (height, width). Got {size.keys()}'''					)
						return center_crop(UpperCamelCase_     ,  size=(size['height'], size['width'])     ,  data_format=UpperCamelCase_     ,  **UpperCamelCase_					)




					def 						__UpperCAmelCase     (  self				:	Optional[int]     ,  UpperCamelCase_				:	np.ndarray     ,  UpperCamelCase_				:	Union[int, float]     ,  UpperCamelCase_				:	Optional[Union[str, ChannelDimension]] = None     ,  **UpperCamelCase_				:	int     ,  )  ->       List[str]:



						'''simple docstring'''





						return rescale(UpperCamelCase_     ,  scale=UpperCamelCase_     ,  data_format=UpperCamelCase_     ,  **UpperCamelCase_					)




					def 						__UpperCAmelCase     (  self				:	str     ,  UpperCamelCase_				:	np.ndarray     ,  UpperCamelCase_				:	Union[float, List[float]]     ,  UpperCamelCase_				:	Union[float, List[float]]     ,  UpperCamelCase_				:	Optional[Union[str, ChannelDimension]] = None     ,  **UpperCamelCase_				:	Optional[int]     ,  )  ->       np.ndarray:



						'''simple docstring'''





						return normalize(UpperCamelCase_     ,  mean=UpperCamelCase_     ,  std=UpperCamelCase_     ,  data_format=UpperCamelCase_     ,  **UpperCamelCase_					)




					def 						__UpperCAmelCase     (  self				:	int     ,  UpperCamelCase_				:	ImageInput     ,  UpperCamelCase_				:	bool = None     ,  UpperCamelCase_				:	Dict[str, int] = None     ,  UpperCamelCase_				:	PILImageResampling = None     ,  UpperCamelCase_				:	bool = None     ,  UpperCamelCase_				:	int = None     ,  UpperCamelCase_				:	bool = None     ,  UpperCamelCase_				:	float = None     ,  UpperCamelCase_				:	bool = None     ,  UpperCamelCase_				:	Optional[Union[float, List[float]]] = None     ,  UpperCamelCase_				:	Optional[Union[float, List[float]]] = None     ,  UpperCamelCase_				:	bool = None     ,  UpperCamelCase_				:	Optional[Union[str, TensorType]] = None     ,  UpperCamelCase_				:	Optional[ChannelDimension] = ChannelDimension.FIRST     ,  **UpperCamelCase_				:	Optional[int]     ,  )  ->       PIL.Image.Image:



						'''simple docstring'''





						_lowercase					:       Union[str, Any]       =		do_resize if do_resize is not None else self.do_resize
						_lowercase					:       Tuple       =		size if size is not None else self.size
						_lowercase					:       Tuple       =		get_size_dict(UpperCamelCase_     ,  param_name='size'     ,  default_to_square=UpperCamelCase_					)
						_lowercase					:       Dict       =		resample if resample is not None else self.resample
						_lowercase					:       Dict       =		do_center_crop if do_center_crop is not None else self.do_center_crop
						_lowercase					:       List[Any]       =		crop_size if crop_size is not None else self.crop_size
						_lowercase					:       Optional[int]       =		get_size_dict(UpperCamelCase_     ,  param_name='crop_size'     ,  default_to_square=UpperCamelCase_					)
						_lowercase					:       Any       =		do_rescale if do_rescale is not None else self.do_rescale
						_lowercase					:       Tuple       =		rescale_factor if rescale_factor is not None else self.rescale_factor
						_lowercase					:       Any       =		do_normalize if do_normalize is not None else self.do_normalize
						_lowercase					:       Any       =		image_mean if image_mean is not None else self.image_mean
						_lowercase					:       Optional[Any]       =		image_std if image_std is not None else self.image_std
						_lowercase					:       Optional[int]       =		do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

						_lowercase					:       int       =		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:
							raise ValueError('Size 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.'					)

						# PIL RGBA images are converted to RGB
						if do_convert_rgb:
							_lowercase					:       Optional[Any]       =		[convert_to_rgb(UpperCamelCase_					) for image in images]

						# All transformations expect numpy arrays.
						_lowercase					:       Optional[Any]       =		[to_numpy_array(UpperCamelCase_					) for image in images]

						if do_resize:
							_lowercase					:       List[str]       =		[self.resize(image=UpperCamelCase_     ,  size=UpperCamelCase_     ,  resample=UpperCamelCase_					) for image in images]

						if do_center_crop:
							_lowercase					:       Optional[int]       =		[self.center_crop(image=UpperCamelCase_     ,  size=UpperCamelCase_					) for image in images]

						if do_rescale:
							_lowercase					:       str       =		[self.rescale(image=UpperCamelCase_     ,  scale=UpperCamelCase_					) for image in images]

						if do_normalize:
							_lowercase					:       Dict       =		[self.normalize(image=UpperCamelCase_     ,  mean=UpperCamelCase_     ,  std=UpperCamelCase_					) for image in images]

						_lowercase					:       List[str]       =		[to_channel_dimension_format(UpperCamelCase_     ,  UpperCamelCase_					) for image in images]

						_lowercase					:       int       =		{'pixel_values': images}
						return BatchFeature(data=UpperCamelCase_     ,  tensor_type=UpperCamelCase_					)





'''simple docstring'''

from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_sentencepiece_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


_A				:    Optional[Any]     						={'''configuration_xlnet''': ['''XLNET_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''XLNetConfig''']}

try:
		if not is_sentencepiece_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		_A				:    Tuple     						=['''XLNetTokenizer''']

try:
		if not is_tokenizers_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		_A				:    str     						=['''XLNetTokenizerFast''']

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		_A				:    Any     						=[
		    '''XLNET_PRETRAINED_MODEL_ARCHIVE_LIST''',
		    '''XLNetForMultipleChoice''',
		    '''XLNetForQuestionAnswering''',
		    '''XLNetForQuestionAnsweringSimple''',
		    '''XLNetForSequenceClassification''',
		    '''XLNetForTokenClassification''',
		    '''XLNetLMHeadModel''',
		    '''XLNetModel''',
		    '''XLNetPreTrainedModel''',
		    '''load_tf_weights_in_xlnet''',
		]

try:
		if not is_tf_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		_A				:    str     						=[
		    '''TF_XLNET_PRETRAINED_MODEL_ARCHIVE_LIST''',
		    '''TFXLNetForMultipleChoice''',
		    '''TFXLNetForQuestionAnsweringSimple''',
		    '''TFXLNetForSequenceClassification''',
		    '''TFXLNetForTokenClassification''',
		    '''TFXLNetLMHeadModel''',
		    '''TFXLNetMainLayer''',
		    '''TFXLNetModel''',
		    '''TFXLNetPreTrainedModel''',
		]


if TYPE_CHECKING:
		from .configuration_xlnet import XLNET_PRETRAINED_CONFIG_ARCHIVE_MAP, XLNetConfig

		try:
				if not is_sentencepiece_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .tokenization_xlnet import XLNetTokenizer

		try:
				if not is_tokenizers_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .tokenization_xlnet_fast import XLNetTokenizerFast

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_xlnet import (
				    XLNET_PRETRAINED_MODEL_ARCHIVE_LIST,
				    XLNetForMultipleChoice,
				    XLNetForQuestionAnswering,
				    XLNetForQuestionAnsweringSimple,
				    XLNetForSequenceClassification,
				    XLNetForTokenClassification,
				    XLNetLMHeadModel,
				    XLNetModel,
				    XLNetPreTrainedModel,
				    load_tf_weights_in_xlnet,
				)

		try:
				if not is_tf_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_tf_xlnet import (
				    TF_XLNET_PRETRAINED_MODEL_ARCHIVE_LIST,
				    TFXLNetForMultipleChoice,
				    TFXLNetForQuestionAnsweringSimple,
				    TFXLNetForSequenceClassification,
				    TFXLNetForTokenClassification,
				    TFXLNetLMHeadModel,
				    TFXLNetMainLayer,
				    TFXLNetModel,
				    TFXLNetPreTrainedModel,
				)

else:
		import sys

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