



'''simple docstring'''



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


if is_torch_available():
				import torch

if is_vision_available():
				from PIL import Image

				from transformers import SwinaSRImageProcessor
				from transformers.image_transforms import get_image_size






class 			_SCREAMING_SNAKE_CASE				(unittest.TestCase      ):



			def __init__(     self		:						Union[str, Any]    ,			__UpperCamelCase		:						int    ,			__UpperCamelCase		:						Tuple=7    ,			__UpperCamelCase		:						Dict=3    ,			__UpperCamelCase		:						Union[str, Any]=18    ,			__UpperCamelCase		:						str=30    ,			__UpperCamelCase		:						Union[str, Any]=400    ,			__UpperCamelCase		:						Tuple=True    ,			__UpperCamelCase		:						Optional[int]=1 / 255    ,			__UpperCamelCase		:						int=True    ,			__UpperCamelCase		:						Dict=8    ,			)      ->      Dict:
							"""simple docstring"""





							snake_case__      :   Optional[Any]      =    parent
							snake_case__      :   str      =    batch_size
							snake_case__      :   List[str]      =    num_channels
							snake_case__      :   Optional[int]      =    image_size
							snake_case__      :   Dict      =    min_resolution
							snake_case__      :   int      =    max_resolution
							snake_case__      :   Tuple      =    do_rescale
							snake_case__      :   str      =    rescale_factor
							snake_case__      :   List[str]      =    do_pad
							snake_case__      :   str      =    pad_size



			def 				lowerCAmelCase (     self		:						Dict			)      ->      Optional[int]:
							"""simple docstring"""





							return {
							    "do_rescale": self.do_rescale,
							    "rescale_factor": self.rescale_factor,
							    "do_pad": self.do_pad,
							    "pad_size": self.pad_size,
							}







			def 				lowerCAmelCase (     self		:						str    ,			__UpperCamelCase		:						Optional[int]=False    ,			__UpperCamelCase		:						int=False    ,			__UpperCamelCase		:						Union[str, Any]=False			)      ->      Optional[int]:
							"""simple docstring"""





							assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

							if equal_resolution:
											snake_case__      :   int      =    []
											for i in range(self.batch_size			):
															image_inputs.append(
															    np.random.randint(
															        255    ,			size=(self.num_channels, self.max_resolution, self.max_resolution)    ,			dtype=np.uinta			)			)
							else:
											snake_case__      :   Dict      =    []
											for i in range(self.batch_size			):
															snake_case__  ,      snake_case__      :   Optional[Any]      =    np.random.choice(np.arange(self.min_resolution    ,			self.max_resolution			)    ,			2			)
															image_inputs.append(np.random.randint(255    ,			size=(self.num_channels, width, height)    ,			dtype=np.uinta			)			)

							if not numpify and not torchify:
											# PIL expects the channel dimension as last dimension
											snake_case__      :   Tuple      =    [Image.fromarray(np.moveaxis(__UpperCamelCase    ,			0    ,			-1			)			) for x in image_inputs]

							if torchify:
											snake_case__      :   str      =    [torch.from_numpy(__UpperCamelCase			) for x in image_inputs]

							return image_inputs






@require_torch
@require_vision
class 			_SCREAMING_SNAKE_CASE				(lowercase__,	unittest.TestCase      ):
			A__								=  SwinaSRImageProcessor if is_vision_available() else None



			def 				lowerCAmelCase (     self		:						Union[str, Any]			)      ->      Optional[Any]:
							"""simple docstring"""





							snake_case__      :   List[str]      =    SwinaSRImageProcessingTester(self			)



			@property
			def 				lowerCAmelCase (     self		:						Dict			)      ->      str:
							"""simple docstring"""





							return self.image_processor_tester.prepare_image_processor_dict()



			def 				lowerCAmelCase (     self		:						Tuple			)      ->      str:
							"""simple docstring"""





							snake_case__      :   List[Any]      =    self.image_processing_class(**self.image_processor_dict			)
							self.assertTrue(hasattr(__UpperCamelCase    ,			'''do_rescale'''			)			)
							self.assertTrue(hasattr(__UpperCamelCase    ,			'''rescale_factor'''			)			)
							self.assertTrue(hasattr(__UpperCamelCase    ,			'''do_pad'''			)			)
							self.assertTrue(hasattr(__UpperCamelCase    ,			'''pad_size'''			)			)



			def 				lowerCAmelCase (     self		:						Union[str, Any]			)      ->      List[str]:
							"""simple docstring"""





							pass



			def 				lowerCAmelCase (     self		:						List[Any]    ,			__UpperCamelCase		:						Optional[int]			)      ->      Any:
							"""simple docstring"""





							snake_case__  ,      snake_case__      :   Any      =    get_image_size(__UpperCamelCase			)
							snake_case__      :   int      =    self.image_processor_tester.pad_size

							snake_case__      :   Any      =    (old_height // size + 1) * size - old_height
							snake_case__      :   List[str]      =    (old_width // size + 1) * size - old_width
							return old_height + pad_height, old_width + pad_width



			def 				lowerCAmelCase (     self		:						List[Any]			)      ->      int:
							"""simple docstring"""





							snake_case__      :   Union[str, Any]      =    self.image_processing_class(**self.image_processor_dict			)
							# create random PIL images
							snake_case__      :   int      =    self.image_processor_tester.prepare_inputs(equal_resolution=__UpperCamelCase			)
							for image in image_inputs:
											self.assertIsInstance(__UpperCamelCase    ,			Image.Image			)

							# Test not batched input
							snake_case__      :   Union[str, Any]      =    image_processor(image_inputs[0]    ,			return_tensors='''pt'''			).pixel_values
							snake_case__  ,      snake_case__      :   Tuple      =    self.calculate_expected_size(np.array(image_inputs[0]			)			)
							self.assertEqual(
							    encoded_images.shape    ,			(
							        1,
							        self.image_processor_tester.num_channels,
							        expected_height,
							        expected_width,
							    )    ,			)



			def 				lowerCAmelCase (     self		:						List[Any]			)      ->      int:
							"""simple docstring"""





							snake_case__      :   Tuple      =    self.image_processing_class(**self.image_processor_dict			)
							# create random numpy tensors
							snake_case__      :   List[str]      =    self.image_processor_tester.prepare_inputs(equal_resolution=__UpperCamelCase    ,			numpify=__UpperCamelCase			)
							for image in image_inputs:
											self.assertIsInstance(__UpperCamelCase    ,			np.ndarray			)

							# Test not batched input
							snake_case__      :   List[Any]      =    image_processor(image_inputs[0]    ,			return_tensors='''pt'''			).pixel_values
							snake_case__  ,      snake_case__      :   Dict      =    self.calculate_expected_size(image_inputs[0]			)
							self.assertEqual(
							    encoded_images.shape    ,			(
							        1,
							        self.image_processor_tester.num_channels,
							        expected_height,
							        expected_width,
							    )    ,			)







			def 				lowerCAmelCase (     self		:						str			)      ->      int:
							"""simple docstring"""





							snake_case__      :   Tuple      =    self.image_processing_class(**self.image_processor_dict			)
							# create random PyTorch tensors
							snake_case__      :   str      =    self.image_processor_tester.prepare_inputs(equal_resolution=__UpperCamelCase    ,			torchify=__UpperCamelCase			)
							for image in image_inputs:
											self.assertIsInstance(__UpperCamelCase    ,			torch.Tensor			)

							# Test not batched input
							snake_case__      :   Optional[Any]      =    image_processor(image_inputs[0]    ,			return_tensors='''pt'''			).pixel_values
							snake_case__  ,      snake_case__      :   Tuple      =    self.calculate_expected_size(image_inputs[0]			)
							self.assertEqual(
							    encoded_images.shape    ,			(
							        1,
							        self.image_processor_tester.num_channels,
							        expected_height,
							        expected_width,
							    )    ,			)












'''simple docstring'''







from typing import TYPE_CHECKING

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


UpperCamelCase_					=				{
    "configuration_flava": [
        "FLAVA_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "FlavaConfig",
        "FlavaImageCodebookConfig",
        "FlavaImageConfig",
        "FlavaMultimodalConfig",
        "FlavaTextConfig",
    ],
}

try:
  if not is_vision_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  UpperCamelCase_					=				["FlavaFeatureExtractor"]
  UpperCamelCase_					=				["FlavaImageProcessor"]
  UpperCamelCase_					=				["FlavaProcessor"]

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  UpperCamelCase_					=				[
      "FLAVA_PRETRAINED_MODEL_ARCHIVE_LIST",
      "FlavaForPreTraining",
      "FlavaImageCodebook",
      "FlavaImageModel",
      "FlavaModel",
      "FlavaMultimodalModel",
      "FlavaPreTrainedModel",
      "FlavaTextModel",
  ]

if TYPE_CHECKING:
  from .configuration_flava import (
      FLAVA_PRETRAINED_CONFIG_ARCHIVE_MAP,
      FlavaConfig,
      FlavaImageCodebookConfig,
      FlavaImageConfig,
      FlavaMultimodalConfig,
      FlavaTextConfig,
  )

  try:
    if not is_vision_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .feature_extraction_flava import FlavaFeatureExtractor
    from .image_processing_flava import FlavaImageProcessor
    from .processing_flava import FlavaProcessor

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_flava import (
        FLAVA_PRETRAINED_MODEL_ARCHIVE_LIST,
        FlavaForPreTraining,
        FlavaImageCodebook,
        FlavaImageModel,
        FlavaModel,
        FlavaMultimodalModel,
        FlavaPreTrainedModel,
        FlavaTextModel,
    )

else:
  import sys

  UpperCamelCase_					=				_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)