

'''simple docstring'''






from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


a_					:    List[str]          =    logging.get_logger(__name__)

a_					:    List[Any]          =    {
    '''shi-labs/dinat-mini-in1k-224''': '''https://huggingface.co/shi-labs/dinat-mini-in1k-224/resolve/main/config.json''',
    # See all Dinat models at https://huggingface.co/models?filter=dinat
}




class  a     (     snake_case__  ,				snake_case__       ):
 _lowerCAmelCase 					=	'''dinat'''

 _lowerCAmelCase 					=	{
     '''num_attention_heads''': '''num_heads''',
     '''num_hidden_layers''': '''num_layers''',
 }
 def __init__( self      ,				__magic_name__=4      ,				__magic_name__=3      ,				__magic_name__=64      ,				__magic_name__=[3, 4, 6, 5]      ,				__magic_name__=[2, 4, 8, 16]      ,				__magic_name__=7      ,				__magic_name__=[[1, 8, 1], [1, 4, 1, 4], [1, 2, 1, 2, 1, 2], [1, 1, 1, 1, 1]]      ,				__magic_name__=3.0      ,				__magic_name__=True      ,				__magic_name__=0.0      ,				__magic_name__=0.0      ,				__magic_name__=0.1      ,				__magic_name__="gelu"      ,				__magic_name__=0.0_2      ,				__magic_name__=1e-5      ,				__magic_name__=0.0      ,				__magic_name__=None      ,				__magic_name__=None      ,				**__magic_name__      ,				)					->							int:
      super().__init__(**_A						)

      _a			      =							patch_size
      _a			      =							num_channels
      _a			      =							embed_dim
      _a			      =							depths
      _a			      =							len(_A						)
      _a			      =							num_heads
      _a			      =							kernel_size
      _a			      =							dilations
      _a			      =							mlp_ratio
      _a			      =							qkv_bias
      _a			      =							hidden_dropout_prob
      _a			      =							attention_probs_dropout_prob
      _a			      =							drop_path_rate
      _a			      =							hidden_act
      _a			      =							layer_norm_eps
      _a			      =							initializer_range
      # we set the hidden_size attribute in order to make Dinat work with VisionEncoderDecoderModel
      # this indicates the channel dimension after the last stage of the model
      _a			      =							int(embed_dim * 2 ** (len(_A						) - 1)						)
      _a			      =							layer_scale_init_value
      _a			      =							['stem'] + [f'stage{idx}' for idx in range(1      ,				len(_A						) + 1						)]
      _a			      =							get_aligned_output_features_output_indices(
          out_features=_A      ,				out_indices=_A      ,				stage_names=self.stage_names						)





'''simple docstring'''






# Copyright 2023 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

import torch

from ..models.auto import AutoModelForVisualQuestionAnswering, AutoProcessor
from ..utils import requires_backends
from .base import PipelineTool


if TYPE_CHECKING:
 from PIL import Image




class  a     (     _SCREAMING_SNAKE_CASE       ):
 _lowerCAmelCase 					=	"""dandelin/vilt-b32-finetuned-vqa"""
 _lowerCAmelCase 					=	(
     """This is a tool that answers a question about an image. It takes an input named `image` which should be the """
     """image containing the information, as well as a `question` which should be the question in English. It """
     """returns a text that is the answer to the question."""
 )
 _lowerCAmelCase 					=	"""image_qa"""
 _lowerCAmelCase 					=	AutoProcessor
 _lowerCAmelCase 					=	AutoModelForVisualQuestionAnswering

 _lowerCAmelCase 					=	["""image""", """text"""]
 _lowerCAmelCase 					=	["""text"""]
 def __init__( self      ,				*__magic_name__      ,				**__magic_name__						)					->							Tuple:
      requires_backends(self      ,				['vision']						)
      super().__init__(*__magic_name__      ,				**__magic_name__						)
 def 							__UpperCAmelCase		( self      ,				__magic_name__      ,				__magic_name__						)					->							Tuple:
      return self.pre_processor(__magic_name__      ,				__magic_name__      ,				return_tensors='pt'						)
 def 							__UpperCAmelCase		( self      ,				__magic_name__						)					->							Any:
      with torch.no_grad():
           return self.model(**__magic_name__						).logits




 def 							__UpperCAmelCase		( self      ,				__magic_name__						)					->							Optional[int]:
      _a			      =							outputs.argmax(-1						).item()
      return self.model.config.idalabel[idx]

