

'''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					:			int       =	logging.get_logger(__name__)







@add_end_docstrings(a   )
class 		lowerCAmelCase__  ( a   ):



 """simple docstring"""



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


      """simple docstring"""




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


      """simple docstring"""




      __SCREAMING_SNAKE_CASE      = {}
      if top_k is not None:
           __SCREAMING_SNAKE_CASE      = top_k
      return {}, {}, postprocess_params
 def __call__(						self   :			Tuple   ,				__SCREAMING_SNAKE_CASE   :			Union[str, List[str], "Image.Image", List["Image.Image"]]   ,				**__SCREAMING_SNAKE_CASE   :			Optional[int]     )    ->					Dict:


      """simple docstring"""




      return super().__call__(__SCREAMING_SNAKE_CASE   ,				**__SCREAMING_SNAKE_CASE     )
 def  UpperCAmelCase__						(						self   :			str   ,				__SCREAMING_SNAKE_CASE   :			str     )    ->					Optional[int]:


      """simple docstring"""




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


      """simple docstring"""




      __SCREAMING_SNAKE_CASE      = self.model(**__SCREAMING_SNAKE_CASE     )
      return model_outputs


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


      """simple docstring"""




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

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

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









'''simple docstring'''



import importlib
import inspect
import os
import re


# All paths are set with the intent you should run this script from the root of the repo with the command
# python utils/check_config_docstrings.py
UpperCAmelCase					:			Any       =	'src/transformers'


# This is to make sure the transformers module imported is the one in the repo.
UpperCAmelCase					:			Optional[int]       =	importlib.util.spec_from_file_location(
    'transformers',
    os.path.join(PATH_TO_TRANSFORMERS, '__init__.py'),
    submodule_search_locations=[PATH_TO_TRANSFORMERS],
)
UpperCAmelCase					:			Dict       =	spec.loader.load_module()

UpperCAmelCase					:			Dict       =	transformers.models.auto.configuration_auto.CONFIG_MAPPING

# Regex pattern used to find the checkpoint mentioned in the docstring of `config_class`.
# For example, `[bert-base-uncased](https://huggingface.co/bert-base-uncased)`
UpperCAmelCase					:			Dict       =	re.compile('\[(.+?)\]\((https://huggingface\.co/.+?)\)')


UpperCAmelCase					:			Any       =	{
    'CLIPConfigMixin',
    'DecisionTransformerConfigMixin',
    'EncoderDecoderConfigMixin',
    'RagConfigMixin',
    'SpeechEncoderDecoderConfigMixin',
    'VisionEncoderDecoderConfigMixin',
    'VisionTextDualEncoderConfigMixin',
}







def   a__			(    ):




     """simple docstring"""


     __SCREAMING_SNAKE_CASE      = []

     for config_class in list(CONFIG_MAPPING.values()		):
          __SCREAMING_SNAKE_CASE      = False

          # source code of `config_class`
          __SCREAMING_SNAKE_CASE      = inspect.getsource(a__		)
          __SCREAMING_SNAKE_CASE      = _re_checkpoint.findall(a__		)

          for checkpoint in checkpoints:
               # Each `checkpoint` is a tuple of a checkpoint name and a checkpoint link.
               # For example, `('bert-base-uncased', 'https://huggingface.co/bert-base-uncased')`
               __SCREAMING_SNAKE_CASE  ,     __SCREAMING_SNAKE_CASE      = checkpoint

               # verify the checkpoint name corresponds to the checkpoint link
               __SCREAMING_SNAKE_CASE      = F'https://huggingface.co/{ckpt_name}'
               if ckpt_link == ckpt_link_from_name:
                    __SCREAMING_SNAKE_CASE      = True
                    break

          __SCREAMING_SNAKE_CASE      = config_class.__name__
          if not checkpoint_found and name not in CONFIG_CLASSES_TO_IGNORE_FOR_DOCSTRING_CHECKPOINT_CHECK:
               configs_without_checkpoint.append(a__		)

     if len(a__		) > 0:
          __SCREAMING_SNAKE_CASE      = """\n""".join(sorted(a__		)		)
          raise ValueError(F'The following configurations don\'t contain any valid checkpoint:\n{message}'		)


if __name__ == "__main__":
  check_config_docstrings_have_checkpoints()






