



"""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    lowercase__     (					unittest.TestCase   ):



       def __init__(							self    :						Optional[int]	,       _UpperCAmelCase    :						str	,       _UpperCAmelCase    :						Optional[int]=7	,       _UpperCAmelCase    :						Optional[Any]=3	,       _UpperCAmelCase    :						Tuple=30	,       _UpperCAmelCase    :						List[str]=400	,       _UpperCAmelCase    :						Tuple=True	,       _UpperCAmelCase    :						Optional[int]=None	,       _UpperCAmelCase    :						Optional[Any]=0.9	,       _UpperCAmelCase    :						Union[str, Any]=None	,       _UpperCAmelCase    :						Union[str, Any]=True	,       _UpperCAmelCase    :						List[str]=[0.5, 0.5, 0.5]	,       _UpperCAmelCase    :						Dict=[0.5, 0.5, 0.5]	,       )				->		Any:


             '''simple docstring'''




             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   lowercase__       (							self    :						int					)				->		Optional[Any]:


             '''simple docstring'''




             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    lowercase__     (					__snake_case       ,      unittest.TestCase   ):
       UpperCamelCase		=  PoolFormerImageProcessor if is_vision_available() else None



       def   lowercase__       (							self    :						Dict					)				->		List[Any]:


             '''simple docstring'''




             UpperCAmelCase_    				=							PoolFormerImageProcessingTester(self					)



       @property
       def   lowercase__       (							self    :						Tuple					)				->		Dict:


             '''simple docstring'''




             return self.image_processor_tester.prepare_image_processor_dict()



       def   lowercase__       (							self    :						Union[str, Any]					)				->		Optional[Any]:


             '''simple docstring'''




             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   lowercase__       (							self    :						List[Any]					)				->		Optional[int]:


             '''simple docstring'''




             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   lowercase__       (							self    :						List[Any]					)				->		Tuple:


             '''simple docstring'''




             pass



       def   lowercase__       (							self    :						List[str]					)				->		Union[str, Any]:


             '''simple docstring'''




             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   lowercase__       (							self    :						Dict					)				->		Any:


             '''simple docstring'''




             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   lowercase__       (							self    :						List[Any]					)				->		Optional[Any]:


             '''simple docstring'''




             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"],
                 )	,       )









"""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      =		logging.get_logger(__name__)

lowerCamelCase      =		{
    """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    lowercase__     (					SCREAMING_SNAKE_CASE   ):







       '''simple docstring'''


       UpperCamelCase		=  '''mobilenet_v1'''



       def __init__(							self    :						Tuple	,       _UpperCAmelCase    :						int=3	,       _UpperCAmelCase    :						Union[str, Any]=224	,       _UpperCAmelCase    :						Any=1.0	,       _UpperCAmelCase    :						Any=8	,       _UpperCAmelCase    :						List[Any]="relu6"	,       _UpperCAmelCase    :						List[str]=True	,       _UpperCAmelCase    :						Dict=0.999	,       _UpperCAmelCase    :						List[Any]=0.02	,       _UpperCAmelCase    :						List[Any]=0.001	,       **_UpperCAmelCase    :						str	,       )				->		Optional[int]:


             '''simple docstring'''




             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_    				=							min_depth
             UpperCAmelCase_    				=							hidden_act
             UpperCAmelCase_    				=							tf_padding
             UpperCAmelCase_    				=							classifier_dropout_prob
             UpperCAmelCase_    				=							initializer_range
             UpperCAmelCase_    				=							layer_norm_eps



class    lowercase__     (					SCREAMING_SNAKE_CASE   ):







       '''simple docstring'''


       UpperCamelCase		=  version.parse('''1.11'''   )



       @property
       def   lowercase__       (							self    :						List[Any]					)				->		Mapping[str, Mapping[int, str]]:


             '''simple docstring'''




             return OrderedDict([("pixel_values", {0: "batch"})]					)



       @property
       def   lowercase__       (							self    :						List[Any]					)				->		Mapping[str, Mapping[int, str]]:


             '''simple docstring'''




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







       @property
       def   lowercase__       (							self    :						Tuple					)				->		float:


             '''simple docstring'''




             return 1e-4




