


'''simple docstring'''





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

__UpperCamelCase       :       Optional[Any]						       =				logging.get_logger(__name__)

@add_end_docstrings(lowerCamelCase__)
class       __magic_name__	(     lowerCamelCase__):


     def __init__(      self							:     Optional[int]							,	*lowerCamelCase__							:     str							,	**lowerCamelCase__							:     int			)  ->      List[Any]:





      '''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      UpperCAmelCase__	(      self							:     str							,	lowerCamelCase__							:     Union[str, Any]=None			)  ->      Optional[Any]:





      '''simple docstring'''






      UpperCamelCase__					:    List[str]          =   {}
      if top_k is not None:
       UpperCamelCase__					:    List[str]          =   top_k
      return {}, {}, postprocess_params


     def __call__(      self							:     str							,	lowerCamelCase__							:     Union[str, Any]							,	**lowerCamelCase__							:     Optional[int]			)  ->      int:





      '''simple docstring'''






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


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





      '''simple docstring'''






      UpperCamelCase__					:    List[Any]          =   load_image(__lowerCamelCase			)
      UpperCamelCase__					:    Dict          =   self.image_processor(images=__lowerCamelCase							,	return_tensors=self.framework			)
      return model_inputs


     def      UpperCAmelCase__	(      self							:     str							,	lowerCamelCase__							:     Tuple			)  ->      Any:





      '''simple docstring'''






      UpperCamelCase__					:    List[str]          =   self.model(**__lowerCamelCase			)
      return model_outputs


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





      '''simple docstring'''






      if top_k > self.model.config.num_labels:
       UpperCamelCase__					:    Tuple          =   self.model.config.num_labels

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

      UpperCamelCase__					:    List[Any]          =   scores.tolist()
      UpperCamelCase__					:    str          =   ids.tolist()
      return [{"score": score, "label": self.model.config.idalabel[_id]} for score, _id in zip(__lowerCamelCase							,	__lowerCamelCase			)]






from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_torch_available,
    is_vision_available,
)


__UpperCamelCase       :       Dict						       =				{
    "configuration_mobilevit": ["MOBILEVIT_PRETRAINED_CONFIG_ARCHIVE_MAP", "MobileViTConfig", "MobileViTOnnxConfig"],
}

try:
       if not is_vision_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       __UpperCamelCase       :       str						       =				["MobileViTFeatureExtractor"]
       __UpperCamelCase       :       Optional[Any]						       =				["MobileViTImageProcessor"]

try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       __UpperCamelCase       :       Union[str, Any]						       =				[
           "MOBILEVIT_PRETRAINED_MODEL_ARCHIVE_LIST",
           "MobileViTForImageClassification",
           "MobileViTForSemanticSegmentation",
           "MobileViTModel",
           "MobileViTPreTrainedModel",
       ]

try:
       if not is_tf_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       __UpperCamelCase       :       Optional[int]						       =				[
           "TF_MOBILEVIT_PRETRAINED_MODEL_ARCHIVE_LIST",
           "TFMobileViTForImageClassification",
           "TFMobileViTForSemanticSegmentation",
           "TFMobileViTModel",
           "TFMobileViTPreTrainedModel",
       ]

if TYPE_CHECKING:
       from .configuration_mobilevit import MOBILEVIT_PRETRAINED_CONFIG_ARCHIVE_MAP, MobileViTConfig, MobileViTOnnxConfig

       try:
              if not is_vision_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .feature_extraction_mobilevit import MobileViTFeatureExtractor
              from .image_processing_mobilevit import MobileViTImageProcessor

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_mobilevit import (
                  MOBILEVIT_PRETRAINED_MODEL_ARCHIVE_LIST,
                  MobileViTForImageClassification,
                  MobileViTForSemanticSegmentation,
                  MobileViTModel,
                  MobileViTPreTrainedModel,
              )

       try:
              if not is_tf_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_tf_mobilevit import (
                  TF_MOBILEVIT_PRETRAINED_MODEL_ARCHIVE_LIST,
                  TFMobileViTForImageClassification,
                  TFMobileViTForSemanticSegmentation,
                  TFMobileViTModel,
                  TFMobileViTPreTrainedModel,
              )


else:
       import sys

       __UpperCamelCase       :       str						       =				_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)


