
'''simple docstring'''



import inspect
from typing import List, Optional, Union

import torch
from torch import nn
from torch.nn import functional as F
from torchvision import transforms
from transformers import CLIPImageProcessor, CLIPModel, CLIPTextModel, CLIPTokenizer

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    DiffusionPipeline,
    DPMSolverMultistepScheduler,
    LMSDiscreteScheduler,
    PNDMScheduler,
    UNetaDConditionModel,
)
from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion import StableDiffusionPipelineOutput




class   UpperCAmelCase_     (		nn.Module ):






						'''simple docstring'''






						def __init__(					self    ,   _lowercase    ,   _lowercase=1.0      ):

												"""simple docstring"""



												super().__init__()

												_lowerCAmelCase  						= cut_size
												_lowerCAmelCase  						= cut_power




						def 					_lowercase	(					self    ,   _lowercase    ,   _lowercase      ):

												"""simple docstring"""



												_lowerCAmelCase  						= pixel_values.shape[2:4]
												_lowerCAmelCase  						= min(A_    ,   A_      )
												_lowerCAmelCase  						= min(A_    ,   A_    ,   self.cut_size      )
												_lowerCAmelCase  						= []
												for _ in range(A_      ):
																		_lowerCAmelCase  						= int(torch.rand([]      ) ** self.cut_power * (max_size - min_size) + min_size      )
																		_lowerCAmelCase  						= torch.randint(0    ,   sideX - size + 1    ,   ()      )
																		_lowerCAmelCase  						= torch.randint(0    ,   sideY - size + 1    ,   ()      )
																		_lowerCAmelCase  						= pixel_values[:, :, offsety : offsety + size, offsetx : offsetx + size]
																		cutouts.append(F.adaptive_avg_poolad(A_    ,   self.cut_size      )      )
												return torch.cat(A_      )






def A      (__lowerCamelCase      :Union[str, Any] ,	__lowerCamelCase      :Tuple		):
						_lowerCAmelCase  						= F.normalize(__lowerCamelCase ,	dim=-1		)
						_lowerCAmelCase  						= F.normalize(__lowerCamelCase ,	dim=-1		)
						return (x - y).norm(dim=-1		).div(2		).arcsin().pow(2		).mul(2		)


def A      (__lowerCamelCase      :Optional[Any] ,	__lowerCamelCase      :Optional[Any]		):
						for param in model.parameters():
												_lowerCAmelCase  						= value





class   UpperCAmelCase_     (		_SCREAMING_SNAKE_CASE ):






						'''simple docstring'''






						def __init__(					self    ,   _lowercase    ,   _lowercase    ,   _lowercase    ,   _lowercase    ,   _lowercase    ,   _lowercase    ,   _lowercase    ,   ):

												"""simple docstring"""



												super().__init__()
												self.register_modules(
												    vae=A_    ,   text_encoder=A_    ,   clip_model=A_    ,   tokenizer=A_    ,   unet=A_    ,   scheduler=A_    ,   feature_extractor=A_    ,   )

												_lowerCAmelCase  						= transforms.Normalize(mean=feature_extractor.image_mean    ,   std=feature_extractor.image_std      )
												_lowerCAmelCase  						= (
												    feature_extractor.size
												    if isinstance(feature_extractor.size    ,   A_      )
												    else feature_extractor.size["shortest_edge"]
												)
												_lowerCAmelCase  						= MakeCutouts(self.cut_out_size      )

												set_requires_grad(self.text_encoder    ,   A_      )
												set_requires_grad(self.clip_model    ,   A_      )




						def 					_lowercase	(					self    ,   _lowercase = "auto"      ):

												"""simple docstring"""



												if slice_size == "auto":
																		# half the attention head size is usually a good trade-off between
																		# speed and memory
																		_lowerCAmelCase  						= self.unet.config.attention_head_dim // 2
												self.unet.set_attention_slice(A_      )




						def 					_lowercase	(					self      ):

												"""simple docstring"""



												self.enable_attention_slicing(A_      )




						def 					_lowercase	(					self      ):

												"""simple docstring"""



												set_requires_grad(self.vae    ,   A_      )




						def 					_lowercase	(					self      ):

												"""simple docstring"""



												set_requires_grad(self.vae    ,   A_      )




						def 					_lowercase	(					self      ):

												"""simple docstring"""



												set_requires_grad(self.unet    ,   A_      )




						def 					_lowercase	(					self      ):

												"""simple docstring"""



												set_requires_grad(self.unet    ,   A_      )




						@torch.enable_grad()
						def 					_lowercase	(					self    ,   _lowercase    ,   _lowercase    ,   _lowercase    ,   _lowercase    ,   _lowercase    ,   _lowercase    ,   _lowercase    ,   _lowercase    ,   _lowercase=True    ,   ):

												"""simple docstring"""



												_lowerCAmelCase  						= latents.detach().requires_grad_()

												_lowerCAmelCase  						= self.scheduler.scale_model_input(A_    ,   A_      )

												# predict the noise residual
												_lowerCAmelCase  						= self.unet(A_    ,   A_    ,   encoder_hidden_states=A_      ).sample

												if isinstance(self.scheduler    ,   (PNDMScheduler, DDIMScheduler, DPMSolverMultistepScheduler)      ):
																		_lowerCAmelCase  						= self.scheduler.alphas_cumprod[timestep]
																		_lowerCAmelCase  						= 1 - alpha_prod_t
																		# compute predicted original sample from predicted noise also called
																		# "predicted x_0" of formula (12) from https://arxiv.org/pdf/2010.02502.pdf
																		_lowerCAmelCase  						= (latents - beta_prod_t ** 0.5 * noise_pred) / alpha_prod_t ** 0.5

																		_lowerCAmelCase  						= torch.sqrt(A_      )
																		_lowerCAmelCase  						= pred_original_sample * (fac) + latents * (1 - fac)
												elif isinstance(self.scheduler    ,   A_      ):
																		_lowerCAmelCase  						= self.scheduler.sigmas[index]
																		_lowerCAmelCase  						= latents - sigma * noise_pred
												else:
																		raise ValueError(F'scheduler type {type(self.scheduler      )} not supported'      )

												_lowerCAmelCase  						= 1 / self.vae.config.scaling_factor * sample
												_lowerCAmelCase  						= self.vae.decode(A_      ).sample
												_lowerCAmelCase  						= (image / 2 + 0.5).clamp(0    ,   1      )

												if use_cutouts:
																		_lowerCAmelCase  						= self.make_cutouts(A_    ,   A_      )
												else:
																		_lowerCAmelCase  						= transforms.Resize(self.cut_out_size      )(A_      )
												_lowerCAmelCase  						= self.normalize(A_      ).to(latents.dtype      )

												_lowerCAmelCase  						= self.clip_model.get_image_features(A_      )
												_lowerCAmelCase  						= image_embeddings_clip / image_embeddings_clip.norm(p=2    ,   dim=-1    ,   keepdim=A_      )

												if use_cutouts:
																		_lowerCAmelCase  						= spherical_dist_loss(A_    ,   A_      )
																		_lowerCAmelCase  						= dists.view([num_cutouts, sample.shape[0], -1]      )
																		_lowerCAmelCase  						= dists.sum(2      ).mean(0      ).sum() * clip_guidance_scale
												else:
																		_lowerCAmelCase  						= spherical_dist_loss(A_    ,   A_      ).mean() * clip_guidance_scale

												_lowerCAmelCase  						= -torch.autograd.grad(A_    ,   A_      )[0]

												if isinstance(self.scheduler    ,   A_      ):
																		_lowerCAmelCase  						= latents.detach() + grads * (sigma**2)
																		_lowerCAmelCase  						= noise_pred_original
												else:
																		_lowerCAmelCase  						= noise_pred_original - torch.sqrt(A_      ) * grads
												return noise_pred, latents




						@torch.no_grad()
						def __call__(					self    ,   _lowercase    ,   _lowercase = 512    ,   _lowercase = 512    ,   _lowercase = 50    ,   _lowercase = 7.5    ,   _lowercase = 1    ,   _lowercase = 0.0    ,   _lowercase = 100    ,   _lowercase = None    ,   _lowercase = 4    ,   _lowercase = True    ,   _lowercase = None    ,   _lowercase = None    ,   _lowercase = "pil"    ,   _lowercase = True    ,   ):

												"""simple docstring"""



												if isinstance(A_    ,   A_      ):
																		_lowerCAmelCase  						= 1
												elif isinstance(A_    ,   A_      ):
																		_lowerCAmelCase  						= len(A_      )
												else:
																		raise ValueError(F'`prompt` has to be of type `str` or `list` but is {type(A_      )}'      )

												if height % 8 != 0 or width % 8 != 0:
																		raise ValueError(F'`height` and `width` have to be divisible by 8 but are {height} and {width}.'      )

												# get prompt text embeddings
												_lowerCAmelCase  						= self.tokenizer(
												    A_    ,   padding="""max_length"""    ,   max_length=self.tokenizer.model_max_length    ,   truncation=A_    ,   return_tensors="""pt"""    ,   )
												_lowerCAmelCase  						= self.text_encoder(text_input.input_ids.to(self.device      )      )[0]
												# duplicate text embeddings for each generation per prompt
												_lowerCAmelCase  						= text_embeddings.repeat_interleave(A_    ,   dim=0      )

												if clip_guidance_scale > 0:
																		if clip_prompt is not None:
																								_lowerCAmelCase  						= self.tokenizer(
																								    A_    ,   padding="""max_length"""    ,   max_length=self.tokenizer.model_max_length    ,   truncation=A_    ,   return_tensors="""pt"""    ,   ).input_ids.to(self.device      )
																		else:
																								_lowerCAmelCase  						= text_input.input_ids.to(self.device      )
																		_lowerCAmelCase  						= self.clip_model.get_text_features(A_      )
																		_lowerCAmelCase  						= text_embeddings_clip / text_embeddings_clip.norm(p=2    ,   dim=-1    ,   keepdim=A_      )
																		# duplicate text embeddings clip for each generation per prompt
																		_lowerCAmelCase  						= text_embeddings_clip.repeat_interleave(A_    ,   dim=0      )

												# here `guidance_scale` is defined analog to the guidance weight `w` of equation (2)
												# of the Imagen paper: https://arxiv.org/pdf/2205.11487.pdf . `guidance_scale = 1`
												# corresponds to doing no classifier free guidance.
												_lowerCAmelCase  						= guidance_scale > 1.0
												# get unconditional embeddings for classifier free guidance
												if do_classifier_free_guidance:
																		_lowerCAmelCase  						= text_input.input_ids.shape[-1]
																		_lowerCAmelCase  						= self.tokenizer([""""""]    ,   padding="""max_length"""    ,   max_length=A_    ,   return_tensors="""pt"""      )
																		_lowerCAmelCase  						= self.text_encoder(uncond_input.input_ids.to(self.device      )      )[0]
																		# duplicate unconditional embeddings for each generation per prompt
																		_lowerCAmelCase  						= uncond_embeddings.repeat_interleave(A_    ,   dim=0      )

																		# For classifier free guidance, we need to do two forward passes.
																		# Here we concatenate the unconditional and text embeddings into a single batch
																		# to avoid doing two forward passes
																		_lowerCAmelCase  						= torch.cat([uncond_embeddings, text_embeddings]      )

												# get the initial random noise unless the user supplied it

												# Unlike in other pipelines, latents need to be generated in the target device
												# for 1-to-1 results reproducibility with the CompVis implementation.
												# However this currently doesn't work in `mps`.
												_lowerCAmelCase  						= (batch_size * num_images_per_prompt, self.unet.config.in_channels, height // 8, width // 8)
												_lowerCAmelCase  						= text_embeddings.dtype
												if latents is None:
																		if self.device.type == "mps":
																								# randn does not work reproducibly on mps
																								_lowerCAmelCase  						= torch.randn(A_    ,   generator=A_    ,   device="""cpu"""    ,   dtype=A_      ).to(
																								    self.device      )
																		else:
																								_lowerCAmelCase  						= torch.randn(A_    ,   generator=A_    ,   device=self.device    ,   dtype=A_      )
												else:
																		if latents.shape != latents_shape:
																								raise ValueError(F'Unexpected latents shape, got {latents.shape}, expected {latents_shape}'      )
																		_lowerCAmelCase  						= latents.to(self.device      )

												# set timesteps
												_lowerCAmelCase  						= "offset" in set(inspect.signature(self.scheduler.set_timesteps      ).parameters.keys()      )
												_lowerCAmelCase  						= {}
												if accepts_offset:
																		_lowerCAmelCase  						= 1

												self.scheduler.set_timesteps(A_    ,   **A_      )

												# Some schedulers like PNDM have timesteps as arrays
												# It's more optimized to move all timesteps to correct device beforehand
												_lowerCAmelCase  						= self.scheduler.timesteps.to(self.device      )

												# scale the initial noise by the standard deviation required by the scheduler
												_lowerCAmelCase  						= latents * self.scheduler.init_noise_sigma

												# prepare extra kwargs for the scheduler step, since not all schedulers have the same signature
												# eta (η) is only used with the DDIMScheduler, it will be ignored for other schedulers.
												# eta corresponds to η in DDIM paper: https://arxiv.org/abs/2010.02502
												# and should be between [0, 1]
												_lowerCAmelCase  						= "eta" in set(inspect.signature(self.scheduler.step      ).parameters.keys()      )
												_lowerCAmelCase  						= {}
												if accepts_eta:
																		_lowerCAmelCase  						= eta

												# check if the scheduler accepts generator
												_lowerCAmelCase  						= "generator" in set(inspect.signature(self.scheduler.step      ).parameters.keys()      )
												if accepts_generator:
																		_lowerCAmelCase  						= generator

												for i, t in enumerate(self.progress_bar(A_      )      ):
																		# expand the latents if we are doing classifier free guidance
																		_lowerCAmelCase  						= torch.cat([latents] * 2      ) if do_classifier_free_guidance else latents
																		_lowerCAmelCase  						= self.scheduler.scale_model_input(A_    ,   A_      )

																		# predict the noise residual
																		_lowerCAmelCase  						= self.unet(A_    ,   A_    ,   encoder_hidden_states=A_      ).sample

																		# perform classifier free guidance
																		if do_classifier_free_guidance:
																								_lowerCAmelCase  						= noise_pred.chunk(2      )
																								_lowerCAmelCase  						= noise_pred_uncond + guidance_scale * (noise_pred_text - noise_pred_uncond)

																		# perform clip guidance
																		if clip_guidance_scale > 0:
																								_lowerCAmelCase  						= (
																								    text_embeddings.chunk(2      )[1] if do_classifier_free_guidance else text_embeddings
																								)
																								_lowerCAmelCase  						= self.cond_fn(
																								    A_    ,   A_    ,   A_    ,   A_    ,   A_    ,   A_    ,   A_    ,   A_    ,   A_    ,   )

																		# compute the previous noisy sample x_t -> x_t-1
																		_lowerCAmelCase  						= self.scheduler.step(A_    ,   A_    ,   A_    ,   **A_      ).prev_sample

												# scale and decode the image latents with vae
												_lowerCAmelCase  						= 1 / self.vae.config.scaling_factor * latents
												_lowerCAmelCase  						= self.vae.decode(A_      ).sample

												_lowerCAmelCase  						= (image / 2 + 0.5).clamp(0    ,   1      )
												_lowerCAmelCase  						= image.cpu().permute(0    ,   2    ,   3    ,   1      ).numpy()

												if output_type == "pil":
																		_lowerCAmelCase  						= self.numpy_to_pil(A_      )

												if not return_dict:
																		return (image, None)

												return StableDiffusionPipelineOutput(images=A_    ,   nsfw_content_detected=A_      )



from typing import Dict, List, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    get_resize_output_image_size,
    normalize,
    pad,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    get_image_size,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, logging
from ...utils.import_utils import is_vision_available


SCREAMING_SNAKE_CASE_						=					logging.get_logger(__name__)


if is_vision_available():
					import PIL

class  a     (		UpperCAmelCase ):
						_lowercase			  =	["pixel_values"]


						def __init__(				self  ,    A_ = True  ,    A_ = None  ,    A_ = PILImageResampling.BILINEAR  ,    A_ = True  ,    A_ = False  ,    A_ = True  ,    A_ = True  ,    A_ = 1 / 255  ,    A_ = True  ,    A_ = None  ,    A_ = None  ,    **A_  ,    ):







										'''simple docstring'''


										super().__init__(**A_		)

										_UpperCAmelCase				:						str       						=			size if size is not None else {"height": 2560, "width": 1920}
										if isinstance(A_  ,    (tuple, list)		):
														# The previous feature extractor size parameter was in (width, height) format
														_UpperCAmelCase				:						List[Any]       						=			size[::-1]
										_UpperCAmelCase				:						Dict       						=			get_size_dict(A_		)

										_UpperCAmelCase				:						int       						=			do_resize
										_UpperCAmelCase				:						Dict       						=			size
										_UpperCAmelCase				:						List[Any]       						=			resample
										_UpperCAmelCase				:						Union[str, Any]       						=			do_thumbnail
										_UpperCAmelCase				:						Optional[int]       						=			do_align_long_axis
										_UpperCAmelCase				:						Optional[Any]       						=			do_pad
										_UpperCAmelCase				:						int       						=			do_rescale
										_UpperCAmelCase				:						List[Any]       						=			rescale_factor
										_UpperCAmelCase				:						Union[str, Any]       						=			do_normalize
										_UpperCAmelCase				:						Any       						=			image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
										_UpperCAmelCase				:						Dict       						=			image_std if image_std is not None else IMAGENET_STANDARD_STD


						def 				_UpperCAmelCase (				self  ,    A_  ,    A_  ,    A_ = None		):







										'''simple docstring'''


										_UpperCAmelCase						,							_UpperCAmelCase				:						List[str]       						=			get_image_size(A_		)
										_UpperCAmelCase						,							_UpperCAmelCase				:						Any       						=			size["height"], size["width"]

										if (output_width < output_height and input_width > input_height) or (
										    output_width > output_height and input_width < input_height
										):
														_UpperCAmelCase				:						Optional[int]       						=			np.rotaa(A_  ,    3		)

										if data_format is not None:
														_UpperCAmelCase				:						List[str]       						=			to_channel_dimension_format(A_  ,    A_		)

										return image


						def 				_UpperCAmelCase (				self  ,    A_  ,    A_  ,    A_ = False  ,    A_ = None  ,    ):







										'''simple docstring'''


										_UpperCAmelCase						,							_UpperCAmelCase				:						Optional[Any]       						=			size["height"], size["width"]
										_UpperCAmelCase						,							_UpperCAmelCase				:						List[Any]       						=			get_image_size(A_		)

										_UpperCAmelCase				:						Optional[Any]       						=			output_width - input_width
										_UpperCAmelCase				:						Any       						=			output_height - input_height

										if random_padding:
														_UpperCAmelCase				:						List[str]       						=			np.random.randint(low=0  ,    high=delta_height + 1		)
														_UpperCAmelCase				:						Optional[int]       						=			np.random.randint(low=0  ,    high=delta_width + 1		)
										else:
														_UpperCAmelCase				:						Union[str, Any]       						=			delta_height // 2
														_UpperCAmelCase				:						str       						=			delta_width // 2

										_UpperCAmelCase				:						Optional[Any]       						=			delta_height - pad_top
										_UpperCAmelCase				:						List[Any]       						=			delta_width - pad_left

										_UpperCAmelCase				:						Optional[Any]       						=			((pad_top, pad_bottom), (pad_left, pad_right))
										return pad(A_  ,    A_  ,    data_format=A_		)


						def 				_UpperCAmelCase (				self  ,    *A_  ,    **A_		):







										'''simple docstring'''


										logger.info("pad is deprecated and will be removed in version 4.27. Please use pad_image instead."		)
										return self.pad_image(*A_  ,    **A_		)


						def 				_UpperCAmelCase (				self  ,    A_  ,    A_  ,    A_ = PILImageResampling.BICUBIC  ,    A_ = None  ,    **A_  ,    ):







										'''simple docstring'''


										_UpperCAmelCase						,							_UpperCAmelCase				:						Union[str, Any]       						=			get_image_size(A_		)
										_UpperCAmelCase						,							_UpperCAmelCase				:						Union[str, Any]       						=			size["height"], size["width"]

										# We always resize to the smallest of either the input or output size.
										_UpperCAmelCase				:						Dict       						=			min(A_  ,    A_		)
										_UpperCAmelCase				:						Tuple       						=			min(A_  ,    A_		)

										if height == input_height and width == input_width:
														return image

										if input_height > input_width:
														_UpperCAmelCase				:						Any       						=			int(input_width * height / input_height		)
										elif input_width > input_height:
														_UpperCAmelCase				:						Any       						=			int(input_height * width / input_width		)

										return resize(
										    A_  ,    size=(height, width)  ,    resample=A_  ,    reducing_gap=2.0  ,    data_format=A_  ,    **A_		)


						def 				_UpperCAmelCase (				self  ,    A_  ,    A_  ,    A_ = PILImageResampling.BICUBIC  ,    A_ = None  ,    **A_  ,    ):







										'''simple docstring'''


										_UpperCAmelCase				:						Any       						=			get_size_dict(A_		)
										_UpperCAmelCase				:						List[str]       						=			min(size["height"]  ,    size["width"]		)
										_UpperCAmelCase				:						Optional[Any]       						=			get_resize_output_image_size(A_  ,    size=A_  ,    default_to_square=A_		)
										_UpperCAmelCase				:						str       						=			resize(A_  ,    size=A_  ,    resample=A_  ,    data_format=A_  ,    **A_		)
										return resized_image


						def 				_UpperCAmelCase (				self  ,    A_  ,    A_  ,    A_ = None  ,    **A_  ,    ):







										'''simple docstring'''


										return rescale(A_  ,    scale=A_  ,    data_format=A_  ,    **A_		)


						def 				_UpperCAmelCase (				self  ,    A_  ,    A_  ,    A_  ,    A_ = None  ,    **A_  ,    ):







										'''simple docstring'''


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





						def 				_UpperCAmelCase (				self  ,    A_  ,    A_ = None  ,    A_ = None  ,    A_ = None  ,    A_ = None  ,    A_ = None  ,    A_ = None  ,    A_ = False  ,    A_ = None  ,    A_ = None  ,    A_ = None  ,    A_ = None  ,    A_ = None  ,    A_ = None  ,    A_ = ChannelDimension.FIRST  ,    **A_  ,    ):







										'''simple docstring'''


										_UpperCAmelCase				:						str       						=			do_resize if do_resize is not None else self.do_resize
										_UpperCAmelCase				:						str       						=			size if size is not None else self.size
										if isinstance(A_  ,    (tuple, list)		):
														# Previous feature extractor had size in (width, height) format
														_UpperCAmelCase				:						List[Any]       						=			size[::-1]
										_UpperCAmelCase				:						Union[str, Any]       						=			get_size_dict(A_		)
										_UpperCAmelCase				:						Dict       						=			resample if resample is not None else self.resample
										_UpperCAmelCase				:						str       						=			do_thumbnail if do_thumbnail is not None else self.do_thumbnail
										_UpperCAmelCase				:						Optional[Any]       						=			do_align_long_axis if do_align_long_axis is not None else self.do_align_long_axis
										_UpperCAmelCase				:						List[str]       						=			do_pad if do_pad is not None else self.do_pad
										_UpperCAmelCase				:						Optional[Any]       						=			do_rescale if do_rescale is not None else self.do_rescale
										_UpperCAmelCase				:						int       						=			rescale_factor if rescale_factor is not None else self.rescale_factor
										_UpperCAmelCase				:						List[str]       						=			do_normalize if do_normalize is not None else self.do_normalize
										_UpperCAmelCase				:						Any       						=			image_mean if image_mean is not None else self.image_mean
										_UpperCAmelCase				:						List[Any]       						=			image_std if image_std is not None else self.image_std

										_UpperCAmelCase				:						str       						=			make_list_of_images(A_		)

										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."		)

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

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

										if do_pad and size is None:
														raise ValueError("Size must be specified if do_pad 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."		)

										# All transformations expect numpy arrays.
										_UpperCAmelCase				:						Union[str, Any]       						=			[to_numpy_array(A_		) for image in images]

										if do_align_long_axis:
														_UpperCAmelCase				:						Tuple       						=			[self.align_long_axis(A_  ,    size=A_		) for image in images]

										if do_resize:
														_UpperCAmelCase				:						Optional[int]       						=			[self.resize(image=A_  ,    size=A_  ,    resample=A_		) for image in images]

										if do_thumbnail:
														_UpperCAmelCase				:						Optional[Any]       						=			[self.thumbnail(image=A_  ,    size=A_		) for image in images]

										if do_pad:
														_UpperCAmelCase				:						List[Any]       						=			[self.pad_image(image=A_  ,    size=A_  ,    random_padding=A_		) for image in images]

										if do_rescale:
														_UpperCAmelCase				:						Tuple       						=			[self.rescale(image=A_  ,    scale=A_		) for image in images]

										if do_normalize:
														_UpperCAmelCase				:						int       						=			[self.normalize(image=A_  ,    mean=A_  ,    std=A_		) for image in images]

										_UpperCAmelCase				:						str       						=			[to_channel_dimension_format(A_  ,    A_		) for image in images]

										_UpperCAmelCase				:						Dict       						=			{"pixel_values": images}
										return BatchFeature(data=A_  ,    tensor_type=A_		)


