




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






			'''simple docstring'''



			def __init__(    self    , lowercase    , lowercase=7    , lowercase=3    , lowercase=18    , lowercase=30    , lowercase=400    , lowercase=True    , lowercase=None    , lowercase=True    , lowercase=None    , lowercase=True    , lowercase=[0.5, 0.5, 0.5]    , lowercase=[0.5, 0.5, 0.5]    , ):
							_lowerCamelCase	:     str       =       size if size is not None else {'shortest_edge': 18}
							_lowerCamelCase	:     Union[str, Any]       =       crop_size if crop_size is not None else {'height': 18, 'width': 18}
							_lowerCamelCase	:     List[Any]       =       parent
							_lowerCamelCase	:     Any       =       batch_size
							_lowerCamelCase	:     Dict       =       num_channels
							_lowerCamelCase	:     Any       =       image_size
							_lowerCamelCase	:     int       =       min_resolution
							_lowerCamelCase	:     Union[str, Any]       =       max_resolution
							_lowerCamelCase	:     Tuple       =       do_resize
							_lowerCamelCase	:     int       =       size
							_lowerCamelCase	:     Optional[int]       =       do_center_crop
							_lowerCamelCase	:     List[Any]       =       crop_size
							_lowerCamelCase	:     Optional[Any]       =       do_normalize
							_lowerCamelCase	:     Optional[Any]       =       image_mean
							_lowerCamelCase	:     Optional[Any]       =       image_std






			def    A_       (    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 lowerCAmelCase__      (	lowercase,      unittest.TestCase		):






			'''simple docstring'''



			lowerCamelCase__ =     LevitImageProcessor if is_vision_available() else None
			def    A_       (    self    ):
							_lowerCamelCase	:     Any       =       LevitImageProcessingTester(self    )
			@property
			def    A_       (    self    ):
							return self.image_processor_tester.prepare_image_processor_dict()
			def    A_       (    self    ):
							_lowerCamelCase	:     Optional[Any]       =       self.image_processing_class(**self.image_processor_dict    )
							self.assertTrue(hasattr(lowercase    , 'image_mean'    )    )
							self.assertTrue(hasattr(lowercase    , 'image_std'    )    )
							self.assertTrue(hasattr(lowercase    , 'do_normalize'    )    )
							self.assertTrue(hasattr(lowercase    , 'do_resize'    )    )
							self.assertTrue(hasattr(lowercase    , 'do_center_crop'    )    )
							self.assertTrue(hasattr(lowercase    , 'size'    )    )
			def    A_       (    self    ):
							_lowerCamelCase	:     Optional[Any]       =       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	:     List[Any]       =       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    ):
							pass
			def    A_       (    self    ):
							# Initialize image_processing
							_lowerCamelCase	:     Dict       =       self.image_processing_class(**self.image_processor_dict    )
							# create random PIL images
							_lowerCamelCase	:     str       =       prepare_image_inputs(self.image_processor_tester    , equal_resolution=lowercase    )
							for image in image_inputs:
											self.assertIsInstance(lowercase    , Image.Image    )

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

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

							# Test not batched input
							_lowerCamelCase	:     str       =       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	:     Optional[int]       =       image_processing(lowercase    , 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 ...utils import (
    OptionalDependencyNotAvailable,
    is_torch_available,
    is_transformers_available,
    is_transformers_version,
)


try:
			if not (is_transformers_available() and is_torch_available() and is_transformers_version(""">=""", """4.25.0""")):
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			from ...utils.dummy_torch_and_transformers_objects import (
			    VersatileDiffusionDualGuidedPipeline,
			    VersatileDiffusionImageVariationPipeline,
			    VersatileDiffusionPipeline,
			    VersatileDiffusionTextToImagePipeline,
			)
else:
			from .modeling_text_unet import UNetFlatConditionModel
			from .pipeline_versatile_diffusion import VersatileDiffusionPipeline
			from .pipeline_versatile_diffusion_dual_guided import VersatileDiffusionDualGuidedPipeline
			from .pipeline_versatile_diffusion_image_variation import VersatileDiffusionImageVariationPipeline
			from .pipeline_versatile_diffusion_text_to_image import VersatileDiffusionTextToImagePipeline