


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


lowerCamelCase : List[Any]						   =       logging.get_logger(__name__)

class 		lowerCAmelCase     ( __a			):

					'''simple docstring'''

					_A						:			str									=      ['''pixel_values''']



					def __init__(  self				:	str		,     __a				:	bool = True		,     __a				:	Dict[str, int] = None		,     __a				:	PILImageResampling = PIL.Image.BICUBIC		,     __a				:	bool = True		,     __a				:	Dict[str, int] = None		,     __a				:	Union[int, float] = 1 / 255		,     __a				:	bool = True		,     __a				:	bool = True		,     __a				:	Optional[Union[float, List[float]]] = None		,     __a				:	Optional[Union[float, List[float]]] = None		,     **__a				:	Tuple		,     )			->  None:


												"""simple docstring"""

												super().__init__(**__a							)
												__lowercase      :							Optional[int]				=     size if size is not None else {"""height""": 256, """width""": 256}
												__lowercase      :							int				=     get_size_dict(__a							)
												__lowercase      :							Optional[Any]				=     crop_size if crop_size is not None else {"""height""": 224, """width""": 224}
												__lowercase      :							List[Any]				=     get_size_dict(__a		,     param_name="""crop_size"""							)

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



					def       lowerCAmelCase				(  self				:	List[str]		,     __a				:	np.ndarray		,     __a				:	Dict[str, int]		,     __a				:	PILImageResampling = PIL.Image.BICUBIC		,     __a				:	Optional[Union[str, ChannelDimension]] = None		,     **__a				:	int		,     )			->  np.ndarray:


												"""simple docstring"""

												__lowercase      :							Union[str, Any]				=     get_size_dict(__a							)
												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(
												    __a		,     size=(size["""height"""], size["""width"""])		,     resample=__a		,     data_format=__a		,     **__a							)



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


												"""simple docstring"""

												__lowercase      :							Dict				=     get_size_dict(__a							)
												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(__a		,     size=(size["""height"""], size["""width"""])		,     data_format=__a		,     **__a							)



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


												"""simple docstring"""

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



					def       lowerCAmelCase				(  self				:	List[Any]		,     __a				:	np.ndarray		,     __a				:	Union[float, List[float]]		,     __a				:	Union[float, List[float]]		,     __a				:	Optional[Union[str, ChannelDimension]] = None		,     **__a				:	List[Any]		,     )			->  np.ndarray:


												"""simple docstring"""

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



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


												"""simple docstring"""

												__lowercase      :							Any				=     do_resize if do_resize is not None else self.do_resize
												__lowercase      :							Optional[Any]				=     resample if resample is not None else self.resample
												__lowercase      :							Any				=     do_center_crop if do_center_crop is not None else self.do_center_crop
												__lowercase      :							int				=     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      :							Optional[Any]				=     do_normalize if do_normalize is not None else self.do_normalize
												__lowercase      :							str				=     image_mean if image_mean is not None else self.image_mean
												__lowercase      :							Dict				=     image_std if image_std is not None else self.image_std

												__lowercase      :							Any				=     size if size is not None else self.size
												__lowercase      :							Optional[int]				=     get_size_dict(__a							)
												__lowercase      :							Dict				=     crop_size if crop_size is not None else self.crop_size
												__lowercase      :							int				=     get_size_dict(__a		,     param_name="""crop_size"""							)

												__lowercase      :							Tuple				=     make_list_of_images(__a							)

												if not valid_images(__a							):
																			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.
												__lowercase      :							Tuple				=     [to_numpy_array(__a							) for image in images]

												if do_resize:
																			__lowercase      :							Tuple				=     [self.resize(image=__a		,     size=__a		,     resample=__a							) for image in images]

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

												if do_rescale:
																			__lowercase      :							List[Any]				=     [self.rescale(image=__a		,     scale=__a							) for image in images]

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

												__lowercase      :							Optional[Any]				=     [to_channel_dimension_format(__a		,     __a							) for image in images]

												__lowercase      :							Union[str, Any]				=     {"""pixel_values""": images}
												return BatchFeature(data=__a		,     tensor_type=__a							)







from typing import TYPE_CHECKING

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


lowerCamelCase : int						   =       {
    '''configuration_funnel''': ['''FUNNEL_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''FunnelConfig'''],
    '''convert_funnel_original_tf_checkpoint_to_pytorch''': [],
    '''tokenization_funnel''': ['''FunnelTokenizer'''],
}

try:
	if not is_tokenizers_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	lowerCamelCase : List[str]						   =       ['''FunnelTokenizerFast''']

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	lowerCamelCase : Union[str, Any]						   =       [
	    '''FUNNEL_PRETRAINED_MODEL_ARCHIVE_LIST''',
	    '''FunnelBaseModel''',
	    '''FunnelForMaskedLM''',
	    '''FunnelForMultipleChoice''',
	    '''FunnelForPreTraining''',
	    '''FunnelForQuestionAnswering''',
	    '''FunnelForSequenceClassification''',
	    '''FunnelForTokenClassification''',
	    '''FunnelModel''',
	    '''FunnelPreTrainedModel''',
	    '''load_tf_weights_in_funnel''',
	]

try:
	if not is_tf_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	lowerCamelCase : str						   =       [
	    '''TF_FUNNEL_PRETRAINED_MODEL_ARCHIVE_LIST''',
	    '''TFFunnelBaseModel''',
	    '''TFFunnelForMaskedLM''',
	    '''TFFunnelForMultipleChoice''',
	    '''TFFunnelForPreTraining''',
	    '''TFFunnelForQuestionAnswering''',
	    '''TFFunnelForSequenceClassification''',
	    '''TFFunnelForTokenClassification''',
	    '''TFFunnelModel''',
	    '''TFFunnelPreTrainedModel''',
	]


if TYPE_CHECKING:
	from .configuration_funnel import FUNNEL_PRETRAINED_CONFIG_ARCHIVE_MAP, FunnelConfig
	from .tokenization_funnel import FunnelTokenizer

	try:
		if not is_tokenizers_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .tokenization_funnel_fast import FunnelTokenizerFast

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_funnel import (
		    FUNNEL_PRETRAINED_MODEL_ARCHIVE_LIST,
		    FunnelBaseModel,
		    FunnelForMaskedLM,
		    FunnelForMultipleChoice,
		    FunnelForPreTraining,
		    FunnelForQuestionAnswering,
		    FunnelForSequenceClassification,
		    FunnelForTokenClassification,
		    FunnelModel,
		    FunnelPreTrainedModel,
		    load_tf_weights_in_funnel,
		)

	try:
		if not is_tf_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_tf_funnel import (
		    TF_FUNNEL_PRETRAINED_MODEL_ARCHIVE_LIST,
		    TFFunnelBaseModel,
		    TFFunnelForMaskedLM,
		    TFFunnelForMultipleChoice,
		    TFFunnelForPreTraining,
		    TFFunnelForQuestionAnswering,
		    TFFunnelForSequenceClassification,
		    TFFunnelForTokenClassification,
		    TFFunnelModel,
		    TFFunnelPreTrainedModel,
		)

else:
	import sys

	lowerCamelCase : Any						   =       _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)