


'''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,
    flip_channel_order,
    get_resize_output_image_size,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_torch_available, is_torch_tensor, is_vision_available, logging


if is_vision_available():
 import PIL

if is_torch_available():
 import torch


UpperCAmelCase_      :		Any          =		logging.get_logger(__name__)







class 					a			(				snake_case__  ):
 '''simple docstring'''




 __lowerCAmelCase						: int							  =		["pixel_values"]




 def __init__(    self		,      lowerCamelCase_ = True		,      lowerCamelCase_ = None		,      lowerCamelCase_ = PILImageResampling.BILINEAR		,      lowerCamelCase_ = True		,      lowerCamelCase_ = 1 / 2_5_5		,      lowerCamelCase_ = True		,      lowerCamelCase_ = None		,      lowerCamelCase_ = True		,      **lowerCamelCase_		,      )      ->    List[str]:
    super().__init__(**snake_case__      )
    _a					:  List[str]						=  size if size is not None else {"shortest_edge": 2_2_4}
    _a					:  List[str]						=  get_size_dict(snake_case__		,      default_to_square=snake_case__      )
    _a					:  Dict						=  crop_size if crop_size is not None else {"height": 2_5_6, "width": 2_5_6}
    _a					:  Dict						=  get_size_dict(snake_case__		,      param_name='crop_size'      )

    _a					:  List[str]						=  do_resize
    _a					:  Tuple						=  size
    _a					:  List[str]						=  resample
    _a					:  str						=  do_rescale
    _a					:  List[str]						=  rescale_factor
    _a					:  str						=  do_center_crop
    _a					:  Dict						=  crop_size
    _a					:  List[str]						=  do_flip_channel_order




 def   __UpperCamelCase   (    self		,      lowerCamelCase_		,      lowerCamelCase_		,      lowerCamelCase_ = PIL.Image.BILINEAR		,      lowerCamelCase_ = None		,      **lowerCamelCase_		,      )      ->    int:
    _a					:  Optional[Any]						=  get_size_dict(snake_case__		,      default_to_square=snake_case__      )
    if "shortest_edge" not in size:
       raise ValueError(F'''The `size` dictionary must contain the key `shortest_edge`. Got {size.keys()}'''      )
    _a					:  Optional[int]						=  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		,      lowerCamelCase_		,      lowerCamelCase_		,      lowerCamelCase_ = None		,      **lowerCamelCase_		,      )      ->    Any:
    _a					:  str						=  get_size_dict(snake_case__      )
    if "height" not in size or "width" not in size:
       raise ValueError(F'''The `size` dictionary must contain the keys `height` and `width`. Got {size.keys()}'''      )
    return center_crop(snake_case__		,      size=(size['height'], size['width'])		,      data_format=snake_case__		,      **snake_case__      )




 def   __UpperCamelCase   (    self		,      lowerCamelCase_		,      lowerCamelCase_		,      lowerCamelCase_ = None		,      **lowerCamelCase_		,      )      ->    Tuple:
    return rescale(snake_case__		,      scale=snake_case__		,      data_format=snake_case__		,      **snake_case__      )




 def   __UpperCamelCase   (    self		,      lowerCamelCase_		,      lowerCamelCase_ = None      )      ->    List[str]:
    return flip_channel_order(snake_case__		,      data_format=snake_case__      )




 def   __UpperCamelCase   (    self		,      lowerCamelCase_		,      lowerCamelCase_ = None		,      lowerCamelCase_ = None		,      lowerCamelCase_ = None		,      lowerCamelCase_ = None		,      lowerCamelCase_ = None		,      lowerCamelCase_ = None		,      lowerCamelCase_ = None		,      lowerCamelCase_ = None		,      lowerCamelCase_ = None		,      lowerCamelCase_ = ChannelDimension.FIRST		,      **lowerCamelCase_		,      )      ->    List[Any]:
    _a					:  Optional[int]						=  do_resize if do_resize is not None else self.do_resize
    _a					:  Union[str, Any]						=  resample if resample is not None else self.resample
    _a					:  Optional[Any]						=  do_rescale if do_rescale is not None else self.do_rescale
    _a					:  Union[str, Any]						=  rescale_factor if rescale_factor is not None else self.rescale_factor
    _a					:  int						=  do_center_crop if do_center_crop is not None else self.do_center_crop
    _a					:  List[str]						=  (
        do_flip_channel_order if do_flip_channel_order is not None else self.do_flip_channel_order
    )

    _a					:  str						=  size if size is not None else self.size
    _a					:  int						=  get_size_dict(snake_case__		,      default_to_square=snake_case__      )
    _a					:  Dict						=  crop_size if crop_size is not None else self.crop_size
    _a					:  Optional[int]						=  get_size_dict(snake_case__		,      param_name='crop_size'      )

    _a					:  Union[str, 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_rescale and rescale_factor is None:
       raise ValueError('Rescale factor must be specified if do_rescale is True.'      )

    if do_center_crop and crop_size is None:
       raise ValueError('Crop size must be specified if do_center_crop is True.'      )

    # All transformations expect numpy arrays.
    _a					:  int						=  [to_numpy_array(snake_case__      ) for image in images]

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

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

    if do_rescale:
       _a					:  str						=  [self.rescale(image=snake_case__		,      scale=snake_case__      ) for image in images]

    # the pretrained checkpoints assume images are BGR, not RGB
    if do_flip_channel_order:
       _a					:  str						=  [self.flip_channel_order(image=snake_case__      ) for image in images]

    _a					:  Union[str, Any]						=  [to_channel_dimension_format(snake_case__		,      snake_case__      ) for image in images]

    _a					:  int						=  {"pixel_values": images}
    return BatchFeature(data=snake_case__		,      tensor_type=snake_case__      )




 def   __UpperCamelCase   (    self		,      lowerCamelCase_		,      lowerCamelCase_ = None      )      ->    Union[str, Any]:
    _a					:  Optional[Any]						=  outputs.logits

    # Resize logits and compute semantic segmentation maps
    if target_sizes is not None:
       if len(snake_case__      ) != len(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(snake_case__      ):
          _a					:  Any						=  target_sizes.numpy()

       _a					:  Optional[Any]						=  []

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

    return semantic_segmentation




'''simple docstring'''





from math import factorial

SCREAMING_SNAKE_CASE     =       {str(digit): factorial(digit) for digit in range(1_0)}







def snake_case_     (					lowercase__		):
  if not isinstance(lowercase__   ,       lowercase__		):
    raise TypeError("Parameter number must be int"		)

  if number < 0:
    raise ValueError("Parameter number must be greater than or equal to 0"		)

  # Converts number in string to iterate on its digits and adds its factorial.
  return sum(DIGIT_FACTORIAL[digit] for digit in str(lowercase__		)		)







def snake_case_     (					lowercase__ = 6_0   ,       lowercase__ = 1_0_0_0_0_0_0		):

  if not isinstance(lowercase__   ,       lowercase__		) or not isinstance(lowercase__   ,       lowercase__		):
    raise TypeError("Parameters chain_length and number_limit must be int"		)

  if chain_length <= 0 or number_limit <= 0:
    raise ValueError(
        "Parameters chain_length and number_limit must be greater than 0"		)

  # the counter for the chains with the exact desired length
  UpperCAmelCase__      :					Union[str, Any]				       =							0
  # the cached sizes of the previous chains
  UpperCAmelCase__      :					dict[int, int]				       =							{}

  for start_chain_element in range(1   ,       lowercase__		):
    # The temporary set will contain the elements of the chain
    UpperCAmelCase__      :					Any				       =							set()
    UpperCAmelCase__      :					int				       =							0

    # Stop computing the chain when you find a cached size, a repeating item or the
    # length is greater then the desired one.
    UpperCAmelCase__      :					List[str]				       =							start_chain_element
    while (
        chain_element not in chain_sets_lengths
        and chain_element not in chain_set
        and chain_set_length <= chain_length
    ):
      chain_set.add(lowercase__		)
      chain_set_length += 1
      UpperCAmelCase__      :					List[str]				       =							digit_factorial_sum(lowercase__		)

    if chain_element in chain_sets_lengths:
      chain_set_length += chain_sets_lengths[chain_element]

    UpperCAmelCase__      :					List[str]				       =							chain_set_length

    # If chain contains the exact amount of elements increase the counter
    if chain_set_length == chain_length:
      chains_counter += 1

  return chains_counter


if __name__ == "__main__":
      import doctest

      doctest.testmod()
      print(F'{solution()}')



