






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

__A    	=   logging.get_logger(__name__)




@add_end_docstrings(UpperCamelCase_							)
class a_    (    UpperCamelCase_							):







   def __init__(self					,   *__a					,   **__a)			->      Optional[Any]:
      """simple docstring"""






      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)			->      Union[str, Any]:
      """simple docstring"""






      __snake_case				:      Optional[Any]     							= {}
      if top_k is not None:
         __snake_case				:      str     							= top_k
      return {}, {}, postprocess_params







   def __call__(self					,   __a					,   **__a)			->      str:
      """simple docstring"""






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







   def     SCREAMING_SNAKE_CASE__					(self					,   __a)			->      Union[str, Any]:
      """simple docstring"""






      __snake_case				:      Tuple     							= load_image(__a)
      __snake_case				:      Optional[int]     							= self.image_processor(images=__a					,   return_tensors=self.framework)
      return model_inputs







   def     SCREAMING_SNAKE_CASE__					(self					,   __a)			->      Optional[int]:
      """simple docstring"""






      __snake_case				:      Union[str, Any]     							= self.model(**__a)
      return model_outputs







   def     SCREAMING_SNAKE_CASE__					(self					,   __a					,   __a=5)			->      str:
      """simple docstring"""






      if top_k > self.model.config.num_labels:
         __snake_case				:      Optional[int]     							= self.model.config.num_labels

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

      __snake_case				:      Any     							= scores.tolist()
      __snake_case				:      int     							= 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_tokenizers_available,
    is_torch_available,
)


__A    	=   {
    '''configuration_distilbert''': [
        '''DISTILBERT_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''DistilBertConfig''',
        '''DistilBertOnnxConfig''',
    ],
    '''tokenization_distilbert''': ['''DistilBertTokenizer'''],
}

try:
      if not is_tokenizers_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      __A    	=   ['''DistilBertTokenizerFast''']

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      __A    	=   [
          '''DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST''',
          '''DistilBertForMaskedLM''',
          '''DistilBertForMultipleChoice''',
          '''DistilBertForQuestionAnswering''',
          '''DistilBertForSequenceClassification''',
          '''DistilBertForTokenClassification''',
          '''DistilBertModel''',
          '''DistilBertPreTrainedModel''',
      ]

try:
      if not is_tf_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      __A    	=   [
          '''TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST''',
          '''TFDistilBertForMaskedLM''',
          '''TFDistilBertForMultipleChoice''',
          '''TFDistilBertForQuestionAnswering''',
          '''TFDistilBertForSequenceClassification''',
          '''TFDistilBertForTokenClassification''',
          '''TFDistilBertMainLayer''',
          '''TFDistilBertModel''',
          '''TFDistilBertPreTrainedModel''',
      ]

try:
      if not is_flax_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      __A    	=   [
          '''FlaxDistilBertForMaskedLM''',
          '''FlaxDistilBertForMultipleChoice''',
          '''FlaxDistilBertForQuestionAnswering''',
          '''FlaxDistilBertForSequenceClassification''',
          '''FlaxDistilBertForTokenClassification''',
          '''FlaxDistilBertModel''',
          '''FlaxDistilBertPreTrainedModel''',
      ]


if TYPE_CHECKING:
      from .configuration_distilbert import (
          DISTILBERT_PRETRAINED_CONFIG_ARCHIVE_MAP,
          DistilBertConfig,
          DistilBertOnnxConfig,
      )
      from .tokenization_distilbert import DistilBertTokenizer

      try:
            if not is_tokenizers_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .tokenization_distilbert_fast import DistilBertTokenizerFast

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_distilbert import (
                DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
                DistilBertForMaskedLM,
                DistilBertForMultipleChoice,
                DistilBertForQuestionAnswering,
                DistilBertForSequenceClassification,
                DistilBertForTokenClassification,
                DistilBertModel,
                DistilBertPreTrainedModel,
            )

      try:
            if not is_tf_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_tf_distilbert import (
                TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
                TFDistilBertForMaskedLM,
                TFDistilBertForMultipleChoice,
                TFDistilBertForQuestionAnswering,
                TFDistilBertForSequenceClassification,
                TFDistilBertForTokenClassification,
                TFDistilBertMainLayer,
                TFDistilBertModel,
                TFDistilBertPreTrainedModel,
            )

      try:
            if not is_flax_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_flax_distilbert import (
                FlaxDistilBertForMaskedLM,
                FlaxDistilBertForMultipleChoice,
                FlaxDistilBertForQuestionAnswering,
                FlaxDistilBertForSequenceClassification,
                FlaxDistilBertForTokenClassification,
                FlaxDistilBertModel,
                FlaxDistilBertPreTrainedModel,
            )

else:
      import sys

      __A    	=   _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)