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 CLIPImageProcessor
class SCREAMING_SNAKE_CASE_		(			unittest.TestCase		):







   def __init__(    self	:	Tuple      ,      lowerCamelCase_	:	List[str]      ,      lowerCamelCase_	:	Union[str, Any]=7      ,      lowerCamelCase_	:	Optional[Any]=3      ,      lowerCamelCase_	:	str=18      ,      lowerCamelCase_	:	Union[str, Any]=30      ,      lowerCamelCase_	:	int=400      ,      lowerCamelCase_	:	List[str]=True      ,      lowerCamelCase_	:	Optional[int]=None      ,      lowerCamelCase_	:	List[Any]=True      ,      lowerCamelCase_	:	List[str]=None      ,      lowerCamelCase_	:	Tuple=True      ,      lowerCamelCase_	:	List[Any]=[0.4_8_1_4_5_4_6_6, 0.4_5_7_8_2_7_5, 0.4_0_8_2_1_0_7_3]      ,      lowerCamelCase_	:	List[str]=[0.2_6_8_6_2_9_5_4, 0.2_6_1_3_0_2_5_8, 0.2_7_5_7_7_7_1_1]      ,      lowerCamelCase_	:	str=True      ,      ):





    """simple docstring"""


    UpperCamelCase      =			size if size is not None else {"""shortest_edge""": 20}
    UpperCamelCase      =			crop_size if crop_size is not None else {"""height""": 18, """width""": 18}
    UpperCamelCase      =			parent
    UpperCamelCase      =			batch_size
    UpperCamelCase      =			num_channels
    UpperCamelCase      =			image_size
    UpperCamelCase      =			min_resolution
    UpperCamelCase      =			max_resolution
    UpperCamelCase      =			do_resize
    UpperCamelCase      =			size
    UpperCamelCase      =			do_center_crop
    UpperCamelCase      =			crop_size
    UpperCamelCase      =			do_normalize
    UpperCamelCase      =			image_mean
    UpperCamelCase      =			image_std
    UpperCamelCase      =			do_convert_rgb







   def 	lowerCamelCase_  (    self	:	Optional[Any]							):





    """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,
    }







   def 	lowerCamelCase_  (    self	:	Union[str, Any]      ,      lowerCamelCase_	:	Optional[Any]=False      ,      lowerCamelCase_	:	Union[str, Any]=False      ,      lowerCamelCase_	:	str=False							):





    """simple docstring"""


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

    if equal_resolution:
     UpperCamelCase      =			[]
     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:
     UpperCamelCase      =			[]
     for i in range(self.batch_size							):
      UpperCamelCase     ,    UpperCamelCase      =			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
     UpperCamelCase      =			[Image.fromarray(np.moveaxis(lowerCamelCase_      ,      0      ,      -1							)							) for x in image_inputs]

    if torchify:
     UpperCamelCase      =			[torch.from_numpy(lowerCamelCase_							) for x in image_inputs]

    return image_inputs





@require_torch
@require_vision
class SCREAMING_SNAKE_CASE_		(			__lowerCAmelCase     ,    unittest.TestCase		):
   __lowerCAmelCase											=							CLIPImageProcessor if is_vision_available() else None







   def 	lowerCamelCase_  (    self	:	int							):





    """simple docstring"""


    UpperCamelCase      =			CLIPImageProcessingTester(self							)







   @property
   def 	lowerCamelCase_  (    self	:	Optional[Any]							):





    """simple docstring"""


    return self.image_processor_tester.prepare_image_processor_dict()







   def 	lowerCamelCase_  (    self	:	Optional[Any]							):





    """simple docstring"""


    UpperCamelCase      =			self.image_processing_class(**self.image_processor_dict							)
    self.assertTrue(hasattr(lowerCamelCase_      ,      """do_resize"""							)							)
    self.assertTrue(hasattr(lowerCamelCase_      ,      """size"""							)							)
    self.assertTrue(hasattr(lowerCamelCase_      ,      """do_center_crop"""							)							)
    self.assertTrue(hasattr(lowerCamelCase_      ,      """center_crop"""							)							)
    self.assertTrue(hasattr(lowerCamelCase_      ,      """do_normalize"""							)							)
    self.assertTrue(hasattr(lowerCamelCase_      ,      """image_mean"""							)							)
    self.assertTrue(hasattr(lowerCamelCase_      ,      """image_std"""							)							)
    self.assertTrue(hasattr(lowerCamelCase_      ,      """do_convert_rgb"""							)							)







   def 	lowerCamelCase_  (    self	:	List[str]							):





    """simple docstring"""


    UpperCamelCase      =			self.image_processing_class.from_dict(self.image_processor_dict							)
    self.assertEqual(image_processor.size      ,      {"""shortest_edge""": 20}							)
    self.assertEqual(image_processor.crop_size      ,      {"""height""": 18, """width""": 18}							)

    UpperCamelCase      =			self.image_processing_class.from_dict(self.image_processor_dict      ,      size=42      ,      crop_size=84							)
    self.assertEqual(image_processor.size      ,      {"""shortest_edge""": 42}							)
    self.assertEqual(image_processor.crop_size      ,      {"""height""": 84, """width""": 84}							)







   def 	lowerCamelCase_  (    self	:	int							):





    """simple docstring"""


    pass







   def 	lowerCamelCase_  (    self	:	Tuple							):





    """simple docstring"""


    UpperCamelCase      =			self.image_processing_class(**self.image_processor_dict							)
    # create random PIL images
    UpperCamelCase      =			self.image_processor_tester.prepare_inputs(equal_resolution=lowerCamelCase_							)
    for image in image_inputs:
     self.assertIsInstance(lowerCamelCase_      ,      Image.Image							)

    # Test not batched input
    UpperCamelCase      =			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
    UpperCamelCase      =			image_processing(lowerCamelCase_      ,      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	:	List[str]							):





    """simple docstring"""


    UpperCamelCase      =			self.image_processing_class(**self.image_processor_dict							)
    # create random numpy tensors
    UpperCamelCase      =			self.image_processor_tester.prepare_inputs(equal_resolution=lowerCamelCase_      ,      numpify=lowerCamelCase_							)
    for image in image_inputs:
     self.assertIsInstance(lowerCamelCase_      ,      np.ndarray							)

    # Test not batched input
    UpperCamelCase      =			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
    UpperCamelCase      =			image_processing(lowerCamelCase_      ,      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	:	Optional[Any]							):





    """simple docstring"""


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

    # Test not batched input
    UpperCamelCase      =			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
    UpperCamelCase      =			image_processing(lowerCamelCase_      ,      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"""],
        )      ,      )





@require_torch
@require_vision
class SCREAMING_SNAKE_CASE_		(			__lowerCAmelCase     ,    unittest.TestCase		):
   __lowerCAmelCase											=							CLIPImageProcessor if is_vision_available() else None







   def 	lowerCamelCase_  (    self	:	List[str]							):





    """simple docstring"""


    UpperCamelCase      =			CLIPImageProcessingTester(self      ,      num_channels=4							)
    UpperCamelCase      =			3







   @property
   def 	lowerCamelCase_  (    self	:	Any							):





    """simple docstring"""


    return self.image_processor_tester.prepare_image_processor_dict()







   def 	lowerCamelCase_  (    self	:	Optional[Any]							):





    """simple docstring"""


    UpperCamelCase      =			self.image_processing_class(**self.image_processor_dict							)
    self.assertTrue(hasattr(lowerCamelCase_      ,      """do_resize"""							)							)
    self.assertTrue(hasattr(lowerCamelCase_      ,      """size"""							)							)
    self.assertTrue(hasattr(lowerCamelCase_      ,      """do_center_crop"""							)							)
    self.assertTrue(hasattr(lowerCamelCase_      ,      """center_crop"""							)							)
    self.assertTrue(hasattr(lowerCamelCase_      ,      """do_normalize"""							)							)
    self.assertTrue(hasattr(lowerCamelCase_      ,      """image_mean"""							)							)
    self.assertTrue(hasattr(lowerCamelCase_      ,      """image_std"""							)							)
    self.assertTrue(hasattr(lowerCamelCase_      ,      """do_convert_rgb"""							)							)







   def 	lowerCamelCase_  (    self	:	str							):





    """simple docstring"""


    pass







   def 	lowerCamelCase_  (    self	:	int							):





    """simple docstring"""


    UpperCamelCase      =			self.image_processing_class(**self.image_processor_dict							)
    # create random PIL images
    UpperCamelCase      =			self.image_processor_tester.prepare_inputs(equal_resolution=lowerCamelCase_							)
    for image in image_inputs:
     self.assertIsInstance(lowerCamelCase_      ,      Image.Image							)

    # Test not batched input
    UpperCamelCase      =			image_processing(image_inputs[0]      ,      return_tensors="""pt"""							).pixel_values
    self.assertEqual(
        encoded_images.shape      ,      (
            1,
            self.expected_encoded_image_num_channels,
            self.image_processor_tester.crop_size["""height"""],
            self.image_processor_tester.crop_size["""width"""],
        )      ,      )

    # Test batched
    UpperCamelCase      =			image_processing(lowerCamelCase_      ,      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.crop_size["""height"""],
            self.image_processor_tester.crop_size["""width"""],
        )      ,      )

from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_torch_available,
)


_SCREAMING_SNAKE_CASE   		=			{
    """configuration_align""": [
        """ALIGN_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """AlignConfig""",
        """AlignTextConfig""",
        """AlignVisionConfig""",
    ],
    """processing_align""": ["""AlignProcessor"""],
}

try:
     if not is_torch_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     _SCREAMING_SNAKE_CASE   		=			[
         """ALIGN_PRETRAINED_MODEL_ARCHIVE_LIST""",
         """AlignModel""",
         """AlignPreTrainedModel""",
         """AlignTextModel""",
         """AlignVisionModel""",
     ]

if TYPE_CHECKING:
     from .configuration_align import (
         ALIGN_PRETRAINED_CONFIG_ARCHIVE_MAP,
         AlignConfig,
         AlignTextConfig,
         AlignVisionConfig,
     )
     from .processing_align import AlignProcessor

     try:
          if not is_torch_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_align import (
              ALIGN_PRETRAINED_MODEL_ARCHIVE_LIST,
              AlignModel,
              AlignPreTrainedModel,
              AlignTextModel,
              AlignVisionModel,
          )

else:
     import sys

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