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


class 	UpperCamelCase__					(      unittest.TestCase):






 def __init__(     self					:Union[str, Any]		,			_A					:Union[str, Any]		,			_A					:int=13		,			_A					:str=3		,			_A					:Tuple=18		,			_A					:Any=30		,			_A					:Optional[int]=400		,			_A					:str=True		,			_A					:str=None		,			_A					:Dict=True		,			_A					:Optional[int]=[0.5, 0.5, 0.5]		,			_A					:List[Any]=[0.5, 0.5, 0.5]		,			)			->     List[Any]:







       '''simple docstring'''



       __A    		=     size if size is not None else {'height': 18, 'width': 18}
       __A    		=     parent
       __A    		=     batch_size
       __A    		=     num_channels
       __A    		=     image_size
       __A    		=     min_resolution
       __A    		=     max_resolution
       __A    		=     do_resize
       __A    		=     size
       __A    		=     do_normalize
       __A    		=     image_mean
       __A    		=     image_std






 def 		lowercase_  (     self					:List[str]     )			->     Union[str, Any]:







       '''simple docstring'''



       return {
           "image_mean": self.image_mean,
           "image_std": self.image_std,
           "do_normalize": self.do_normalize,
           "do_resize": self.do_resize,
           "size": self.size,
       }


@require_torch
@require_vision
class 	UpperCamelCase__					(      A__ ,       unittest.TestCase):
 UpperCAmelCase__      :      Dict  			=   EfficientNetImageProcessor if is_vision_available() else None






 def 		lowercase_  (     self					:Optional[int]     )			->     str:







       '''simple docstring'''



       __A    		=     EfficientNetImageProcessorTester(self     )






 @property
 def 		lowercase_  (     self					:int     )			->     int:







       '''simple docstring'''



       return self.image_processor_tester.prepare_image_processor_dict()






 def 		lowercase_  (     self					:Optional[Any]     )			->     Dict:







       '''simple docstring'''



       __A    		=     self.image_processing_class(**self.image_processor_dict     )
       self.assertTrue(hasattr(snake_case_		,			'image_mean'     )     )
       self.assertTrue(hasattr(snake_case_		,			'image_std'     )     )
       self.assertTrue(hasattr(snake_case_		,			'do_normalize'     )     )
       self.assertTrue(hasattr(snake_case_		,			'do_resize'     )     )
       self.assertTrue(hasattr(snake_case_		,			'size'     )     )






 def 		lowercase_  (     self					:List[str]     )			->     Union[str, Any]:







       '''simple docstring'''



       __A    		=     self.image_processing_class.from_dict(self.image_processor_dict     )
       self.assertEqual(image_processor.size		,			{'height': 18, 'width': 18}     )

       __A    		=     self.image_processing_class.from_dict(self.image_processor_dict		,			size=42     )
       self.assertEqual(image_processor.size		,			{'height': 42, 'width': 42}     )






 def 		lowercase_  (     self					:List[str]     )			->     Union[str, Any]:







       '''simple docstring'''



       __A    		=     self.image_processing_class(**self.image_processor_dict     )
       # create random PIL images
       __A    		=     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
       __A    		=     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.size['height'],
               self.image_processor_tester.size['width'],
           )		,			)

       # Test batched
       __A    		=     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.size['height'],
               self.image_processor_tester.size['width'],
           )		,			)






 def 		lowercase_  (     self					:List[Any]     )			->     int:







       '''simple docstring'''



       __A    		=     self.image_processing_class(**self.image_processor_dict     )
       # create random numpy tensors
       __A    		=     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
       __A    		=     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.size['height'],
               self.image_processor_tester.size['width'],
           )		,			)

       # Test batched
       __A    		=     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.size['height'],
               self.image_processor_tester.size['width'],
           )		,			)






 def 		lowercase_  (     self					:Optional[Any]     )			->     Union[str, Any]:







       '''simple docstring'''



       __A    		=     self.image_processing_class(**self.image_processor_dict     )
       # create random PyTorch tensors
       __A    		=     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
       __A    		=     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.size['height'],
               self.image_processor_tester.size['width'],
           )		,			)

       # Test batched
       __A    		=     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.size['height'],
               self.image_processor_tester.size['width'],
           )		,			)








'''simple docstring'''





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






 def 		lowercase_  (     self					:Optional[int]     )			->     List[Any]:







       '''simple docstring'''



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

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

       __A    		=     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     )






