"""simple docstring"""



from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


SCREAMING_SNAKE_CASE__:List[Any]			=	logging.get_logger(__name__)

SCREAMING_SNAKE_CASE__:List[str]			=	{
    """google/mobilenet_v1_1.0_224""": """https://huggingface.co/google/mobilenet_v1_1.0_224/resolve/main/config.json""",
    """google/mobilenet_v1_0.75_192""": """https://huggingface.co/google/mobilenet_v1_0.75_192/resolve/main/config.json""",
    # See all MobileNetV1 models at https://huggingface.co/models?filter=mobilenet_v1
}






class 				snake_case__     (   snake_case_   ):
 _snake_case   :			Dict           =		"""mobilenet_v1"""


 def __init__(				self  ,						lowerCamelCase=3  ,						lowerCamelCase=224  ,						lowerCamelCase=1.0  ,						lowerCamelCase=8  ,						lowerCamelCase="relu6"  ,						lowerCamelCase=True  ,						lowerCamelCase=0.999  ,						lowerCamelCase=0.02  ,						lowerCamelCase=0.001  ,						**lowerCamelCase  ,						):
        super().__init__(**lowerCamelCase		)

        if depth_multiplier <= 0:
               raise ValueError("depth_multiplier must be greater than zero."		)

        __a     				=  num_channels
        __a     				=  image_size
        __a     				=  depth_multiplier
        __a     				=  min_depth
        __a     				=  hidden_act
        __a     				=  tf_padding
        __a     				=  classifier_dropout_prob
        __a     				=  initializer_range
        __a     				=  layer_norm_eps






class 				snake_case__     (   snake_case_   ):
 _snake_case   :			int           =		version.parse("""1.11"""   )


 @property
 def 		a__ (				self		):
        return OrderedDict([("pixel_values", {0: "batch"})]		)


 @property
 def 		a__ (				self		):
        if self.task == "image-classification":
               return OrderedDict([("logits", {0: "batch"})]		)
        else:
               return OrderedDict([("last_hidden_state", {0: "batch"}), ("pooler_output", {0: "batch"})]		)






 @property
 def 		a__ (				self		):
        return 1E-4

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

SCREAMING_SNAKE_CASE__:Optional[Any]			=	logging.get_logger(__name__)






@add_end_docstrings(snake_case_   )
class 				snake_case__     (   snake_case_   ):


 def __init__(				self  ,						*lowerCamelCase  ,						**lowerCamelCase		):
        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 		a__ (				self  ,						lowerCamelCase=None		):
        __a     				=  {}
        if top_k is not None:
               __a     				=  top_k
        return {}, {}, postprocess_params


 def __call__(				self  ,						lowerCamelCase  ,						**lowerCamelCase		):
        return super().__call__(lowerCamelCase  ,						**lowerCamelCase		)


 def 		a__ (				self  ,						lowerCamelCase		):
        __a     				=  load_image(lowerCamelCase		)
        __a     				=  self.image_processor(images=lowerCamelCase  ,						return_tensors=self.framework		)
        return model_inputs


 def 		a__ (				self  ,						lowerCamelCase		):
        __a     				=  self.model(**lowerCamelCase		)
        return model_outputs






 def 		a__ (				self  ,						lowerCamelCase  ,						lowerCamelCase=5		):
        if top_k > self.model.config.num_labels:
               __a     				=  self.model.config.num_labels

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

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