






from typing import Dict, List, Optional, Union

import numpy as np

from transformers.utils import is_vision_available
from transformers.utils.generic import TensorType

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 logging


if is_vision_available():
 import PIL

_a        =			logging.get_logger(__name__)


def 				snake_case__							(							UpperCAmelCase							:  Optional[Any]       ):
    if isinstance(UpperCAmelCase    ,			(list, tuple)       ) and isinstance(videos[0]    ,			(list, tuple)       ) and is_valid_image(videos[0][0]       ):
        return videos

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

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

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







class 	_UpperCAmelCase  (  __a		):




      """simple docstring"""



      A          =    ['''pixel_values''']
      def __init__(   self    ,	_lowerCAmelCase = True    ,	_lowerCAmelCase = None    ,	_lowerCAmelCase = PILImageResampling.BILINEAR    ,	_lowerCAmelCase = True    ,	_lowerCAmelCase = None    ,	_lowerCAmelCase = True    ,	_lowerCAmelCase = 1 / 255    ,	_lowerCAmelCase = True    ,	_lowerCAmelCase = True    ,	_lowerCAmelCase = None    ,	_lowerCAmelCase = None    ,	**_lowerCAmelCase    ,	):



          '''simple docstring'''
          super().__init__(**A__		)
          lowerCAmelCase__   :Union[str, Any]      							=				size if size is not None else {"shortest_edge": 256}
          lowerCAmelCase__   :int      							=				get_size_dict(A__    ,	default_to_square=A__		)
          lowerCAmelCase__   :Any      							=				crop_size if crop_size is not None else {"height": 224, "width": 224}
          lowerCAmelCase__   :str      							=				get_size_dict(A__    ,	param_name="crop_size"		)

          lowerCAmelCase__   :Dict      							=				do_resize
          lowerCAmelCase__   :int      							=				size
          lowerCAmelCase__   :Union[str, Any]      							=				do_center_crop
          lowerCAmelCase__   :List[Any]      							=				crop_size
          lowerCAmelCase__   :List[Any]      							=				resample
          lowerCAmelCase__   :Tuple      							=				do_rescale
          lowerCAmelCase__   :Tuple      							=				rescale_factor
          lowerCAmelCase__   :int      							=				offset
          lowerCAmelCase__   :Tuple      							=				do_normalize
          lowerCAmelCase__   :str      							=				image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
          lowerCAmelCase__   :Union[str, Any]      							=				image_std if image_std is not None else IMAGENET_STANDARD_STD
      def 			snake_case_      (   self    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase = PILImageResampling.BILINEAR    ,	_lowerCAmelCase = None    ,	**_lowerCAmelCase    ,	):



          '''simple docstring'''
          lowerCAmelCase__   :Optional[Any]      							=				get_size_dict(A__    ,	default_to_square=A__		)
          if "shortest_edge" in size:
              lowerCAmelCase__   :List[str]      							=				get_resize_output_image_size(A__    ,	size["shortest_edge"]    ,	default_to_square=A__		)
          elif "height" in size and "width" in size:
              lowerCAmelCase__   :Dict      							=				(size["height"], size["width"])
          else:
              raise ValueError(f'''Size must have \'height\' and \'width\' or \'shortest_edge\' as keys. Got {size.keys()}'''		)
          return resize(A__    ,	size=A__    ,	resample=A__    ,	data_format=A__    ,	**A__		)
      def 			snake_case_      (   self    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase = None    ,	**_lowerCAmelCase    ,	):



          '''simple docstring'''
          lowerCAmelCase__   :Union[str, Any]      							=				get_size_dict(A__		)
          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(A__    ,	size=(size["height"], size["width"])    ,	data_format=A__    ,	**A__		)
      def 			snake_case_      (   self    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase = True    ,	_lowerCAmelCase = None    ,	**_lowerCAmelCase    ,	):



          '''simple docstring'''
          lowerCAmelCase__   :Any      							=				image.astype(np.floataa		)
          if offset:
              lowerCAmelCase__   :List[Any]      							=				image - (scale / 2)
          return rescale(A__    ,	scale=A__    ,	data_format=A__    ,	**A__		)
      def 			snake_case_      (   self    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase = None    ,	**_lowerCAmelCase    ,	):



          '''simple docstring'''
          return normalize(A__    ,	mean=A__    ,	std=A__    ,	data_format=A__    ,	**A__		)
      def 			snake_case_      (   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    ,	):



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

          if offset and not do_rescale:
              raise ValueError("For offset, do_rescale must also be set to True."		)

          # All transformations expect numpy arrays.
          lowerCAmelCase__   :int      							=				to_numpy_array(A__		)

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

          if do_center_crop:
              lowerCAmelCase__   :Optional[Any]      							=				self.center_crop(A__    ,	size=A__		)

          if do_rescale:
              lowerCAmelCase__   :Tuple      							=				self.rescale(image=A__    ,	scale=A__    ,	offset=A__		)

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

          lowerCAmelCase__   :Optional[int]      							=				to_channel_dimension_format(A__    ,	A__		)
          return image



      def 			snake_case_      (   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 = None    ,	_lowerCAmelCase = ChannelDimension.FIRST    ,	**_lowerCAmelCase    ,	):



          '''simple docstring'''
          lowerCAmelCase__   :List[Any]      							=				do_resize if do_resize is not None else self.do_resize
          lowerCAmelCase__   :str      							=				resample if resample is not None else self.resample
          lowerCAmelCase__   :List[Any]      							=				do_center_crop if do_center_crop is not None else self.do_center_crop
          lowerCAmelCase__   :Optional[int]      							=				do_rescale if do_rescale is not None else self.do_rescale
          lowerCAmelCase__   :List[str]      							=				rescale_factor if rescale_factor is not None else self.rescale_factor
          lowerCAmelCase__   :Optional[Any]      							=				offset if offset is not None else self.offset
          lowerCAmelCase__   :Optional[int]      							=				do_normalize if do_normalize is not None else self.do_normalize
          lowerCAmelCase__   :Union[str, Any]      							=				image_mean if image_mean is not None else self.image_mean
          lowerCAmelCase__   :Union[str, Any]      							=				image_std if image_std is not None else self.image_std

          lowerCAmelCase__   :int      							=				size if size is not None else self.size
          lowerCAmelCase__   :str      							=				get_size_dict(A__    ,	default_to_square=A__		)
          lowerCAmelCase__   :List[Any]      							=				crop_size if crop_size is not None else self.crop_size
          lowerCAmelCase__   :Union[str, Any]      							=				get_size_dict(A__    ,	param_name="crop_size"		)

          if not valid_images(A__		):
              raise ValueError(
                  "Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, "
                  "torch.Tensor, tf.Tensor or jax.ndarray."		)

          lowerCAmelCase__   :Union[str, Any]      							=				make_batched(A__		)

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

          lowerCAmelCase__   :Optional[int]      							=				{"pixel_values": videos}
          return BatchFeature(data=A__    ,	tensor_type=A__		)











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


_a    :   Dict        =			logging.get_logger(__name__)

_a    :   Optional[Any]        =			{
    """caidas/swin2sr-classicalsr-x2-64""": (
        """https://huggingface.co/caidas/swin2sr-classicalsr-x2-64/resolve/main/config.json"""
    ),
}







class 	_UpperCAmelCase  (  _A		):




      """simple docstring"""



      A          =    '''swin2sr'''

      A          =    {
          '''hidden_size''': '''embed_dim''',
          '''num_attention_heads''': '''num_heads''',
          '''num_hidden_layers''': '''num_layers''',
      }
      def __init__(   self    ,	_lowerCAmelCase=64    ,	_lowerCAmelCase=1    ,	_lowerCAmelCase=3    ,	_lowerCAmelCase=180    ,	_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    ,	):



          '''simple docstring'''
          super().__init__(**_lowerCAmelCase		)

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



