

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


_a       =							logging.get_logger(__name__)




class 					_lowerCAmelCase  (	lowercase   ):







 """simple docstring"""







 __UpperCAmelCase	:					Tuple   		=	["pixel_values"]


 def __init__(			self							:			Optional[int],					UpperCAmelCase__							:			bool = True,					UpperCAmelCase__							:			Optional[Dict[str, int]] = None,					UpperCAmelCase__							:			PILImageResampling = PILImageResampling.BILINEAR,					UpperCAmelCase__							:			bool = True,					UpperCAmelCase__							:			Dict[str, int] = None,					UpperCAmelCase__							:			bool = True,					UpperCAmelCase__							:			Union[int, float] = 1 / 2_5_5,					UpperCAmelCase__							:			bool = True,					UpperCAmelCase__							:			Optional[Union[float, List[float]]] = None,					UpperCAmelCase__							:			Optional[Union[float, List[float]]] = None,					**UpperCAmelCase__							:			Any,					):
    super().__init__(**UpperCAmelCase__	)
    __lowercase								=						size if size is not None else {"shortest_edge": 2_5_6}
    __lowercase								=						get_size_dict(UpperCAmelCase__,					default_to_square=UpperCAmelCase__	)
    __lowercase								=						crop_size if crop_size is not None else {"height": 2_2_4, "width": 2_2_4}
    __lowercase								=						get_size_dict(UpperCAmelCase__,					param_name="crop_size"	)
    __lowercase								=						do_resize
    __lowercase								=						size
    __lowercase								=						resample
    __lowercase								=						do_center_crop
    __lowercase								=						crop_size
    __lowercase								=						do_rescale
    __lowercase								=						rescale_factor
    __lowercase								=						do_normalize
    __lowercase								=						image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
    __lowercase								=						image_std if image_std is not None else IMAGENET_STANDARD_STD


 def 					_lowercase (			self							:			Union[str, Any],					UpperCAmelCase__							:			np.ndarray,					UpperCAmelCase__							:			Dict[str, int],					UpperCAmelCase__							:			PILImageResampling = PILImageResampling.BICUBIC,					UpperCAmelCase__							:			Optional[Union[str, ChannelDimension]] = None,					**UpperCAmelCase__							:			Union[str, Any],					):
    __lowercase								=						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								=						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 					_lowercase (			self							:			Optional[int],					UpperCAmelCase__							:			np.ndarray,					UpperCAmelCase__							:			Dict[str, int],					UpperCAmelCase__							:			Optional[Union[str, ChannelDimension]] = None,					**UpperCAmelCase__							:			Optional[int],					):
    __lowercase								=						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` and `width`. Got {size.keys()}"""	)
    return center_crop(UpperCAmelCase__,					size=(size["height"], size["width"]),					data_format=UpperCAmelCase__,					**UpperCAmelCase__	)


 def 					_lowercase (			self							:			str,					UpperCAmelCase__							:			np.ndarray,					UpperCAmelCase__							:			float,					UpperCAmelCase__							:			Optional[Union[str, ChannelDimension]] = None,					**UpperCAmelCase__							:			Union[str, Any]	):
    return rescale(UpperCAmelCase__,					scale=UpperCAmelCase__,					data_format=UpperCAmelCase__,					**UpperCAmelCase__	)


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


 def 					_lowercase (			self							:			Dict,					UpperCAmelCase__							:			ImageInput,					UpperCAmelCase__							:			Optional[bool] = None,					UpperCAmelCase__							:			Dict[str, int] = None,					UpperCAmelCase__							:			PILImageResampling = None,					UpperCAmelCase__							:			bool = None,					UpperCAmelCase__							:			Dict[str, int] = 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__							:			Union[str, ChannelDimension] = ChannelDimension.FIRST,					**UpperCAmelCase__							:			Optional[Any],					):
    __lowercase								=						do_resize if do_resize is not None else self.do_resize
    __lowercase								=						size if size is not None else self.size
    __lowercase								=						get_size_dict(UpperCAmelCase__,					default_to_square=UpperCAmelCase__	)
    __lowercase								=						resample if resample is not None else self.resample
    __lowercase								=						do_center_crop if do_center_crop is not None else self.do_center_crop
    __lowercase								=						crop_size if crop_size is not None else self.crop_size
    __lowercase								=						get_size_dict(UpperCAmelCase__,					param_name="crop_size"	)
    __lowercase								=						do_rescale if do_rescale is not None else self.do_rescale
    __lowercase								=						rescale_factor if rescale_factor is not None else self.rescale_factor
    __lowercase								=						do_normalize if do_normalize is not None else self.do_normalize
    __lowercase								=						image_mean if image_mean is not None else self.image_mean
    __lowercase								=						image_std if image_std is not None else self.image_std

    __lowercase								=						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."	)

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

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

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

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

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

    __lowercase								=						[to_channel_dimension_format(UpperCAmelCase__,					UpperCAmelCase__	) for image in images]

    __lowercase								=						{"pixel_values": images}
    return BatchFeature(data=UpperCAmelCase__,					tensor_type=UpperCAmelCase__	)



 def 					_lowercase (			self							:			Optional[Any],					UpperCAmelCase__							:			Tuple,					UpperCAmelCase__							:			List[Tuple] = None	):
    __lowercase								=						outputs.logits

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

       if is_torch_tensor(UpperCAmelCase__	):
          __lowercase								=						target_sizes.numpy()

       __lowercase								=						[]

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

    return semantic_segmentation










from collections import OrderedDict
from typing import Mapping

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


__lowerCAmelCase		:				int       			=		{
    '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     snake_case__							(_UpperCamelCase   ):
				"""simple docstring"""



				SCREAMING_SNAKE_CASE_       :							Optional[int]							 =					"""albert"""





				def __init__(      self				:     List[str]					,      __lowerCamelCase				:     Union[str, Any]=3_00_00					,      __lowerCamelCase				:     Union[str, Any]=1_28					,      __lowerCamelCase				:     Any=40_96					,      __lowerCamelCase				:     str=12					,      __lowerCamelCase				:     Union[str, Any]=1					,      __lowerCamelCase				:     Union[str, Any]=64					,      __lowerCamelCase				:     Dict=1_63_84					,      __lowerCamelCase				:     List[Any]=1					,      __lowerCamelCase				:     Optional[Any]="gelu_new"					,      __lowerCamelCase				:     List[str]=0					,      __lowerCamelCase				:     List[str]=0					,      __lowerCamelCase				:     Tuple=5_12					,      __lowerCamelCase				:     Optional[Any]=2					,      __lowerCamelCase				:     Optional[Any]=0.02					,      __lowerCamelCase				:     Optional[Any]=1e-12					,      __lowerCamelCase				:     Union[str, Any]=0.1					,      __lowerCamelCase				:     Any="absolute"					,      __lowerCamelCase				:     List[str]=0					,      __lowerCamelCase				:     List[str]=2					,      __lowerCamelCase				:     Any=3					,      **__lowerCamelCase				:     int					,      )					->     int:
							super().__init__(pad_token_id=__lowerCamelCase					,      bos_token_id=__lowerCamelCase					,      eos_token_id=__lowerCamelCase					,      **__lowerCamelCase							)

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




class     snake_case__							(_UpperCamelCase   ):
				"""simple docstring"""



				@property
				def 							__UpperCAmelCase							(      self				:     List[Any]							)					->     Mapping[str, Mapping[int, str]]:
							if self.task == "multiple-choice":
										a    =			{0: "batch", 1: "choice", 2: "sequence"}
							else:
										a    =			{0: "batch", 1: "sequence"}
							return OrderedDict(
							    [
							        ("input_ids", dynamic_axis),
							        ("attention_mask", dynamic_axis),
							        ("token_type_ids", dynamic_axis),
							    ]							)






