

'''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 					__a   (		unittest.TestCase  ):

						def __init__(		self	:						Optional[int]    ,			lowercase__	:						Optional[Any]    ,			lowercase__	:						Optional[Any]=7    ,			lowercase__	:						Optional[int]=3    ,			lowercase__	:						Dict=18    ,			lowercase__	:						Dict=30    ,			lowercase__	:						str=4_00    ,			lowercase__	:						Optional[Any]=True    ,			lowercase__	:						int=None    ,			lowercase__	:						List[Any]=True    ,			lowercase__	:						str=None    ,			)						->str:

							"""simple docstring"""



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


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

							"""simple docstring"""



							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 					__a   (		SCREAMING_SNAKE_CASE_							,unittest.TestCase  ):
						__SCREAMING_SNAKE_CASE     :					Any  =      MobileNetVaImageProcessor if is_vision_available() else None

						def 	_UpperCAmelCase							(		self	:						str)						->Tuple:

							"""simple docstring"""



							_lowercase							=     MobileNetVaImageProcessingTester(self)

						@property
						def 	_UpperCAmelCase							(		self	:						Optional[int])						->List[str]:

							"""simple docstring"""



							return self.image_processor_tester.prepare_image_processor_dict()

						def 	_UpperCAmelCase							(		self	:						Optional[Any])						->Union[str, Any]:

							"""simple docstring"""



							_lowercase							=     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	:						Dict)						->List[Any]:

							"""simple docstring"""



							_lowercase							=     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})

							_lowercase							=     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	:						List[str])						->Tuple:

							"""simple docstring"""



							pass

						def 	_UpperCAmelCase							(		self	:						Optional[int])						->int:

							"""simple docstring"""



							_lowercase							=     self.image_processing_class(**self.image_processor_dict)
							# create random PIL images
							_lowercase							=     prepare_image_inputs(self.image_processor_tester    ,			equal_resolution=__UpperCAmelCase)
							for image in image_inputs:
								self.assertIsInstance(__UpperCAmelCase    ,			Image.Image)

							# Test not batched input
							_lowercase							=     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
							_lowercase							=     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	:						Tuple)						->Optional[int]:

							"""simple docstring"""



							_lowercase							=     self.image_processing_class(**self.image_processor_dict)
							# create random numpy tensors
							_lowercase							=     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
							_lowercase							=     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
							_lowercase							=     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	:						Union[str, Any])						->Any:

							"""simple docstring"""



							_lowercase							=     self.image_processing_class(**self.image_processor_dict)
							# create random PyTorch tensors
							_lowercase							=     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
							_lowercase							=     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
							_lowercase							=     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