




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






@add_end_docstrings(UpperCAmelCase__				)
class     __magic_name__							(       UpperCAmelCase__				):






				'''simple docstring'''





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





							"""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    _lowerCAmelCase				(       self		, _a=None ):





							"""simple docstring"""
							lowerCamelCase			      =					{}
							if top_k is not None:
										lowerCamelCase			      =					top_k
							return {}, {}, postprocess_params





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





							"""simple docstring"""
							return super().__call__(_a		, **_a )





				def    _lowerCAmelCase				(       self		, _a ):





							"""simple docstring"""
							lowerCamelCase			      =					load_image(_a )
							lowerCamelCase			      =					self.image_processor(images=_a		, return_tensors=self.framework )
							return model_inputs





				def    _lowerCAmelCase				(       self		, _a ):





							"""simple docstring"""
							lowerCamelCase			      =					self.model(**_a )
							return model_outputs





				def    _lowerCAmelCase				(       self		, _a		, _a=5 ):





							"""simple docstring"""
							if top_k > self.model.config.num_labels:
										lowerCamelCase			      =					self.model.config.num_labels

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

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









"""simple docstring"""




def     a__ (				snake_case__       , snake_case__ = False				)						->					str:

			if not isinstance(snake_case__       , snake_case__				):
						lowerCamelCase			      =					F'Expected string as input, found {type(snake_case__				)}'
						raise ValueError(snake_case__				)
			if not isinstance(snake_case__       , snake_case__				):
						lowerCamelCase			      =					F'Expected boolean as use_pascal parameter, found {type(snake_case__				)}'
						raise ValueError(snake_case__				)

			lowerCamelCase			      =					input_str.split("""_"""				)

			lowerCamelCase			      =					0 if use_pascal else 1

			lowerCamelCase			      =					words[start_index:]

			lowerCamelCase			      =					[word[0].upper() + word[1:] for word in words_to_capitalize]

			lowerCamelCase			      =					"""""" if use_pascal else words[0]

			return "".join([initial_word, *capitalized_words]				)


if __name__ == "__main__":
					from doctest import testmod

					testmod()



