
'''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, prepare_image_inputs


if is_torch_available():
						import torch

if is_vision_available():
						from PIL import Image

						from transformers import OwlViTImageProcessor






class      snake_case__    (	unittest.TestCase ):







		"""simple docstring"""

		def __init__(	self							:       Optional[Any]   ,     UpperCamelCase__							:       Optional[int]   ,     UpperCamelCase__							:       Union[str, Any]=7   ,     UpperCamelCase__							:       Optional[Any]=3   ,     UpperCamelCase__							:       Union[str, Any]=18   ,     UpperCamelCase__							:       int=30   ,     UpperCamelCase__							:       Union[str, Any]=400   ,     UpperCamelCase__							:       Tuple=True   ,     UpperCamelCase__							:       List[str]=None   ,     UpperCamelCase__							:       Dict=True   ,     UpperCamelCase__							:       Tuple=None   ,     UpperCamelCase__							:       int=True   ,     UpperCamelCase__							:       str=[0.48_145_466, 0.4_578_275, 0.40_821_073]   ,     UpperCamelCase__							:       Union[str, Any]=[0.26_862_954, 0.26_130_258, 0.27_577_711]   ,     UpperCamelCase__							:       Optional[Any]=True   ,     )		->       Tuple:






				"""simple docstring"""







				snake_case   :    int			       =		parent
				snake_case   :    str			       =		batch_size
				snake_case   :    int			       =		num_channels
				snake_case   :    Union[str, Any]			       =		image_size
				snake_case   :    str			       =		min_resolution
				snake_case   :    Optional[Any]			       =		max_resolution
				snake_case   :    Tuple			       =		do_resize
				snake_case   :    int			       =		size if size is not None else {'''height''': 18, '''width''': 18}
				snake_case   :    Optional[Any]			       =		do_center_crop
				snake_case   :    Any			       =		crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}
				snake_case   :    int			       =		do_normalize
				snake_case   :    str			       =		image_mean
				snake_case   :    Tuple			       =		image_std
				snake_case   :    int			       =		do_convert_rgb



		def 	lowerCAmelCase							(	self							:       Union[str, Any]	)		->       int:






				"""simple docstring"""







				return {
				    "do_resize": self.do_resize,
				    "size": self.size,
				    "do_center_crop": self.do_center_crop,
				    "crop_size": self.crop_size,
				    "do_normalize": self.do_normalize,
				    "image_mean": self.image_mean,
				    "image_std": self.image_std,
				    "do_convert_rgb": self.do_convert_rgb,
				}







@require_torch
@require_vision
class      snake_case__    (	__SCREAMING_SNAKE_CASE  , unittest.TestCase ):







		"""simple docstring"""

		lowerCamelCase							=		OwlViTImageProcessor if is_vision_available() else None



		def 	lowerCAmelCase							(	self							:       str	)		->       Optional[Any]:






				"""simple docstring"""







				snake_case   :    int			       =		OwlViTImageProcessingTester(self	)



		@property
		def 	lowerCAmelCase							(	self							:       Optional[int]	)		->       Optional[int]:






				"""simple docstring"""







				return self.image_processor_tester.prepare_image_processor_dict()



		def 	lowerCAmelCase							(	self							:       Tuple	)		->       Optional[Any]:






				"""simple docstring"""







				snake_case   :    int			       =		self.image_processing_class(**self.image_processor_dict	)
				self.assertTrue(hasattr(UpperCamelCase__   ,     '''do_resize'''	)	)
				self.assertTrue(hasattr(UpperCamelCase__   ,     '''size'''	)	)
				self.assertTrue(hasattr(UpperCamelCase__   ,     '''do_center_crop'''	)	)
				self.assertTrue(hasattr(UpperCamelCase__   ,     '''center_crop'''	)	)
				self.assertTrue(hasattr(UpperCamelCase__   ,     '''do_normalize'''	)	)
				self.assertTrue(hasattr(UpperCamelCase__   ,     '''image_mean'''	)	)
				self.assertTrue(hasattr(UpperCamelCase__   ,     '''image_std'''	)	)
				self.assertTrue(hasattr(UpperCamelCase__   ,     '''do_convert_rgb'''	)	)



		def 	lowerCAmelCase							(	self							:       Optional[Any]	)		->       str:






				"""simple docstring"""







				snake_case   :    List[Any]			       =		self.image_processing_class.from_dict(self.image_processor_dict	)
				self.assertEqual(image_processor.size   ,     {'''height''': 18, '''width''': 18}	)
				self.assertEqual(image_processor.crop_size   ,     {'''height''': 18, '''width''': 18}	)

				snake_case   :    Union[str, Any]			       =		self.image_processing_class.from_dict(self.image_processor_dict   ,     size=42   ,     crop_size=84	)
				self.assertEqual(image_processor.size   ,     {'''height''': 42, '''width''': 42}	)
				self.assertEqual(image_processor.crop_size   ,     {'''height''': 84, '''width''': 84}	)



		def 	lowerCAmelCase							(	self							:       int	)		->       Dict:






				"""simple docstring"""







				snake_case   :    Optional[int]			       =		self.image_processing_class(**self.image_processor_dict	)
				# create random PIL images
				snake_case   :    Tuple			       =		prepare_image_inputs(self.image_processor_tester   ,     equal_resolution=UpperCamelCase__	)

				for image in image_inputs:
						self.assertIsInstance(UpperCamelCase__   ,     Image.Image	)

				# Test not batched input
				snake_case   :    Tuple			       =		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.crop_size['''height'''],
				        self.image_processor_tester.crop_size['''width'''],
				    )   ,     )

				# Test batched
				snake_case   :    Optional[int]			       =		image_processing(UpperCamelCase__   ,     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.crop_size['''height'''],
				        self.image_processor_tester.crop_size['''width'''],
				    )   ,     )



		def 	lowerCAmelCase							(	self							:       str	)		->       str:






				"""simple docstring"""







				snake_case   :    Tuple			       =		self.image_processing_class(**self.image_processor_dict	)
				# create random numpy tensors
				snake_case   :    Tuple			       =		prepare_image_inputs(self.image_processor_tester   ,     equal_resolution=UpperCamelCase__   ,     numpify=UpperCamelCase__	)
				for image in image_inputs:
						self.assertIsInstance(UpperCamelCase__   ,     np.ndarray	)

				# Test not batched input
				snake_case   :    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.crop_size['''height'''],
				        self.image_processor_tester.crop_size['''width'''],
				    )   ,     )

				# Test batched
				snake_case   :    Any			       =		image_processing(UpperCamelCase__   ,     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.crop_size['''height'''],
				        self.image_processor_tester.crop_size['''width'''],
				    )   ,     )



		def 	lowerCAmelCase							(	self							:       Any	)		->       int:






				"""simple docstring"""







				snake_case   :    List[Any]			       =		self.image_processing_class(**self.image_processor_dict	)
				# create random PyTorch tensors
				snake_case   :    List[Any]			       =		prepare_image_inputs(self.image_processor_tester   ,     equal_resolution=UpperCamelCase__   ,     torchify=UpperCamelCase__	)
				for image in image_inputs:
						self.assertIsInstance(UpperCamelCase__   ,     torch.Tensor	)

				# Test not batched input
				snake_case   :    List[Any]			       =		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.crop_size['''height'''],
				        self.image_processor_tester.crop_size['''width'''],
				    )   ,     )

				# Test batched
				snake_case   :    Any			       =		image_processing(UpperCamelCase__   ,     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.crop_size['''height'''],
				        self.image_processor_tester.crop_size['''width'''],
				    )   ,     )



from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


UpperCAmelCase							= {'''configuration_nat''': ['''NAT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''NatConfig''']}


try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 UpperCAmelCase							= [
     '''NAT_PRETRAINED_MODEL_ARCHIVE_LIST''',
     '''NatForImageClassification''',
     '''NatModel''',
     '''NatPreTrainedModel''',
     '''NatBackbone''',
 ]

if TYPE_CHECKING:
 from .configuration_nat import NAT_PRETRAINED_CONFIG_ARCHIVE_MAP, NatConfig

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_nat import (
      NAT_PRETRAINED_MODEL_ARCHIVE_LIST,
      NatBackbone,
      NatForImageClassification,
      NatModel,
      NatPreTrainedModel,
  )

else:
 import sys

 UpperCAmelCase							= _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)



