



'''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 LevitImageProcessor
class 				lowercase       (							unittest.TestCase      ):


    '''simple docstring'''

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

     '''simple docstring'''




     lowerCamelCase__  =     size if size is not None else {"shortest_edge": 18}
     lowerCamelCase__  =     crop_size if crop_size is not None else {"height": 18, "width": 18}
     lowerCamelCase__  =     parent
     lowerCamelCase__  =     batch_size
     lowerCamelCase__  =     num_channels
     lowerCamelCase__  =     image_size
     lowerCamelCase__  =     min_resolution
     lowerCamelCase__  =     max_resolution
     lowerCamelCase__  =     do_resize
     lowerCamelCase__  =     size
     lowerCamelCase__  =     do_center_crop
     lowerCamelCase__  =     crop_size
     lowerCamelCase__  =     do_normalize
     lowerCamelCase__  =     image_mean
     lowerCamelCase__  =     image_std




    def    a__				(					self     :     Optional[int]     )							->							Dict:

     '''simple docstring'''




     return {
         "image_mean": self.image_mean,
         "image_std": self.image_std,
         "do_normalize": self.do_normalize,
         "do_resize": self.do_resize,
         "do_center_crop": self.do_center_crop,
         "size": self.size,
         "crop_size": self.crop_size,
     }
@require_torch
@require_vision
class 				lowercase       (							__lowercase ,       unittest.TestCase      ):


    '''simple docstring'''

    lowerCAmelCase__      				=							LevitImageProcessor if is_vision_available() else None

    def    a__				(					self     :     str     )							->							Dict:

     '''simple docstring'''




     lowerCamelCase__  =     LevitImageProcessingTester(self     )

    @property
    def    a__				(					self     :     Optional[int]     )							->							int:

     '''simple docstring'''




     return self.image_processor_tester.prepare_image_processor_dict()

    def    a__				(					self     :     Any     )							->							List[str]:

     '''simple docstring'''




     lowerCamelCase__  =     self.image_processing_class(**self.image_processor_dict     )
     self.assertTrue(hasattr(__A				,     "image_mean"     )     )
     self.assertTrue(hasattr(__A				,     "image_std"     )     )
     self.assertTrue(hasattr(__A				,     "do_normalize"     )     )
     self.assertTrue(hasattr(__A				,     "do_resize"     )     )
     self.assertTrue(hasattr(__A				,     "do_center_crop"     )     )
     self.assertTrue(hasattr(__A				,     "size"     )     )

    def    a__				(					self     :     List[Any]     )							->							Optional[int]:

     '''simple docstring'''




     lowerCamelCase__  =     self.image_processing_class.from_dict(self.image_processor_dict     )
     self.assertEqual(image_processor.size				,     {"shortest_edge": 18}     )
     self.assertEqual(image_processor.crop_size				,     {"height": 18, "width": 18}     )

     lowerCamelCase__  =     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    a__				(					self     :     Optional[Any]     )							->							List[str]:

     '''simple docstring'''




     pass

    def    a__				(					self     :     Optional[int]     )							->							Optional[Any]:

     '''simple docstring'''




     lowerCamelCase__  =     self.image_processing_class(**self.image_processor_dict     )
     # create random PIL images
     lowerCamelCase__  =     prepare_image_inputs(self.image_processor_tester				,     equal_resolution=__A     )
     for image in image_inputs:
      self.assertIsInstance(__A				,     Image.Image     )

     # Test not batched input
     lowerCamelCase__  =     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
     lowerCamelCase__  =     image_processing(__A				,     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    a__				(					self     :     Tuple     )							->							int:

     '''simple docstring'''




     lowerCamelCase__  =     self.image_processing_class(**self.image_processor_dict     )
     # create random numpy tensors
     lowerCamelCase__  =     prepare_image_inputs(self.image_processor_tester				,     equal_resolution=__A				,     numpify=__A     )
     for image in image_inputs:
      self.assertIsInstance(__A				,     np.ndarray     )

     # Test not batched input
     lowerCamelCase__  =     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
     lowerCamelCase__  =     image_processing(__A				,     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    a__				(					self     :     int     )							->							int:

     '''simple docstring'''




     lowerCamelCase__  =     self.image_processing_class(**self.image_processor_dict     )
     # create random PyTorch tensors
     lowerCamelCase__  =     prepare_image_inputs(self.image_processor_tester				,     equal_resolution=__A				,     torchify=__A     )
     for image in image_inputs:
      self.assertIsInstance(__A				,     torch.Tensor     )

     # Test not batched input
     lowerCamelCase__  =     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
     lowerCamelCase__  =     image_processing(__A				,     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


__A							:							Optional[int]  							=		logging.get_logger(__name__)

__A							:							Tuple  							=		{
    """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       (							_lowerCamelCase      ):


    '''simple docstring'''

    lowerCAmelCase__      				=							"mobilenet_v1"

    def __init__(					self     :     Union[str, Any]				,     __lowerCamelCase     :     Tuple=3				,     __lowerCamelCase     :     Any=224				,     __lowerCamelCase     :     Tuple=1.0				,     __lowerCamelCase     :     Optional[int]=8				,     __lowerCamelCase     :     str="relu6"				,     __lowerCamelCase     :     Any=True				,     __lowerCamelCase     :     Union[str, Any]=0.9_9_9				,     __lowerCamelCase     :     List[Any]=0.0_2				,     __lowerCamelCase     :     str=0.0_0_1				,     **__lowerCamelCase     :     str				,     )							->							Dict:

     '''simple docstring'''




     super().__init__(**__lowerCamelCase     )

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

     lowerCamelCase__  =     num_channels
     lowerCamelCase__  =     image_size
     lowerCamelCase__  =     depth_multiplier
     lowerCamelCase__  =     min_depth
     lowerCamelCase__  =     hidden_act
     lowerCamelCase__  =     tf_padding
     lowerCamelCase__  =     classifier_dropout_prob
     lowerCamelCase__  =     initializer_range
     lowerCamelCase__  =     layer_norm_eps
class 				lowercase       (							_lowerCamelCase      ):


    '''simple docstring'''

    lowerCAmelCase__      				=							version.parse("1.11"      )

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

     '''simple docstring'''




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

    @property
    def    a__				(					self     :     str     )							->							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    a__				(					self     :     List[Any]     )							->							float:

     '''simple docstring'''




     return 1E-4

