






'''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_video_inputs


if is_torch_available():
 import torch

if is_vision_available():
 from PIL import Image

 from transformers import VivitImageProcessor
class 				__SCREAMING_SNAKE_CASE							(				unittest.TestCase  ):




      def __init__(	self			, lowerCamelCase			, lowerCamelCase=7			, lowerCamelCase=3			, lowerCamelCase=10			, lowerCamelCase=18			, lowerCamelCase=30			, lowerCamelCase=400			, lowerCamelCase=True			, lowerCamelCase=None			, lowerCamelCase=True			, lowerCamelCase=[0.5, 0.5, 0.5]			, lowerCamelCase=[0.5, 0.5, 0.5]			, lowerCamelCase=None			, )				->Dict:



         '''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 			__UpperCamelCase				(	self   )				->Dict:



         '''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 				__SCREAMING_SNAKE_CASE							(				_lowerCAmelCase   ,   unittest.TestCase  ):
      __a	       =VivitImageProcessor if is_vision_available() else None




      def 			__UpperCamelCase				(	self   )				->Dict:



         '''simple docstring'''
         __a					  =     VivitImageProcessingTester(self   )




      @property
      def 			__UpperCamelCase				(	self   )				->int:



         '''simple docstring'''
         return self.image_processor_tester.prepare_image_processor_dict()




      def 			__UpperCamelCase				(	self   )				->int:



         '''simple docstring'''
         __a					  =     self.image_processing_class(**self.image_processor_dict   )
         self.assertTrue(hasattr(lowerCamelCase			, 'image_mean'   )   )
         self.assertTrue(hasattr(lowerCamelCase			, 'image_std'   )   )
         self.assertTrue(hasattr(lowerCamelCase			, 'do_normalize'   )   )
         self.assertTrue(hasattr(lowerCamelCase			, 'do_resize'   )   )
         self.assertTrue(hasattr(lowerCamelCase			, 'do_center_crop'   )   )
         self.assertTrue(hasattr(lowerCamelCase			, 'size'   )   )




      def 			__UpperCamelCase				(	self   )				->Dict:



         '''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 			__UpperCamelCase				(	self   )				->Dict:



         '''simple docstring'''
         # Initialize image_processing
         __a					  =     self.image_processing_class(**self.image_processor_dict   )
         # create random PIL videos
         __a					  =     prepare_video_inputs(self.image_processor_tester			, equal_resolution=lowerCamelCase   )
         for video in video_inputs:
            self.assertIsInstance(lowerCamelCase			, lowerCamelCase   )
            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(lowerCamelCase			, 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 			__UpperCamelCase				(	self   )				->Tuple:



         '''simple docstring'''
         # Initialize image_processing
         __a					  =     self.image_processing_class(**self.image_processor_dict   )
         # create random numpy tensors
         __a					  =     prepare_video_inputs(self.image_processor_tester			, equal_resolution=lowerCamelCase			, numpify=lowerCamelCase   )
         for video in video_inputs:
            self.assertIsInstance(lowerCamelCase			, lowerCamelCase   )
            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(lowerCamelCase			, 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 			__UpperCamelCase				(	self   )				->int:



         '''simple docstring'''
         # Initialize image_processing
         __a					  =     self.image_processing_class(**self.image_processor_dict   )
         # create random PyTorch tensors
         __a					  =     prepare_video_inputs(self.image_processor_tester			, equal_resolution=lowerCamelCase			, torchify=lowerCamelCase   )
         for video in video_inputs:
            self.assertIsInstance(lowerCamelCase			, lowerCamelCase   )
            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(lowerCamelCase			, 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'],
             )			, )







'''simple docstring'''



import copy
import os
from typing import TYPE_CHECKING, List, Union


if TYPE_CHECKING:
 pass

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


__UpperCamelCase   :							int         =   logging.get_logger(__name__)

__UpperCamelCase   :							int         =   {
    """kakaobrain/align-base""": """https://huggingface.co/kakaobrain/align-base/resolve/main/config.json""",
}
class 				__SCREAMING_SNAKE_CASE							(				_lowerCAmelCase  ):
      __a	       ="align_text_model"




      def __init__(	self			, lowerCamelCase=3_0522			, lowerCamelCase=768			, lowerCamelCase=12			, lowerCamelCase=12			, lowerCamelCase=3072			, lowerCamelCase="gelu"			, lowerCamelCase=0.1			, lowerCamelCase=0.1			, lowerCamelCase=512			, lowerCamelCase=2			, lowerCamelCase=0.02			, lowerCamelCase=1e-12			, lowerCamelCase=0			, lowerCamelCase="absolute"			, lowerCamelCase=True			, **lowerCamelCase			, )				->List[Any]:



         '''simple docstring'''
         super().__init__(**lowerCamelCase   )

         __a					  =     vocab_size
         __a					  =     hidden_size
         __a					  =     num_hidden_layers
         __a					  =     num_attention_heads
         __a					  =     hidden_act
         __a					  =     intermediate_size
         __a					  =     hidden_dropout_prob
         __a					  =     attention_probs_dropout_prob
         __a					  =     max_position_embeddings
         __a					  =     type_vocab_size
         __a					  =     initializer_range
         __a					  =     layer_norm_eps
         __a					  =     position_embedding_type
         __a					  =     use_cache
         __a					  =     pad_token_id






      @classmethod
      def 			__UpperCamelCase				(	cls			, lowerCamelCase			, **lowerCamelCase   )				->"PretrainedConfig":



         '''simple docstring'''
         cls._set_token_in_kwargs(lowerCamelCase   )

         __a  ,      __a					  =     cls.get_config_dict(lowerCamelCase			, **lowerCamelCase   )

         # get the text config dict if we are loading from AlignConfig
         if config_dict.get('model_type'   ) == "align":
            __a					  =     config_dict['text_config']

         if "model_type" in config_dict and hasattr(cls			, 'model_type'   ) and config_dict["model_type"] != cls.model_type:
            logger.warning(
                F"""You are using a model of type {config_dict["model_type"]} to instantiate a model of type """
                F"""{cls.model_type}. This is not supported for all configurations of models and can yield errors."""   )

         return cls.from_dict(lowerCamelCase			, **lowerCamelCase   )







class 				__SCREAMING_SNAKE_CASE							(				_lowerCAmelCase  ):
      __a	       ="align_vision_model"




      def __init__(	self			, lowerCamelCase = 3			, lowerCamelCase = 600			, lowerCamelCase = 2.0			, lowerCamelCase = 3.1			, lowerCamelCase = 8			, lowerCamelCase = [3, 3, 5, 3, 5, 5, 3]			, lowerCamelCase = [32, 16, 24, 40, 80, 112, 192]			, lowerCamelCase = [16, 24, 40, 80, 112, 192, 320]			, lowerCamelCase = []			, lowerCamelCase = [1, 2, 2, 2, 1, 2, 1]			, lowerCamelCase = [1, 2, 2, 3, 3, 4, 1]			, lowerCamelCase = [1, 6, 6, 6, 6, 6, 6]			, lowerCamelCase = 0.25			, lowerCamelCase = "swish"			, lowerCamelCase = 2560			, lowerCamelCase = "mean"			, lowerCamelCase = 0.02			, lowerCamelCase = 0.001			, lowerCamelCase = 0.99			, lowerCamelCase = 0.2			, **lowerCamelCase			, )				->Dict:



         '''simple docstring'''
         super().__init__(**lowerCamelCase   )

         __a					  =     num_channels
         __a					  =     image_size
         __a					  =     width_coefficient
         __a					  =     depth_coefficient
         __a					  =     depth_divisor
         __a					  =     kernel_sizes
         __a					  =     in_channels
         __a					  =     out_channels
         __a					  =     depthwise_padding
         __a					  =     strides
         __a					  =     num_block_repeats
         __a					  =     expand_ratios
         __a					  =     squeeze_expansion_ratio
         __a					  =     hidden_act
         __a					  =     hidden_dim
         __a					  =     pooling_type
         __a					  =     initializer_range
         __a					  =     batch_norm_eps
         __a					  =     batch_norm_momentum
         __a					  =     drop_connect_rate
         __a					  =     sum(lowerCamelCase   ) * 4






      @classmethod
      def 			__UpperCamelCase				(	cls			, lowerCamelCase			, **lowerCamelCase   )				->"PretrainedConfig":



         '''simple docstring'''
         cls._set_token_in_kwargs(lowerCamelCase   )

         __a  ,      __a					  =     cls.get_config_dict(lowerCamelCase			, **lowerCamelCase   )

         # get the vision config dict if we are loading from AlignConfig
         if config_dict.get('model_type'   ) == "align":
            __a					  =     config_dict['vision_config']

         if "model_type" in config_dict and hasattr(cls			, 'model_type'   ) and config_dict["model_type"] != cls.model_type:
            logger.warning(
                F"""You are using a model of type {config_dict["model_type"]} to instantiate a model of type """
                F"""{cls.model_type}. This is not supported for all configurations of models and can yield errors."""   )

         return cls.from_dict(lowerCamelCase			, **lowerCamelCase   )







class 				__SCREAMING_SNAKE_CASE							(				_lowerCAmelCase  ):
      __a	       ="align"
      __a	       =True




      def __init__(	self			, lowerCamelCase=None			, lowerCamelCase=None			, lowerCamelCase=640			, lowerCamelCase=1.0			, lowerCamelCase=0.02			, **lowerCamelCase			, )				->Union[str, Any]:



         '''simple docstring'''
         super().__init__(**lowerCamelCase   )

         if text_config is None:
            __a					  =     {}
            logger.info('text_config is None. Initializing the AlignTextConfig with default values.'   )

         if vision_config is None:
            __a					  =     {}
            logger.info('vision_config is None. Initializing the AlignVisionConfig with default values.'   )

         __a					  =     AlignTextConfig(**lowerCamelCase   )
         __a					  =     AlignVisionConfig(**lowerCamelCase   )

         __a					  =     projection_dim
         __a					  =     temperature_init_value
         __a					  =     initializer_range




      @classmethod
      def 			__UpperCamelCase				(	cls			, lowerCamelCase			, lowerCamelCase			, **lowerCamelCase   )				->int:



         '''simple docstring'''
         return cls(text_config=text_config.to_dict()			, vision_config=vision_config.to_dict()			, **lowerCamelCase   )






      def 			__UpperCamelCase				(	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