





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


_UpperCAmelCase				:       int	   =				logging.get_logger(__name__)

_UpperCAmelCase				:       Tuple	   =				{
    """google/vivit-b-16x2-kinetics400""": (
        """https://huggingface.co/google/vivit-b-16x2-kinetics400/resolve/main/config.json"""
    ),
    # See all Vivit models at https://huggingface.co/models?filter=vivit
}

class    lowerCAmelCase							(					__UpperCamelCase			):
 UpperCAmelCase__													=		"""vivit"""
 def __init__(      self  :      Optional[int]			,     UpperCAmelCase  :      List[Any]=224			,     UpperCAmelCase  :      List[str]=32			,     UpperCAmelCase  :      Optional[int]=[2, 16, 16]			,     UpperCAmelCase  :      int=3			,     UpperCAmelCase  :      int=768			,     UpperCAmelCase  :      List[str]=12			,     UpperCAmelCase  :      int=12			,     UpperCAmelCase  :      List[Any]=3072			,     UpperCAmelCase  :      Optional[Any]="gelu_fast"			,     UpperCAmelCase  :      Any=0.0			,     UpperCAmelCase  :      int=0.0			,     UpperCAmelCase  :      Optional[int]=0.0_2			,     UpperCAmelCase  :      Tuple=1e-06			,     UpperCAmelCase  :      Optional[int]=True			,     **UpperCAmelCase  :      Dict			,     )			->	str:
     lowerCamelCase__    :      Any					 =		hidden_size
     lowerCamelCase__    :      List[str]					 =		num_hidden_layers
     lowerCamelCase__    :      Dict					 =		num_attention_heads
     lowerCamelCase__    :      List[Any]					 =		intermediate_size
     lowerCamelCase__    :      Any					 =		hidden_act
     lowerCamelCase__    :      Tuple					 =		hidden_dropout_prob
     lowerCamelCase__    :      Union[str, Any]					 =		attention_probs_dropout_prob
     lowerCamelCase__    :      Optional[int]					 =		initializer_range
     lowerCamelCase__    :      Dict					 =		layer_norm_eps

     lowerCamelCase__    :      int					 =		image_size
     lowerCamelCase__    :      Any					 =		num_frames
     lowerCamelCase__    :      Optional[Any]					 =		tubelet_size
     lowerCamelCase__    :      Tuple					 =		num_channels
     lowerCamelCase__    :      Any					 =		qkv_bias

     super().__init__(**UpperCAmelCase	)













"""simple docstring"""



import unittest

from transformers import MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING, is_vision_available
from transformers.pipelines import pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_tf,
    require_torch,
    require_vision,
    slow,
)

from .test_pipelines_common import ANY


if is_vision_available():
    from PIL import Image
else:

    class        a     :







        @staticmethod
        def 			UpperCamelCase_      (			*_lowerCamelCase							,		**_lowerCamelCase       ):
          pass

@is_pipeline_test
@require_torch
@require_vision
class        a     (   unittest.TestCase	):
    UpperCAmelCase_ :     Union[str, Any]	     =MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING







    def 			UpperCamelCase_      (			self							,		_lowerCamelCase							,		_lowerCamelCase							,		_lowerCamelCase       ):
      lowercase							    =       pipeline('visual-question-answering'							,		model='hf-internal-testing/tiny-vilt-random-vqa'       )
      lowercase							    =       [
          {
              'image': Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'       ),
              'question': 'How many cats are there?',
          },
          {
              'image': './tests/fixtures/tests_samples/COCO/000000039769.png',
              'question': 'How many cats are there?',
          },
      ]
      return vqa_pipeline, examples







    def 			UpperCamelCase_      (			self							,		_lowerCamelCase							,		_lowerCamelCase       ):
      lowercase							    =       vqa_pipeline(_lowerCamelCase							,		top_k=1       )
      self.assertEqual(
          _lowerCamelCase							,		[
              [{'score': ANY(_lowerCamelCase       ), 'answer': ANY(_lowerCamelCase       )}],
              [{'score': ANY(_lowerCamelCase       ), 'answer': ANY(_lowerCamelCase       )}],
          ]							,		)







    @require_torch
    def 			UpperCamelCase_      (			self       ):
      lowercase							    =       pipeline('visual-question-answering'							,		model='hf-internal-testing/tiny-vilt-random-vqa'       )
      lowercase							    =       './tests/fixtures/tests_samples/COCO/000000039769.png'
      lowercase							    =       'How many cats are there?'

      lowercase							    =       vqa_pipeline(image=_lowerCamelCase							,		question='How many cats are there?'							,		top_k=2       )
      self.assertEqual(
          _lowerCamelCase							,		[{'score': ANY(_lowerCamelCase       ), 'answer': ANY(_lowerCamelCase       )}, {'score': ANY(_lowerCamelCase       ), 'answer': ANY(_lowerCamelCase       )}]       )

      lowercase							    =       vqa_pipeline({'image': image, 'question': question}							,		top_k=2       )
      self.assertEqual(
          _lowerCamelCase							,		[{'score': ANY(_lowerCamelCase       ), 'answer': ANY(_lowerCamelCase       )}, {'score': ANY(_lowerCamelCase       ), 'answer': ANY(_lowerCamelCase       )}]       )







    @slow
    @require_torch
    def 			UpperCamelCase_      (			self       ):
      lowercase							    =       pipeline('visual-question-answering'							,		model='dandelin/vilt-b32-finetuned-vqa'       )
      lowercase							    =       './tests/fixtures/tests_samples/COCO/000000039769.png'
      lowercase							    =       'How many cats are there?'

      lowercase							    =       vqa_pipeline(image=_lowerCamelCase							,		question=_lowerCamelCase							,		top_k=2       )
      self.assertEqual(
          nested_simplify(_lowerCamelCase							,		decimals=4       )							,		[{'score': 0.8_7_9_9, 'answer': '2'}, {'score': 0.2_9_6, 'answer': '1'}]       )

      lowercase							    =       vqa_pipeline({'image': image, 'question': question}							,		top_k=2       )
      self.assertEqual(
          nested_simplify(_lowerCamelCase							,		decimals=4       )							,		[{'score': 0.8_7_9_9, 'answer': '2'}, {'score': 0.2_9_6, 'answer': '1'}]       )

      lowercase							    =       vqa_pipeline(
          [{'image': image, 'question': question}, {'image': image, 'question': question}]							,		top_k=2       )
      self.assertEqual(
          nested_simplify(_lowerCamelCase							,		decimals=4       )							,		[[{'score': 0.8_7_9_9, 'answer': '2'}, {'score': 0.2_9_6, 'answer': '1'}]] * 2							,		)







    @require_tf
    @unittest.skip('Visual question answering not implemented in TF'       )
    def 			UpperCamelCase_      (			self       ):
      pass


