



from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


a			:     Any     = {
    'configuration_swin2sr': ['SWIN2SR_PRETRAINED_CONFIG_ARCHIVE_MAP', 'Swin2SRConfig'],
}


try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	a			:     int     = [
	    'SWIN2SR_PRETRAINED_MODEL_ARCHIVE_LIST',
	    'Swin2SRForImageSuperResolution',
	    'Swin2SRModel',
	    'Swin2SRPreTrainedModel',
	]


try:
	if not is_vision_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	a			:     List[Any]     = ['Swin2SRImageProcessor']


if TYPE_CHECKING:
	from .configuration_swinasr import SWIN2SR_PRETRAINED_CONFIG_ARCHIVE_MAP, SwinaSRConfig

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_swinasr import (
		    SWIN2SR_PRETRAINED_MODEL_ARCHIVE_LIST,
		    SwinaSRForImageSuperResolution,
		    SwinaSRModel,
		    SwinaSRPreTrainedModel,
		)

	try:
		if not is_vision_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .image_processing_swinasr import SwinaSRImageProcessor


else:
	import sys

	a			:     str     = _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)











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 ViTImageProcessor







class 							_a							(      unittest.TestCase				):

			def __init__(self,      SCREAMING_SNAKE_CASE_,      SCREAMING_SNAKE_CASE_=7,      SCREAMING_SNAKE_CASE_=3,      SCREAMING_SNAKE_CASE_=18,      SCREAMING_SNAKE_CASE_=30,      SCREAMING_SNAKE_CASE_=400,      SCREAMING_SNAKE_CASE_=True,      SCREAMING_SNAKE_CASE_=None,      SCREAMING_SNAKE_CASE_=True,      SCREAMING_SNAKE_CASE_=[0.5, 0.5, 0.5],      SCREAMING_SNAKE_CASE_=[0.5, 0.5, 0.5],      )					->      Union[str, Any]:
						UpperCAmelCase_:		Any       			=    size if size is not None else {"""height""": 18, """width""": 18}
						UpperCAmelCase_:		str       			=    parent
						UpperCAmelCase_:		int       			=    batch_size
						UpperCAmelCase_:		Tuple       			=    num_channels
						UpperCAmelCase_:		Optional[int]       			=    image_size
						UpperCAmelCase_:		Optional[int]       			=    min_resolution
						UpperCAmelCase_:		Optional[int]       			=    max_resolution
						UpperCAmelCase_:		Optional[Any]       			=    do_resize
						UpperCAmelCase_:		Optional[int]       			=    size
						UpperCAmelCase_:		int       			=    do_normalize
						UpperCAmelCase_:		List[str]       			=    image_mean
						UpperCAmelCase_:		Tuple       			=    image_std

			def     __snake_case					(self				)					->      Tuple:
						return {
						    "image_mean": self.image_mean,
						    "image_std": self.image_std,
						    "do_normalize": self.do_normalize,
						    "do_resize": self.do_resize,
						    "size": self.size,
						}







@require_torch
@require_vision
class 							_a							(      _lowerCAmelCase   ,		unittest.TestCase				):
			A					=  ViTImageProcessor if is_vision_available() else None

			def     __snake_case					(self				)					->      Optional[int]:
						UpperCAmelCase_:		str       			=    ViTImageProcessingTester(self				)

			@property
			def     __snake_case					(self				)					->      List[str]:
						return self.image_processor_tester.prepare_image_processor_dict()

			def     __snake_case					(self				)					->      int:
						UpperCAmelCase_:		Any       			=    self.image_processing_class(**self.image_processor_dict				)
						self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_,      """image_mean"""				)				)
						self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_,      """image_std"""				)				)
						self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_,      """do_normalize"""				)				)
						self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_,      """do_resize"""				)				)
						self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_,      """size"""				)				)

			def     __snake_case					(self				)					->      Union[str, Any]:
						UpperCAmelCase_:		List[str]       			=    self.image_processing_class.from_dict(self.image_processor_dict				)
						self.assertEqual(image_processor.size,      {"""height""": 18, """width""": 18}				)

						UpperCAmelCase_:		Union[str, Any]       			=    self.image_processing_class.from_dict(self.image_processor_dict,      size=42				)
						self.assertEqual(image_processor.size,      {"""height""": 42, """width""": 42}				)

			def     __snake_case					(self				)					->      Optional[Any]:
						pass

			def     __snake_case					(self				)					->      List[str]:
						# Initialize image_processing
						UpperCAmelCase_:		Any       			=    self.image_processing_class(**self.image_processor_dict				)
						# create random PIL images
						UpperCAmelCase_:		List[Any]       			=    prepare_image_inputs(self.image_processor_tester,      equal_resolution=SCREAMING_SNAKE_CASE_				)
						for image in image_inputs:
									self.assertIsInstance(SCREAMING_SNAKE_CASE_,      Image.Image				)

						# Test not batched input
						UpperCAmelCase_:		List[str]       			=    image_processing(image_inputs[0],      return_tensors="""pt"""				).pixel_values
						self.assertEqual(
						    encoded_images.shape,      (
						        1,
						        self.image_processor_tester.num_channels,
						        self.image_processor_tester.size["""height"""],
						        self.image_processor_tester.size["""width"""],
						    ),      )

						# Test batched
						UpperCAmelCase_:		str       			=    image_processing(SCREAMING_SNAKE_CASE_,      return_tensors="""pt"""				).pixel_values
						self.assertEqual(
						    encoded_images.shape,      (
						        self.image_processor_tester.batch_size,
						        self.image_processor_tester.num_channels,
						        self.image_processor_tester.size["""height"""],
						        self.image_processor_tester.size["""width"""],
						    ),      )

			def     __snake_case					(self				)					->      Dict:
						# Initialize image_processing
						UpperCAmelCase_:		List[Any]       			=    self.image_processing_class(**self.image_processor_dict				)
						# create random numpy tensors
						UpperCAmelCase_:		int       			=    prepare_image_inputs(self.image_processor_tester,      equal_resolution=SCREAMING_SNAKE_CASE_,      numpify=SCREAMING_SNAKE_CASE_				)
						for image in image_inputs:
									self.assertIsInstance(SCREAMING_SNAKE_CASE_,      np.ndarray				)

						# Test not batched input
						UpperCAmelCase_:		Dict       			=    image_processing(image_inputs[0],      return_tensors="""pt"""				).pixel_values
						self.assertEqual(
						    encoded_images.shape,      (
						        1,
						        self.image_processor_tester.num_channels,
						        self.image_processor_tester.size["""height"""],
						        self.image_processor_tester.size["""width"""],
						    ),      )

						# Test batched
						UpperCAmelCase_:		Optional[Any]       			=    image_processing(SCREAMING_SNAKE_CASE_,      return_tensors="""pt"""				).pixel_values
						self.assertEqual(
						    encoded_images.shape,      (
						        self.image_processor_tester.batch_size,
						        self.image_processor_tester.num_channels,
						        self.image_processor_tester.size["""height"""],
						        self.image_processor_tester.size["""width"""],
						    ),      )

			def     __snake_case					(self				)					->      Tuple:
						# Initialize image_processing
						UpperCAmelCase_:		List[Any]       			=    self.image_processing_class(**self.image_processor_dict				)
						# create random PyTorch tensors
						UpperCAmelCase_:		Any       			=    prepare_image_inputs(self.image_processor_tester,      equal_resolution=SCREAMING_SNAKE_CASE_,      torchify=SCREAMING_SNAKE_CASE_				)
						for image in image_inputs:
									self.assertIsInstance(SCREAMING_SNAKE_CASE_,      torch.Tensor				)

						# Test not batched input
						UpperCAmelCase_:		Dict       			=    image_processing(image_inputs[0],      return_tensors="""pt"""				).pixel_values
						self.assertEqual(
						    encoded_images.shape,      (
						        1,
						        self.image_processor_tester.num_channels,
						        self.image_processor_tester.size["""height"""],
						        self.image_processor_tester.size["""width"""],
						    ),      )

						# Test batched
						UpperCAmelCase_:		str       			=    image_processing(SCREAMING_SNAKE_CASE_,      return_tensors="""pt"""				).pixel_values
						self.assertEqual(
						    encoded_images.shape,      (
						        self.image_processor_tester.batch_size,
						        self.image_processor_tester.num_channels,
						        self.image_processor_tester.size["""height"""],
						        self.image_processor_tester.size["""width"""],
						    ),      )






