





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_			=      logging.get_logger(__name__)






@add_end_docstrings(SCREAMING_SNAKE_CASE__					)
class 		__snake_case (		SCREAMING_SNAKE_CASE__					):





 """simple docstring"""


 def __init__(   self ,						*__lowerCamelCase ,						**__lowerCamelCase  ):



     '''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 ,						__lowerCamelCase=None  ):



     '''simple docstring'''




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

 def __call__(   self ,						__lowerCamelCase ,						**__lowerCamelCase  ):



     '''simple docstring'''




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

 def  UpperCamelCase__(   self ,						__lowerCamelCase  ):



     '''simple docstring'''




     __A   :						Any									=					load_image(__lowerCamelCase  )
     __A   :						Tuple									=					self.image_processor(images=__lowerCamelCase ,						return_tensors=self.framework  )
     return model_inputs

 def  UpperCamelCase__(   self ,						__lowerCamelCase  ):



     '''simple docstring'''




     __A   :						Any									=					self.model(**__lowerCamelCase  )
     return model_outputs







 def  UpperCamelCase__(   self ,						__lowerCamelCase ,						__lowerCamelCase=5  ):



     '''simple docstring'''




     if top_k > self.model.config.num_labels:
         __A   :						List[Any]									=					self.model.config.num_labels

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

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











"""simple docstring"""



from typing import TYPE_CHECKING

from ..utils import _LazyModule


a_			=      {
    """config""": [
        """EXTERNAL_DATA_FORMAT_SIZE_LIMIT""",
        """OnnxConfig""",
        """OnnxConfigWithPast""",
        """OnnxSeq2SeqConfigWithPast""",
        """PatchingSpec""",
    ],
    """convert""": ["""export""", """validate_model_outputs"""],
    """features""": ["""FeaturesManager"""],
    """utils""": ["""ParameterFormat""", """compute_serialized_parameters_size"""],
}


if TYPE_CHECKING:
       from .config import (
           EXTERNAL_DATA_FORMAT_SIZE_LIMIT,
           OnnxConfig,
           OnnxConfigWithPast,
           OnnxSeqaSeqConfigWithPast,
           PatchingSpec,
       )
       from .convert import export, validate_model_outputs
       from .features import FeaturesManager
       from .utils import ParameterFormat, compute_serialized_parameters_size

else:
       import sys

       a_			=      _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)




