
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

snake_case :		int							      =  logging.get_logger(__name__)





@add_end_docstrings(snake_case				)
class       _snake_case					(     snake_case				):







			def __init__(				self						,   *_a						,   **_a		):
				super().__init__(*_a						,   **_a		)
				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						,   _a=None		):
				__magic_name__		:		Dict	   =     {}
				if top_k is not None:
					__magic_name__		:		Optional[Any]	   =     top_k
				return {}, {}, postprocess_params







			def __call__(				self						,   _a						,   **_a		):
				return super().__call__(_a						,   **_a		)







			def 			SCREAMING_SNAKE_CASE    (				self						,   _a		):
				__magic_name__		:		Dict	   =     load_image(_a		)
				__magic_name__		:		List[Any]	   =     self.image_processor(images=_a						,   return_tensors=self.framework		)
				return model_inputs







			def 			SCREAMING_SNAKE_CASE    (				self						,   _a		):
				__magic_name__		:		Any	   =     self.model(**_a		)
				return model_outputs







			def 			SCREAMING_SNAKE_CASE    (				self						,   _a						,   _a=5		):
				if top_k > self.model.config.num_labels:
					__magic_name__		:		Optional[int]	   =     self.model.config.num_labels

				if self.framework == "pt":
					__magic_name__		:		Any	   =     model_outputs.logits.softmax(-1		)[0]
					__magic_name__   ,    __magic_name__		:		List[Any]	   =     probs.topk(_a		)
				elif self.framework == "tf":
					__magic_name__		:		int	   =     stable_softmax(model_outputs.logits						,   axis=-1		)[0]
					__magic_name__		:		List[str]	   =     tf.math.top_k(_a						,   k=_a		)
					__magic_name__   ,    __magic_name__		:		Optional[int]	   =     topk.values.numpy(), topk.indices.numpy()
				else:
					raise ValueError(f'''Unsupported framework: {self.framework}'''		)

				__magic_name__		:		Dict	   =     scores.tolist()
				__magic_name__		:		str	   =     ids.tolist()
				return [{"score": score, "label": self.model.config.idalabel[_id]} for score, _id in zip(_a						,   _a		)]


from collections import OrderedDict
from typing import Mapping

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


snake_case :		Dict							      =  logging.get_logger(__name__)

snake_case :		List[Any]							      =  {
    "YituTech/conv-bert-base": "https://huggingface.co/YituTech/conv-bert-base/resolve/main/config.json",
    "YituTech/conv-bert-medium-small": (
        "https://huggingface.co/YituTech/conv-bert-medium-small/resolve/main/config.json"
    ),
    "YituTech/conv-bert-small": "https://huggingface.co/YituTech/conv-bert-small/resolve/main/config.json",
    # See all ConvBERT models at https://huggingface.co/models?filter=convbert
}





class       _snake_case					(     snake_case				):
			UpperCamelCase__          =    'convbert'







			def __init__(				self						,   _a=30_522						,   _a=768						,   _a=12						,   _a=12						,   _a=3_072						,   _a="gelu"						,   _a=0.1						,   _a=0.1						,   _a=512						,   _a=2						,   _a=0.02						,   _a=1e-12						,   _a=1						,   _a=0						,   _a=2						,   _a=768						,   _a=2						,   _a=9						,   _a=1						,   _a=None						,   **_a						,   ):
				super().__init__(
				    pad_token_id=_a						,   bos_token_id=_a						,   eos_token_id=_a						,   **_a						,   )

				__magic_name__		:		Tuple	   =     vocab_size
				__magic_name__		:		List[Any]	   =     hidden_size
				__magic_name__		:		Union[str, Any]	   =     num_hidden_layers
				__magic_name__		:		List[Any]	   =     num_attention_heads
				__magic_name__		:		str	   =     intermediate_size
				__magic_name__		:		Any	   =     hidden_act
				__magic_name__		:		List[Any]	   =     hidden_dropout_prob
				__magic_name__		:		Optional[int]	   =     attention_probs_dropout_prob
				__magic_name__		:		Tuple	   =     max_position_embeddings
				__magic_name__		:		str	   =     type_vocab_size
				__magic_name__		:		List[str]	   =     initializer_range
				__magic_name__		:		Tuple	   =     layer_norm_eps
				__magic_name__		:		List[Any]	   =     embedding_size
				__magic_name__		:		List[Any]	   =     head_ratio
				__magic_name__		:		str	   =     conv_kernel_size
				__magic_name__		:		Dict	   =     num_groups
				__magic_name__		:		str	   =     classifier_dropout







class       _snake_case					(     snake_case				):







			@property
			def 			SCREAMING_SNAKE_CASE    (				self		):
				if self.task == "multiple-choice":
					__magic_name__		:		Dict	   =     {0: "batch", 1: "choice", 2: "sequence"}
				else:
					__magic_name__		:		Dict	   =     {0: "batch", 1: "sequence"}
				return OrderedDict(
				    [
				        ("input_ids", dynamic_axis),
				        ("attention_mask", dynamic_axis),
				        ("token_type_ids", dynamic_axis),
				    ]		)
