


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







						'''simple docstring'''




						def __init__(				self   ,						__lowercase   ,						__lowercase=7   ,						__lowercase=3   ,						__lowercase=1_8   ,						__lowercase=3_0   ,						__lowercase=4_0_0   ,						__lowercase=True   ,						__lowercase=None   ,						__lowercase=True   ,						__lowercase=None   ,						__lowercase=True   ,						__lowercase=[0.5, 0.5, 0.5]   ,						__lowercase=[0.5, 0.5, 0.5]   ,						)					->    List[str]:
										lowerCAmelCase_ :      int    				=				size if size is not None else {'''shortest_edge''': 1_8}
										lowerCAmelCase_ :      Dict    				=				crop_size if crop_size is not None else {'''height''': 1_8, '''width''': 1_8}
										lowerCAmelCase_ :      str    				=				parent
										lowerCAmelCase_ :      Tuple    				=				batch_size
										lowerCAmelCase_ :      Optional[int]    				=				num_channels
										lowerCAmelCase_ :      List[Any]    				=				image_size
										lowerCAmelCase_ :      Any    				=				min_resolution
										lowerCAmelCase_ :      str    				=				max_resolution
										lowerCAmelCase_ :      List[str]    				=				do_resize
										lowerCAmelCase_ :      int    				=				size
										lowerCAmelCase_ :      Tuple    				=				do_center_crop
										lowerCAmelCase_ :      Optional[Any]    				=				crop_size
										lowerCAmelCase_ :      Optional[int]    				=				do_normalize
										lowerCAmelCase_ :      int    				=				image_mean
										lowerCAmelCase_ :      Dict    				=				image_std




						def 						lowercase_ (				self							)					->    int:
										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 				snake_case__(							UpperCAmelCase__,						unittest.TestCase							):







						'''simple docstring'''




						SCREAMING_SNAKE_CASE__      :  Tuple					=							LevitImageProcessor if is_vision_available() else None




						def 						lowercase_ (				self							)					->    str:
										lowerCAmelCase_ :      int    				=				LevitImageProcessingTester(self							)




						@property
						def 						lowercase_ (				self							)					->    Any:
										return self.image_processor_tester.prepare_image_processor_dict()




						def 						lowercase_ (				self							)					->    List[Any]:
										lowerCAmelCase_ :      Dict    				=				self.image_processing_class(**self.image_processor_dict							)
										self.assertTrue(hasattr(_lowerCAmelCase   ,						'''image_mean'''							)							)
										self.assertTrue(hasattr(_lowerCAmelCase   ,						'''image_std'''							)							)
										self.assertTrue(hasattr(_lowerCAmelCase   ,						'''do_normalize'''							)							)
										self.assertTrue(hasattr(_lowerCAmelCase   ,						'''do_resize'''							)							)
										self.assertTrue(hasattr(_lowerCAmelCase   ,						'''do_center_crop'''							)							)
										self.assertTrue(hasattr(_lowerCAmelCase   ,						'''size'''							)							)




						def 						lowercase_ (				self							)					->    List[Any]:
										lowerCAmelCase_ :      Tuple    				=				self.image_processing_class.from_dict(self.image_processor_dict							)
										self.assertEqual(image_processor.size   ,						{'''shortest_edge''': 1_8}							)
										self.assertEqual(image_processor.crop_size   ,						{'''height''': 1_8, '''width''': 1_8}							)

										lowerCAmelCase_ :      Dict    				=				self.image_processing_class.from_dict(self.image_processor_dict   ,						size=4_2   ,						crop_size=8_4							)
										self.assertEqual(image_processor.size   ,						{'''shortest_edge''': 4_2}							)
										self.assertEqual(image_processor.crop_size   ,						{'''height''': 8_4, '''width''': 8_4}							)




						def 						lowercase_ (				self							)					->    int:
										pass




						def 						lowercase_ (				self							)					->    Optional[Any]:
										# Initialize image_processing
										lowerCAmelCase_ :      Optional[int]    				=				self.image_processing_class(**self.image_processor_dict							)
										# create random PIL images
										lowerCAmelCase_ :      Dict    				=				prepare_image_inputs(self.image_processor_tester   ,						equal_resolution=_lowerCAmelCase							)
										for image in image_inputs:
														self.assertIsInstance(_lowerCAmelCase   ,						Image.Image							)

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

										# Test not batched input
										lowerCAmelCase_ :      List[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(_lowerCAmelCase   ,						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'''],
										    )   ,						)



_UpperCAmelCase			:  int     =frozenset(
    [
        """prompt""",
        """height""",
        """width""",
        """guidance_scale""",
        """negative_prompt""",
        """prompt_embeds""",
        """negative_prompt_embeds""",
        """cross_attention_kwargs""",
    ]
)

_UpperCAmelCase			:  List[Any]     =frozenset(["""prompt""", """negative_prompt"""])

_UpperCAmelCase			:  Dict     =frozenset([])

_UpperCAmelCase			:  int     =frozenset(["""image"""])

_UpperCAmelCase			:  Tuple     =frozenset(
    [
        """image""",
        """height""",
        """width""",
        """guidance_scale""",
    ]
)

_UpperCAmelCase			:  int     =frozenset(["""image"""])

_UpperCAmelCase			:  str     =frozenset(
    [
        """prompt""",
        """image""",
        """height""",
        """width""",
        """guidance_scale""",
        """negative_prompt""",
        """prompt_embeds""",
        """negative_prompt_embeds""",
    ]
)

_UpperCAmelCase			:  int     =frozenset(["""prompt""", """image""", """negative_prompt"""])

_UpperCAmelCase			:  Optional[int]     =frozenset(
    [
        # Text guided image variation with an image mask
        """prompt""",
        """image""",
        """mask_image""",
        """height""",
        """width""",
        """guidance_scale""",
        """negative_prompt""",
        """prompt_embeds""",
        """negative_prompt_embeds""",
    ]
)

_UpperCAmelCase			:  Optional[int]     =frozenset(["""prompt""", """image""", """mask_image""", """negative_prompt"""])

_UpperCAmelCase			:  Optional[Any]     =frozenset(
    [
        # image variation with an image mask
        """image""",
        """mask_image""",
        """height""",
        """width""",
        """guidance_scale""",
    ]
)

_UpperCAmelCase			:  Optional[Any]     =frozenset(["""image""", """mask_image"""])

_UpperCAmelCase			:  Union[str, Any]     =frozenset(
    [
        """example_image""",
        """image""",
        """mask_image""",
        """height""",
        """width""",
        """guidance_scale""",
    ]
)

_UpperCAmelCase			:  Tuple     =frozenset(["""example_image""", """image""", """mask_image"""])

_UpperCAmelCase			:  Any     =frozenset(["""class_labels"""])

_UpperCAmelCase			:  List[Any]     =frozenset(["""class_labels"""])

_UpperCAmelCase			:  int     =frozenset(["""batch_size"""])

_UpperCAmelCase			:  str     =frozenset([])

_UpperCAmelCase			:  str     =frozenset(["""batch_size"""])

_UpperCAmelCase			:  Optional[Any]     =frozenset([])

_UpperCAmelCase			:  Tuple     =frozenset(
    [
        """prompt""",
        """audio_length_in_s""",
        """guidance_scale""",
        """negative_prompt""",
        """prompt_embeds""",
        """negative_prompt_embeds""",
        """cross_attention_kwargs""",
    ]
)

_UpperCAmelCase			:  Tuple     =frozenset(["""prompt""", """negative_prompt"""])
_UpperCAmelCase			:  List[str]     =frozenset(["""input_tokens"""])

_UpperCAmelCase			:  Optional[Any]     =frozenset(["""input_tokens"""])