






import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
 import torch

if is_vision_available():
 from PIL import Image

 from transformers import GLPNImageProcessor



class 							_UpperCamelCase			(unittest.TestCase			):


      def __init__(	self					,						__UpperCamelCase					,						__UpperCamelCase=7					,						__UpperCamelCase=3					,						__UpperCamelCase=1_8					,						__UpperCamelCase=3_0					,						__UpperCamelCase=4_0_0					,						__UpperCamelCase=True					,						__UpperCamelCase=3_2					,						__UpperCamelCase=True					,						)->	Tuple:
           __lowerCAmelCase								=					parent
           __lowerCAmelCase								=					batch_size
           __lowerCAmelCase								=					num_channels
           __lowerCAmelCase								=					image_size
           __lowerCAmelCase								=					min_resolution
           __lowerCAmelCase								=					max_resolution
           __lowerCAmelCase								=					do_resize
           __lowerCAmelCase								=					size_divisor
           __lowerCAmelCase								=					do_rescale


      def  __UpperCAmelCase		(	self	)->	List[Any]:
           return {
               "do_resize": self.do_resize,
               "size_divisor": self.size_divisor,
               "do_rescale": self.do_rescale,
           }



@require_torch
@require_vision
class 							_UpperCamelCase			(__a							,		unittest.TestCase			):
      snake_case_  =							GLPNImageProcessor if is_vision_available() else None


      def  __UpperCAmelCase		(	self	)->	Optional[Any]:
           __lowerCAmelCase								=					GLPNImageProcessingTester(self	)


      @property
      def  __UpperCAmelCase		(	self	)->	Dict:
           return self.image_processor_tester.prepare_image_processor_dict()


      def  __UpperCAmelCase		(	self	)->	Any:
           __lowerCAmelCase								=					self.image_processing_class(**self.image_processor_dict	)
           self.assertTrue(hasattr(lowerCAmelCase_					,						"do_resize"	)	)
           self.assertTrue(hasattr(lowerCAmelCase_					,						"size_divisor"	)	)
           self.assertTrue(hasattr(lowerCAmelCase_					,						"resample"	)	)
           self.assertTrue(hasattr(lowerCAmelCase_					,						"do_rescale"	)	)


      def  __UpperCAmelCase		(	self	)->	Optional[int]:
           pass


      def  __UpperCAmelCase		(	self	)->	Any:
           __lowerCAmelCase								=					self.image_processing_class(**self.image_processor_dict	)
           # create random PIL images
           __lowerCAmelCase								=					prepare_image_inputs(self.image_processor_tester					,						equal_resolution=lowerCAmelCase_	)
           for image in image_inputs:
                self.assertIsInstance(lowerCAmelCase_					,						Image.Image	)

           # Test not batched input (GLPNImageProcessor doesn't support batching)
           __lowerCAmelCase								=					image_processing(image_inputs[0]					,						return_tensors="pt"	).pixel_values
           self.assertTrue(encoded_images.shape[-1] % self.image_processor_tester.size_divisor == 0	)
           self.assertTrue(encoded_images.shape[-2] % self.image_processor_tester.size_divisor == 0	)


      def  __UpperCAmelCase		(	self	)->	List[Any]:
           __lowerCAmelCase								=					self.image_processing_class(**self.image_processor_dict	)
           # create random numpy tensors
           __lowerCAmelCase								=					prepare_image_inputs(self.image_processor_tester					,						equal_resolution=lowerCAmelCase_					,						numpify=lowerCAmelCase_	)
           for image in image_inputs:
                self.assertIsInstance(lowerCAmelCase_					,						np.ndarray	)

           # Test not batched input (GLPNImageProcessor doesn't support batching)
           __lowerCAmelCase								=					image_processing(image_inputs[0]					,						return_tensors="pt"	).pixel_values
           self.assertTrue(encoded_images.shape[-1] % self.image_processor_tester.size_divisor == 0	)
           self.assertTrue(encoded_images.shape[-2] % self.image_processor_tester.size_divisor == 0	)


      def  __UpperCAmelCase		(	self	)->	int:
           __lowerCAmelCase								=					self.image_processing_class(**self.image_processor_dict	)
           # create random PyTorch tensors
           __lowerCAmelCase								=					prepare_image_inputs(self.image_processor_tester					,						equal_resolution=lowerCAmelCase_					,						torchify=lowerCAmelCase_	)
           for image in image_inputs:
                self.assertIsInstance(lowerCAmelCase_					,						torch.Tensor	)

           # Test not batched input (GLPNImageProcessor doesn't support batching)
           __lowerCAmelCase								=					image_processing(image_inputs[0]					,						return_tensors="pt"	).pixel_values
           self.assertTrue(encoded_images.shape[-1] % self.image_processor_tester.size_divisor == 0	)
           self.assertTrue(encoded_images.shape[-2] % self.image_processor_tester.size_divisor == 0	)














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


lowerCamelCase			:					int         =	logging.get_logger(__name__)

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



class 							_UpperCamelCase			(a_			):
      snake_case_  =							"""swin2sr"""

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


      def __init__(	self					,						__UpperCamelCase=6_4					,						__UpperCamelCase=1					,						__UpperCamelCase=3					,						__UpperCamelCase=1_8_0					,						__UpperCamelCase=[6, 6, 6, 6, 6, 6]					,						__UpperCamelCase=[6, 6, 6, 6, 6, 6]					,						__UpperCamelCase=8					,						__UpperCamelCase=2.0					,						__UpperCamelCase=True					,						__UpperCamelCase=0.0					,						__UpperCamelCase=0.0					,						__UpperCamelCase=0.1					,						__UpperCamelCase="gelu"					,						__UpperCamelCase=False					,						__UpperCamelCase=0.0_2					,						__UpperCamelCase=1e-5					,						__UpperCamelCase=2					,						__UpperCamelCase=1.0					,						__UpperCamelCase="1conv"					,						__UpperCamelCase="pixelshuffle"					,						**__UpperCamelCase					,						)->	Tuple:
           super().__init__(**__UpperCamelCase	)

           __lowerCAmelCase								=					image_size
           __lowerCAmelCase								=					patch_size
           __lowerCAmelCase								=					num_channels
           __lowerCAmelCase								=					embed_dim
           __lowerCAmelCase								=					depths
           __lowerCAmelCase								=					len(__UpperCamelCase	)
           __lowerCAmelCase								=					num_heads
           __lowerCAmelCase								=					window_size
           __lowerCAmelCase								=					mlp_ratio
           __lowerCAmelCase								=					qkv_bias
           __lowerCAmelCase								=					hidden_dropout_prob
           __lowerCAmelCase								=					attention_probs_dropout_prob
           __lowerCAmelCase								=					drop_path_rate
           __lowerCAmelCase								=					hidden_act
           __lowerCAmelCase								=					use_absolute_embeddings
           __lowerCAmelCase								=					layer_norm_eps
           __lowerCAmelCase								=					initializer_range
           __lowerCAmelCase								=					upscale
           __lowerCAmelCase								=					img_range
           __lowerCAmelCase								=					resi_connection
           __lowerCAmelCase								=					upsampler






