






'''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(lowerCamelCase			)
class        __SCREAMING_SNAKE_CASE (     lowerCamelCase			):




 def __init__( self		:							str   , *__lowercase		:							Tuple   , **__lowercase		:							Optional[Any] )		->  List[str]:
       super().__init__(*__lowercase   , **__lowercase )
       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        __magic_name__		( self		:							Tuple   , __lowercase		:							Tuple=None )		->  Optional[Any]:
       SCREAMING_SNAKE_CASE__       :			str													={}
       if top_k is not None:
             SCREAMING_SNAKE_CASE__       :			Optional[int]													=top_k
       return {}, {}, postprocess_params




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




 def        __magic_name__		( self		:							Optional[int]   , __lowercase		:							Any )		->  List[str]:
       SCREAMING_SNAKE_CASE__       :			Dict													=load_image(__lowercase )
       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=self.image_processor(images=__lowercase   , return_tensors=self.framework )
       return model_inputs




 def        __magic_name__		( self		:							Optional[Any]   , __lowercase		:							Tuple )		->  str:
       SCREAMING_SNAKE_CASE__       :			Dict													=self.model(**__lowercase )
       return model_outputs




 def        __magic_name__		( self		:							Optional[int]   , __lowercase		:							Optional[Any]   , __lowercase		:							List[str]=5 )		->  List[str]:
       if top_k > self.model.config.num_labels:
             SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=self.model.config.num_labels

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

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







'''simple docstring'''
from typing import TYPE_CHECKING

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


a_					=	{
    'configuration_lxmert': ['LXMERT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'LxmertConfig'],
    'tokenization_lxmert': ['LxmertTokenizer'],
}

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

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  a_					=	[
      'LxmertEncoder',
      'LxmertForPreTraining',
      'LxmertForQuestionAnswering',
      'LxmertModel',
      'LxmertPreTrainedModel',
      'LxmertVisualFeatureEncoder',
      'LxmertXLayer',
  ]

try:
  if not is_tf_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  a_					=	[
      'TF_LXMERT_PRETRAINED_MODEL_ARCHIVE_LIST',
      'TFLxmertForPreTraining',
      'TFLxmertMainLayer',
      'TFLxmertModel',
      'TFLxmertPreTrainedModel',
      'TFLxmertVisualFeatureEncoder',
  ]


if TYPE_CHECKING:
  from .configuration_lxmert import LXMERT_PRETRAINED_CONFIG_ARCHIVE_MAP, LxmertConfig
  from .tokenization_lxmert import LxmertTokenizer

  try:
    if not is_tokenizers_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .tokenization_lxmert_fast import LxmertTokenizerFast

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_lxmert import (
        LxmertEncoder,
        LxmertForPreTraining,
        LxmertForQuestionAnswering,
        LxmertModel,
        LxmertPreTrainedModel,
        LxmertVisualFeatureEncoder,
        LxmertXLayer,
    )

  try:
    if not is_tf_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_tf_lxmert import (
        TF_LXMERT_PRETRAINED_MODEL_ARCHIVE_LIST,
        TFLxmertForPreTraining,
        TFLxmertMainLayer,
        TFLxmertModel,
        TFLxmertPreTrainedModel,
        TFLxmertVisualFeatureEncoder,
    )

else:
  import sys

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