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


class 					a_					(unittest.TestCase      ):




       def __init__(       self				,				snake_case_				,				snake_case_=7				,				snake_case_=3				,				snake_case_=1_8				,				snake_case_=3_0				,				snake_case_=4_0_0				,				snake_case_=True				,				snake_case_=None				,				snake_case_=True				,				snake_case_=None				,				snake_case_=True				,				snake_case_=[0.5, 0.5, 0.5]				,				snake_case_=[0.5, 0.5, 0.5]				,				):
         _lowerCAmelCase    :					Optional[Any]							=   size if size is not None else {"""height""": 2_0, """width""": 2_0}
         _lowerCAmelCase    :					List[Any]							=   crop_size if crop_size is not None else {"""height""": 1_8, """width""": 1_8}

         _lowerCAmelCase    :					int							=   parent
         _lowerCAmelCase    :					int							=   batch_size
         _lowerCAmelCase    :					Dict							=   num_channels
         _lowerCAmelCase    :					List[Any]							=   image_size
         _lowerCAmelCase    :					str							=   min_resolution
         _lowerCAmelCase    :					Union[str, Any]							=   max_resolution
         _lowerCAmelCase    :					Union[str, Any]							=   do_resize
         _lowerCAmelCase    :					int							=   size
         _lowerCAmelCase    :					Optional[int]							=   do_center_crop
         _lowerCAmelCase    :					Any							=   crop_size
         _lowerCAmelCase    :					Any							=   do_normalize
         _lowerCAmelCase    :					Optional[Any]							=   image_mean
         _lowerCAmelCase    :					Optional[Any]							=   image_std







       def 							__UpperCamelCase    (       self					):
         return {
             "do_resize": self.do_resize,
             "size": self.size,
             "do_center_crop": self.do_center_crop,
             "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 					a_					(_a							,     unittest.TestCase      ):
       __lowerCAmelCase      :			int      = DeiTImageProcessor if is_vision_available() else None
       __lowerCAmelCase      :			Any      = True




       def 							__UpperCamelCase    (       self					):
         _lowerCAmelCase    :					int							=   DeiTImageProcessingTester(self					)




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




       def 							__UpperCamelCase    (       self					):
         _lowerCAmelCase    :					Any							=   self.image_processing_class(**self.image_processor_dict					)
         self.assertTrue(hasattr(snake_case_				,				"""do_resize"""					)					)
         self.assertTrue(hasattr(snake_case_				,				"""size"""					)					)
         self.assertTrue(hasattr(snake_case_				,				"""do_center_crop"""					)					)
         self.assertTrue(hasattr(snake_case_				,				"""center_crop"""					)					)
         self.assertTrue(hasattr(snake_case_				,				"""do_normalize"""					)					)
         self.assertTrue(hasattr(snake_case_				,				"""image_mean"""					)					)
         self.assertTrue(hasattr(snake_case_				,				"""image_std"""					)					)




       def 							__UpperCamelCase    (       self					):
         _lowerCAmelCase    :					int							=   self.image_processing_class.from_dict(self.image_processor_dict					)
         self.assertEqual(image_processor.size				,				{"""height""": 2_0, """width""": 2_0}					)
         self.assertEqual(image_processor.crop_size				,				{"""height""": 1_8, """width""": 1_8}					)

         _lowerCAmelCase    :					int							=   self.image_processing_class.from_dict(self.image_processor_dict				,				size=4_2				,				crop_size=8_4					)
         self.assertEqual(image_processor.size				,				{"""height""": 4_2, """width""": 4_2}					)
         self.assertEqual(image_processor.crop_size				,				{"""height""": 8_4, """width""": 8_4}					)




       def 							__UpperCamelCase    (       self					):
         pass




       def 							__UpperCamelCase    (       self					):
         # Initialize image_processing
         _lowerCAmelCase    :					str							=   self.image_processing_class(**self.image_processor_dict					)
         # create random PIL images
         _lowerCAmelCase    :					Any							=   prepare_image_inputs(self.image_processor_tester				,				equal_resolution=snake_case_					)
         for image in image_inputs:
           self.assertIsInstance(snake_case_				,				Image.Image					)

         # Test not batched input
         _lowerCAmelCase    :					Optional[Any]							=   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    :					Any							=   image_processing(snake_case_				,				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					):
         # Initialize image_processing
         _lowerCAmelCase    :					str							=   self.image_processing_class(**self.image_processor_dict					)
         # create random numpy tensors
         _lowerCAmelCase    :					List[str]							=   prepare_image_inputs(self.image_processor_tester				,				equal_resolution=snake_case_				,				numpify=snake_case_					)
         for image in image_inputs:
           self.assertIsInstance(snake_case_				,				np.ndarray					)

         # Test not batched input
         _lowerCAmelCase    :					Optional[Any]							=   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    :					Dict							=   image_processing(snake_case_				,				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					):
         # Initialize image_processing
         _lowerCAmelCase    :					Any							=   self.image_processing_class(**self.image_processor_dict					)
         # create random PyTorch tensors
         _lowerCAmelCase    :					Tuple							=   prepare_image_inputs(self.image_processor_tester				,				equal_resolution=snake_case_				,				torchify=snake_case_					)
         for image in image_inputs:
           self.assertIsInstance(snake_case_				,				torch.Tensor					)

         # Test not batched input
         _lowerCAmelCase    :					int							=   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    :					Dict							=   image_processing(snake_case_				,				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


UpperCamelCase_            =    logging.get_logger(__name__)

UpperCamelCase_            =    {
    """apple/mobilevit-small""": """https://huggingface.co/apple/mobilevit-small/resolve/main/config.json""",
    """apple/mobilevit-x-small""": """https://huggingface.co/apple/mobilevit-x-small/resolve/main/config.json""",
    """apple/mobilevit-xx-small""": """https://huggingface.co/apple/mobilevit-xx-small/resolve/main/config.json""",
    """apple/deeplabv3-mobilevit-small""": (
        """https://huggingface.co/apple/deeplabv3-mobilevit-small/resolve/main/config.json"""
    ),
    """apple/deeplabv3-mobilevit-x-small""": (
        """https://huggingface.co/apple/deeplabv3-mobilevit-x-small/resolve/main/config.json"""
    ),
    """apple/deeplabv3-mobilevit-xx-small""": (
        """https://huggingface.co/apple/deeplabv3-mobilevit-xx-small/resolve/main/config.json"""
    ),
    # See all MobileViT models at https://huggingface.co/models?filter=mobilevit
}


class 					a_					(_a      ):
       __lowerCAmelCase      :			List[str]      = """mobilevit"""




       def __init__(       self				,				snake_case_=3				,				snake_case_=2_5_6				,				snake_case_=2				,				snake_case_=[1_4_4, 1_9_2, 2_4_0]				,				snake_case_=[1_6, 3_2, 6_4, 9_6, 1_2_8, 1_6_0, 6_4_0]				,				snake_case_=4				,				snake_case_=2.0				,				snake_case_=4.0				,				snake_case_="silu"				,				snake_case_=3				,				snake_case_=3_2				,				snake_case_=0.1				,				snake_case_=0.0				,				snake_case_=0.1				,				snake_case_=0.02				,				snake_case_=1E-5				,				snake_case_=True				,				snake_case_=2_5_6				,				snake_case_=[6, 1_2, 1_8]				,				snake_case_=0.1				,				snake_case_=2_5_5				,				**snake_case_				,				):
         super().__init__(**snake_case_					)

         _lowerCAmelCase    :					Optional[Any]							=   num_channels
         _lowerCAmelCase    :					Optional[int]							=   image_size
         _lowerCAmelCase    :					Union[str, Any]							=   patch_size
         _lowerCAmelCase    :					Any							=   hidden_sizes
         _lowerCAmelCase    :					List[Any]							=   neck_hidden_sizes
         _lowerCAmelCase    :					Any							=   num_attention_heads
         _lowerCAmelCase    :					List[Any]							=   mlp_ratio
         _lowerCAmelCase    :					Optional[Any]							=   expand_ratio
         _lowerCAmelCase    :					List[Any]							=   hidden_act
         _lowerCAmelCase    :					Dict							=   conv_kernel_size
         _lowerCAmelCase    :					Tuple							=   output_stride
         _lowerCAmelCase    :					Dict							=   hidden_dropout_prob
         _lowerCAmelCase    :					Tuple							=   attention_probs_dropout_prob
         _lowerCAmelCase    :					Optional[int]							=   classifier_dropout_prob
         _lowerCAmelCase    :					int							=   initializer_range
         _lowerCAmelCase    :					List[Any]							=   layer_norm_eps
         _lowerCAmelCase    :					List[Any]							=   qkv_bias

         # decode head attributes for semantic segmentation
         _lowerCAmelCase    :					str							=   aspp_out_channels
         _lowerCAmelCase    :					Optional[Any]							=   atrous_rates
         _lowerCAmelCase    :					Any							=   aspp_dropout_prob
         _lowerCAmelCase    :					Union[str, Any]							=   semantic_loss_ignore_index



class 					a_					(_a      ):
       __lowerCAmelCase      :			Optional[int]      = version.parse("""1.11"""      )




       @property
       def 							__UpperCamelCase    (       self					):
         return OrderedDict([("""pixel_values""", {0: """batch""", 1: """num_channels""", 2: """height""", 3: """width"""})]					)




       @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


