






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_video_inputs


if is_torch_available():
  import torch

if is_vision_available():
  from PIL import Image

  from transformers import VideoMAEImageProcessor


class  __lowercase (		unittest.TestCase					):







     '''simple docstring'''




     def __init__(			self    :     Dict	,		UpperCamelCase_    :     Any	,		UpperCamelCase_    :     List[Any]=7	,		UpperCamelCase_    :     Any=3	,		UpperCamelCase_    :     str=10	,		UpperCamelCase_    :     Any=18	,		UpperCamelCase_    :     Union[str, Any]=30	,		UpperCamelCase_    :     List[str]=400	,		UpperCamelCase_    :     List[str]=True	,		UpperCamelCase_    :     Union[str, Any]=None	,		UpperCamelCase_    :     List[str]=True	,		UpperCamelCase_    :     Union[str, Any]=[0.5, 0.5, 0.5]	,		UpperCamelCase_    :     Union[str, Any]=[0.5, 0.5, 0.5]	,		UpperCamelCase_    :     Optional[int]=None	,		):


            """simple docstring"""



            __A             =		size if size is not None else {"""shortest_edge""": 18}
            __A             =		crop_size if crop_size is not None else {"""height""": 18, """width""": 18}

            __A             =		parent
            __A             =		batch_size
            __A             =		num_channels
            __A             =		num_frames
            __A             =		image_size
            __A             =		min_resolution
            __A             =		max_resolution
            __A             =		do_resize
            __A             =		size
            __A             =		do_normalize
            __A             =		image_mean
            __A             =		image_std
            __A             =		crop_size





     def 						lowerCAmelCase_       (			self    :     List[str]			):


            """simple docstring"""



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


@require_torch
@require_vision
class  __lowercase (		lowercase_     , unittest.TestCase					):







     '''simple docstring'''
     SCREAMING_SNAKE_CASE				  =			VideoMAEImageProcessor if is_vision_available() else None




     def 						lowerCAmelCase_       (			self    :     str			):


            """simple docstring"""



            __A             =		VideoMAEImageProcessingTester(self			)




     @property
     def 						lowerCAmelCase_       (			self    :     Tuple			):


            """simple docstring"""



            return self.image_processor_tester.prepare_image_processor_dict()




     def 						lowerCAmelCase_       (			self    :     List[Any]			):


            """simple docstring"""



            __A             =		self.image_processing_class(**self.image_processor_dict			)
            self.assertTrue(hasattr(UpperCamelCase_	,		"""image_mean"""			)			)
            self.assertTrue(hasattr(UpperCamelCase_	,		"""image_std"""			)			)
            self.assertTrue(hasattr(UpperCamelCase_	,		"""do_normalize"""			)			)
            self.assertTrue(hasattr(UpperCamelCase_	,		"""do_resize"""			)			)
            self.assertTrue(hasattr(UpperCamelCase_	,		"""do_center_crop"""			)			)
            self.assertTrue(hasattr(UpperCamelCase_	,		"""size"""			)			)




     def 						lowerCAmelCase_       (			self    :     int			):


            """simple docstring"""



            __A             =		self.image_processing_class.from_dict(self.image_processor_dict			)
            self.assertEqual(image_processor.size	,		{"""shortest_edge""": 18}			)
            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 						lowerCAmelCase_       (			self    :     List[str]			):


            """simple docstring"""



            pass




     def 						lowerCAmelCase_       (			self    :     Any			):


            """simple docstring"""



            __A             =		self.image_processing_class(**self.image_processor_dict			)
            # create random PIL videos
            __A             =		prepare_video_inputs(self.image_processor_tester	,		equal_resolution=UpperCamelCase_			)
            for video in video_inputs:
                   self.assertIsInstance(UpperCamelCase_	,		UpperCamelCase_			)
                   self.assertIsInstance(video[0]	,		Image.Image			)

            # Test not batched input
            __A             =		image_processing(video_inputs[0]	,		return_tensors="""pt"""			).pixel_values
            self.assertEqual(
                encoded_videos.shape	,		(
                    1,
                    self.image_processor_tester.num_frames,
                    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_videos.shape	,		(
                    self.image_processor_tester.batch_size,
                    self.image_processor_tester.num_frames,
                    self.image_processor_tester.num_channels,
                    self.image_processor_tester.crop_size["""height"""],
                    self.image_processor_tester.crop_size["""width"""],
                )	,		)




     def 						lowerCAmelCase_       (			self    :     Tuple			):


            """simple docstring"""



            __A             =		self.image_processing_class(**self.image_processor_dict			)
            # create random numpy tensors
            __A             =		prepare_video_inputs(self.image_processor_tester	,		equal_resolution=UpperCamelCase_	,		numpify=UpperCamelCase_			)
            for video in video_inputs:
                   self.assertIsInstance(UpperCamelCase_	,		UpperCamelCase_			)
                   self.assertIsInstance(video[0]	,		np.ndarray			)

            # Test not batched input
            __A             =		image_processing(video_inputs[0]	,		return_tensors="""pt"""			).pixel_values
            self.assertEqual(
                encoded_videos.shape	,		(
                    1,
                    self.image_processor_tester.num_frames,
                    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_videos.shape	,		(
                    self.image_processor_tester.batch_size,
                    self.image_processor_tester.num_frames,
                    self.image_processor_tester.num_channels,
                    self.image_processor_tester.crop_size["""height"""],
                    self.image_processor_tester.crop_size["""width"""],
                )	,		)





     def 						lowerCAmelCase_       (			self    :     Optional[int]			):


            """simple docstring"""



            __A             =		self.image_processing_class(**self.image_processor_dict			)
            # create random PyTorch tensors
            __A             =		prepare_video_inputs(self.image_processor_tester	,		equal_resolution=UpperCamelCase_	,		torchify=UpperCamelCase_			)
            for video in video_inputs:
                   self.assertIsInstance(UpperCamelCase_	,		UpperCamelCase_			)
                   self.assertIsInstance(video[0]	,		torch.Tensor			)

            # Test not batched input
            __A             =		image_processing(video_inputs[0]	,		return_tensors="""pt"""			).pixel_values
            self.assertEqual(
                encoded_videos.shape	,		(
                    1,
                    self.image_processor_tester.num_frames,
                    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_videos.shape	,		(
                    self.image_processor_tester.batch_size,
                    self.image_processor_tester.num_frames,
                    self.image_processor_tester.num_channels,
                    self.image_processor_tester.crop_size["""height"""],
                    self.image_processor_tester.crop_size["""width"""],
                )	,		)












import copy

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


__a :    Tuple								=				logging.get_logger(__name__)


class  __lowercase (		lowercase_					):







     '''simple docstring'''
     SCREAMING_SNAKE_CASE				  =			"hybrid-clip"
     SCREAMING_SNAKE_CASE				  =			True




     def __init__(			self    :     Optional[Any]	,		UpperCamelCase_    :     Optional[Any]=512	,		**UpperCamelCase_    :     List[Any]			):


         """simple docstring"""



         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 						lowerCAmelCase_       (			cls    :     int	,		UpperCamelCase_    :     PretrainedConfig	,		UpperCamelCase_    :     PretrainedConfig	,		**UpperCamelCase_    :     Union[str, Any]			):


         """simple docstring"""



         return cls(text_config=text_config.to_dict()	,		vision_config=vision_config.to_dict()	,		**UpperCamelCase_			)





     def 						lowerCAmelCase_       (			self    :     Tuple			):


         """simple docstring"""



         __A             =		copy.deepcopy(self.__dict__			)
         __A             =		self.text_config.to_dict()
         __A             =		self.vision_config.to_dict()
         __A             =		self.__class__.model_type
         return output




