
'''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	:	str     =     logging.get_logger(__name__)
class 						__UpperCamelCase	(						lowercase__							):
							lowercase			:		Union[str, Any]   		=  ['pixel_values']





							def __init__(  self		:Dict  ,_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		:Dict  ,):
									super().__init__(**_UpperCamelCase			)
									snake_case_		:							Dict			       =						size if size is not None else {"""shortest_edge""": 2_5_6}
									snake_case_		:							str			       =						get_size_dict(_UpperCamelCase  ,default_to_square=_UpperCamelCase			)
									snake_case_		:							int			       =						crop_size if crop_size is not None else {"""height""": 2_2_4, """width""": 2_2_4}
									snake_case_		:							Optional[Any]			       =						get_size_dict(_UpperCamelCase  ,param_name="""crop_size"""			)
									snake_case_		:							Dict			       =						do_resize
									snake_case_		:							Dict			       =						size
									snake_case_		:							Optional[int]			       =						resample
									snake_case_		:							Dict			       =						do_center_crop
									snake_case_		:							Tuple			       =						crop_size
									snake_case_		:							str			       =						do_rescale
									snake_case_		:							List[Any]			       =						rescale_factor
									snake_case_		:							Dict			       =						do_normalize
									snake_case_		:							Union[str, Any]			       =						image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
									snake_case_		:							Any			       =						image_std if image_std is not None else IMAGENET_STANDARD_STD





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





							def 		a__   (  self		:int  ,_UpperCamelCase		:np.ndarray  ,_UpperCamelCase		:float  ,_UpperCamelCase		:Optional[Union[str, ChannelDimension]] = None  ,**_UpperCamelCase		:Tuple			):
									return rescale(_UpperCamelCase  ,scale=_UpperCamelCase  ,data_format=_UpperCamelCase  ,**_UpperCamelCase			)





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





							def 		a__   (  self		:str  ,_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		:Tuple  ,):
									snake_case_		:							Dict			       =						do_resize if do_resize is not None else self.do_resize
									snake_case_		:							Optional[int]			       =						size if size is not None else self.size
									snake_case_		:							Union[str, Any]			       =						get_size_dict(_UpperCamelCase  ,default_to_square=_UpperCamelCase			)
									snake_case_		:							List[str]			       =						resample if resample is not None else self.resample
									snake_case_		:							Optional[Any]			       =						do_center_crop if do_center_crop is not None else self.do_center_crop
									snake_case_		:							Tuple			       =						crop_size if crop_size is not None else self.crop_size
									snake_case_		:							Dict			       =						get_size_dict(_UpperCamelCase  ,param_name="""crop_size"""			)
									snake_case_		:							Any			       =						do_rescale if do_rescale is not None else self.do_rescale
									snake_case_		:							List[Any]			       =						rescale_factor if rescale_factor is not None else self.rescale_factor
									snake_case_		:							Union[str, Any]			       =						do_normalize if do_normalize is not None else self.do_normalize
									snake_case_		:							str			       =						image_mean if image_mean is not None else self.image_mean
									snake_case_		:							List[Any]			       =						image_std if image_std is not None else self.image_std

									snake_case_		:							Tuple			       =						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.
									snake_case_		:							List[Any]			       =						[to_numpy_array(_UpperCamelCase			) for image in images]

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

									if do_center_crop:
											snake_case_		:							Union[str, Any]			       =						[self.center_crop(image=_UpperCamelCase  ,size=_UpperCamelCase			) for image in images]

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

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

									snake_case_		:							Tuple			       =						[to_channel_dimension_format(_UpperCamelCase  ,_UpperCamelCase			) for image in images]

									snake_case_		:							Tuple			       =						{"""pixel_values""": images}
									return BatchFeature(data=_UpperCamelCase  ,tensor_type=_UpperCamelCase			)





							def 		a__   (  self		:Optional[Any]  ,_UpperCamelCase		:List[Any]  ,_UpperCamelCase		:List[Tuple] = None			):
									snake_case_		:							Optional[Any]			       =						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			):
													snake_case_		:							str			       =						target_sizes.numpy()

											snake_case_		:							Tuple			       =						[]

											for idx in range(len(_UpperCamelCase			)			):
													snake_case_		:							Dict			       =						torch.nn.functional.interpolate(
													    logits[idx].unsqueeze(dim=0			)  ,size=target_sizes[idx]  ,mode="""bilinear"""  ,align_corners=_UpperCamelCase			)
													snake_case_		:							List[Any]			       =						resized_logits[0].argmax(dim=0			)
													semantic_segmentation.append(_UpperCamelCase			)
									else:
											snake_case_		:							Optional[int]			       =						logits.argmax(dim=1			)
											snake_case_		:							List[str]			       =						[semantic_segmentation[i] for i in range(semantic_segmentation.shape[0]			)]

									return semantic_segmentation



'''simple docstring'''






def      UpperCAmelCase      (		lowerCamelCase_  :int ):







		'''simple docstring'''
		if num < 0:
				return False

		snake_case_		:							int			       =						num
		snake_case_		:							int			       =						0
		while num > 0:
				snake_case_		:							Tuple			       =						rev_num * 10 + (num % 10)
				num //= 10

		return num_copy == rev_num


if __name__ == "__main__":
							import doctest

							doctest.testmod()