





"""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

lowerCamelCase__						= logging.get_logger(__name__)



@add_end_docstrings(_UpperCamelCase )
class   __SCREAMING_SNAKE_CASE     (    _UpperCamelCase ):







  '''simple docstring'''


  def __init__(		self :							Dict       , *__a :							Tuple       , **__a :							Any						)		->					Union[str, Any]:
        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 :							Optional[int]       , __a :							Any=None						)		->					Optional[int]:
        _UpperCamelCase   :						str    =							{}
        if top_k is not None:
              _UpperCamelCase   :						int    =							top_k
        return {}, {}, postprocess_params

  def __call__(		self :							List[str]       , __a :							Union[str, List[str], "Image.Image", List["Image.Image"]]       , **__a :							Dict						)		->					List[str]:
        return super().__call__(__a       , **__a						)

  def  __SCREAMING_SNAKE_CASE					(		self :							List[str]       , __a :							Union[str, Any]						)		->					List[Any]:
        _UpperCamelCase   :						Tuple    =							load_image(__a						)
        _UpperCamelCase   :						Union[str, Any]    =							self.image_processor(images=__a       , return_tensors=self.framework						)
        return model_inputs

  def  __SCREAMING_SNAKE_CASE					(		self :							Union[str, Any]       , __a :							List[Any]						)		->					List[Any]:
        _UpperCamelCase   :						int    =							self.model(**__a						)
        return model_outputs


  def  __SCREAMING_SNAKE_CASE					(		self :							List[Any]       , __a :							Dict       , __a :							str=5						)		->					Optional[int]:
        if top_k > self.model.config.num_labels:
              _UpperCamelCase   :						int    =							self.model.config.num_labels

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

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







"""simple docstring"""


from typing import TYPE_CHECKING

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


lowerCamelCase__						= {
    "configuration_resnet": ["RESNET_PRETRAINED_CONFIG_ARCHIVE_MAP", "ResNetConfig", "ResNetOnnxConfig"]
}

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  lowerCamelCase__						= [
      "RESNET_PRETRAINED_MODEL_ARCHIVE_LIST",
      "ResNetForImageClassification",
      "ResNetModel",
      "ResNetPreTrainedModel",
      "ResNetBackbone",
  ]

try:
  if not is_tf_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  lowerCamelCase__						= [
      "TF_RESNET_PRETRAINED_MODEL_ARCHIVE_LIST",
      "TFResNetForImageClassification",
      "TFResNetModel",
      "TFResNetPreTrainedModel",
  ]

try:
  if not is_flax_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  lowerCamelCase__						= [
      "FlaxResNetForImageClassification",
      "FlaxResNetModel",
      "FlaxResNetPreTrainedModel",
  ]

if TYPE_CHECKING:
  from .configuration_resnet import RESNET_PRETRAINED_CONFIG_ARCHIVE_MAP, ResNetConfig, ResNetOnnxConfig

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_resnet import (
        RESNET_PRETRAINED_MODEL_ARCHIVE_LIST,
        ResNetBackbone,
        ResNetForImageClassification,
        ResNetModel,
        ResNetPreTrainedModel,
    )

  try:
    if not is_tf_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_tf_resnet import (
        TF_RESNET_PRETRAINED_MODEL_ARCHIVE_LIST,
        TFResNetForImageClassification,
        TFResNetModel,
        TFResNetPreTrainedModel,
    )

  try:
    if not is_flax_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_flax_resnet import FlaxResNetForImageClassification, FlaxResNetModel, FlaxResNetPreTrainedModel


else:
  import sys

  lowerCamelCase__						= _LazyModule(__name__, globals()["__file__"], _import_structure)
