





from typing import Dict, List, Optional, 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,
    is_valid_image,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


if is_vision_available():
     import PIL


UpperCAmelCase	:	List[str]		     =       logging.get_logger(__name__)
def      _A       (		SCREAMING_SNAKE_CASE     :   int						):





  """simple docstring"""



  if isinstance(SCREAMING_SNAKE_CASE       ,       (list, tuple)						) and isinstance(videos[0]       ,       (list, tuple)						) and is_valid_image(videos[0][0]						):
    return videos

  elif isinstance(SCREAMING_SNAKE_CASE       ,       (list, tuple)						) and is_valid_image(videos[0]						):
    return [videos]

  elif is_valid_image(SCREAMING_SNAKE_CASE						):
    return [[videos]]

  raise ValueError(f'''Could not make batched video from {videos}'''						)







class 				__lowerCAmelCase       (    UpperCamelCase__):
      _lowercase				:					Dict						=			["""pixel_values"""]







      def __init__(    self		,      lowerCAmelCase__ = True		,      lowerCAmelCase__ = None		,      lowerCAmelCase__ = PILImageResampling.BILINEAR		,      lowerCAmelCase__ = True		,      lowerCAmelCase__ = None		,      lowerCAmelCase__ = True		,      lowerCAmelCase__ = 1 / 2_5_5		,      lowerCAmelCase__ = True		,      lowerCAmelCase__ = None		,      lowerCAmelCase__ = None		,      **lowerCAmelCase__		,      )   ->						None:



        '''simple docstring'''




        super().__init__(**lowerCAmelCase__							)
        a__	:					List[str]										=size if size is not None else {"shortest_edge": 2_2_4}
        a__	:					Union[str, Any]										=get_size_dict(lowerCAmelCase__		,      default_to_square=lowerCAmelCase__							)
        a__	:					int										=crop_size if crop_size is not None else {"height": 2_2_4, "width": 2_2_4}
        a__	:					Any										=get_size_dict(lowerCAmelCase__		,      param_name="crop_size"							)

        a__	:					Any										=do_resize
        a__	:					Optional[int]										=size
        a__	:					Tuple										=do_center_crop
        a__	:					Optional[int]										=crop_size
        a__	:					Optional[int]										=resample
        a__	:					str										=do_rescale
        a__	:					str										=rescale_factor
        a__	:					Dict										=do_normalize
        a__	:					Union[str, Any]										=image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
        a__	:					str										=image_std if image_std is not None else IMAGENET_STANDARD_STD







      def    _lowercase  (    self		,      lowerCAmelCase__		,      lowerCAmelCase__		,      lowerCAmelCase__ = PILImageResampling.BILINEAR		,      lowerCAmelCase__ = None		,      **lowerCAmelCase__		,      )   ->						np.ndarray:



        '''simple docstring'''




        a__	:					List[Any]										=get_size_dict(lowerCAmelCase__		,      default_to_square=lowerCAmelCase__							)
        if "shortest_edge" in size:
          a__	:					int										=get_resize_output_image_size(lowerCAmelCase__		,      size["shortest_edge"]		,      default_to_square=lowerCAmelCase__							)
        elif "height" in size and "width" in size:
          a__	:					int										=(size["height"], size["width"])
        else:
          raise ValueError(F'''Size must have \'height\' and \'width\' or \'shortest_edge\' as keys. Got {size.keys()}'''							)
        return resize(lowerCAmelCase__		,      size=lowerCAmelCase__		,      resample=lowerCAmelCase__		,      data_format=lowerCAmelCase__		,      **lowerCAmelCase__							)







      def    _lowercase  (    self		,      lowerCAmelCase__		,      lowerCAmelCase__		,      lowerCAmelCase__ = None		,      **lowerCAmelCase__		,      )   ->						np.ndarray:



        '''simple docstring'''




        a__	:					Union[str, Any]										=get_size_dict(lowerCAmelCase__							)
        if "height" not in size or "width" not in size:
          raise ValueError(F'''Size must have \'height\' and \'width\' as keys. Got {size.keys()}'''							)
        return center_crop(lowerCAmelCase__		,      size=(size["height"], size["width"])		,      data_format=lowerCAmelCase__		,      **lowerCAmelCase__							)







      def    _lowercase  (    self		,      lowerCAmelCase__		,      lowerCAmelCase__		,      lowerCAmelCase__ = None		,      **lowerCAmelCase__		,      )   ->						int:



        '''simple docstring'''




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







      def    _lowercase  (    self		,      lowerCAmelCase__		,      lowerCAmelCase__		,      lowerCAmelCase__		,      lowerCAmelCase__ = None		,      **lowerCAmelCase__		,      )   ->						np.ndarray:



        '''simple docstring'''




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







      def    _lowercase  (    self		,      lowerCAmelCase__		,      lowerCAmelCase__ = None		,      lowerCAmelCase__ = None		,      lowerCAmelCase__ = None		,      lowerCAmelCase__ = None		,      lowerCAmelCase__ = None		,      lowerCAmelCase__ = None		,      lowerCAmelCase__ = None		,      lowerCAmelCase__ = None		,      lowerCAmelCase__ = None		,      lowerCAmelCase__ = None		,      lowerCAmelCase__ = ChannelDimension.FIRST		,      )   ->						np.ndarray:



        '''simple docstring'''




        if do_resize and size is None or resample is None:
          raise ValueError("Size and resample 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__	:					List[Any]										=to_numpy_array(lowerCAmelCase__							)

        if do_resize:
          a__	:					int										=self.resize(image=lowerCAmelCase__		,      size=lowerCAmelCase__		,      resample=lowerCAmelCase__							)

        if do_center_crop:
          a__	:					Union[str, Any]										=self.center_crop(lowerCAmelCase__		,      size=lowerCAmelCase__							)

        if do_rescale:
          a__	:					List[Any]										=self.rescale(image=lowerCAmelCase__		,      scale=lowerCAmelCase__							)

        if do_normalize:
          a__	:					Dict										=self.normalize(image=lowerCAmelCase__		,      mean=lowerCAmelCase__		,      std=lowerCAmelCase__							)

        a__	:					int										=to_channel_dimension_format(lowerCAmelCase__		,      lowerCAmelCase__							)
        return image







      def    _lowercase  (    self		,      lowerCAmelCase__		,      lowerCAmelCase__ = None		,      lowerCAmelCase__ = None		,      lowerCAmelCase__ = None		,      lowerCAmelCase__ = None		,      lowerCAmelCase__ = None		,      lowerCAmelCase__ = None		,      lowerCAmelCase__ = None		,      lowerCAmelCase__ = None		,      lowerCAmelCase__ = None		,      lowerCAmelCase__ = None		,      lowerCAmelCase__ = None		,      lowerCAmelCase__ = ChannelDimension.FIRST		,      **lowerCAmelCase__		,      )   ->						PIL.Image.Image:



        '''simple docstring'''




        a__	:					int										=do_resize if do_resize is not None else self.do_resize
        a__	:					List[str]										=resample if resample is not None else self.resample
        a__	:					List[Any]										=do_center_crop if do_center_crop is not None else self.do_center_crop
        a__	:					int										=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__	:					Dict										=do_normalize if do_normalize is not None else self.do_normalize
        a__	:					Tuple										=image_mean if image_mean is not None else self.image_mean
        a__	:					Tuple										=image_std if image_std is not None else self.image_std

        a__	:					Tuple										=size if size is not None else self.size
        a__	:					str										=get_size_dict(lowerCAmelCase__		,      default_to_square=lowerCAmelCase__							)
        a__	:					Any										=crop_size if crop_size is not None else self.crop_size
        a__	:					Dict										=get_size_dict(lowerCAmelCase__		,      param_name="crop_size"							)

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

        a__	:					List[Any]										=make_batched(lowerCAmelCase__							)

        a__	:					str										=[
            [
                self._preprocess_image(
                    image=lowerCAmelCase__		,      do_resize=lowerCAmelCase__		,      size=lowerCAmelCase__		,      resample=lowerCAmelCase__		,      do_center_crop=lowerCAmelCase__		,      crop_size=lowerCAmelCase__		,      do_rescale=lowerCAmelCase__		,      rescale_factor=lowerCAmelCase__		,      do_normalize=lowerCAmelCase__		,      image_mean=lowerCAmelCase__		,      image_std=lowerCAmelCase__		,      data_format=lowerCAmelCase__		,      )
                for img in video
            ]
            for video in videos
        ]

        a__	:					Tuple										={"pixel_values": videos}
        return BatchFeature(data=lowerCAmelCase__		,      tensor_type=lowerCAmelCase__							)













from ...configuration_utils import PretrainedConfig
from ...utils import logging


UpperCAmelCase	:	Dict		     =       logging.get_logger(__name__)

UpperCAmelCase	:	Tuple		     =       {
    """caidas/swin2sr-classicalsr-x2-64""": (
        """https://huggingface.co/caidas/swin2sr-classicalsr-x2-64/resolve/main/config.json"""
    ),
}







class 				__lowerCAmelCase       (    UpperCamelCase__):
      _lowercase				:					Any						=			"""swin2sr"""

      _lowercase				:					Tuple						=			{
          """hidden_size""": """embed_dim""",
          """num_attention_heads""": """num_heads""",
          """num_hidden_layers""": """num_layers""",
      }







      def __init__(    self		,      lowerCAmelCase__=6_4		,      lowerCAmelCase__=1		,      lowerCAmelCase__=3		,      lowerCAmelCase__=1_8_0		,      lowerCAmelCase__=[6, 6, 6, 6, 6, 6]		,      lowerCAmelCase__=[6, 6, 6, 6, 6, 6]		,      lowerCAmelCase__=8		,      lowerCAmelCase__=2.0		,      lowerCAmelCase__=True		,      lowerCAmelCase__=0.0		,      lowerCAmelCase__=0.0		,      lowerCAmelCase__=0.1		,      lowerCAmelCase__="gelu"		,      lowerCAmelCase__=False		,      lowerCAmelCase__=0.02		,      lowerCAmelCase__=1E-5		,      lowerCAmelCase__=2		,      lowerCAmelCase__=1.0		,      lowerCAmelCase__="1conv"		,      lowerCAmelCase__="pixelshuffle"		,      **lowerCAmelCase__		,      )   ->						int:



        '''simple docstring'''




        super().__init__(**lowerCAmelCase__							)

        a__	:					Optional[Any]										=image_size
        a__	:					Dict										=patch_size
        a__	:					Tuple										=num_channels
        a__	:					Union[str, Any]										=embed_dim
        a__	:					Optional[Any]										=depths
        a__	:					List[str]										=len(lowerCAmelCase__							)
        a__	:					Any										=num_heads
        a__	:					Any										=window_size
        a__	:					str										=mlp_ratio
        a__	:					List[str]										=qkv_bias
        a__	:					Dict										=hidden_dropout_prob
        a__	:					List[str]										=attention_probs_dropout_prob
        a__	:					Dict										=drop_path_rate
        a__	:					Optional[Any]										=hidden_act
        a__	:					Union[str, Any]										=use_absolute_embeddings
        a__	:					Optional[Any]										=layer_norm_eps
        a__	:					List[Any]										=initializer_range
        a__	:					int										=upscale
        a__	:					Optional[int]										=img_range
        a__	:					Any										=resi_connection
        a__	:					Optional[Any]										=upsampler






