





'''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       __SCREAMING_SNAKE_CASE	(						unittest.TestCase			):



     '''simple docstring'''






     def __init__(					self						,   lowerCamelCase						,   lowerCamelCase=7						,   lowerCamelCase=3						,   lowerCamelCase=18						,   lowerCamelCase=30						,   lowerCamelCase=400						,   lowerCamelCase=True						,   lowerCamelCase=None						,   lowerCamelCase=True						,   lowerCamelCase=None						,   lowerCamelCase=True						,   lowerCamelCase=[0.5, 0.5, 0.5]						,   lowerCamelCase=[0.5, 0.5, 0.5]						,   ):
       _snake_case     		=				size if size is not None else {"shortest_edge": 18}
       _snake_case     		=				crop_size if crop_size is not None else {"height": 18, "width": 18}
       _snake_case     		=				parent
       _snake_case     		=				batch_size
       _snake_case     		=				num_channels
       _snake_case     		=				image_size
       _snake_case     		=				min_resolution
       _snake_case     		=				max_resolution
       _snake_case     		=				do_resize
       _snake_case     		=				size
       _snake_case     		=				do_center_crop
       _snake_case     		=				crop_size
       _snake_case     		=				do_normalize
       _snake_case     		=				image_mean
       _snake_case     		=				image_std






     def 	UpperCamelCase(					self	):
       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       __SCREAMING_SNAKE_CASE	(						_UpperCAmelCase					,    unittest.TestCase			):



     '''simple docstring'''






     UpperCAmelCase__       :						Optional[Any]      =   LevitImageProcessor if is_vision_available() else None

     def 	UpperCamelCase(					self	):
       _snake_case     		=				LevitImageProcessingTester(self	)

     @property
     def 	UpperCamelCase(					self	):
       return self.image_processor_tester.prepare_image_processor_dict()

     def 	UpperCamelCase(					self	):
       _snake_case     		=				self.image_processing_class(**self.image_processor_dict	)
       self.assertTrue(hasattr(__UpperCamelCase						,   "image_mean"	)	)
       self.assertTrue(hasattr(__UpperCamelCase						,   "image_std"	)	)
       self.assertTrue(hasattr(__UpperCamelCase						,   "do_normalize"	)	)
       self.assertTrue(hasattr(__UpperCamelCase						,   "do_resize"	)	)
       self.assertTrue(hasattr(__UpperCamelCase						,   "do_center_crop"	)	)
       self.assertTrue(hasattr(__UpperCamelCase						,   "size"	)	)

     def 	UpperCamelCase(					self	):
       _snake_case     		=				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}	)

       _snake_case     		=				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	):
       pass

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

       # Test not batched input
       _snake_case     		=				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
       _snake_case     		=				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	):
       _snake_case     		=				self.image_processing_class(**self.image_processor_dict	)
       # create random numpy tensors
       _snake_case     		=				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
       _snake_case     		=				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
       _snake_case     		=				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	):
       _snake_case     		=				self.image_processing_class(**self.image_processor_dict	)
       # create random PyTorch tensors
       _snake_case     		=				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
       _snake_case     		=				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
       _snake_case     		=				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


__magic_name__   :						Dict    =			logging.get_logger(__name__)

__magic_name__   :						Dict    =			{
    """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       __SCREAMING_SNAKE_CASE	(						__UpperCamelCase			):



     '''simple docstring'''






     UpperCAmelCase__       :						List[Any]      =   '''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."	)

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







class       __SCREAMING_SNAKE_CASE	(						__UpperCamelCase			):



     '''simple docstring'''






     UpperCAmelCase__       :						int      =   version.parse('''1.11'''			)

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

     @property
     def 	UpperCamelCase(					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 	UpperCamelCase(					self	):
       return 1e-4


