





'''simple docstring'''

from typing import Dict, List, Optional, Tuple, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    center_crop,
    get_resize_output_image_size,
    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_torch_available, is_torch_tensor, logging


if is_torch_available():
   import torch


lowercase__		:     Tuple			=							logging.get_logger(__name__)
class 							__lowerCAmelCase	(       __magic_name__					):






       """simple docstring"""
       _snake_case      :	Any									=       ['pixel_values']





       def __init__(				self  :						Optional[int]			,					lowerCAmelCase__  :						bool = True			,					lowerCAmelCase__  :						Optional[Dict[str, int]] = None			,					lowerCAmelCase__  :						PILImageResampling = PILImageResampling.BILINEAR			,					lowerCAmelCase__  :						bool = True			,					lowerCAmelCase__  :						Dict[str, int] = None			,					lowerCAmelCase__  :						bool = True			,					lowerCAmelCase__  :						Union[int, float] = 1 / 255			,					lowerCAmelCase__  :						bool = True			,					lowerCAmelCase__  :						Optional[Union[float, List[float]]] = None			,					lowerCAmelCase__  :						Optional[Union[float, List[float]]] = None			,					**lowerCAmelCase__  :						Union[str, Any]			,					)       ->	None:

            '''simple docstring'''




            super().__init__(**lowerCAmelCase__	)
            _UpperCamelCase							       =			size if size is not None else {'''shortest_edge''': 256}
            _UpperCamelCase							       =			get_size_dict(lowerCAmelCase__			,					default_to_square=lowerCAmelCase__	)
            _UpperCamelCase							       =			crop_size if crop_size is not None else {'''height''': 224, '''width''': 224}
            _UpperCamelCase							       =			get_size_dict(lowerCAmelCase__			,					param_name='''crop_size'''	)
            _UpperCamelCase							       =			do_resize
            _UpperCamelCase							       =			size
            _UpperCamelCase							       =			resample
            _UpperCamelCase							       =			do_center_crop
            _UpperCamelCase							       =			crop_size
            _UpperCamelCase							       =			do_rescale
            _UpperCamelCase							       =			rescale_factor
            _UpperCamelCase							       =			do_normalize
            _UpperCamelCase							       =			image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
            _UpperCamelCase							       =			image_std if image_std is not None else IMAGENET_STANDARD_STD





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

            '''simple docstring'''




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





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

            '''simple docstring'''




            _UpperCamelCase							       =			get_size_dict(lowerCAmelCase__	)
            if "height" not in size or "width" not in size:
                 raise ValueError(f"""The `size` parameter must contain the keys `height` and `width`. Got {size.keys()}"""	)
            return center_crop(lowerCAmelCase__			,					size=(size['''height'''], size['''width'''])			,					data_format=lowerCAmelCase__			,					**lowerCAmelCase__	)





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

            '''simple docstring'''




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





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

            '''simple docstring'''




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





       def snake_case__		(				self  :						Any			,					lowerCAmelCase__  :						ImageInput			,					lowerCAmelCase__  :						Optional[bool] = None			,					lowerCAmelCase__  :						Dict[str, int] = None			,					lowerCAmelCase__  :						PILImageResampling = None			,					lowerCAmelCase__  :						bool = None			,					lowerCAmelCase__  :						Dict[str, int] = None			,					lowerCAmelCase__  :						Optional[bool] = None			,					lowerCAmelCase__  :						Optional[float] = None			,					lowerCAmelCase__  :						Optional[bool] = None			,					lowerCAmelCase__  :						Optional[Union[float, List[float]]] = None			,					lowerCAmelCase__  :						Optional[Union[float, List[float]]] = None			,					lowerCAmelCase__  :						Optional[Union[str, TensorType]] = None			,					lowerCAmelCase__  :						Union[str, ChannelDimension] = ChannelDimension.FIRST			,					**lowerCAmelCase__  :						Optional[Any]			,					)       ->	List[str]:

            '''simple docstring'''




            _UpperCamelCase							       =			do_resize if do_resize is not None else self.do_resize
            _UpperCamelCase							       =			size if size is not None else self.size
            _UpperCamelCase							       =			get_size_dict(lowerCAmelCase__			,					default_to_square=lowerCAmelCase__	)
            _UpperCamelCase							       =			resample if resample is not None else self.resample
            _UpperCamelCase							       =			do_center_crop if do_center_crop is not None else self.do_center_crop
            _UpperCamelCase							       =			crop_size if crop_size is not None else self.crop_size
            _UpperCamelCase							       =			get_size_dict(lowerCAmelCase__			,					param_name='''crop_size'''	)
            _UpperCamelCase							       =			do_rescale if do_rescale is not None else self.do_rescale
            _UpperCamelCase							       =			rescale_factor if rescale_factor is not None else self.rescale_factor
            _UpperCamelCase							       =			do_normalize if do_normalize is not None else self.do_normalize
            _UpperCamelCase							       =			image_mean if image_mean is not None else self.image_mean
            _UpperCamelCase							       =			image_std if image_std is not None else self.image_std

            _UpperCamelCase							       =			make_list_of_images(lowerCAmelCase__	)

            if not valid_images(lowerCAmelCase__	):
                 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.'''	)

            # All transformations expect numpy arrays.
            _UpperCamelCase							       =			[to_numpy_array(lowerCAmelCase__	) for image in images]

            if do_resize:
                 _UpperCamelCase							       =			[self.resize(image=lowerCAmelCase__			,					size=lowerCAmelCase__			,					resample=lowerCAmelCase__	) for image in images]

            if do_center_crop:
                 _UpperCamelCase							       =			[self.center_crop(image=lowerCAmelCase__			,					size=lowerCAmelCase__	) for image in images]

            if do_rescale:
                 _UpperCamelCase							       =			[self.rescale(image=lowerCAmelCase__			,					scale=lowerCAmelCase__	) for image in images]

            if do_normalize:
                 _UpperCamelCase							       =			[self.normalize(image=lowerCAmelCase__			,					mean=lowerCAmelCase__			,					std=lowerCAmelCase__	) for image in images]

            _UpperCamelCase							       =			[to_channel_dimension_format(lowerCAmelCase__			,					lowerCAmelCase__	) for image in images]

            _UpperCamelCase							       =			{'''pixel_values''': images}
            return BatchFeature(data=lowerCAmelCase__			,					tensor_type=lowerCAmelCase__	)







       def snake_case__		(				self  :						List[str]			,					lowerCAmelCase__  :						Dict			,					lowerCAmelCase__  :						List[Tuple] = None	)       ->	List[str]:

            '''simple docstring'''




            _UpperCamelCase							       =			outputs.logits

            # Resize logits and compute semantic segmentation maps
            if target_sizes is not None:
                 if len(lowerCAmelCase__	) != len(lowerCAmelCase__	):
                      raise ValueError(
                          '''Make sure that you pass in as many target sizes as the batch dimension of the logits'''	)

                 if is_torch_tensor(lowerCAmelCase__	):
                      _UpperCamelCase							       =			target_sizes.numpy()

                 _UpperCamelCase							       =			[]

                 for idx in range(len(lowerCAmelCase__	)	):
                      _UpperCamelCase							       =			torch.nn.functional.interpolate(
                          logits[idx].unsqueeze(dim=0	)			,					size=target_sizes[idx]			,					mode='''bilinear'''			,					align_corners=lowerCAmelCase__	)
                      _UpperCamelCase							       =			resized_logits[0].argmax(dim=0	)
                      semantic_segmentation.append(lowerCAmelCase__	)
            else:
                 _UpperCamelCase							       =			logits.argmax(dim=1	)
                 _UpperCamelCase							       =			[semantic_segmentation[i] for i in range(semantic_segmentation.shape[0]	)]

            return semantic_segmentation




'''simple docstring'''




from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig


__lowercase        =    {
    '''albert-base-v1''': '''https://huggingface.co/albert-base-v1/resolve/main/config.json''',
    '''albert-large-v1''': '''https://huggingface.co/albert-large-v1/resolve/main/config.json''',
    '''albert-xlarge-v1''': '''https://huggingface.co/albert-xlarge-v1/resolve/main/config.json''',
    '''albert-xxlarge-v1''': '''https://huggingface.co/albert-xxlarge-v1/resolve/main/config.json''',
    '''albert-base-v2''': '''https://huggingface.co/albert-base-v2/resolve/main/config.json''',
    '''albert-large-v2''': '''https://huggingface.co/albert-large-v2/resolve/main/config.json''',
    '''albert-xlarge-v2''': '''https://huggingface.co/albert-xlarge-v2/resolve/main/config.json''',
    '''albert-xxlarge-v2''': '''https://huggingface.co/albert-xxlarge-v2/resolve/main/config.json''',
}






class 							a__(   lowerCAmelCase__      ):


			'''simple docstring'''






			UpperCAmelCase_     :	List[str]						=			'''albert'''



			def __init__(  self			,       __lowerCAmelCase=30000			,       __lowerCAmelCase=128			,       __lowerCAmelCase=4096			,       __lowerCAmelCase=12			,       __lowerCAmelCase=1			,       __lowerCAmelCase=64			,       __lowerCAmelCase=16384			,       __lowerCAmelCase=1			,       __lowerCAmelCase="gelu_new"			,       __lowerCAmelCase=0			,       __lowerCAmelCase=0			,       __lowerCAmelCase=512			,       __lowerCAmelCase=2			,       __lowerCAmelCase=0.02			,       __lowerCAmelCase=1E-1_2			,       __lowerCAmelCase=0.1			,       __lowerCAmelCase="absolute"			,       __lowerCAmelCase=0			,       __lowerCAmelCase=2			,       __lowerCAmelCase=3			,       **__lowerCAmelCase			,       ):




					"""simple docstring"""


					super().__init__(pad_token_id=__lowerCAmelCase			,       bos_token_id=__lowerCAmelCase			,       eos_token_id=__lowerCAmelCase			,       **__lowerCAmelCase)

					lowerCAmelCase     =    vocab_size
					lowerCAmelCase     =    embedding_size
					lowerCAmelCase     =    hidden_size
					lowerCAmelCase     =    num_hidden_layers
					lowerCAmelCase     =    num_hidden_groups
					lowerCAmelCase     =    num_attention_heads
					lowerCAmelCase     =    inner_group_num
					lowerCAmelCase     =    hidden_act
					lowerCAmelCase     =    intermediate_size
					lowerCAmelCase     =    hidden_dropout_prob
					lowerCAmelCase     =    attention_probs_dropout_prob
					lowerCAmelCase     =    max_position_embeddings
					lowerCAmelCase     =    type_vocab_size
					lowerCAmelCase     =    initializer_range
					lowerCAmelCase     =    layer_norm_eps
					lowerCAmelCase     =    classifier_dropout_prob
					lowerCAmelCase     =    position_embedding_type







class 							a__(   lowerCAmelCase__      ):


			'''simple docstring'''






			@property
			def 				a_			(  self):




					"""simple docstring"""


					if self.task == "multiple-choice":
							lowerCAmelCase     =    {0: """batch""", 1: """choice""", 2: """sequence"""}
					else:
							lowerCAmelCase     =    {0: """batch""", 1: """sequence"""}
					return OrderedDict(
					    [
					        ("""input_ids""", dynamic_axis),
					        ("""attention_mask""", dynamic_axis),
					        ("""token_type_ids""", dynamic_axis),
					    ])




