






"""simple docstring"""
from ...configuration_utils import PretrainedConfig
from ...utils import logging


_lowerCAmelCase         =							logging.get_logger(__name__)

_lowerCAmelCase         =							{
    "microsoft/cvt-13": "https://huggingface.co/microsoft/cvt-13/resolve/main/config.json",
    # See all Cvt models at https://huggingface.co/models?filter=cvt
}



class      SCREAMING_SNAKE_CASE  (				__lowerCAmelCase						):





	"""simple docstring"""




	_A       :				List[Any]    =				'''cvt'''





	def __init__(self     ,     lowerCAmelCase_=3     ,     lowerCAmelCase_=[7, 3, 3]     ,     lowerCAmelCase_=[4, 2, 2]     ,     lowerCAmelCase_=[2, 1, 1]     ,     lowerCAmelCase_=[64, 192, 384]     ,     lowerCAmelCase_=[1, 3, 6]     ,     lowerCAmelCase_=[1, 2, 10]     ,     lowerCAmelCase_=[4.0, 4.0, 4.0]     ,     lowerCAmelCase_=[0.0, 0.0, 0.0]     ,     lowerCAmelCase_=[0.0, 0.0, 0.0]     ,     lowerCAmelCase_=[0.0, 0.0, 0.1]     ,     lowerCAmelCase_=[True, True, True]     ,     lowerCAmelCase_=[False, False, True]     ,     lowerCAmelCase_=["dw_bn", "dw_bn", "dw_bn"]     ,     lowerCAmelCase_=[3, 3, 3]     ,     lowerCAmelCase_=[1, 1, 1]     ,     lowerCAmelCase_=[2, 2, 2]     ,     lowerCAmelCase_=[1, 1, 1]     ,     lowerCAmelCase_=[1, 1, 1]     ,     lowerCAmelCase_=0.02     ,     lowerCAmelCase_=1e-1_2     ,     **lowerCAmelCase_     ,     ):
		super().__init__(**lowerCAmelCase_							)
		A_		:						str	    =   num_channels
		A_		:						Dict	    =   patch_sizes
		A_		:						List[str]	    =   patch_stride
		A_		:						Optional[int]	    =   patch_padding
		A_		:						Optional[Any]	    =   embed_dim
		A_		:						Tuple	    =   num_heads
		A_		:						Any	    =   depth
		A_		:						Optional[Any]	    =   mlp_ratio
		A_		:						Any	    =   attention_drop_rate
		A_		:						List[Any]	    =   drop_rate
		A_		:						int	    =   drop_path_rate
		A_		:						List[Any]	    =   qkv_bias
		A_		:						Optional[Any]	    =   cls_token
		A_		:						Optional[Any]	    =   qkv_projection_method
		A_		:						int	    =   kernel_qkv
		A_		:						Union[str, Any]	    =   padding_kv
		A_		:						Dict	    =   stride_kv
		A_		:						List[Any]	    =   padding_q
		A_		:						int	    =   stride_q
		A_		:						Dict	    =   initializer_range
		A_		:						Optional[Any]	    =   layer_norm_eps









"""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      SCREAMING_SNAKE_CASE  :





								"""simple docstring"""




								@staticmethod
								def    lowerCamelCase(*lowerCAmelCase_     ,     **lowerCAmelCase_							):
									pass



@is_pipeline_test
@require_torch
@require_vision
class      SCREAMING_SNAKE_CASE  (				unittest.TestCase						):





	"""simple docstring"""




	_A       :				List[Any]    =				MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING





	def    lowerCamelCase(self     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_							):
		A_		:						Union[str, Any]	    =   pipeline("""visual-question-answering"""     ,     model="""hf-internal-testing/tiny-vilt-random-vqa"""							)
		A_		:						Union[str, Any]	    =   [
		    {
		        """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    lowerCamelCase(self     ,     lowerCAmelCase_     ,     lowerCAmelCase_							):
		A_		:						str	    =   vqa_pipeline(lowerCAmelCase_     ,     top_k=1							)
		self.assertEqual(
		    lowerCAmelCase_     ,     [
		        [{"""score""": ANY(lowerCAmelCase_							), """answer""": ANY(lowerCAmelCase_							)}],
		        [{"""score""": ANY(lowerCAmelCase_							), """answer""": ANY(lowerCAmelCase_							)}],
		    ]     ,     )





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

		A_		:						Optional[int]	    =   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_							)}]							)

		A_		:						Any	    =   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    lowerCamelCase(self							):
		A_		:						int	    =   pipeline("""visual-question-answering"""     ,     model="""dandelin/vilt-b32-finetuned-vqa"""							)
		A_		:						Tuple	    =   """./tests/fixtures/tests_samples/COCO/000000039769.png"""
		A_		:						int	    =   """How many cats are there?"""

		A_		:						List[Any]	    =   vqa_pipeline(image=lowerCAmelCase_     ,     question=lowerCAmelCase_     ,     top_k=2							)
		self.assertEqual(
		    nested_simplify(lowerCAmelCase_     ,     decimals=4							)     ,     [{"""score""": 0.8799, """answer""": """2"""}, {"""score""": 0.296, """answer""": """1"""}]							)

		A_		:						Any	    =   vqa_pipeline({"""image""": image, """question""": question}     ,     top_k=2							)
		self.assertEqual(
		    nested_simplify(lowerCAmelCase_     ,     decimals=4							)     ,     [{"""score""": 0.8799, """answer""": """2"""}, {"""score""": 0.296, """answer""": """1"""}]							)

		A_		:						Tuple	    =   vqa_pipeline(
		    [{"""image""": image, """question""": question}, {"""image""": image, """question""": question}]     ,     top_k=2							)
		self.assertEqual(
		    nested_simplify(lowerCAmelCase_     ,     decimals=4							)     ,     [[{"""score""": 0.8799, """answer""": """2"""}, {"""score""": 0.296, """answer""": """1"""}]] * 2     ,     )





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

