from typing import List, Union

from ..utils import (
    add_end_docstrings,
    is_tf_available,
    is_torch_available,
    is_vision_available,
    logging,
    requires_backends,
)
from .base import PIPELINE_INIT_ARGS, Pipeline


if is_vision_available():
		from PIL import Image

		from ..image_utils import load_image

if is_tf_available():
		import tensorflow as tf

		from ..models.auto.modeling_tf_auto import TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING
		from ..tf_utils import stable_softmax

if is_torch_available():
		from ..models.auto.modeling_auto import MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING

__a  :     int       =  logging.get_logger(__name__)




@add_end_docstrings(_UpperCAmelCase )
class    _UpperCamelCase      (						_UpperCAmelCase ):


			"""simple docstring"""






			def __init__(   self      ,   *lowerCAmelCase__      ,   **lowerCAmelCase__						)     ->					str:

							'''simple docstring'''


							super().__init__(*lowerCAmelCase__      ,   **lowerCAmelCase__						)
							requires_backends(self      ,   '''vision'''						)
							self.check_model_type(
							    TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING
							    if self.framework == '''tf'''
							    else MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING						)





			def        _SCREAMING_SNAKE_CASE			(   self      ,   lowerCAmelCase__=None						)     ->					List[Any]:

							'''simple docstring'''


							__lowercase 			=							{}
							if top_k is not None:
											__lowercase 			=							top_k
							return {}, {}, postprocess_params





			def __call__(   self      ,   lowerCAmelCase__      ,   **lowerCAmelCase__						)     ->					Tuple:

							'''simple docstring'''


							return super().__call__(lowerCAmelCase__      ,   **lowerCAmelCase__						)





			def        _SCREAMING_SNAKE_CASE			(   self      ,   lowerCAmelCase__						)     ->					Union[str, Any]:

							'''simple docstring'''


							__lowercase 			=							load_image(lowerCAmelCase__						)
							__lowercase 			=							self.image_processor(images=lowerCAmelCase__      ,   return_tensors=self.framework						)
							return model_inputs





			def        _SCREAMING_SNAKE_CASE			(   self      ,   lowerCAmelCase__						)     ->					List[Any]:

							'''simple docstring'''


							__lowercase 			=							self.model(**lowerCAmelCase__						)
							return model_outputs





			def        _SCREAMING_SNAKE_CASE			(   self      ,   lowerCAmelCase__      ,   lowerCAmelCase__=5						)     ->					List[Any]:

							'''simple docstring'''


							if top_k > self.model.config.num_labels:
											__lowercase 			=							self.model.config.num_labels

							if self.framework == "pt":
											__lowercase 			=							model_outputs.logits.softmax(-1						)[0]
											__lowercase			,     __lowercase 			=							probs.topk(lowerCAmelCase__						)
							elif self.framework == "tf":
											__lowercase 			=							stable_softmax(model_outputs.logits      ,   axis=-1						)[0]
											__lowercase 			=							tf.math.top_k(lowerCAmelCase__      ,   k=lowerCAmelCase__						)
											__lowercase			,     __lowercase 			=							topk.values.numpy(), topk.indices.numpy()
							else:
											raise ValueError(F"Unsupported framework: {self.framework}"						)

							__lowercase 			=							scores.tolist()
							__lowercase 			=							ids.tolist()
							return [{"score": score, "label": self.model.config.idalabel[_id]} for score, _id in zip(lowerCAmelCase__      ,   lowerCAmelCase__						)]
from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


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

__a  :     Tuple       =  {
    """facebook/data2vec-text-base""": """https://huggingface.co/data2vec/resolve/main/config.json""",
}




class    _UpperCamelCase      (						_UpperCAmelCase ):


			"""simple docstring"""






			__a  : Dict			 =						'''data2vec-text'''





			def __init__(   self      ,   lowerCAmelCase__=3_05_22      ,   lowerCAmelCase__=7_68      ,   lowerCAmelCase__=12      ,   lowerCAmelCase__=12      ,   lowerCAmelCase__=30_72      ,   lowerCAmelCase__="gelu"      ,   lowerCAmelCase__=0.1      ,   lowerCAmelCase__=0.1      ,   lowerCAmelCase__=5_12      ,   lowerCAmelCase__=2      ,   lowerCAmelCase__=0.02      ,   lowerCAmelCase__=1E-12      ,   lowerCAmelCase__=1      ,   lowerCAmelCase__=0      ,   lowerCAmelCase__=2      ,   lowerCAmelCase__="absolute"      ,   lowerCAmelCase__=True      ,   lowerCAmelCase__=None      ,   **lowerCAmelCase__      ,   )     ->					Any:

							'''simple docstring'''


							super().__init__(pad_token_id=lowerCAmelCase__      ,   bos_token_id=lowerCAmelCase__      ,   eos_token_id=lowerCAmelCase__      ,   **lowerCAmelCase__						)

							__lowercase 			=							vocab_size
							__lowercase 			=							hidden_size
							__lowercase 			=							num_hidden_layers
							__lowercase 			=							num_attention_heads
							__lowercase 			=							hidden_act
							__lowercase 			=							intermediate_size
							__lowercase 			=							hidden_dropout_prob
							__lowercase 			=							attention_probs_dropout_prob
							__lowercase 			=							max_position_embeddings
							__lowercase 			=							type_vocab_size
							__lowercase 			=							initializer_range
							__lowercase 			=							layer_norm_eps
							__lowercase 			=							position_embedding_type
							__lowercase 			=							use_cache
							__lowercase 			=							classifier_dropout




class    _UpperCamelCase      (						_UpperCAmelCase ):


			"""simple docstring"""






			@property
			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					Mapping[str, Mapping[int, str]]:

							'''simple docstring'''


							if self.task == "multiple-choice":
											__lowercase 			=							{0: '''batch''', 1: '''choice''', 2: '''sequence'''}
							else:
											__lowercase 			=							{0: '''batch''', 1: '''sequence'''}
							return OrderedDict(
							    [
							        ('''input_ids''', dynamic_axis),
							        ('''attention_mask''', dynamic_axis),
							    ]						)