





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

lowercase_		:				int				=						logging.get_logger(__name__)


@add_end_docstrings(__lowercase     )
class 			lowercase				(							__lowercase     ):



						"""simple docstring"""

						def __init__(    self			:		str ,				*lowerCamelCase_			:		Tuple ,				**lowerCamelCase_			:		Dict					):





										'''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			:		List[Any] ,				lowerCamelCase_			:		Any=None					):





										'''simple docstring'''







										_snake_case :			Dict  						=   {}
										if top_k is not None:
														_snake_case :			Optional[int]  						=   top_k
										return {}, {}, postprocess_params







						def __call__(    self			:		Tuple ,				lowerCamelCase_			:		Union[str, List[str], "Image.Image", List["Image.Image"]] ,				**lowerCamelCase_			:		int					):





										'''simple docstring'''







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







						def 		__UpperCAmelCase       (    self			:		Any ,				lowerCamelCase_			:		Optional[int]					):





										'''simple docstring'''







										_snake_case :			int  						=   load_image(lowerCamelCase_					)
										_snake_case :			str  						=   self.image_processor(images=lowerCamelCase_ ,				return_tensors=self.framework					)
										return model_inputs







						def 		__UpperCAmelCase       (    self			:		int ,				lowerCamelCase_			:		Any					):





										'''simple docstring'''







										_snake_case :			Any  						=   self.model(**lowerCamelCase_					)
										return model_outputs







						def 		__UpperCAmelCase       (    self			:		List[Any] ,				lowerCamelCase_			:		str ,				lowerCamelCase_			:		List[Any]=5					):





										'''simple docstring'''







										if top_k > self.model.config.num_labels:
														_snake_case :			Dict  						=   self.model.config.num_labels

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

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













from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available, is_torch_available


lowercase_		:				Optional[Any]				=						{
    '''configuration_roc_bert''': ['''ROC_BERT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''RoCBertConfig'''],
    '''tokenization_roc_bert''': ['''RoCBertTokenizer'''],
}

try:
		if not is_tokenizers_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		pass

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		lowercase_		:				Tuple				=						[
		    '''ROC_BERT_PRETRAINED_MODEL_ARCHIVE_LIST''',
		    '''RoCBertForCausalLM''',
		    '''RoCBertForMaskedLM''',
		    '''RoCBertForMultipleChoice''',
		    '''RoCBertForPreTraining''',
		    '''RoCBertForQuestionAnswering''',
		    '''RoCBertForSequenceClassification''',
		    '''RoCBertForTokenClassification''',
		    '''RoCBertLayer''',
		    '''RoCBertModel''',
		    '''RoCBertPreTrainedModel''',
		    '''load_tf_weights_in_roc_bert''',
		]

if TYPE_CHECKING:
		from .configuration_roc_bert import ROC_BERT_PRETRAINED_CONFIG_ARCHIVE_MAP, RoCBertConfig
		from .tokenization_roc_bert import RoCBertTokenizer

		try:
				if not is_tokenizers_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				raise OptionalDependencyNotAvailable()

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_roc_bert import (
				    ROC_BERT_PRETRAINED_MODEL_ARCHIVE_LIST,
				    RoCBertForCausalLM,
				    RoCBertForMaskedLM,
				    RoCBertForMultipleChoice,
				    RoCBertForPreTraining,
				    RoCBertForQuestionAnswering,
				    RoCBertForSequenceClassification,
				    RoCBertForTokenClassification,
				    RoCBertLayer,
				    RoCBertModel,
				    RoCBertPreTrainedModel,
				    load_tf_weights_in_roc_bert,
				)


else:
		import sys

		lowercase_		:				Tuple				=						_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)






