






"""simple docstring"""






from typing import TYPE_CHECKING

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


UpperCAmelCase_     :				Any         =				{
    """configuration_mobilebert""": [
        """MOBILEBERT_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """MobileBertConfig""",
        """MobileBertOnnxConfig""",
    ],
    """tokenization_mobilebert""": ["""MobileBertTokenizer"""],
}

try:
  if not is_tokenizers_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  UpperCAmelCase_     :				Any         =				["""MobileBertTokenizerFast"""]

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  UpperCAmelCase_     :				List[str]         =				[
      """MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST""",
      """MobileBertForMaskedLM""",
      """MobileBertForMultipleChoice""",
      """MobileBertForNextSentencePrediction""",
      """MobileBertForPreTraining""",
      """MobileBertForQuestionAnswering""",
      """MobileBertForSequenceClassification""",
      """MobileBertForTokenClassification""",
      """MobileBertLayer""",
      """MobileBertModel""",
      """MobileBertPreTrainedModel""",
      """load_tf_weights_in_mobilebert""",
  ]

try:
  if not is_tf_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  UpperCAmelCase_     :				List[str]         =				[
      """TF_MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST""",
      """TFMobileBertForMaskedLM""",
      """TFMobileBertForMultipleChoice""",
      """TFMobileBertForNextSentencePrediction""",
      """TFMobileBertForPreTraining""",
      """TFMobileBertForQuestionAnswering""",
      """TFMobileBertForSequenceClassification""",
      """TFMobileBertForTokenClassification""",
      """TFMobileBertMainLayer""",
      """TFMobileBertModel""",
      """TFMobileBertPreTrainedModel""",
  ]


if TYPE_CHECKING:
  from .configuration_mobilebert import (
      MOBILEBERT_PRETRAINED_CONFIG_ARCHIVE_MAP,
      MobileBertConfig,
      MobileBertOnnxConfig,
  )
  from .tokenization_mobilebert import MobileBertTokenizer

  try:
    if not is_tokenizers_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .tokenization_mobilebert_fast import MobileBertTokenizerFast

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_mobilebert import (
        MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
        MobileBertForMaskedLM,
        MobileBertForMultipleChoice,
        MobileBertForNextSentencePrediction,
        MobileBertForPreTraining,
        MobileBertForQuestionAnswering,
        MobileBertForSequenceClassification,
        MobileBertForTokenClassification,
        MobileBertLayer,
        MobileBertModel,
        MobileBertPreTrainedModel,
        load_tf_weights_in_mobilebert,
    )

  try:
    if not is_tf_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_tf_mobilebert import (
        TF_MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
        TFMobileBertForMaskedLM,
        TFMobileBertForMultipleChoice,
        TFMobileBertForNextSentencePrediction,
        TFMobileBertForPreTraining,
        TFMobileBertForQuestionAnswering,
        TFMobileBertForSequenceClassification,
        TFMobileBertForTokenClassification,
        TFMobileBertMainLayer,
        TFMobileBertModel,
        TFMobileBertPreTrainedModel,
    )

else:
  import sys

  UpperCAmelCase_     :				int         =				_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)










"""simple docstring"""






from typing import List, Union

import numpy as np

from ..utils import add_end_docstrings, 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_torch_available():
  import torch

  from ..models.auto.modeling_auto import MODEL_FOR_DEPTH_ESTIMATION_MAPPING

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




@add_end_docstrings(UpperCAmelCase__				)
class 							lowerCAmelCase__       (    UpperCAmelCase__				):






      '''simple docstring'''

      def __init__(		self  :						Union[str, Any]		,			*lowercase_  :						Any		,			**lowercase_  :						Any):




          '''simple docstring'''


          super().__init__(*lowercase_		,			**lowercase_)
          requires_backends(self		,			'''vision''')
          self.check_model_type(lowercase_)
      def __call__(		self  :						int		,			lowercase_  :						Union[str, List[str], "Image.Image", List["Image.Image"]]		,			**lowercase_  :						Optional[Any]):




          '''simple docstring'''


          return super().__call__(lowercase_		,			**lowercase_)
      def _SCREAMING_SNAKE_CASE				(		self  :						List[str]		,			**lowercase_  :						List[str]):




          '''simple docstring'''


          return {}, {}, {}
      def _SCREAMING_SNAKE_CASE				(		self  :						List[Any]		,			lowercase_  :						Dict):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_   :						Dict							=	load_image(lowercase_)
          SCREAMING_SNAKE_CASE_   :						Optional[Any]							=	image.size
          SCREAMING_SNAKE_CASE_   :						int							=	self.image_processor(images=lowercase_		,			return_tensors=self.framework)
          return model_inputs
      def _SCREAMING_SNAKE_CASE				(		self  :						Dict		,			lowercase_  :						int):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_   :						Any							=	self.model(**lowercase_)
          return model_outputs



      def _SCREAMING_SNAKE_CASE				(		self  :						Any		,			lowercase_  :						int):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_   :						Union[str, Any]							=	model_outputs.predicted_depth
          SCREAMING_SNAKE_CASE_   :						List[Any]							=	torch.nn.functional.interpolate(
              predicted_depth.unsqueeze(1)		,			size=self.image_size[::-1]		,			mode='''bicubic'''		,			align_corners=lowercase_)
          SCREAMING_SNAKE_CASE_   :						Any							=	prediction.squeeze().cpu().numpy()
          SCREAMING_SNAKE_CASE_   :						List[str]							=	(output * 255 / np.max(lowercase_)).astype('''uint8''')
          SCREAMING_SNAKE_CASE_   :						List[Any]							=	Image.fromarray(lowercase_)
          SCREAMING_SNAKE_CASE_   :						Optional[int]							=	{}
          SCREAMING_SNAKE_CASE_   :						Union[str, Any]							=	predicted_depth
          SCREAMING_SNAKE_CASE_   :						Optional[int]							=	depth
          return output_dict


