




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


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


class 				UpperCamelCase_    ( UpperCAmelCase__     ):

    '''simple docstring'''






    UpperCAmelCase__							  =      ['pixel_values']


    def __init__(			self      :	str					, UpperCAmelCase__      :	List[str] = True					, UpperCAmelCase__      :	str = None					, UpperCAmelCase__      :	Dict = PILImageResampling.BILINEAR					, UpperCAmelCase__      :	Union[str, Any] = True					, UpperCAmelCase__      :	List[Any] = None					, UpperCAmelCase__      :	List[str] = True					, UpperCAmelCase__      :	List[Any] = 1 / 255					, UpperCAmelCase__      :	Union[str, Any] = True					, UpperCAmelCase__      :	Tuple = None					, UpperCAmelCase__      :	List[str] = None					, **UpperCAmelCase__      :	Tuple					, )						->None:





           '''simple docstring'''

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


    def        SCREAMING_SNAKE_CASE							(			self      :	Dict					, UpperCAmelCase__      :	Optional[int]					, UpperCAmelCase__      :	Optional[Any]					, UpperCAmelCase__      :	List[Any] = PILImageResampling.BICUBIC					, UpperCAmelCase__      :	List[Any] = None					, **UpperCAmelCase__      :	int					, )						->np.ndarray:





           '''simple docstring'''

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


    def        SCREAMING_SNAKE_CASE							(			self      :	Optional[int]					, UpperCAmelCase__      :	List[Any]					, UpperCAmelCase__      :	Tuple					, UpperCAmelCase__      :	List[str] = None					, **UpperCAmelCase__      :	int					, )						->np.ndarray:





           '''simple docstring'''

           A__       =    get_size_dict(_SCREAMING_SNAKE_CASE)
           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(_SCREAMING_SNAKE_CASE					, size=(size['''height'''], size['''width'''])					, data_format=_SCREAMING_SNAKE_CASE					, **_SCREAMING_SNAKE_CASE)


    def        SCREAMING_SNAKE_CASE							(			self      :	Any					, UpperCAmelCase__      :	Any					, UpperCAmelCase__      :	Tuple					, UpperCAmelCase__      :	Tuple = None					, **UpperCAmelCase__      :	List[str])						->np.ndarray:





           '''simple docstring'''

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


    def        SCREAMING_SNAKE_CASE							(			self      :	List[str]					, UpperCAmelCase__      :	int					, UpperCAmelCase__      :	List[str]					, UpperCAmelCase__      :	Tuple					, UpperCAmelCase__      :	Union[str, Any] = None					, **UpperCAmelCase__      :	str					, )						->np.ndarray:





           '''simple docstring'''

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


    def        SCREAMING_SNAKE_CASE							(			self      :	List[Any]					, UpperCAmelCase__      :	Union[str, Any]					, UpperCAmelCase__      :	int = None					, UpperCAmelCase__      :	Any = None					, UpperCAmelCase__      :	Any = None					, UpperCAmelCase__      :	Union[str, Any] = None					, UpperCAmelCase__      :	int = None					, UpperCAmelCase__      :	Any = None					, UpperCAmelCase__      :	Optional[Any] = None					, UpperCAmelCase__      :	str = None					, UpperCAmelCase__      :	Any = None					, UpperCAmelCase__      :	Union[str, Any] = None					, UpperCAmelCase__      :	int = None					, UpperCAmelCase__      :	Any = ChannelDimension.FIRST					, **UpperCAmelCase__      :	Any					, )						->Optional[Any]:





           '''simple docstring'''

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

           A__       =    make_list_of_images(_SCREAMING_SNAKE_CASE)

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

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

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

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

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

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

           A__       =    [to_channel_dimension_format(_SCREAMING_SNAKE_CASE					, _SCREAMING_SNAKE_CASE) for image in images]

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





    def        SCREAMING_SNAKE_CASE							(			self      :	Optional[int]					, UpperCAmelCase__      :	Union[str, Any]					, UpperCAmelCase__      :	Any = None)						->List[Any]:





           '''simple docstring'''

           A__       =    outputs.logits

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

                  if is_torch_tensor(_SCREAMING_SNAKE_CASE):
                         A__       =    target_sizes.numpy()

                  A__       =    []

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

           return semantic_segmentation







"""simple docstring"""
A:   int								=		range(2, 2_0 + 1)
A:   Any								=		[1_0**k for k in range(ks[-1] + 1)]
A:   dict[int, dict[int, list[list[int]]]]								=		{}

def       _snake_case						(						UpperCamelCase						:		Dict			,		UpperCamelCase						:		Any			,		UpperCamelCase						:		Any			,		UpperCamelCase						:		int						):
 UpperCAmelCase	:					List[str]	=	sum(a_i[j] for j in range(UpperCamelCase			,		len(UpperCamelCase						)						)						)
 UpperCAmelCase	:					str	=	sum(a_i[j] * base[j] for j in range(min(len(UpperCamelCase						)			,		UpperCamelCase						)						)						)

 UpperCAmelCase	,		UpperCAmelCase	:					str	=	0, 0
 UpperCAmelCase	:					Optional[Any]	=	n - i

 UpperCAmelCase	:					Optional[int]	=	memo.get(UpperCamelCase						)

 if sub_memo is not None:
  UpperCAmelCase	:					str	=	sub_memo.get(UpperCamelCase						)

  if jumps is not None and len(UpperCamelCase						) > 0:
   # find and make the largest jump without going over
   UpperCAmelCase	:					Tuple	=	-1
   for _k in range(len(UpperCamelCase						) - 1			,		-1			,		-1						):
    if jumps[_k][2] <= k and jumps[_k][1] <= max_dn:
     UpperCAmelCase	:					int	=	_k
     break

   if max_jump >= 0:
    UpperCAmelCase	,		UpperCAmelCase	,		UpperCAmelCase	:					Optional[Any]	=	jumps[max_jump]
    # since the difference between jumps is cached, add c
    UpperCAmelCase	:					List[str]	=	diff + c
    for j in range(min(UpperCamelCase			,		len(UpperCamelCase						)						)						):
     UpperCAmelCase	,		UpperCAmelCase	:					Union[str, Any]	=	divmod(UpperCamelCase			,		10						)
    if new_c > 0:
     add(UpperCamelCase			,		UpperCamelCase			,		UpperCamelCase						)

  else:
   UpperCAmelCase	:					int	=	[]
 else:
  UpperCAmelCase	:					List[str]	=	{c: []}
  UpperCAmelCase	:					str	=	sub_memo

 if dn >= max_dn or c + diff >= base[k]:
  return diff, dn

 if k > ks[0]:
  while True:
   # keep doing smaller jumps
   UpperCAmelCase	,		UpperCAmelCase	:					List[str]	=	next_term(UpperCamelCase			,		k - 1			,		i + dn			,		UpperCamelCase						)
   diff += _diff
   dn += terms_jumped

   if dn >= max_dn or c + diff >= base[k]:
    break
 else:
  # would be too small a jump, just compute sequential terms instead
  UpperCAmelCase	,		UpperCAmelCase	:					int	=	compute(UpperCamelCase			,		UpperCamelCase			,		i + dn			,		UpperCamelCase						)
  diff += _diff
  dn += terms_jumped

 UpperCAmelCase	:					Dict	=	sub_memo[c]

 # keep jumps sorted by # of terms skipped
 UpperCAmelCase	:					str	=	0
 while j < len(UpperCamelCase						):
  if jumps[j][1] > dn:
   break
  j += 1

 # cache the jump for this value digitsum(b) and c
 sub_memo[c].insert(UpperCamelCase			,		(diff, dn, k)						)
 return (diff, dn)

def       _snake_case						(						UpperCamelCase						:		int			,		UpperCamelCase						:		Tuple			,		UpperCamelCase						:		Union[str, Any]			,		UpperCamelCase						:		Any						):
 if i >= n:
  return 0, i
 if k > len(UpperCamelCase						):
  a_i.extend([0 for _ in range(k - len(UpperCamelCase						)						)]						)

 # note: a_i -> b * 10^k + c
 # ds_b -> digitsum(b)
 # ds_c -> digitsum(c)
 UpperCAmelCase	:					List[str]	=	i
 UpperCAmelCase	,		UpperCAmelCase	,		UpperCAmelCase	:					Optional[int]	=	0, 0, 0
 for j in range(len(UpperCamelCase						)						):
  if j >= k:
   ds_b += a_i[j]
  else:
   ds_c += a_i[j]

 while i < n:
  i += 1
  UpperCAmelCase	:					Optional[int]	=	ds_c + ds_b
  diff += addend
  UpperCAmelCase	:					str	=	0
  for j in range(UpperCamelCase						):
   UpperCAmelCase	:					Any	=	a_i[j] + addend
   UpperCAmelCase	,		UpperCAmelCase	:					Any	=	divmod(UpperCamelCase			,		10						)

   ds_c += a_i[j]

  if addend > 0:
   break

 if addend > 0:
  add(UpperCamelCase			,		UpperCamelCase			,		UpperCamelCase						)
 return diff, i - start_i

def       _snake_case						(						UpperCamelCase						:		Union[str, Any]			,		UpperCamelCase						:		str			,		UpperCamelCase						:		Optional[int]						):
 for j in range(UpperCamelCase			,		len(UpperCamelCase						)						):
  UpperCAmelCase	:					Optional[int]	=	digits[j] + addend
  if s >= 10:
   UpperCAmelCase	,		UpperCAmelCase	:					int	=	divmod(UpperCamelCase			,		10						)
   UpperCAmelCase	:					str	=	addend // 10 + quotient
  else:
   UpperCAmelCase	:					Any	=	s
   UpperCAmelCase	:					Union[str, Any]	=	addend // 10

  if addend == 0:
   break

 while addend > 0:
  UpperCAmelCase	,		UpperCAmelCase	:					Any	=	divmod(UpperCamelCase			,		10						)
  digits.append(UpperCamelCase						)

def       _snake_case						(						UpperCamelCase						:		int = 10**15						):
 UpperCAmelCase	:					Dict	=	[1]
 UpperCAmelCase	:					int	=	1
 UpperCAmelCase	:					Tuple	=	0
 while True:
  UpperCAmelCase	,		UpperCAmelCase	:					Tuple	=	next_term(UpperCamelCase			,		20			,		i + dn			,		UpperCamelCase						)
  dn += terms_jumped
  if dn == n - i:
   break

 UpperCAmelCase	:					Any	=	0
 for j in range(len(UpperCamelCase						)						):
  a_n += digits[j] * 10**j
 return a_n


if __name__ == "__main__":
      print(f"""{solution() = }""")
