





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


__lowerCamelCase						: Union[str, Any]		=   logging.get_logger(__name__)

__lowerCamelCase						: int		=   {
    'google/mobilenet_v2_1.4_224': 'https://huggingface.co/google/mobilenet_v2_1.4_224/resolve/main/config.json',
    'google/mobilenet_v2_1.0_224': 'https://huggingface.co/google/mobilenet_v2_1.0_224/resolve/main/config.json',
    'google/mobilenet_v2_0.75_160': 'https://huggingface.co/google/mobilenet_v2_0.75_160/resolve/main/config.json',
    'google/mobilenet_v2_0.35_96': 'https://huggingface.co/google/mobilenet_v2_0.35_96/resolve/main/config.json',
    # See all MobileNetV2 models at https://huggingface.co/models?filter=mobilenet_v2
}







class 		UpperCAmelCase   (				lowercase_):


  """simple docstring"""







  lowerCAmelCase_					=				"""mobilenet_v2"""


  def __init__(				self    :					Tuple							,	UpperCamelCase__    :					Union[str, Any]=3							,	UpperCamelCase__    :					Dict=224							,	UpperCamelCase__    :					str=1.0							,	UpperCamelCase__    :					List[Any]=8							,	UpperCamelCase__    :					Union[str, Any]=8							,	UpperCamelCase__    :					str=6							,	UpperCamelCase__    :					str=32							,	UpperCamelCase__    :					str=True							,	UpperCamelCase__    :					int=True							,	UpperCamelCase__    :					str="relu6"							,	UpperCamelCase__    :					Tuple=True							,	UpperCamelCase__    :					List[str]=0.8							,	UpperCamelCase__    :					List[str]=0.02							,	UpperCamelCase__    :					str=0.001							,	UpperCamelCase__    :					Dict=255							,	**UpperCamelCase__    :					Tuple							,	)     ->						List[Any]:
    super().__init__(**UpperCamelCase__  )

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

    _UpperCamelCase       			=num_channels
    _UpperCamelCase       			=image_size
    _UpperCamelCase       			=depth_multiplier
    _UpperCamelCase       			=depth_divisible_by
    _UpperCamelCase       			=min_depth
    _UpperCamelCase       			=expand_ratio
    _UpperCamelCase       			=output_stride
    _UpperCamelCase       			=first_layer_is_expansion
    _UpperCamelCase       			=finegrained_output
    _UpperCamelCase       			=hidden_act
    _UpperCamelCase       			=tf_padding
    _UpperCamelCase       			=classifier_dropout_prob
    _UpperCamelCase       			=initializer_range
    _UpperCamelCase       			=layer_norm_eps
    _UpperCamelCase       			=semantic_loss_ignore_index







class 		UpperCAmelCase   (				lowercase_):


  """simple docstring"""







  lowerCAmelCase_					=				version.parse("""1.11""")


  @property
  def   UpperCamelCase__      (				self    :					str  )     ->						Mapping[str, Mapping[int, str]]:
    return OrderedDict([('''pixel_values''', {0: '''batch'''})]  )


  @property
  def   UpperCamelCase__      (				self    :					Optional[Any]  )     ->						Mapping[str, Mapping[int, str]]:
    if self.task == "image-classification":
      return OrderedDict([('''logits''', {0: '''batch'''})]  )
    else:
      return OrderedDict([('''last_hidden_state''', {0: '''batch'''}), ('''pooler_output''', {0: '''batch'''})]  )




  @property
  def   UpperCamelCase__      (				self    :					List[Any]  )     ->						float:
    return 1E-4













'''simple docstring'''






import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
      import torch

if is_vision_available():
      from PIL import Image

      from transformers import PoolFormerImageProcessor







class 		UpperCAmelCase   (				unittest.TestCase):


  """simple docstring"""







  def __init__(				self    :					Optional[int]							,	UpperCamelCase__    :					Union[str, Any]							,	UpperCamelCase__    :					Any=7							,	UpperCamelCase__    :					List[Any]=3							,	UpperCamelCase__    :					Dict=30							,	UpperCamelCase__    :					Union[str, Any]=400							,	UpperCamelCase__    :					List[Any]=True							,	UpperCamelCase__    :					List[str]=None							,	UpperCamelCase__    :					List[str]=0.9							,	UpperCamelCase__    :					Any=None							,	UpperCamelCase__    :					Any=True							,	UpperCamelCase__    :					Optional[Any]=[0.5, 0.5, 0.5]							,	UpperCamelCase__    :					List[str]=[0.5, 0.5, 0.5]							,	)     ->						Dict:
    _UpperCamelCase       			=size if size is not None else {'''shortest_edge''': 30}
    _UpperCamelCase       			=crop_size if crop_size is not None else {'''height''': 30, '''width''': 30}
    _UpperCamelCase       			=parent
    _UpperCamelCase       			=batch_size
    _UpperCamelCase       			=num_channels
    _UpperCamelCase       			=min_resolution
    _UpperCamelCase       			=max_resolution
    _UpperCamelCase       			=do_resize_and_center_crop
    _UpperCamelCase       			=size
    _UpperCamelCase       			=crop_pct
    _UpperCamelCase       			=crop_size
    _UpperCamelCase       			=do_normalize
    _UpperCamelCase       			=image_mean
    _UpperCamelCase       			=image_std




  def   UpperCamelCase__      (				self    :					str  )     ->						Union[str, Any]:
    return {
        "size": self.size,
        "do_resize_and_center_crop": self.do_resize_and_center_crop,
        "crop_pct": self.crop_pct,
        "crop_size": self.crop_size,
        "do_normalize": self.do_normalize,
        "image_mean": self.image_mean,
        "image_std": self.image_std,
    }







@require_torch
@require_vision
class 		UpperCAmelCase   (				lowercase_   ,     unittest.TestCase):


  """simple docstring"""







  lowerCAmelCase_					=				PoolFormerImageProcessor if is_vision_available() else None


  def   UpperCamelCase__      (				self    :					Optional[int]  )     ->						int:
    _UpperCamelCase       			=PoolFormerImageProcessingTester(self  )


  @property
  def   UpperCamelCase__      (				self    :					Tuple  )     ->						Optional[int]:
    return self.image_processor_tester.prepare_image_processor_dict()


  def   UpperCamelCase__      (				self    :					Optional[Any]  )     ->						int:
    _UpperCamelCase       			=self.image_processing_class(**self.image_processor_dict  )
    self.assertTrue(hasattr(UpperCamelCase__							,	'''do_resize_and_center_crop'''  )  )
    self.assertTrue(hasattr(UpperCamelCase__							,	'''size'''  )  )
    self.assertTrue(hasattr(UpperCamelCase__							,	'''crop_pct'''  )  )
    self.assertTrue(hasattr(UpperCamelCase__							,	'''do_normalize'''  )  )
    self.assertTrue(hasattr(UpperCamelCase__							,	'''image_mean'''  )  )
    self.assertTrue(hasattr(UpperCamelCase__							,	'''image_std'''  )  )


  def   UpperCamelCase__      (				self    :					Any  )     ->						Dict:
    _UpperCamelCase       			=self.image_processing_class.from_dict(self.image_processor_dict  )
    self.assertEqual(image_processor.size							,	{'''shortest_edge''': 30}  )
    self.assertEqual(image_processor.crop_size							,	{'''height''': 30, '''width''': 30}  )

    _UpperCamelCase       			=self.image_processing_class.from_dict(self.image_processor_dict							,	size=42							,	crop_size=84  )
    self.assertEqual(image_processor.size							,	{'''shortest_edge''': 42}  )
    self.assertEqual(image_processor.crop_size							,	{'''height''': 84, '''width''': 84}  )


  def   UpperCamelCase__      (				self    :					Dict  )     ->						Optional[Any]:
    pass


  def   UpperCamelCase__      (				self    :					Union[str, Any]  )     ->						List[Any]:
    # Initialize image_processing
    _UpperCamelCase       			=self.image_processing_class(**self.image_processor_dict  )
    # create random PIL images
    _UpperCamelCase       			=prepare_image_inputs(self.image_processor_tester							,	equal_resolution=UpperCamelCase__  )
    for image in image_inputs:
      self.assertIsInstance(UpperCamelCase__							,	Image.Image  )

    # Test not batched input
    _UpperCamelCase       			=image_processing(image_inputs[0]							,	return_tensors='''pt'''  ).pixel_values

    self.assertEqual(
        encoded_images.shape							,	(
            1,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.crop_size['''height'''],
            self.image_processor_tester.crop_size['''width'''],
        )							,	)

    # Test batched
    _UpperCamelCase       			=image_processing(UpperCamelCase__							,	return_tensors='''pt'''  ).pixel_values
    self.assertEqual(
        encoded_images.shape							,	(
            self.image_processor_tester.batch_size,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.crop_size['''height'''],
            self.image_processor_tester.crop_size['''width'''],
        )							,	)


  def   UpperCamelCase__      (				self    :					Union[str, Any]  )     ->						Optional[int]:
    # Initialize image_processing
    _UpperCamelCase       			=self.image_processing_class(**self.image_processor_dict  )
    # create random numpy tensors
    _UpperCamelCase       			=prepare_image_inputs(self.image_processor_tester							,	equal_resolution=UpperCamelCase__							,	numpify=UpperCamelCase__  )
    for image in image_inputs:
      self.assertIsInstance(UpperCamelCase__							,	np.ndarray  )

    # Test not batched input
    _UpperCamelCase       			=image_processing(image_inputs[0]							,	return_tensors='''pt'''  ).pixel_values
    self.assertEqual(
        encoded_images.shape							,	(
            1,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.crop_size['''height'''],
            self.image_processor_tester.crop_size['''width'''],
        )							,	)

    # Test batched
    _UpperCamelCase       			=image_processing(UpperCamelCase__							,	return_tensors='''pt'''  ).pixel_values
    self.assertEqual(
        encoded_images.shape							,	(
            self.image_processor_tester.batch_size,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.crop_size['''height'''],
            self.image_processor_tester.crop_size['''width'''],
        )							,	)




  def   UpperCamelCase__      (				self    :					str  )     ->						List[Any]:
    # Initialize image_processing
    _UpperCamelCase       			=self.image_processing_class(**self.image_processor_dict  )
    # create random PyTorch tensors
    _UpperCamelCase       			=prepare_image_inputs(self.image_processor_tester							,	equal_resolution=UpperCamelCase__							,	torchify=UpperCamelCase__  )
    for image in image_inputs:
      self.assertIsInstance(UpperCamelCase__							,	torch.Tensor  )

    # Test not batched input
    _UpperCamelCase       			=image_processing(image_inputs[0]							,	return_tensors='''pt'''  ).pixel_values
    self.assertEqual(
        encoded_images.shape							,	(
            1,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.crop_size['''height'''],
            self.image_processor_tester.crop_size['''width'''],
        )							,	)

    # Test batched
    _UpperCamelCase       			=image_processing(UpperCamelCase__							,	return_tensors='''pt'''  ).pixel_values
    self.assertEqual(
        encoded_images.shape							,	(
            self.image_processor_tester.batch_size,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.crop_size['''height'''],
            self.image_processor_tester.crop_size['''width'''],
        )							,	)






