





'''simple docstring'''






from typing import Optional, Tuple, Union

import tensorflow as tf

from ...activations_tf import ACTaFN
from ...file_utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward
from ...modeling_tf_outputs import (
    TFBaseModelOutputWithNoAttention,
    TFBaseModelOutputWithPoolingAndNoAttention,
    TFSequenceClassifierOutput,
)
from ...modeling_tf_utils import TFPreTrainedModel, TFSequenceClassificationLoss, keras_serializable, unpack_inputs
from ...tf_utils import shape_list
from ...utils import logging
from .configuration_regnet import RegNetConfig


A__    :       Optional[int]              =logging.get_logger(__name__)

# General docstring
A__    :       Dict              ='''RegNetConfig'''

# Base docstring
A__    :       Tuple              ='''facebook/regnet-y-040'''
A__    :       List[Any]              =[1, 10_88, 7, 7]

# Image classification docstring
A__    :       List[Any]              ='''facebook/regnet-y-040'''
A__    :       Tuple              ='''tabby, tabby cat'''

A__    :       List[str]              =[
    '''facebook/regnet-y-040''',
    # See all regnet models at https://huggingface.co/models?filter=regnet
]




class 			UpperCAmelCase					(      tf.keras.layers.Layer       ):




      def __init__(      self      :			Any      ,      __snake_case      :			Dict      ,      __snake_case      :			Optional[int] = 3      ,      __snake_case      :			List[Any] = 1      ,      __snake_case      :			str = 1      ,      __snake_case      :			Any = "relu"      ,      **__snake_case      :			Tuple      ,      )    ->				str:
            super().__init__(**_a  )
            # The padding and conv has been verified in
            # https://colab.research.google.com/gist/sayakpaul/854bc10eeaf21c9ee2119e0b9f3841a7/scratchpad.ipynb
            _lowerCAmelCase												=							tf.keras.layers.ZeroPaddingaD(padding=kernel_size // 2  )
            _lowerCAmelCase												=							tf.keras.layers.ConvaD(
                filters=_a      ,      kernel_size=_a      ,      strides=_a      ,      padding="""VALID"""      ,      groups=_a      ,      use_bias=_a      ,      name="""convolution"""      ,      )
            _lowerCAmelCase												=							tf.keras.layers.BatchNormalization(epsilon=1E-5      ,      momentum=0.9      ,      name="""normalization"""  )
            _lowerCAmelCase												=							ACTaFN[activation] if activation is not None else tf.identity




      def     lowercase__   (      self      :			Any      ,      __snake_case      :			List[str]  )    ->				List[Any]:
            _lowerCAmelCase												=							self.convolution(self.padding(_a  )  )
            _lowerCAmelCase												=							self.normalization(_a  )
            _lowerCAmelCase												=							self.activation(_a  )
            return hidden_state




class 			UpperCAmelCase					(      tf.keras.layers.Layer       ):




      def __init__(      self      :			Dict      ,      __snake_case      :			Dict      ,      **__snake_case      :			Union[str, Any]  )    ->				Tuple:
            super().__init__(**_a  )
            _lowerCAmelCase												=							config.num_channels
            _lowerCAmelCase												=							TFRegNetConvLayer(
                out_channels=config.embedding_size      ,      kernel_size=3      ,      stride=2      ,      activation=config.hidden_act      ,      name="""embedder"""      ,      )




      def     lowercase__   (      self      :			Any      ,      __snake_case      :			Union[str, Any]  )    ->				Union[str, Any]:
            _lowerCAmelCase												=							shape_list(_a  )[1]
            if tf.executing_eagerly() and num_channels != self.num_channels:
                  raise ValueError(
                      """Make sure that the channel dimension of the pixel values match with the one set in the configuration."""  )

            # When running on CPU, `tf.keras.layers.Conv2D` doesn't support `NCHW` format.
            # So change the input format from `NCHW` to `NHWC`.
            # shape = (batch_size, in_height, in_width, in_channels=num_channels)
            _lowerCAmelCase												=							tf.transpose(_a      ,      perm=(0, 2, 3, 1)  )
            _lowerCAmelCase												=							self.embedder(_a  )
            return hidden_state




class 			UpperCAmelCase					(      tf.keras.layers.Layer       ):




      def __init__(      self      :			Optional[int]      ,      __snake_case      :			Union[str, Any]      ,      __snake_case      :			List[str] = 2      ,      **__snake_case      :			List[str]  )    ->				int:
            super().__init__(**_a  )
            _lowerCAmelCase												=							tf.keras.layers.ConvaD(
                filters=_a      ,      kernel_size=1      ,      strides=_a      ,      use_bias=_a      ,      name="""convolution"""  )
            _lowerCAmelCase												=							tf.keras.layers.BatchNormalization(epsilon=1E-5      ,      momentum=0.9      ,      name="""normalization"""  )




      def     lowercase__   (      self      :			List[Any]      ,      __snake_case      :			Union[str, Any]      ,      __snake_case      :			int = False  )    ->				tf.Tensor:
            return self.normalization(self.convolution(_a  )      ,      training=_a  )




class 			UpperCAmelCase					(      tf.keras.layers.Layer       ):




      def __init__(      self      :			Optional[Any]      ,      __snake_case      :			List[str]      ,      __snake_case      :			Optional[int]      ,      **__snake_case      :			int  )    ->				int:
            super().__init__(**_a  )
            _lowerCAmelCase												=							tf.keras.layers.GlobalAveragePoolingaD(keepdims=_a      ,      name="""pooler"""  )
            _lowerCAmelCase												=							[
                tf.keras.layers.ConvaD(filters=_a      ,      kernel_size=1      ,      activation="""relu"""      ,      name="""attention.0"""  ),
                tf.keras.layers.ConvaD(filters=_a      ,      kernel_size=1      ,      activation="""sigmoid"""      ,      name="""attention.2"""  ),
            ]




      def     lowercase__   (      self      :			Union[str, Any]      ,      __snake_case      :			Tuple  )    ->				List[Any]:
            # [batch_size, h, w, num_channels] -> [batch_size, 1, 1, num_channels]
            _lowerCAmelCase												=							self.pooler(_a  )
            for layer_module in self.attention:
                  _lowerCAmelCase												=							layer_module(_a  )
            _lowerCAmelCase												=							hidden_state * pooled
            return hidden_state




class 			UpperCAmelCase					(      tf.keras.layers.Layer       ):




      def __init__(      self      :			Any      ,      __snake_case      :			Optional[int]      ,      __snake_case      :			List[str]      ,      __snake_case      :			Union[str, Any]      ,      __snake_case      :			str = 1      ,      **__snake_case      :			Dict  )    ->				Union[str, Any]:
            super().__init__(**_a  )
            _lowerCAmelCase												=							in_channels != out_channels or stride != 1
            _lowerCAmelCase												=							max(1      ,      out_channels // config.groups_width  )
            _lowerCAmelCase												=							(
                TFRegNetShortCut(_a      ,      stride=_a      ,      name="""shortcut"""  )
                if should_apply_shortcut
                else tf.keras.layers.Activation("""linear"""      ,      name="""shortcut"""  )
            )
            # `self.layers` instead of `self.layer` because that is a reserved argument.
            _lowerCAmelCase												=							[
                TFRegNetConvLayer(_a      ,      kernel_size=1      ,      activation=config.hidden_act      ,      name="""layer.0"""  ),
                TFRegNetConvLayer(
                    _a      ,      stride=_a      ,      groups=_a      ,      activation=config.hidden_act      ,      name="""layer.1"""  ),
                TFRegNetConvLayer(_a      ,      kernel_size=1      ,      activation=_a      ,      name="""layer.2"""  ),
            ]
            _lowerCAmelCase												=							ACTaFN[config.hidden_act]




      def     lowercase__   (      self      :			Union[str, Any]      ,      __snake_case      :			str  )    ->				Any:
            _lowerCAmelCase												=							hidden_state
            for layer_module in self.layers:
                  _lowerCAmelCase												=							layer_module(_a  )
            _lowerCAmelCase												=							self.shortcut(_a  )
            hidden_state += residual
            _lowerCAmelCase												=							self.activation(_a  )
            return hidden_state




class 			UpperCAmelCase					(      tf.keras.layers.Layer       ):




      def __init__(      self      :			Any      ,      __snake_case      :			Tuple      ,      __snake_case      :			Tuple      ,      __snake_case      :			Union[str, Any]      ,      __snake_case      :			str = 1      ,      **__snake_case      :			Dict  )    ->				List[str]:
            super().__init__(**_a  )
            _lowerCAmelCase												=							in_channels != out_channels or stride != 1
            _lowerCAmelCase												=							max(1      ,      out_channels // config.groups_width  )
            _lowerCAmelCase												=							(
                TFRegNetShortCut(_a      ,      stride=_a      ,      name="""shortcut"""  )
                if should_apply_shortcut
                else tf.keras.layers.Activation("""linear"""      ,      name="""shortcut"""  )
            )
            _lowerCAmelCase												=							[
                TFRegNetConvLayer(_a      ,      kernel_size=1      ,      activation=config.hidden_act      ,      name="""layer.0"""  ),
                TFRegNetConvLayer(
                    _a      ,      stride=_a      ,      groups=_a      ,      activation=config.hidden_act      ,      name="""layer.1"""  ),
                TFRegNetSELayer(_a      ,      reduced_channels=int(round(in_channels / 4  )  )      ,      name="""layer.2"""  ),
                TFRegNetConvLayer(_a      ,      kernel_size=1      ,      activation=_a      ,      name="""layer.3"""  ),
            ]
            _lowerCAmelCase												=							ACTaFN[config.hidden_act]




      def     lowercase__   (      self      :			Dict      ,      __snake_case      :			List[str]  )    ->				List[str]:
            _lowerCAmelCase												=							hidden_state
            for layer_module in self.layers:
                  _lowerCAmelCase												=							layer_module(_a  )
            _lowerCAmelCase												=							self.shortcut(_a  )
            hidden_state += residual
            _lowerCAmelCase												=							self.activation(_a  )
            return hidden_state




class 			UpperCAmelCase					(      tf.keras.layers.Layer       ):




      def __init__(      self      :			Optional[Any]      ,      __snake_case      :			List[str]      ,      __snake_case      :			Any      ,      __snake_case      :			Tuple      ,      __snake_case      :			str = 2      ,      __snake_case      :			Optional[Any] = 2      ,      **__snake_case      :			Dict  )    ->				Union[str, Any]:
            super().__init__(**_a  )

            _lowerCAmelCase												=							TFRegNetXLayer if config.layer_type == '''x''' else TFRegNetYLayer
            _lowerCAmelCase												=							[
                # downsampling is done in the first layer with stride of 2
                layer(_a      ,      _a      ,      _a      ,      stride=_a      ,      name="""layers.0"""  ),
                *[layer(_a      ,      _a      ,      _a      ,      name=f"layers.{i+1}"  ) for i in range(depth - 1  )],
            ]




      def     lowercase__   (      self      :			List[Any]      ,      __snake_case      :			Any  )    ->				Any:
            for layer_module in self.layers:
                  _lowerCAmelCase												=							layer_module(_a  )
            return hidden_state




class 			UpperCAmelCase					(      tf.keras.layers.Layer       ):




      def __init__(      self      :			Union[str, Any]      ,      __snake_case      :			Any      ,      **__snake_case      :			List[Any]  )    ->				List[str]:
            super().__init__(**_a  )
            _lowerCAmelCase												=							[]
            # based on `downsample_in_first_stage`, the first layer of the first stage may or may not downsample the input
            self.stages.append(
                TFRegNetStage(
                    _a      ,      config.embedding_size      ,      config.hidden_sizes[0]      ,      stride=2 if config.downsample_in_first_stage else 1      ,      depth=config.depths[0]      ,      name="""stages.0"""      ,      )  )
            _lowerCAmelCase												=							zip(config.hidden_sizes      ,      config.hidden_sizes[1:]  )
            for i, ((in_channels, out_channels), depth) in enumerate(zip(_a      ,      config.depths[1:]  )  ):
                  self.stages.append(TFRegNetStage(_a      ,      _a      ,      _a      ,      depth=_a      ,      name=f"stages.{i+1}"  )  )




      def     lowercase__   (      self      :			Optional[int]      ,      __snake_case      :			int      ,      __snake_case      :			List[str] = False      ,      __snake_case      :			List[str] = True  )    ->				TFBaseModelOutputWithNoAttention:
            _lowerCAmelCase												=							() if output_hidden_states else None

            for stage_module in self.stages:
                  if output_hidden_states:
                        _lowerCAmelCase												=							hidden_states + (hidden_state,)

                  _lowerCAmelCase												=							stage_module(_a  )

            if output_hidden_states:
                  _lowerCAmelCase												=							hidden_states + (hidden_state,)

            if not return_dict:
                  return tuple(v for v in [hidden_state, hidden_states] if v is not None  )

            return TFBaseModelOutputWithNoAttention(last_hidden_state=_a      ,      hidden_states=_a  )




@keras_serializable
class 			UpperCAmelCase					(      tf.keras.layers.Layer       ):
      _lowercase:      Optional[Any]											=       RegNetConfig




      def __init__(      self      :			Optional[Any]      ,      __snake_case      :			Any      ,      **__snake_case      :			Optional[Any]  )    ->				Optional[int]:
            super().__init__(**_a  )
            _lowerCAmelCase												=							config
            _lowerCAmelCase												=							TFRegNetEmbeddings(_a      ,      name="""embedder"""  )
            _lowerCAmelCase												=							TFRegNetEncoder(_a      ,      name="""encoder"""  )
            _lowerCAmelCase												=							tf.keras.layers.GlobalAveragePoolingaD(keepdims=_a      ,      name="""pooler"""  )




      @unpack_inputs
      def     lowercase__   (      self      :			Union[str, Any]      ,      __snake_case      :			Dict      ,      __snake_case      :			Tuple = None      ,      __snake_case      :			Optional[int] = None      ,      __snake_case      :			int = False      ,      )    ->				TFBaseModelOutputWithPoolingAndNoAttention:
            _lowerCAmelCase												=							(
                output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
            )
            _lowerCAmelCase												=							return_dict if return_dict is not None else self.config.use_return_dict

            _lowerCAmelCase												=							self.embedder(_a      ,      training=_a  )

            _lowerCAmelCase												=							self.encoder(
                _a      ,      output_hidden_states=_a      ,      return_dict=_a      ,      training=_a  )

            _lowerCAmelCase												=							encoder_outputs[0]
            _lowerCAmelCase												=							self.pooler(_a  )

            # Change to NCHW output format have uniformity in the modules
            _lowerCAmelCase												=							tf.transpose(_a      ,      perm=(0, 3, 1, 2)  )
            _lowerCAmelCase												=							tf.transpose(_a      ,      perm=(0, 3, 1, 2)  )

            # Change the other hidden state outputs to NCHW as well
            if output_hidden_states:
                  _lowerCAmelCase												=							tuple([tf.transpose(_a      ,      perm=(0, 3, 1, 2)  ) for h in encoder_outputs[1]]  )

            if not return_dict:
                  return (last_hidden_state, pooled_output) + encoder_outputs[1:]

            return TFBaseModelOutputWithPoolingAndNoAttention(
                last_hidden_state=_a      ,      pooler_output=_a      ,      hidden_states=hidden_states if output_hidden_states else encoder_outputs.hidden_states      ,      )




class 			UpperCAmelCase					(      __lowercase       ):
      _lowercase:      Union[str, Any]											=       RegNetConfig
      _lowercase:      int											=       "regnet"
      _lowercase:      Dict											=       "pixel_values"




      @property
      def     lowercase__   (      self      :			int  )    ->				Tuple:
            return {"pixel_values": tf.TensorSpec(shape=(None, self.config.num_channels, 2_24, 2_24)      ,      dtype=tf.floataa  )}




A__    :       Optional[Any]              =r'''
    Parameters:
    This model is a Tensorflow
    [tf.keras.layers.Layer](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Layer) sub-class. Use it as a
    regular Tensorflow Module and refer to the Tensorflow documentation for all matter related to general usage and
    behavior.
        config ([`RegNetConfig`]): Model configuration class with all the parameters of the model.
            Initializing with a config file does not load the weights associated with the model, only the
            configuration. Check out the [`~TFPreTrainedModel.from_pretrained`] method to load the model weights.
'''

A__    :       Dict              =r'''
    Args:
        pixel_values (`tf.Tensor` of shape `(batch_size, num_channels, height, width)`):
            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See
            [`ConveNextImageProcessor.__call__`] for details.
        output_hidden_states (`bool`, *optional*):
            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
            more detail.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
'''




@add_start_docstrings(
    '''The bare RegNet model outputting raw features without any specific head on top.'''							,		__lowercase							,		)
class 			UpperCAmelCase					(      __lowercase       ):




      def __init__(      self      :			Optional[Any]      ,      __snake_case      :			Tuple      ,      *__snake_case      :			str      ,      **__snake_case      :			Optional[Any]  )    ->				Any:
            super().__init__(_a      ,      *_a      ,      **_a  )
            _lowerCAmelCase												=							TFRegNetMainLayer(_a      ,      name="""regnet"""  )




      @unpack_inputs
      @add_start_docstrings_to_model_forward(_a  )
      @add_code_sample_docstrings(
          checkpoint=_CHECKPOINT_FOR_DOC      ,      output_type=_a      ,      config_class=_CONFIG_FOR_DOC      ,      modality="""vision"""      ,      expected_output=_EXPECTED_OUTPUT_SHAPE      ,      )
      def     lowercase__   (      self      :			List[Any]      ,      __snake_case      :			str      ,      __snake_case      :			List[Any] = None      ,      __snake_case      :			Optional[Any] = None      ,      __snake_case      :			Union[str, Any]=False      ,      )    ->				Union[TFBaseModelOutputWithPoolingAndNoAttention, Tuple[tf.Tensor]]:
            _lowerCAmelCase												=							(
                output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
            )
            _lowerCAmelCase												=							return_dict if return_dict is not None else self.config.use_return_dict

            _lowerCAmelCase												=							self.regnet(
                pixel_values=_a      ,      output_hidden_states=_a      ,      return_dict=_a      ,      training=_a      ,      )
            if not return_dict:
                  return (outputs[0],) + outputs[1:]

            return TFBaseModelOutputWithPoolingAndNoAttention(
                last_hidden_state=outputs.last_hidden_state      ,      pooler_output=outputs.pooler_output      ,      hidden_states=outputs.hidden_states      ,      )




@add_start_docstrings(
    '''\n    RegNet Model with an image classification head on top (a linear layer on top of the pooled features), e.g. for\n    ImageNet.\n    '''							,		__lowercase							,		)
class 			UpperCAmelCase					(      __lowercase							,		__lowercase       ):




      def __init__(      self      :			Any      ,      __snake_case      :			Optional[Any]      ,      *__snake_case      :			List[str]      ,      **__snake_case      :			Any  )    ->				Tuple:
            super().__init__(_a      ,      *_a      ,      **_a  )
            _lowerCAmelCase												=							config.num_labels
            _lowerCAmelCase												=							TFRegNetMainLayer(_a      ,      name="""regnet"""  )
            # classification head
            _lowerCAmelCase												=							[
                tf.keras.layers.Flatten(),
                tf.keras.layers.Dense(config.num_labels      ,      name="""classifier.1"""  ) if config.num_labels > 0 else tf.identity,
            ]




      @unpack_inputs
      @add_start_docstrings_to_model_forward(_a  )
      @add_code_sample_docstrings(
          checkpoint=_IMAGE_CLASS_CHECKPOINT      ,      output_type=_a      ,      config_class=_CONFIG_FOR_DOC      ,      expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT      ,      )
      def     lowercase__   (      self      :			Union[str, Any]      ,      __snake_case      :			List[Any] = None      ,      __snake_case      :			Union[str, Any] = None      ,      __snake_case      :			Optional[Any] = None      ,      __snake_case      :			Tuple = None      ,      __snake_case      :			str=False      ,      )    ->				Union[TFSequenceClassifierOutput, Tuple[tf.Tensor]]:
            _lowerCAmelCase												=							(
                output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
            )
            _lowerCAmelCase												=							return_dict if return_dict is not None else self.config.use_return_dict

            _lowerCAmelCase												=							self.regnet(
                _a      ,      output_hidden_states=_a      ,      return_dict=_a      ,      training=_a  )

            _lowerCAmelCase												=							outputs.pooler_output if return_dict else outputs[1]

            _lowerCAmelCase												=							self.classifier[0](_a  )
            _lowerCAmelCase												=							self.classifier[1](_a  )

            _lowerCAmelCase												=							None if labels is None else self.hf_compute_loss(labels=_a      ,      logits=_a  )

            if not return_dict:
                  _lowerCAmelCase												=							(logits,) + outputs[2:]
                  return ((loss,) + output) if loss is not None else output

            return TFSequenceClassifierOutput(loss=_a      ,      logits=_a      ,      hidden_states=outputs.hidden_states  )













'''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 			UpperCAmelCase					:




            @staticmethod
            def     lowercase__   (      *__snake_case      :			Optional[Any]      ,      **__snake_case      :			Any  )    ->				Tuple:
                  pass




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




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




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

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

            _lowerCAmelCase												=							vqa_pipeline({"""image""": image, """question""": question}      ,      top_k=2  )
            self.assertEqual(
                __snake_case      ,      [{"""score""": ANY(__snake_case  ), """answer""": ANY(__snake_case  )}, {"""score""": ANY(__snake_case  ), """answer""": ANY(__snake_case  )}]  )




      @slow
      @require_torch
      def     lowercase__   (      self      :			List[Any]  )    ->				List[str]:
            _lowerCAmelCase												=							pipeline("""visual-question-answering"""      ,      model="""dandelin/vilt-b32-finetuned-vqa"""  )
            _lowerCAmelCase												=							"""./tests/fixtures/tests_samples/COCO/000000039769.png"""
            _lowerCAmelCase												=							"""How many cats are there?"""

            _lowerCAmelCase												=							vqa_pipeline(image=__snake_case      ,      question=__snake_case      ,      top_k=2  )
            self.assertEqual(
                nested_simplify(__snake_case      ,      decimals=4  )      ,      [{"""score""": 0.87_99, """answer""": """2"""}, {"""score""": 0.2_96, """answer""": """1"""}]  )

            _lowerCAmelCase												=							vqa_pipeline({"""image""": image, """question""": question}      ,      top_k=2  )
            self.assertEqual(
                nested_simplify(__snake_case      ,      decimals=4  )      ,      [{"""score""": 0.87_99, """answer""": """2"""}, {"""score""": 0.2_96, """answer""": """1"""}]  )

            _lowerCAmelCase												=							vqa_pipeline(
                [{"""image""": image, """question""": question}, {"""image""": image, """question""": question}]      ,      top_k=2  )
            self.assertEqual(
                nested_simplify(__snake_case      ,      decimals=4  )      ,      [[{"""score""": 0.87_99, """answer""": """2"""}, {"""score""": 0.2_96, """answer""": """1"""}]] * 2      ,      )




      @require_tf
      @unittest.skip("""Visual question answering not implemented in TF"""  )
      def     lowercase__   (      self      :			List[str]  )    ->				Union[str, Any]:
            pass






