






'''simple docstring'''







from typing import TYPE_CHECKING

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


UpperCamelCase     :   Dict	      =		{
    'configuration_mobilebert': [
        'MOBILEBERT_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'MobileBertConfig',
        'MobileBertOnnxConfig',
    ],
    'tokenization_mobilebert': ['MobileBertTokenizer'],
}

try:
							if not is_tokenizers_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							UpperCamelCase     :   Optional[Any]	      =		['MobileBertTokenizerFast']

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							UpperCamelCase     :   Optional[Any]	      =		[
							    'MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST',
							    'MobileBertForMaskedLM',
							    'MobileBertForMultipleChoice',
							    'MobileBertForNextSentencePrediction',
							    'MobileBertForPreTraining',
							    'MobileBertForQuestionAnswering',
							    'MobileBertForSequenceClassification',
							    'MobileBertForTokenClassification',
							    'MobileBertLayer',
							    'MobileBertModel',
							    'MobileBertPreTrainedModel',
							    'load_tf_weights_in_mobilebert',
							]

try:
							if not is_tf_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							UpperCamelCase     :   List[str]	      =		[
							    'TF_MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST',
							    'TFMobileBertForMaskedLM',
							    'TFMobileBertForMultipleChoice',
							    'TFMobileBertForNextSentencePrediction',
							    'TFMobileBertForPreTraining',
							    'TFMobileBertForQuestionAnswering',
							    'TFMobileBertForSequenceClassification',
							    'TFMobileBertForTokenClassification',
							    'TFMobileBertMainLayer',
							    'TFMobileBertModel',
							    'TFMobileBertPreTrainedModel',
							]


if TYPE_CHECKING:
							from .configuration_mobilebert import (
							    MOBILEBERT_PRETRAINED_CONFIG_ARCHIVE_MAP,
							    MobileBertConfig,
							    MobileBertOnnxConfig,
							)
							from .tokenization_mobilebert import MobileBertTokenizer

							try:
														if not is_tokenizers_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .tokenization_mobilebert_fast import MobileBertTokenizerFast

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_mobilebert import (
														    MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
														    MobileBertForMaskedLM,
														    MobileBertForMultipleChoice,
														    MobileBertForNextSentencePrediction,
														    MobileBertForPreTraining,
														    MobileBertForQuestionAnswering,
														    MobileBertForSequenceClassification,
														    MobileBertForTokenClassification,
														    MobileBertLayer,
														    MobileBertModel,
														    MobileBertPreTrainedModel,
														    load_tf_weights_in_mobilebert,
														)

							try:
														if not is_tf_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_tf_mobilebert import (
														    TF_MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
														    TFMobileBertForMaskedLM,
														    TFMobileBertForMultipleChoice,
														    TFMobileBertForNextSentencePrediction,
														    TFMobileBertForPreTraining,
														    TFMobileBertForQuestionAnswering,
														    TFMobileBertForSequenceClassification,
														    TFMobileBertForTokenClassification,
														    TFMobileBertMainLayer,
														    TFMobileBertModel,
														    TFMobileBertPreTrainedModel,
														)

else:
							import sys

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





'''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


UpperCAmelCase_						:  int				  =						logging.get_logger(__name__)


if is_vision_available():
				import PIL





class        lowercase__    (		_snake_case   ):





							'''simple docstring'''


							A_				: int       =    ["""pixel_values"""]






							def __init__(       self       ,   __snake_case = True       ,   __snake_case = None       ,   __snake_case = PILImageResampling.BICUBIC       ,   __snake_case = True       ,   __snake_case = None       ,   __snake_case = True       ,   __snake_case = 1 / 255       ,   __snake_case = True       ,   __snake_case = None       ,   __snake_case = None       ,   __snake_case = True       ,   **__snake_case       ,   ):
											super().__init__(**__snake_case    )
											_SCREAMING_SNAKE_CASE					:			int							= size if size is not None else {"""shortest_edge""": 224}
											_SCREAMING_SNAKE_CASE					:			Optional[Any]							= get_size_dict(__snake_case       ,   default_to_square=__snake_case    )
											_SCREAMING_SNAKE_CASE					:			Optional[Any]							= crop_size if crop_size is not None else {"""height""": 224, """width""": 224}
											_SCREAMING_SNAKE_CASE					:			Any							= get_size_dict(__snake_case       ,   default_to_square=__snake_case       ,   param_name="""crop_size"""    )

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






							def UpperCAmelCase_      (       self       ,   __snake_case       ,   __snake_case       ,   __snake_case = PILImageResampling.BICUBIC       ,   __snake_case = None       ,   **__snake_case       ,   ):
											_SCREAMING_SNAKE_CASE					:			int							= get_size_dict(__snake_case       ,   default_to_square=__snake_case    )
											if "shortest_edge" not in size:
															raise ValueError(f"""The `size` parameter must contain the key `shortest_edge`. Got {size.keys()}"""    )
											_SCREAMING_SNAKE_CASE					:			Any							= get_resize_output_image_size(__snake_case       ,   size=size["""shortest_edge"""]       ,   default_to_square=__snake_case    )
											return resize(__snake_case       ,   size=__snake_case       ,   resample=__snake_case       ,   data_format=__snake_case       ,   **__snake_case    )






							def UpperCAmelCase_      (       self       ,   __snake_case       ,   __snake_case       ,   __snake_case = None       ,   **__snake_case       ,   ):
											_SCREAMING_SNAKE_CASE					:			List[str]							= get_size_dict(__snake_case    )
											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(__snake_case       ,   size=(size["""height"""], size["""width"""])       ,   data_format=__snake_case       ,   **__snake_case    )






							def UpperCAmelCase_      (       self       ,   __snake_case       ,   __snake_case       ,   __snake_case = None       ,   **__snake_case       ,   ):
											return rescale(__snake_case       ,   scale=__snake_case       ,   data_format=__snake_case       ,   **__snake_case    )






							def UpperCAmelCase_      (       self       ,   __snake_case       ,   __snake_case       ,   __snake_case       ,   __snake_case = None       ,   **__snake_case       ,   ):
											return normalize(__snake_case       ,   mean=__snake_case       ,   std=__snake_case       ,   data_format=__snake_case       ,   **__snake_case    )






							def UpperCAmelCase_      (       self       ,   __snake_case       ,   __snake_case = None       ,   __snake_case = None       ,   __snake_case = None       ,   __snake_case = None       ,   __snake_case = None       ,   __snake_case = None       ,   __snake_case = None       ,   __snake_case = None       ,   __snake_case = None       ,   __snake_case = None       ,   __snake_case = None       ,   __snake_case = None       ,   __snake_case = ChannelDimension.FIRST       ,   **__snake_case       ,   ):
											_SCREAMING_SNAKE_CASE					:			Optional[int]							= do_resize if do_resize is not None else self.do_resize
											_SCREAMING_SNAKE_CASE					:			Any							= size if size is not None else self.size
											_SCREAMING_SNAKE_CASE					:			List[str]							= get_size_dict(__snake_case       ,   param_name="""size"""       ,   default_to_square=__snake_case    )
											_SCREAMING_SNAKE_CASE					:			Any							= resample if resample is not None else self.resample
											_SCREAMING_SNAKE_CASE					:			Optional[Any]							= do_center_crop if do_center_crop is not None else self.do_center_crop
											_SCREAMING_SNAKE_CASE					:			str							= crop_size if crop_size is not None else self.crop_size
											_SCREAMING_SNAKE_CASE					:			Optional[int]							= get_size_dict(__snake_case       ,   param_name="""crop_size"""       ,   default_to_square=__snake_case    )
											_SCREAMING_SNAKE_CASE					:			Optional[int]							= do_rescale if do_rescale is not None else self.do_rescale
											_SCREAMING_SNAKE_CASE					:			int							= rescale_factor if rescale_factor is not None else self.rescale_factor
											_SCREAMING_SNAKE_CASE					:			Tuple							= do_normalize if do_normalize is not None else self.do_normalize
											_SCREAMING_SNAKE_CASE					:			List[str]							= image_mean if image_mean is not None else self.image_mean
											_SCREAMING_SNAKE_CASE					:			List[Any]							= image_std if image_std is not None else self.image_std
											_SCREAMING_SNAKE_CASE					:			Any							= do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

											_SCREAMING_SNAKE_CASE					:			Optional[Any]							= make_list_of_images(__snake_case    )

											if not valid_images(__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:
															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:
															_SCREAMING_SNAKE_CASE					:			Optional[int]							= [convert_to_rgb(__snake_case    ) for image in images]

											# All transformations expect numpy arrays.
											_SCREAMING_SNAKE_CASE					:			str							= [to_numpy_array(__snake_case    ) for image in images]

											if do_resize:
															_SCREAMING_SNAKE_CASE					:			Optional[Any]							= [self.resize(image=__snake_case       ,   size=__snake_case       ,   resample=__snake_case    ) for image in images]

											if do_center_crop:
															_SCREAMING_SNAKE_CASE					:			Tuple							= [self.center_crop(image=__snake_case       ,   size=__snake_case    ) for image in images]

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

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

											_SCREAMING_SNAKE_CASE					:			str							= [to_channel_dimension_format(__snake_case       ,   __snake_case    ) for image in images]

											_SCREAMING_SNAKE_CASE					:			int							= {"""pixel_values""": images}
											return BatchFeature(data=__snake_case       ,   tensor_type=__snake_case    )




