




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 BlipImageProcessor






class      A     (						unittest.TestCase						):
     """simple docstring"""

     def __init__(      self					:				Optional[int]		,					A__					:				Optional[Any]		,					A__					:				Union[str, Any]=7		,					A__					:				Optional[Any]=3		,					A__					:				Dict=1_8		,					A__					:				List[str]=3_0		,					A__					:				Dict=4_0_0		,					A__					:				List[str]=True		,					A__					:				str=None		,					A__					:				List[str]=True		,					A__					:				List[Any]=False		,					A__					:				Any=[0.48145466, 0.4578275, 0.40821073]		,					A__					:				Union[str, Any]=[0.26862954, 0.26130258, 0.27577711]		,					A__					:				Tuple=True		,					)			->    Optional[Any]:
      lowerCamelCase__ 					=			size if size is not None else {'height': 2_0, 'width': 2_0}
      lowerCamelCase__ 					=			parent
      lowerCamelCase__ 					=			batch_size
      lowerCamelCase__ 					=			num_channels
      lowerCamelCase__ 					=			image_size
      lowerCamelCase__ 					=			min_resolution
      lowerCamelCase__ 					=			max_resolution
      lowerCamelCase__ 					=			do_resize
      lowerCamelCase__ 					=			size
      lowerCamelCase__ 					=			do_normalize
      lowerCamelCase__ 					=			image_mean
      lowerCamelCase__ 					=			image_std
      lowerCamelCase__ 					=			do_pad
      lowerCamelCase__ 					=			do_convert_rgb




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




     def 	__snake_case				(      self					:				Optional[Any]		,					A__					:				Union[str, Any]=False		,					A__					:				Optional[int]=False		,					A__					:				Tuple=False     )			->    Optional[int]:
      assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

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

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

      if torchify:
       lowerCamelCase__ 					=			[torch.from_numpy(A__     ) for x in image_inputs]

      return image_inputs






@require_torch
@require_vision
class      A     (						_lowerCAmelCase     ,  unittest.TestCase						):
     """simple docstring"""

     _snake_case:		Optional[Any]       =BlipImageProcessor if is_vision_available() else None




     def 	__snake_case				(      self					:				Any     )			->    Optional[Any]:
      lowerCamelCase__ 					=			BlipImageProcessingTester(self     )




     @property
     def 	__snake_case				(      self					:				Tuple     )			->    Any:
      return self.image_processor_tester.prepare_image_processor_dict()




     def 	__snake_case				(      self					:				List[Any]     )			->    List[Any]:
      lowerCamelCase__ 					=			self.image_processing_class(**self.image_processor_dict     )
      self.assertTrue(hasattr(A__		,					'do_resize'     )     )
      self.assertTrue(hasattr(A__		,					'size'     )     )
      self.assertTrue(hasattr(A__		,					'do_normalize'     )     )
      self.assertTrue(hasattr(A__		,					'image_mean'     )     )
      self.assertTrue(hasattr(A__		,					'image_std'     )     )
      self.assertTrue(hasattr(A__		,					'do_convert_rgb'     )     )




     def 	__snake_case				(      self					:				List[str]     )			->    List[str]:
      pass




     def 	__snake_case				(      self					:				Optional[Any]     )			->    Any:
      # Initialize image_processor
      lowerCamelCase__ 					=			self.image_processing_class(**self.image_processor_dict     )
      # create random PIL images
      lowerCamelCase__ 					=			self.image_processor_tester.prepare_inputs(equal_resolution=A__     )
      for image in image_inputs:
       self.assertIsInstance(A__		,					Image.Image     )

      # Test not batched input
      lowerCamelCase__ 					=			image_processor(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
      lowerCamelCase__ 					=			image_processor(A__		,					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					:				List[str]     )			->    List[str]:
      # Initialize image_processor
      lowerCamelCase__ 					=			self.image_processing_class(**self.image_processor_dict     )
      # create random numpy tensors
      lowerCamelCase__ 					=			self.image_processor_tester.prepare_inputs(equal_resolution=A__		,					numpify=A__     )
      for image in image_inputs:
       self.assertIsInstance(A__		,					np.ndarray     )

      # Test not batched input
      lowerCamelCase__ 					=			image_processor(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
      lowerCamelCase__ 					=			image_processor(A__		,					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					:				Optional[Any]     )			->    Optional[int]:
      # Initialize image_processor
      lowerCamelCase__ 					=			self.image_processing_class(**self.image_processor_dict     )
      # create random PyTorch tensors
      lowerCamelCase__ 					=			self.image_processor_tester.prepare_inputs(equal_resolution=A__		,					torchify=A__     )
      for image in image_inputs:
       self.assertIsInstance(A__		,					torch.Tensor     )

      # Test not batched input
      lowerCamelCase__ 					=			image_processor(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
      lowerCamelCase__ 					=			image_processor(A__		,					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'],
          )		,					)






@require_torch
@require_vision
class      A     (						_lowerCAmelCase     ,  unittest.TestCase						):
     """simple docstring"""

     _snake_case:		Optional[int]       =BlipImageProcessor if is_vision_available() else None




     def 	__snake_case				(      self					:				List[str]     )			->    int:
      lowerCamelCase__ 					=			BlipImageProcessingTester(self		,					num_channels=4     )
      lowerCamelCase__ 					=			3




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




     def 	__snake_case				(      self					:				Any     )			->    Dict:
      lowerCamelCase__ 					=			self.image_processing_class(**self.image_processor_dict     )
      self.assertTrue(hasattr(A__		,					'do_resize'     )     )
      self.assertTrue(hasattr(A__		,					'size'     )     )
      self.assertTrue(hasattr(A__		,					'do_normalize'     )     )
      self.assertTrue(hasattr(A__		,					'image_mean'     )     )
      self.assertTrue(hasattr(A__		,					'image_std'     )     )
      self.assertTrue(hasattr(A__		,					'do_convert_rgb'     )     )




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




     def 	__snake_case				(      self					:				Union[str, Any]     )			->    Any:
      # Initialize image_processor
      lowerCamelCase__ 					=			self.image_processing_class(**self.image_processor_dict     )
      # create random PIL images
      lowerCamelCase__ 					=			self.image_processor_tester.prepare_inputs(equal_resolution=A__     )
      for image in image_inputs:
       self.assertIsInstance(A__		,					Image.Image     )

      # Test not batched input
      lowerCamelCase__ 					=			image_processor(image_inputs[0]		,					return_tensors='pt'     ).pixel_values
      self.assertEqual(
          encoded_images.shape		,					(
              1,
              self.expected_encoded_image_num_channels,
              self.image_processor_tester.size['height'],
              self.image_processor_tester.size['width'],
          )		,					)

      # Test batched
      lowerCamelCase__ 					=			image_processor(A__		,					return_tensors='pt'     ).pixel_values
      self.assertEqual(
          encoded_images.shape		,					(
              self.image_processor_tester.batch_size,
              self.expected_encoded_image_num_channels,
              self.image_processor_tester.size['height'],
              self.image_processor_tester.size['width'],
          )		,					)





from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


__SCREAMING_SNAKE_CASE      :				int				      ={"""configuration_nat""": ["""NAT_PRETRAINED_CONFIG_ARCHIVE_MAP""", """NatConfig"""]}


try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      __SCREAMING_SNAKE_CASE      :				Optional[int]				      =[
          """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

      __SCREAMING_SNAKE_CASE      :				Any				      =_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)