


import gc
import unittest

import numpy as np
import torch
from transformers import CLIPTextConfig, CLIPTextModel, CLIPTokenizer

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    EulerAncestralDiscreteScheduler,
    LMSDiscreteScheduler,
    PNDMScheduler,
    StableDiffusionPanoramaPipeline,
    UNetaDConditionModel,
)
from diffusers.utils import slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu, skip_mps

from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS
from ..test_pipelines_common import PipelineLatentTesterMixin, PipelineTesterMixin


enable_full_determinism()

@skip_mps
class 						A__							(		snake_case__   ,     snake_case__   ,     unittest.TestCase  ):
						UpperCAmelCase             =						StableDiffusionPanoramaPipeline
						UpperCAmelCase             =						TEXT_TO_IMAGE_PARAMS
						UpperCAmelCase             =						TEXT_TO_IMAGE_BATCH_PARAMS
						UpperCAmelCase             =						TEXT_TO_IMAGE_IMAGE_PARAMS
						UpperCAmelCase             =						TEXT_TO_IMAGE_IMAGE_PARAMS




						def 							__UpperCamelCase				(       self					:      Dict  )							->     int:


										"""simple docstring"""





										torch.manual_seed(0  )
										_SCREAMING_SNAKE_CASE			  =UNetaDConditionModel(
										    block_out_channels=(32, 64)				,    layers_per_block=1				,    sample_size=32				,    in_channels=4				,    out_channels=4				,    down_block_types=('''DownBlock2D''', '''CrossAttnDownBlock2D''')				,    up_block_types=('''CrossAttnUpBlock2D''', '''UpBlock2D''')				,    cross_attention_dim=32				,    )
										_SCREAMING_SNAKE_CASE			  =DDIMScheduler()
										torch.manual_seed(0  )
										_SCREAMING_SNAKE_CASE			  =AutoencoderKL(
										    block_out_channels=[32, 64]				,    in_channels=3				,    out_channels=3				,    down_block_types=['''DownEncoderBlock2D''', '''DownEncoderBlock2D''']				,    up_block_types=['''UpDecoderBlock2D''', '''UpDecoderBlock2D''']				,    latent_channels=4				,    )
										torch.manual_seed(0  )
										_SCREAMING_SNAKE_CASE			  =CLIPTextConfig(
										    bos_token_id=0				,    eos_token_id=2				,    hidden_size=32				,    intermediate_size=37				,    layer_norm_eps=1E-05				,    num_attention_heads=4				,    num_hidden_layers=5				,    pad_token_id=1				,    vocab_size=1000				,    )
										_SCREAMING_SNAKE_CASE			  =CLIPTextModel(_A  )
										_SCREAMING_SNAKE_CASE			  =CLIPTokenizer.from_pretrained('''hf-internal-testing/tiny-random-clip'''  )

										_SCREAMING_SNAKE_CASE			  ={
										    'unet': unet,
										    'scheduler': scheduler,
										    'vae': vae,
										    'text_encoder': text_encoder,
										    'tokenizer': tokenizer,
										    'safety_checker': None,
										    'feature_extractor': None,
										}
										return components




						def 							__UpperCamelCase				(       self					:      Tuple				,    _a					:      List[str]				,    _a					:      Any=0  )							->     Tuple:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =torch.manual_seed(_A  )
										_SCREAMING_SNAKE_CASE			  ={
										    'prompt': 'a photo of the dolomites',
										    'generator': generator,
										    # Setting height and width to None to prevent OOMs on CPU.
										    'height': None,
										    'width': None,
										    'num_inference_steps': 1,
										    'guidance_scale': 6.0,
										    'output_type': 'numpy',
										}
										return inputs




						def 							__UpperCamelCase				(       self					:      Dict  )							->     Any:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  ='cpu'  # ensure determinism for the device-dependent torch.Generator
										_SCREAMING_SNAKE_CASE			  =self.get_dummy_components()
										_SCREAMING_SNAKE_CASE			  =StableDiffusionPanoramaPipeline(**_A  )
										_SCREAMING_SNAKE_CASE			  =sd_pipe.to(_A  )
										sd_pipe.set_progress_bar_config(disable=_A  )

										_SCREAMING_SNAKE_CASE			  =self.get_dummy_inputs(_A  )
										_SCREAMING_SNAKE_CASE			  =sd_pipe(**_A  ).images
										_SCREAMING_SNAKE_CASE			  =image[0, -3:, -3:, -1]
										assert image.shape == (1, 64, 64, 3)

										_SCREAMING_SNAKE_CASE			  =np.array([0.61_86, 0.53_74, 0.49_15, 0.41_35, 0.41_14, 0.45_63, 0.51_28, 0.49_77, 0.47_57]  )

										assert np.abs(image_slice.flatten() - expected_slice  ).max() < 1E-2




						def 							__UpperCamelCase				(       self					:      Optional[int]  )							->     Dict:


										"""simple docstring"""





										super().test_inference_batch_consistent(batch_sizes=[1, 2]  )




						def 							__UpperCamelCase				(       self					:      Any  )							->     List[str]:


										"""simple docstring"""





										super().test_inference_batch_single_identical(batch_size=2				,    expected_max_diff=3.25E-3  )




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


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  ='cpu'  # ensure determinism for the device-dependent torch.Generator
										_SCREAMING_SNAKE_CASE			  =self.get_dummy_components()
										_SCREAMING_SNAKE_CASE			  =StableDiffusionPanoramaPipeline(**_A  )
										_SCREAMING_SNAKE_CASE			  =sd_pipe.to(_A  )
										sd_pipe.set_progress_bar_config(disable=_A  )

										_SCREAMING_SNAKE_CASE			  =self.get_dummy_inputs(_A  )
										_SCREAMING_SNAKE_CASE			  ='french fries'
										_SCREAMING_SNAKE_CASE			  =sd_pipe(**_A				,    negative_prompt=_A  )
										_SCREAMING_SNAKE_CASE			  =output.images
										_SCREAMING_SNAKE_CASE			  =image[0, -3:, -3:, -1]

										assert image.shape == (1, 64, 64, 3)

										_SCREAMING_SNAKE_CASE			  =np.array([0.61_87, 0.53_75, 0.49_15, 0.41_36, 0.41_14, 0.45_63, 0.51_28, 0.49_76, 0.47_57]  )

										assert np.abs(image_slice.flatten() - expected_slice  ).max() < 1E-2




						def 							__UpperCamelCase				(       self					:      List[str]  )							->     str:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  ='cpu'  # ensure determinism for the device-dependent torch.Generator
										_SCREAMING_SNAKE_CASE			  =self.get_dummy_components()
										_SCREAMING_SNAKE_CASE			  =StableDiffusionPanoramaPipeline(**_A  )
										_SCREAMING_SNAKE_CASE			  =sd_pipe.to(_A  )
										sd_pipe.set_progress_bar_config(disable=_A  )

										_SCREAMING_SNAKE_CASE			  =self.get_dummy_inputs(_A  )
										_SCREAMING_SNAKE_CASE			  =sd_pipe(**_A				,    view_batch_size=2  )
										_SCREAMING_SNAKE_CASE			  =output.images
										_SCREAMING_SNAKE_CASE			  =image[0, -3:, -3:, -1]

										assert image.shape == (1, 64, 64, 3)

										_SCREAMING_SNAKE_CASE			  =np.array([0.61_87, 0.53_75, 0.49_15, 0.41_36, 0.41_14, 0.45_63, 0.51_28, 0.49_76, 0.47_57]  )

										assert np.abs(image_slice.flatten() - expected_slice  ).max() < 1E-2




						def 							__UpperCamelCase				(       self					:      List[Any]  )							->     str:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  ='cpu'  # ensure determinism for the device-dependent torch.Generator
										_SCREAMING_SNAKE_CASE			  =self.get_dummy_components()
										_SCREAMING_SNAKE_CASE			  =EulerAncestralDiscreteScheduler(
										    beta_start=0.0_00_85				,    beta_end=0.0_12				,    beta_schedule='''scaled_linear'''  )
										_SCREAMING_SNAKE_CASE			  =StableDiffusionPanoramaPipeline(**_A  )
										_SCREAMING_SNAKE_CASE			  =sd_pipe.to(_A  )
										sd_pipe.set_progress_bar_config(disable=_A  )

										_SCREAMING_SNAKE_CASE			  =self.get_dummy_inputs(_A  )
										_SCREAMING_SNAKE_CASE			  =sd_pipe(**_A  ).images
										_SCREAMING_SNAKE_CASE			  =image[0, -3:, -3:, -1]

										assert image.shape == (1, 64, 64, 3)

										_SCREAMING_SNAKE_CASE			  =np.array([0.40_24, 0.65_10, 0.49_01, 0.53_78, 0.58_13, 0.56_22, 0.47_95, 0.44_67, 0.49_52]  )

										assert np.abs(image_slice.flatten() - expected_slice  ).max() < 1E-2




						def 							__UpperCamelCase				(       self					:      Tuple  )							->     Union[str, Any]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  ='cpu'  # ensure determinism for the device-dependent torch.Generator
										_SCREAMING_SNAKE_CASE			  =self.get_dummy_components()
										_SCREAMING_SNAKE_CASE			  =PNDMScheduler(
										    beta_start=0.0_00_85				,    beta_end=0.0_12				,    beta_schedule='''scaled_linear'''				,    skip_prk_steps=_A  )
										_SCREAMING_SNAKE_CASE			  =StableDiffusionPanoramaPipeline(**_A  )
										_SCREAMING_SNAKE_CASE			  =sd_pipe.to(_A  )
										sd_pipe.set_progress_bar_config(disable=_A  )

										_SCREAMING_SNAKE_CASE			  =self.get_dummy_inputs(_A  )
										_SCREAMING_SNAKE_CASE			  =sd_pipe(**_A  ).images
										_SCREAMING_SNAKE_CASE			  =image[0, -3:, -3:, -1]

										assert image.shape == (1, 64, 64, 3)

										_SCREAMING_SNAKE_CASE			  =np.array([0.63_91, 0.62_91, 0.48_61, 0.51_34, 0.55_52, 0.45_78, 0.50_32, 0.50_23, 0.45_39]  )

										assert np.abs(image_slice.flatten() - expected_slice  ).max() < 1E-2

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




						def 							__UpperCamelCase				(       self					:      Any  )							->     List[str]:


										"""simple docstring"""





										super().tearDown()
										gc.collect()
										torch.cuda.empty_cache()




						def 							__UpperCamelCase				(       self					:      Optional[Any]				,    _a					:      List[str]=0  )							->     int:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =torch.manual_seed(_A  )
										_SCREAMING_SNAKE_CASE			  ={
										    'prompt': 'a photo of the dolomites',
										    'generator': generator,
										    'num_inference_steps': 3,
										    'guidance_scale': 7.5,
										    'output_type': 'numpy',
										}
										return inputs




						def 							__UpperCamelCase				(       self					:      Tuple  )							->     Any:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  ='stabilityai/stable-diffusion-2-base'
										_SCREAMING_SNAKE_CASE			  =DDIMScheduler.from_pretrained(_A				,    subfolder='''scheduler'''  )
										_SCREAMING_SNAKE_CASE			  =StableDiffusionPanoramaPipeline.from_pretrained(_A				,    scheduler=_A				,    safety_checker=_A  )
										pipe.to(_A  )
										pipe.set_progress_bar_config(disable=_A  )
										pipe.enable_attention_slicing()

										_SCREAMING_SNAKE_CASE			  =self.get_inputs()
										_SCREAMING_SNAKE_CASE			  =pipe(**_A  ).images
										_SCREAMING_SNAKE_CASE			  =image[0, -3:, -3:, -1].flatten()

										assert image.shape == (1, 512, 2048, 3)

										_SCREAMING_SNAKE_CASE			  =np.array(
										    [
										        0.36_96_83_92,
										        0.27_02_53_72,
										        0.32_44_67_66,
										        0.28_37_93_87,
										        0.36_36_32_74,
										        0.30_73_33_47,
										        0.27_10_00_27,
										        0.27_05_41_25,
										        0.25_53_60_96,
										    ]  )

										assert np.abs(expected_slice - image_slice  ).max() < 1E-2




						def 							__UpperCamelCase				(       self					:      Tuple  )							->     List[Any]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =StableDiffusionPanoramaPipeline.from_pretrained(
										    '''stabilityai/stable-diffusion-2-base'''				,    safety_checker=_A  )
										_SCREAMING_SNAKE_CASE			  =LMSDiscreteScheduler.from_config(pipe.scheduler.config  )
										pipe.to(_A  )
										pipe.set_progress_bar_config(disable=_A  )
										pipe.enable_attention_slicing()

										_SCREAMING_SNAKE_CASE			  =self.get_inputs()
										_SCREAMING_SNAKE_CASE			  =pipe(**_A  ).images
										_SCREAMING_SNAKE_CASE			  =image[0, -3:, -3:, -1].flatten()

										assert image.shape == (1, 512, 2048, 3)

										_SCREAMING_SNAKE_CASE			  =np.array(
										    [
										        [
										            0.0,
										            0.0,
										            0.0,
										            0.0,
										            0.0,
										            0.0,
										            0.0,
										            0.0,
										            0.0,
										        ]
										    ]  )

										assert np.abs(expected_slice - image_slice  ).max() < 1E-3




						def 							__UpperCamelCase				(       self					:      str  )							->     Tuple:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =0

										def callback_fn(_a					:      int				,    _a					:      Dict				,    _a					:      Union[str, Any]  ) -> None:
														_SCREAMING_SNAKE_CASE			  =True
														nonlocal number_of_steps
														number_of_steps += 1
														if step == 1:
																		_SCREAMING_SNAKE_CASE			  =latents.detach().cpu().numpy()
																		assert latents.shape == (1, 4, 64, 256)
																		_SCREAMING_SNAKE_CASE			  =latents[0, -3:, -3:, -1]

																		_SCREAMING_SNAKE_CASE			  =np.array(
																		    [
																		        0.18_68_18_69,
																		        0.33_90_78_16,
																		        0.5_36_12_76,
																		        0.14_43_28_65,
																		        -0.02_85_66_11,
																		        -0.73_94_11_23,
																		        0.23_39_79_87,
																		        0.47_32_26_82,
																		        -0.37_82_31_64,
																		    ]  )
																		assert np.abs(latents_slice.flatten() - expected_slice  ).max() < 5E-2
														elif step == 2:
																		_SCREAMING_SNAKE_CASE			  =latents.detach().cpu().numpy()
																		assert latents.shape == (1, 4, 64, 256)
																		_SCREAMING_SNAKE_CASE			  =latents[0, -3:, -3:, -1]

																		_SCREAMING_SNAKE_CASE			  =np.array(
																		    [
																		        0.18_53_96_45,
																		        0.33_98_72_48,
																		        0.5_37_85_59,
																		        0.14_43_71_42,
																		        -0.02_45_52_61,
																		        -0.7_33_83_17,
																		        0.23_99_07_55,
																		        0.47_35_62_72,
																		        -0.3_78_65_05,
																		    ]  )

																		assert np.abs(latents_slice.flatten() - expected_slice  ).max() < 5E-2

										_SCREAMING_SNAKE_CASE			  =False

										_SCREAMING_SNAKE_CASE			  ='stabilityai/stable-diffusion-2-base'
										_SCREAMING_SNAKE_CASE			  =DDIMScheduler.from_pretrained(_A				,    subfolder='''scheduler'''  )
										_SCREAMING_SNAKE_CASE			  =StableDiffusionPanoramaPipeline.from_pretrained(_A				,    scheduler=_A				,    safety_checker=_A  )
										_SCREAMING_SNAKE_CASE			  =pipe.to(_A  )
										pipe.set_progress_bar_config(disable=_A  )
										pipe.enable_attention_slicing()

										_SCREAMING_SNAKE_CASE			  =self.get_inputs()
										pipe(**_A				,    callback=_A				,    callback_steps=1  )
										assert callback_fn.has_been_called
										assert number_of_steps == 3




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


										"""simple docstring"""





										torch.cuda.empty_cache()
										torch.cuda.reset_max_memory_allocated()
										torch.cuda.reset_peak_memory_stats()

										_SCREAMING_SNAKE_CASE			  ='stabilityai/stable-diffusion-2-base'
										_SCREAMING_SNAKE_CASE			  =DDIMScheduler.from_pretrained(_A				,    subfolder='''scheduler'''  )
										_SCREAMING_SNAKE_CASE			  =StableDiffusionPanoramaPipeline.from_pretrained(_A				,    scheduler=_A				,    safety_checker=_A  )
										_SCREAMING_SNAKE_CASE			  =pipe.to(_A  )
										pipe.set_progress_bar_config(disable=_A  )
										pipe.enable_attention_slicing(1  )
										pipe.enable_sequential_cpu_offload()

										_SCREAMING_SNAKE_CASE			  =self.get_inputs()
										_SCREAMING_SNAKE_CASE			  =pipe(**_A  )

										_SCREAMING_SNAKE_CASE			  =torch.cuda.max_memory_allocated()
										# make sure that less than 5.2 GB is allocated
										assert mem_bytes < 5.5 * 10**9





from typing import Dict, List, Optional, Union

import numpy as np

from transformers.utils import is_vision_available
from transformers.utils.generic import TensorType

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    center_crop,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    is_valid_image,
    to_numpy_array,
    valid_images,
)
from ...utils import logging


if is_vision_available():
							import PIL

snake_case_						:			Union[str, Any]													=							logging.get_logger(__name__)







def 						lowerCamelCase(   a__):
				if isinstance(a__	,(list, tuple)) and isinstance(videos[0]	,(list, tuple)) and is_valid_image(videos[0][0]):
								return videos

				elif isinstance(a__	,(list, tuple)) and is_valid_image(videos[0]):
								return [videos]

				elif is_valid_image(a__):
								return [[videos]]

				raise ValueError(f"Could not make batched video from {videos}")


class 						A__							(		UpperCamelCase__  ):
						UpperCAmelCase             =						["pixel_values"]




						def __init__(       self					:      Tuple				,    _a					:      bool = True				,    _a					:      Dict[str, int] = None				,    _a					:      PILImageResampling = PILImageResampling.BILINEAR				,    _a					:      bool = True				,    _a					:      Dict[str, int] = None				,    _a					:      bool = True				,    _a					:      Union[int, float] = 1 / 255				,    _a					:      bool = True				,    _a					:      bool = True				,    _a					:      Optional[Union[float, List[float]]] = None				,    _a					:      Optional[Union[float, List[float]]] = None				,    **_a					:      Any				,    )							->     None:


										"""simple docstring"""





										super().__init__(**_a  )
										_SCREAMING_SNAKE_CASE			  =size if size is not None else {'''shortest_edge''': 256}
										_SCREAMING_SNAKE_CASE			  =get_size_dict(_a				,    default_to_square=_a  )
										_SCREAMING_SNAKE_CASE			  =crop_size if crop_size is not None else {'''height''': 224, '''width''': 224}
										_SCREAMING_SNAKE_CASE			  =get_size_dict(_a				,    param_name='''crop_size'''  )

										_SCREAMING_SNAKE_CASE			  =do_resize
										_SCREAMING_SNAKE_CASE			  =size
										_SCREAMING_SNAKE_CASE			  =do_center_crop
										_SCREAMING_SNAKE_CASE			  =crop_size
										_SCREAMING_SNAKE_CASE			  =resample
										_SCREAMING_SNAKE_CASE			  =do_rescale
										_SCREAMING_SNAKE_CASE			  =rescale_factor
										_SCREAMING_SNAKE_CASE			  =offset
										_SCREAMING_SNAKE_CASE			  =do_normalize
										_SCREAMING_SNAKE_CASE			  =image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
										_SCREAMING_SNAKE_CASE			  =image_std if image_std is not None else IMAGENET_STANDARD_STD




						def 							__UpperCamelCase				(       self					:      List[Any]				,    _a					:      np.ndarray				,    _a					:      Dict[str, int]				,    _a					:      PILImageResampling = PILImageResampling.BILINEAR				,    _a					:      Optional[Union[str, ChannelDimension]] = None				,    **_a					:      List[Any]				,    )							->     np.ndarray:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =get_size_dict(_a				,    default_to_square=_a  )
										if "shortest_edge" in size:
														_SCREAMING_SNAKE_CASE			  =get_resize_output_image_size(_a				,    size['''shortest_edge''']				,    default_to_square=_a  )
										elif "height" in size and "width" in size:
														_SCREAMING_SNAKE_CASE			  =(size['''height'''], size['''width'''])
										else:
														raise ValueError(f"Size must have 'height' and 'width' or 'shortest_edge' as keys. Got {size.keys()}"  )
										return resize(_a				,    size=_a				,    resample=_a				,    data_format=_a				,    **_a  )




						def 							__UpperCamelCase				(       self					:      int				,    _a					:      np.ndarray				,    _a					:      Dict[str, int]				,    _a					:      Optional[Union[str, ChannelDimension]] = None				,    **_a					:      Dict				,    )							->     np.ndarray:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =get_size_dict(_a  )
										if "height" not in size or "width" not in size:
														raise ValueError(f"Size must have 'height' and 'width' as keys. Got {size.keys()}"  )
										return center_crop(_a				,    size=(size['''height'''], size['''width'''])				,    data_format=_a				,    **_a  )




						def 							__UpperCamelCase				(       self					:      Dict				,    _a					:      np.ndarray				,    _a					:      Union[int, float]				,    _a					:      bool = True				,    _a					:      Optional[Union[str, ChannelDimension]] = None				,    **_a					:      List[str]				,    )							->     Tuple:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =image.astype(np.floataa  )
										if offset:
														_SCREAMING_SNAKE_CASE			  =image - (scale / 2)
										return rescale(_a				,    scale=_a				,    data_format=_a				,    **_a  )




						def 							__UpperCamelCase				(       self					:      List[str]				,    _a					:      np.ndarray				,    _a					:      Union[float, List[float]]				,    _a					:      Union[float, List[float]]				,    _a					:      Optional[Union[str, ChannelDimension]] = None				,    **_a					:      Any				,    )							->     np.ndarray:


										"""simple docstring"""





										return normalize(_a				,    mean=_a				,    std=_a				,    data_format=_a				,    **_a  )




						def 							__UpperCamelCase				(       self					:      Tuple				,    _a					:      ImageInput				,    _a					:      bool = None				,    _a					:      Dict[str, int] = None				,    _a					:      PILImageResampling = None				,    _a					:      bool = None				,    _a					:      Dict[str, int] = None				,    _a					:      bool = None				,    _a					:      float = None				,    _a					:      bool = None				,    _a					:      bool = None				,    _a					:      Optional[Union[float, List[float]]] = None				,    _a					:      Optional[Union[float, List[float]]] = None				,    _a					:      Optional[ChannelDimension] = ChannelDimension.FIRST				,    )							->     np.ndarray:


										"""simple docstring"""





										if do_resize and size is None or resample is None:
														raise ValueError('''Size and resample must be specified if do_resize is True.'''  )

										if do_center_crop and crop_size is None:
														raise ValueError('''Crop size must be specified if do_center_crop is True.'''  )

										if do_rescale and rescale_factor is None:
														raise ValueError('''Rescale factor must be specified if do_rescale is True.'''  )

										if do_normalize and (image_mean is None or image_std is None):
														raise ValueError('''Image mean and std must be specified if do_normalize is True.'''  )

										if offset and not do_rescale:
														raise ValueError('''For offset, do_rescale must also be set to True.'''  )

										# All transformations expect numpy arrays.
										_SCREAMING_SNAKE_CASE			  =to_numpy_array(_a  )

										if do_resize:
														_SCREAMING_SNAKE_CASE			  =self.resize(image=_a				,    size=_a				,    resample=_a  )

										if do_center_crop:
														_SCREAMING_SNAKE_CASE			  =self.center_crop(_a				,    size=_a  )

										if do_rescale:
														_SCREAMING_SNAKE_CASE			  =self.rescale(image=_a				,    scale=_a				,    offset=_a  )

										if do_normalize:
														_SCREAMING_SNAKE_CASE			  =self.normalize(image=_a				,    mean=_a				,    std=_a  )

										_SCREAMING_SNAKE_CASE			  =to_channel_dimension_format(_a				,    _a  )
										return image




						def 							__UpperCamelCase				(       self					:      Tuple				,    _a					:      ImageInput				,    _a					:      bool = None				,    _a					:      Dict[str, int] = None				,    _a					:      PILImageResampling = None				,    _a					:      bool = None				,    _a					:      Dict[str, int] = None				,    _a					:      bool = None				,    _a					:      float = None				,    _a					:      bool = None				,    _a					:      bool = None				,    _a					:      Optional[Union[float, List[float]]] = None				,    _a					:      Optional[Union[float, List[float]]] = None				,    _a					:      Optional[Union[str, TensorType]] = None				,    _a					:      ChannelDimension = ChannelDimension.FIRST				,    **_a					:      str				,    )							->     PIL.Image.Image:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =do_resize if do_resize is not None else self.do_resize
										_SCREAMING_SNAKE_CASE			  =resample if resample is not None else self.resample
										_SCREAMING_SNAKE_CASE			  =do_center_crop if do_center_crop is not None else self.do_center_crop
										_SCREAMING_SNAKE_CASE			  =do_rescale if do_rescale is not None else self.do_rescale
										_SCREAMING_SNAKE_CASE			  =rescale_factor if rescale_factor is not None else self.rescale_factor
										_SCREAMING_SNAKE_CASE			  =offset if offset is not None else self.offset
										_SCREAMING_SNAKE_CASE			  =do_normalize if do_normalize is not None else self.do_normalize
										_SCREAMING_SNAKE_CASE			  =image_mean if image_mean is not None else self.image_mean
										_SCREAMING_SNAKE_CASE			  =image_std if image_std is not None else self.image_std

										_SCREAMING_SNAKE_CASE			  =size if size is not None else self.size
										_SCREAMING_SNAKE_CASE			  =get_size_dict(_a				,    default_to_square=_a  )
										_SCREAMING_SNAKE_CASE			  =crop_size if crop_size is not None else self.crop_size
										_SCREAMING_SNAKE_CASE			  =get_size_dict(_a				,    param_name='''crop_size'''  )

										if not valid_images(_a  ):
														raise ValueError(
														    '''Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, '''
														    '''torch.Tensor, tf.Tensor or jax.ndarray.'''  )

										_SCREAMING_SNAKE_CASE			  =make_batched(_a  )

										_SCREAMING_SNAKE_CASE			  =[
										    [
										        self._preprocess_image(
										            image=_a				,    do_resize=_a				,    size=_a				,    resample=_a				,    do_center_crop=_a				,    crop_size=_a				,    do_rescale=_a				,    rescale_factor=_a				,    offset=_a				,    do_normalize=_a				,    image_mean=_a				,    image_std=_a				,    data_format=_a				,    )
										        for img in video
										    ]
										    for video in videos
										]

										_SCREAMING_SNAKE_CASE			  ={'''pixel_values''': videos}
										return BatchFeature(data=_a				,    tensor_type=_a  )