





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


if is_torch_available():
							import torch

if is_vision_available():
							from PIL import Image

							from transformers import BlipImageProcessor

class    __A  (    unittest.TestCase     ):


				def __init__(		self ,			UpperCAmelCase_ ,			UpperCAmelCase_=7 ,			UpperCAmelCase_=3 ,			UpperCAmelCase_=18 ,			UpperCAmelCase_=30 ,			UpperCAmelCase_=400 ,			UpperCAmelCase_=True ,			UpperCAmelCase_=None ,			UpperCAmelCase_=True ,			UpperCAmelCase_=False ,			UpperCAmelCase_=[0.4_8_1_4_5_4_6_6, 0.4_5_7_8_2_7_5, 0.4_0_8_2_1_0_7_3] ,			UpperCAmelCase_=[0.2_6_8_6_2_9_5_4, 0.2_6_1_3_0_2_5_8, 0.2_7_5_7_7_7_1_1] ,			UpperCAmelCase_=True ,			):
								lowerCamelCase									=size if size is not None else {"""height""": 20, """width""": 20}
								lowerCamelCase									=parent
								lowerCamelCase									=batch_size
								lowerCamelCase									=num_channels
								lowerCamelCase									=image_size
								lowerCamelCase									=min_resolution
								lowerCamelCase									=max_resolution
								lowerCamelCase									=do_resize
								lowerCamelCase									=size
								lowerCamelCase									=do_normalize
								lowerCamelCase									=image_mean
								lowerCamelCase									=image_std
								lowerCamelCase									=do_pad
								lowerCamelCase									=do_convert_rgb


				def _snake_case							(		self				):
								return {
								    "do_resize": self.do_resize,
								    "size": self.size,
								    "do_normalize": self.do_normalize,
								    "image_mean": self.image_mean,
								    "image_std": self.image_std,
								    "do_convert_rgb": self.do_convert_rgb,
								    "do_pad": self.do_pad,
								}


				def _snake_case							(		self ,			UpperCAmelCase_=False ,			UpperCAmelCase_=False ,			UpperCAmelCase_=False				):
								assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

								if equal_resolution:
												lowerCamelCase									=[]
												for i in range(self.batch_size				):
																image_inputs.append(
																    np.random.randint(
																        255 ,			size=(self.num_channels, self.max_resolution, self.max_resolution) ,			dtype=np.uinta				)				)
								else:
												lowerCamelCase									=[]
												for i in range(self.batch_size				):
																lowerCamelCase			,	lowerCamelCase									=np.random.choice(np.arange(self.min_resolution ,			self.max_resolution				) ,			2				)
																image_inputs.append(np.random.randint(255 ,			size=(self.num_channels, width, height) ,			dtype=np.uinta				)				)

								if not numpify and not torchify:
												# PIL expects the channel dimension as last dimension
												lowerCamelCase									=[Image.fromarray(np.moveaxis(A__ ,			0 ,			-1				)				) for x in image_inputs]

								if torchify:
												lowerCamelCase									=[torch.from_numpy(A__				) for x in image_inputs]

								return image_inputs




@require_torch
@require_vision
class    __A  (    SCREAMING_SNAKE_CASE__     ,       unittest.TestCase     ):
				__A  =					BlipImageProcessor if is_vision_available() else None


				def _snake_case							(		self				):
								lowerCamelCase									=BlipImageProcessingTester(self				)


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


				def _snake_case							(		self				):
								lowerCamelCase									=self.image_processing_class(**self.image_processor_dict				)
								self.assertTrue(hasattr(A__ ,			"""do_resize"""				)				)
								self.assertTrue(hasattr(A__ ,			"""size"""				)				)
								self.assertTrue(hasattr(A__ ,			"""do_normalize"""				)				)
								self.assertTrue(hasattr(A__ ,			"""image_mean"""				)				)
								self.assertTrue(hasattr(A__ ,			"""image_std"""				)				)
								self.assertTrue(hasattr(A__ ,			"""do_convert_rgb"""				)				)


				def _snake_case							(		self				):
								pass


				def _snake_case							(		self				):
								# Initialize image_processor
								lowerCamelCase									=self.image_processing_class(**self.image_processor_dict				)
								# create random PIL images
								lowerCamelCase									=self.image_processor_tester.prepare_inputs(equal_resolution=A__				)
								for image in image_inputs:
												self.assertIsInstance(A__ ,			Image.Image				)

								# Test not batched input
								lowerCamelCase									=image_processor(image_inputs[0] ,			return_tensors="""pt"""				).pixel_values
								self.assertEqual(
								    encoded_images.shape ,			(
								        1,
								        self.image_processor_tester.num_channels,
								        self.image_processor_tester.size["""height"""],
								        self.image_processor_tester.size["""width"""],
								    ) ,			)

								# Test batched
								lowerCamelCase									=image_processor(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.size["""height"""],
								        self.image_processor_tester.size["""width"""],
								    ) ,			)


				def _snake_case							(		self				):
								# Initialize image_processor
								lowerCamelCase									=self.image_processing_class(**self.image_processor_dict				)
								# create random numpy tensors
								lowerCamelCase									=self.image_processor_tester.prepare_inputs(equal_resolution=A__ ,			numpify=A__				)
								for image in image_inputs:
												self.assertIsInstance(A__ ,			np.ndarray				)

								# Test not batched input
								lowerCamelCase									=image_processor(image_inputs[0] ,			return_tensors="""pt"""				).pixel_values
								self.assertEqual(
								    encoded_images.shape ,			(
								        1,
								        self.image_processor_tester.num_channels,
								        self.image_processor_tester.size["""height"""],
								        self.image_processor_tester.size["""width"""],
								    ) ,			)

								# Test batched
								lowerCamelCase									=image_processor(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.size["""height"""],
								        self.image_processor_tester.size["""width"""],
								    ) ,			)


				def _snake_case							(		self				):
								# Initialize image_processor
								lowerCamelCase									=self.image_processing_class(**self.image_processor_dict				)
								# create random PyTorch tensors
								lowerCamelCase									=self.image_processor_tester.prepare_inputs(equal_resolution=A__ ,			torchify=A__				)
								for image in image_inputs:
												self.assertIsInstance(A__ ,			torch.Tensor				)

								# Test not batched input
								lowerCamelCase									=image_processor(image_inputs[0] ,			return_tensors="""pt"""				).pixel_values
								self.assertEqual(
								    encoded_images.shape ,			(
								        1,
								        self.image_processor_tester.num_channels,
								        self.image_processor_tester.size["""height"""],
								        self.image_processor_tester.size["""width"""],
								    ) ,			)

								# Test batched
								lowerCamelCase									=image_processor(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.size["""height"""],
								        self.image_processor_tester.size["""width"""],
								    ) ,			)




@require_torch
@require_vision
class    __A  (    SCREAMING_SNAKE_CASE__     ,       unittest.TestCase     ):
				__A  =					BlipImageProcessor if is_vision_available() else None


				def _snake_case							(		self				):
								lowerCamelCase									=BlipImageProcessingTester(self ,			num_channels=4				)
								lowerCamelCase									=3


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


				def _snake_case							(		self				):
								lowerCamelCase									=self.image_processing_class(**self.image_processor_dict				)
								self.assertTrue(hasattr(A__ ,			"""do_resize"""				)				)
								self.assertTrue(hasattr(A__ ,			"""size"""				)				)
								self.assertTrue(hasattr(A__ ,			"""do_normalize"""				)				)
								self.assertTrue(hasattr(A__ ,			"""image_mean"""				)				)
								self.assertTrue(hasattr(A__ ,			"""image_std"""				)				)
								self.assertTrue(hasattr(A__ ,			"""do_convert_rgb"""				)				)


				def _snake_case							(		self				):
								pass


				def _snake_case							(		self				):
								# Initialize image_processor
								lowerCamelCase									=self.image_processing_class(**self.image_processor_dict				)
								# create random PIL images
								lowerCamelCase									=self.image_processor_tester.prepare_inputs(equal_resolution=A__				)
								for image in image_inputs:
												self.assertIsInstance(A__ ,			Image.Image				)

								# Test not batched input
								lowerCamelCase									=image_processor(image_inputs[0] ,			return_tensors="""pt"""				).pixel_values
								self.assertEqual(
								    encoded_images.shape ,			(
								        1,
								        self.expected_encoded_image_num_channels,
								        self.image_processor_tester.size["""height"""],
								        self.image_processor_tester.size["""width"""],
								    ) ,			)

								# Test batched
								lowerCamelCase									=image_processor(A__ ,			return_tensors="""pt"""				).pixel_values
								self.assertEqual(
								    encoded_images.shape ,			(
								        self.image_processor_tester.batch_size,
								        self.expected_encoded_image_num_channels,
								        self.image_processor_tester.size["""height"""],
								        self.image_processor_tester.size["""width"""],
								    ) ,			)







import unittest

import torch

from diffusers import DDIMScheduler, TextToVideoZeroPipeline
from diffusers.utils import load_pt, require_torch_gpu, slow

from ..test_pipelines_common import assert_mean_pixel_difference







@slow
@require_torch_gpu
class 							lowercase						(   unittest.TestCase						):




							def 					A__ (							self):
												lowercase		      =		'''runwayml/stable-diffusion-v1-5'''
												lowercase		      =		TextToVideoZeroPipeline.from_pretrained(A__  ,torch_dtype=torch.floataa).to('''cuda''')
												lowercase		      =		DDIMScheduler.from_config(pipe.scheduler.config)
												lowercase		      =		torch.Generator(device='''cuda''').manual_seed(0)

												lowercase		      =		'''A bear is playing a guitar on Times Square'''
												lowercase		      =		pipe(prompt=A__  ,generator=A__).images

												lowercase		      =		load_pt(
												    '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/text-to-video/A bear is playing a guitar on Times Square.pt''')

												assert_mean_pixel_difference(A__  ,A__)




