
"""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 MobileNetVaImageProcessor





class 							snake_case       (     unittest.TestCase		):







   def __init__( self       ,							__UpperCAmelCase       ,							__UpperCAmelCase=7       ,							__UpperCAmelCase=3       ,							__UpperCAmelCase=18       ,							__UpperCAmelCase=30       ,							__UpperCAmelCase=4_00       ,							__UpperCAmelCase=True       ,							__UpperCAmelCase=None       ,							__UpperCAmelCase=True       ,							__UpperCAmelCase=None       ,							)   ->str:
      a_						   =     size if size is not None else {"shortest_edge": 20}
      a_						   =     crop_size if crop_size is not None else {"height": 18, "width": 18}
      a_						   =     parent
      a_						   =     batch_size
      a_						   =     num_channels
      a_						   =     image_size
      a_						   =     min_resolution
      a_						   =     max_resolution
      a_						   =     do_resize
      a_						   =     size
      a_						   =     do_center_crop
      a_						   =     crop_size







   def    UpperCAmelCase__	( self)   ->Union[str, Any]:
      return {
          "do_resize": self.do_resize,
          "size": self.size,
          "do_center_crop": self.do_center_crop,
          "crop_size": self.crop_size,
      }






@require_torch
@require_vision
class 							snake_case       (     SCREAMING_SNAKE_CASE_							,       unittest.TestCase		):
   a_					:		Any     					=     MobileNetVaImageProcessor if is_vision_available() else None







   def    UpperCAmelCase__	( self)   ->Tuple:
      a_						   =     MobileNetVaImageProcessingTester(self)







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







   def    UpperCAmelCase__	( self)   ->Union[str, Any]:
      a_						   =     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"))







   def    UpperCAmelCase__	( self)   ->List[Any]:
      a_						   =     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})

      a_						   =     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    UpperCAmelCase__	( self)   ->Tuple:
      pass







   def    UpperCAmelCase__	( self)   ->int:
      # Initialize image_processing
      a_						   =     self.image_processing_class(**self.image_processor_dict)
      # create random PIL images
      a_						   =     prepare_image_inputs(self.image_processor_tester       ,							equal_resolution=__UpperCAmelCase)
      for image in image_inputs:
         self.assertIsInstance(__UpperCAmelCase       ,							Image.Image)

      # Test not batched input
      a_						   =     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
      a_						   =     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    UpperCAmelCase__	( self)   ->Optional[int]:
      # Initialize image_processing
      a_						   =     self.image_processing_class(**self.image_processor_dict)
      # create random numpy tensors
      a_						   =     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
      a_						   =     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
      a_						   =     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    UpperCAmelCase__	( self)   ->Any:
      # Initialize image_processing
      a_						   =     self.image_processing_class(**self.image_processor_dict)
      # create random PyTorch tensors
      a_						   =     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
      a_						   =     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
      a_						   =     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"],
          )       ,							)

"""simple docstring"""






import copy

from transformers.configuration_utils import PretrainedConfig
from transformers.utils import logging


UpperCamelCase_						   =   logging.get_logger(__name__)





class 							snake_case       (     SCREAMING_SNAKE_CASE_		):
   a_					:		Tuple     					=     """hybrid-clip"""
   a_					:		Optional[Any]     					=     True







   def __init__( self       ,							__UpperCAmelCase=5_12       ,							**__UpperCAmelCase)   ->Dict:
      super().__init__(**__UpperCAmelCase)

      if "text_config" not in kwargs:
         raise ValueError("`text_config` can not be `None`.")

      if "vision_config" not in kwargs:
         raise ValueError("`vision_config` can not be `None`.")

      a_						   =     kwargs.pop("text_config")
      a_						   =     kwargs.pop("vision_config")

      a_						   =     text_config.pop("model_type")
      a_						   =     vision_config.pop("model_type")

      from transformers import AutoConfig

      a_						   =     AutoConfig.for_model(__UpperCAmelCase       ,							**__UpperCAmelCase)

      if vision_model_type == "clip":
         a_						   =     AutoConfig.for_model(__UpperCAmelCase       ,							**__UpperCAmelCase).vision_config
      elif vision_model_type == "clip_vision_model":
         from transformers import CLIPVisionConfig

         a_						   =     CLIPVisionConfig(**__UpperCAmelCase)
      else:
         a_						   =     AutoConfig.for_model(__UpperCAmelCase       ,							**__UpperCAmelCase)

      a_						   =     projection_dim
      a_						   =     1.0







   @classmethod
   def    UpperCAmelCase__	( cls       ,							__UpperCAmelCase       ,							__UpperCAmelCase       ,							**__UpperCAmelCase)   ->Optional[int]:
      return cls(text_config=text_config.to_dict()       ,							vision_config=vision_config.to_dict()       ,							**__UpperCAmelCase)







   def    UpperCAmelCase__	( self)   ->str:
      a_						   =     copy.deepcopy(self.__dict__)
      a_						   =     self.text_config.to_dict()
      a_						   =     self.vision_config.to_dict()
      a_						   =     self.__class__.model_type
      return output