




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

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


@add_end_docstrings(UpperCAmelCase__     )
class 				UpperCamelCase_    ( UpperCAmelCase__     ):

    '''simple docstring'''






    def __init__(			self      :	Union[str, Any]					, *UpperCAmelCase__      :	Tuple					, **UpperCAmelCase__      :	Union[str, Any])						->Optional[int]:





           '''simple docstring'''

           super().__init__(*UpperCAmelCase__					, **UpperCAmelCase__)
           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      :	Optional[Any]					, UpperCAmelCase__      :	Dict=None)						->Union[str, Any]:





           '''simple docstring'''

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


    def __call__(			self      :	int					, UpperCAmelCase__      :	Union[str, List[str], "Image.Image", List["Image.Image"]]					, **UpperCAmelCase__      :	Optional[int])						->int:





           '''simple docstring'''

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


    def        SCREAMING_SNAKE_CASE							(			self      :	str					, UpperCAmelCase__      :	str)						->Union[str, Any]:





           '''simple docstring'''

           A__       =    load_image(UpperCAmelCase__)
           A__       =    self.image_processor(images=UpperCAmelCase__					, return_tensors=self.framework)
           return model_inputs


    def        SCREAMING_SNAKE_CASE							(			self      :	List[Any]					, UpperCAmelCase__      :	Tuple)						->int:





           '''simple docstring'''

           A__       =    self.model(**UpperCAmelCase__)
           return model_outputs





    def        SCREAMING_SNAKE_CASE							(			self      :	str					, UpperCAmelCase__      :	Optional[Any]					, UpperCAmelCase__      :	int=5)						->List[str]:





           '''simple docstring'''

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

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

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








from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


_lowerCamelCase	:		List[str]							       =   {"""configuration_vit_msn""": ["""VIT_MSN_PRETRAINED_CONFIG_ARCHIVE_MAP""", """ViTMSNConfig"""]}

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  _lowerCamelCase	:		List[Any]							       =   [
      """VIT_MSN_PRETRAINED_MODEL_ARCHIVE_LIST""",
      """ViTMSNModel""",
      """ViTMSNForImageClassification""",
      """ViTMSNPreTrainedModel""",
  ]

if TYPE_CHECKING:
  from .configuration_vit_msn import VIT_MSN_PRETRAINED_CONFIG_ARCHIVE_MAP, ViTMSNConfig

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_vit_msn import (
        VIT_MSN_PRETRAINED_MODEL_ARCHIVE_LIST,
        ViTMSNForImageClassification,
        ViTMSNModel,
        ViTMSNPreTrainedModel,
    )

else:
  import sys

  _lowerCamelCase	:		Tuple							       =   _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)


