


"""simple docstring"""







import gc
import unittest

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

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    PNDMScheduler,
    StableDiffusionLDMaDPipeline,
    UNetaDConditionModel,
)
from diffusers.utils import nightly, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu

from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS


enable_full_determinism()




class 			UpperCamelCase_     (			unittest.TestCase):

	"""simple docstring"""





	snake_case__    :  Tuple    =      StableDiffusionLDMaDPipeline
	snake_case__    :  int    =      TEXT_TO_IMAGE_PARAMS
	snake_case__    :  Optional[int]    =      TEXT_TO_IMAGE_BATCH_PARAMS
	snake_case__    :  List[Any]    =      TEXT_TO_IMAGE_IMAGE_PARAMS




	def   UpperCAmelCase_				(			self      :    Any       )	->     Dict:
						torch.manual_seed(0       )
						__SCREAMING_SNAKE_CASE						       =    UNetaDConditionModel(
						    block_out_channels=(3_2, 6_4)      ,      layers_per_block=2      ,      sample_size=3_2      ,      in_channels=4      ,      out_channels=4      ,      down_block_types=("DownBlock2D", "CrossAttnDownBlock2D")      ,      up_block_types=("CrossAttnUpBlock2D", "UpBlock2D")      ,      cross_attention_dim=3_2      ,      )
						__SCREAMING_SNAKE_CASE						       =    DDIMScheduler(
						    beta_start=0.00_085      ,      beta_end=0.012      ,      beta_schedule="scaled_linear"      ,      clip_sample=UpperCAmelCase__      ,      set_alpha_to_one=UpperCAmelCase__      ,      )
						torch.manual_seed(0       )
						__SCREAMING_SNAKE_CASE						       =    AutoencoderKL(
						    block_out_channels=[3_2, 6_4]      ,      in_channels=6      ,      out_channels=6      ,      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=3_2      ,      intermediate_size=3_7      ,      layer_norm_eps=1E-05      ,      num_attention_heads=4      ,      num_hidden_layers=5      ,      pad_token_id=1      ,      vocab_size=1_0_0_0      ,      )
						__SCREAMING_SNAKE_CASE						       =    CLIPTextModel(UpperCAmelCase__       )
						__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      :    List[Any]      ,      UpperCAmelCase__      :    Union[str, Any]      ,      UpperCAmelCase__      :    Optional[int]=0       )	->     Tuple:
						if str(UpperCAmelCase__       ).startswith("mps"       ):
											__SCREAMING_SNAKE_CASE						       =    torch.manual_seed(UpperCAmelCase__       )
						else:
											__SCREAMING_SNAKE_CASE						       =    torch.Generator(device=UpperCAmelCase__       ).manual_seed(UpperCAmelCase__       )
						__SCREAMING_SNAKE_CASE						       =    {
						    "prompt": "A painting of a squirrel eating a burger",
						    "generator": generator,
						    "num_inference_steps": 2,
						    "guidance_scale": 6.0,
						    "output_type": "numpy",
						}
						return inputs




	def   UpperCAmelCase_				(			self      :    Optional[int]       )	->     Any:
						__SCREAMING_SNAKE_CASE						       =    "cpu"  # ensure determinism for the device-dependent torch.Generator

						__SCREAMING_SNAKE_CASE						       =    self.get_dummy_components()
						__SCREAMING_SNAKE_CASE						       =    StableDiffusionLDMaDPipeline(**UpperCAmelCase__       )
						__SCREAMING_SNAKE_CASE						       =    ldmad_pipe.to(UpperCAmelCase__       )
						ldmad_pipe.set_progress_bar_config(disable=UpperCAmelCase__       )

						__SCREAMING_SNAKE_CASE						       =    self.get_dummy_inputs(UpperCAmelCase__       )
						__SCREAMING_SNAKE_CASE						       =    ldmad_pipe(**UpperCAmelCase__       )
						__SCREAMING_SNAKE_CASE       ,  __SCREAMING_SNAKE_CASE						       =    output.rgb, output.depth

						__SCREAMING_SNAKE_CASE						       =    rgb[0, -3:, -3:, -1]
						__SCREAMING_SNAKE_CASE						       =    depth[0, -3:, -1]

						assert rgb.shape == (1, 6_4, 6_4, 3)
						assert depth.shape == (1, 6_4, 6_4)

						__SCREAMING_SNAKE_CASE						       =    np.array(
						    [0.37_338_176, 0.70_247, 0.74_203_193, 0.51_643_604, 0.58_256_793, 0.60_932_136, 0.4_181_095, 0.48_355_877, 0.46_535_262]       )
						__SCREAMING_SNAKE_CASE						       =    np.array([103.46_727, 85.812_004, 87.849_236]       )

						assert np.abs(image_slice_rgb.flatten() - expected_slice_rgb       ).max() < 1E-2
						assert np.abs(image_slice_depth.flatten() - expected_slice_depth       ).max() < 1E-2




	def   UpperCAmelCase_				(			self      :    List[str]       )	->     Any:
						__SCREAMING_SNAKE_CASE						       =    self.get_dummy_components()
						__SCREAMING_SNAKE_CASE						       =    StableDiffusionLDMaDPipeline(**UpperCAmelCase__       )
						__SCREAMING_SNAKE_CASE						       =    ldmad_pipe.to(UpperCAmelCase__       )
						ldmad_pipe.set_progress_bar_config(disable=UpperCAmelCase__       )

						__SCREAMING_SNAKE_CASE						       =    self.get_dummy_inputs(UpperCAmelCase__       )
						__SCREAMING_SNAKE_CASE						       =    3 * [inputs["prompt"]]

						# forward
						__SCREAMING_SNAKE_CASE						       =    ldmad_pipe(**UpperCAmelCase__       )
						__SCREAMING_SNAKE_CASE       ,  __SCREAMING_SNAKE_CASE						       =    output.rgb, output.depth
						__SCREAMING_SNAKE_CASE						       =    rgb_slice_a[0, -3:, -3:, -1]
						__SCREAMING_SNAKE_CASE						       =    depth_slice_a[0, -3:, -1]

						__SCREAMING_SNAKE_CASE						       =    self.get_dummy_inputs(UpperCAmelCase__       )
						__SCREAMING_SNAKE_CASE						       =    3 * [inputs.pop("prompt"       )]

						__SCREAMING_SNAKE_CASE						       =    ldmad_pipe.tokenizer(
						    UpperCAmelCase__      ,      padding="max_length"      ,      max_length=ldmad_pipe.tokenizer.model_max_length      ,      truncation=UpperCAmelCase__      ,      return_tensors="pt"      ,      )
						__SCREAMING_SNAKE_CASE						       =    text_inputs["input_ids"].to(UpperCAmelCase__       )

						__SCREAMING_SNAKE_CASE						       =    ldmad_pipe.text_encoder(UpperCAmelCase__       )[0]

						__SCREAMING_SNAKE_CASE						       =    prompt_embeds

						# forward
						__SCREAMING_SNAKE_CASE						       =    ldmad_pipe(**UpperCAmelCase__       )
						__SCREAMING_SNAKE_CASE       ,  __SCREAMING_SNAKE_CASE						       =    output.rgb, output.depth
						__SCREAMING_SNAKE_CASE						       =    rgb_slice_a[0, -3:, -3:, -1]
						__SCREAMING_SNAKE_CASE						       =    depth_slice_a[0, -3:, -1]

						assert np.abs(rgb_slice_a.flatten() - rgb_slice_a.flatten()       ).max() < 1E-4
						assert np.abs(depth_slice_a.flatten() - depth_slice_a.flatten()       ).max() < 1E-4




	def   UpperCAmelCase_				(			self      :    Union[str, Any]       )	->     Dict:
						__SCREAMING_SNAKE_CASE						       =    "cpu"  # ensure determinism for the device-dependent torch.Generator
						__SCREAMING_SNAKE_CASE						       =    self.get_dummy_components()
						__SCREAMING_SNAKE_CASE						       =    PNDMScheduler(skip_prk_steps=UpperCAmelCase__       )
						__SCREAMING_SNAKE_CASE						       =    StableDiffusionLDMaDPipeline(**UpperCAmelCase__       )
						__SCREAMING_SNAKE_CASE						       =    ldmad_pipe.to(UpperCAmelCase__       )
						ldmad_pipe.set_progress_bar_config(disable=UpperCAmelCase__       )

						__SCREAMING_SNAKE_CASE						       =    self.get_dummy_inputs(UpperCAmelCase__       )
						__SCREAMING_SNAKE_CASE						       =    "french fries"
						__SCREAMING_SNAKE_CASE						       =    ldmad_pipe(**UpperCAmelCase__      ,      negative_prompt=UpperCAmelCase__       )

						__SCREAMING_SNAKE_CASE       ,  __SCREAMING_SNAKE_CASE						       =    output.rgb, output.depth
						__SCREAMING_SNAKE_CASE						       =    rgb[0, -3:, -3:, -1]
						__SCREAMING_SNAKE_CASE						       =    depth[0, -3:, -1]

						assert rgb.shape == (1, 6_4, 6_4, 3)
						assert depth.shape == (1, 6_4, 6_4)

						__SCREAMING_SNAKE_CASE						       =    np.array(
						    [0.37_044, 0.71_811_503, 0.7_223_251, 0.48_603_675, 0.5_638_391, 0.6_364_948, 0.42_833_704, 0.4_901_315, 0.47_926_217]       )
						__SCREAMING_SNAKE_CASE						       =    np.array([107.84_738, 84.62_802, 89.962_135]       )
						assert np.abs(rgb_slice.flatten() - expected_slice_rgb       ).max() < 1E-2
						assert np.abs(depth_slice.flatten() - expected_slice_depth       ).max() < 1E-2




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

	"""simple docstring"""





	def   UpperCAmelCase_				(			self      :    Tuple       )	->     Dict:
						super().tearDown()
						gc.collect()
						torch.cuda.empty_cache()




	def   UpperCAmelCase_				(			self      :    Any      ,      UpperCAmelCase__      :    List[Any]      ,      UpperCAmelCase__      :    Any="cpu"      ,      UpperCAmelCase__      :    Optional[int]=torch.floataa      ,      UpperCAmelCase__      :    Tuple=0       )	->     Optional[int]:
						__SCREAMING_SNAKE_CASE						       =    torch.Generator(device=UpperCAmelCase__       ).manual_seed(UpperCAmelCase__       )
						__SCREAMING_SNAKE_CASE						       =    np.random.RandomState(UpperCAmelCase__       ).standard_normal((1, 4, 6_4, 6_4)       )
						__SCREAMING_SNAKE_CASE						       =    torch.from_numpy(UpperCAmelCase__       ).to(device=UpperCAmelCase__      ,      dtype=UpperCAmelCase__       )
						__SCREAMING_SNAKE_CASE						       =    {
						    "prompt": "a photograph of an astronaut riding a horse",
						    "latents": latents,
						    "generator": generator,
						    "num_inference_steps": 3,
						    "guidance_scale": 7.5,
						    "output_type": "numpy",
						}
						return inputs




	def   UpperCAmelCase_				(			self      :    Tuple       )	->     Any:
						__SCREAMING_SNAKE_CASE						       =    StableDiffusionLDMaDPipeline.from_pretrained("Intel/ldm3d"       )
						__SCREAMING_SNAKE_CASE						       =    ldmad_pipe.to(UpperCAmelCase__       )
						ldmad_pipe.set_progress_bar_config(disable=UpperCAmelCase__       )

						__SCREAMING_SNAKE_CASE						       =    self.get_inputs(UpperCAmelCase__       )
						__SCREAMING_SNAKE_CASE						       =    ldmad_pipe(**UpperCAmelCase__       )
						__SCREAMING_SNAKE_CASE       ,  __SCREAMING_SNAKE_CASE						       =    output.rgb, output.depth
						__SCREAMING_SNAKE_CASE						       =    rgb[0, -3:, -3:, -1].flatten()
						__SCREAMING_SNAKE_CASE						       =    rgb[0, -3:, -1].flatten()

						assert rgb.shape == (1, 5_1_2, 5_1_2, 3)
						assert depth.shape == (1, 5_1_2, 5_1_2)

						__SCREAMING_SNAKE_CASE						       =    np.array(
						    [0.53_805_465, 0.56_707_305, 0.5_486_515, 0.57_012_236, 0.5_814_511, 0.56_253_487, 0.54_843_014, 0.55_092_263, 0.6_459_706]       )
						__SCREAMING_SNAKE_CASE						       =    np.array(
						    [0.9_263_781, 0.6_678_672, 0.5_486_515, 0.92_202_145, 0.67_831_135, 0.56_253_487, 0.9_241_694, 0.7_551_478, 0.6_459_706]       )
						assert np.abs(rgb_slice - expected_slice_rgb       ).max() < 3E-3
						assert np.abs(depth_slice - expected_slice_depth       ).max() < 3E-3




@nightly
@require_torch_gpu
class 			UpperCamelCase_     (			unittest.TestCase):

	"""simple docstring"""





	def   UpperCAmelCase_				(			self      :    int       )	->     Union[str, Any]:
						super().tearDown()
						gc.collect()
						torch.cuda.empty_cache()




	def   UpperCAmelCase_				(			self      :    Any      ,      UpperCAmelCase__      :    List[Any]      ,      UpperCAmelCase__      :    Optional[int]="cpu"      ,      UpperCAmelCase__      :    Optional[Any]=torch.floataa      ,      UpperCAmelCase__      :    Optional[Any]=0       )	->     Tuple:
						__SCREAMING_SNAKE_CASE						       =    torch.Generator(device=UpperCAmelCase__       ).manual_seed(UpperCAmelCase__       )
						__SCREAMING_SNAKE_CASE						       =    np.random.RandomState(UpperCAmelCase__       ).standard_normal((1, 4, 6_4, 6_4)       )
						__SCREAMING_SNAKE_CASE						       =    torch.from_numpy(UpperCAmelCase__       ).to(device=UpperCAmelCase__      ,      dtype=UpperCAmelCase__       )
						__SCREAMING_SNAKE_CASE						       =    {
						    "prompt": "a photograph of an astronaut riding a horse",
						    "latents": latents,
						    "generator": generator,
						    "num_inference_steps": 5_0,
						    "guidance_scale": 7.5,
						    "output_type": "numpy",
						}
						return inputs




	def   UpperCAmelCase_				(			self      :    List[str]       )	->     Optional[int]:
						__SCREAMING_SNAKE_CASE						       =    StableDiffusionLDMaDPipeline.from_pretrained("Intel/ldm3d"       ).to(UpperCAmelCase__       )
						ldmad_pipe.set_progress_bar_config(disable=UpperCAmelCase__       )

						__SCREAMING_SNAKE_CASE						       =    self.get_inputs(UpperCAmelCase__       )
						__SCREAMING_SNAKE_CASE						       =    ldmad_pipe(**UpperCAmelCase__       )
						__SCREAMING_SNAKE_CASE       ,  __SCREAMING_SNAKE_CASE						       =    output.rgb, output.depth

						__SCREAMING_SNAKE_CASE						       =    0.495_586
						__SCREAMING_SNAKE_CASE						       =    0.33_795_515
						__SCREAMING_SNAKE_CASE						       =    112.48_518
						__SCREAMING_SNAKE_CASE						       =    98.489_746
						assert np.abs(expected_rgb_mean - rgb.mean()       ) < 1E-3
						assert np.abs(expected_rgb_std - rgb.std()       ) < 1E-3
						assert np.abs(expected_depth_mean - depth.mean()       ) < 1E-3
						assert np.abs(expected_depth_std - depth.std()       ) < 1E-3




	def   UpperCAmelCase_				(			self      :    Optional[Any]       )	->     List[str]:
						__SCREAMING_SNAKE_CASE						       =    StableDiffusionLDMaDPipeline.from_pretrained("Intel/ldm3d-4c"       ).to(UpperCAmelCase__       )
						ldmad_pipe.set_progress_bar_config(disable=UpperCAmelCase__       )

						__SCREAMING_SNAKE_CASE						       =    self.get_inputs(UpperCAmelCase__       )
						__SCREAMING_SNAKE_CASE						       =    ldmad_pipe(**UpperCAmelCase__       )
						__SCREAMING_SNAKE_CASE       ,  __SCREAMING_SNAKE_CASE						       =    output.rgb, output.depth

						__SCREAMING_SNAKE_CASE						       =    0.4_194_127
						__SCREAMING_SNAKE_CASE						       =    0.35_375_586
						__SCREAMING_SNAKE_CASE						       =    0.5_638_502
						__SCREAMING_SNAKE_CASE						       =    0.34_686_103

						assert rgb.shape == (1, 5_1_2, 5_1_2, 3)
						assert depth.shape == (1, 5_1_2, 5_1_2, 1)
						assert np.abs(expected_rgb_mean - rgb.mean()       ) < 1E-3
						assert np.abs(expected_rgb_std - rgb.std()       ) < 1E-3
						assert np.abs(expected_depth_mean - depth.mean()       ) < 1E-3
						assert np.abs(expected_depth_std - depth.std()       ) < 1E-3




"""simple docstring"""







from typing import Dict, List, Optional, Tuple, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    center_crop,
    flip_channel_order,
    get_resize_output_image_size,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_torch_available, is_torch_tensor, is_vision_available, logging


if is_vision_available():
		import PIL

if is_torch_available():
		import torch


a__    :							Optional[int]            =					logging.get_logger(__name__)




class 			UpperCamelCase_     (			UpperCamelCase):

	"""simple docstring"""





	snake_case__    :  Optional[Any]    =      ["pixel_values"]




	def __init__(			self      :    Dict      ,      UpperCAmelCase__      :    bool = True      ,      UpperCAmelCase__      :    Dict[str, int] = None      ,      UpperCAmelCase__      :    PILImageResampling = PILImageResampling.BILINEAR      ,      UpperCAmelCase__      :    bool = True      ,      UpperCAmelCase__      :    Union[int, float] = 1 / 2_5_5      ,      UpperCAmelCase__      :    bool = True      ,      UpperCAmelCase__      :    Dict[str, int] = None      ,      UpperCAmelCase__      :    bool = True      ,      **UpperCAmelCase__      :    Dict      ,      )	->     None:
						super().__init__(**UpperCAmelCase__       )
						__SCREAMING_SNAKE_CASE						       =    size if size is not None else {"shortest_edge": 2_2_4}
						__SCREAMING_SNAKE_CASE						       =    get_size_dict(UpperCAmelCase__      ,      default_to_square=UpperCAmelCase__       )
						__SCREAMING_SNAKE_CASE						       =    crop_size if crop_size is not None else {"height": 2_5_6, "width": 2_5_6}
						__SCREAMING_SNAKE_CASE						       =    get_size_dict(UpperCAmelCase__      ,      param_name="crop_size"       )

						__SCREAMING_SNAKE_CASE						       =    do_resize
						__SCREAMING_SNAKE_CASE						       =    size
						__SCREAMING_SNAKE_CASE						       =    resample
						__SCREAMING_SNAKE_CASE						       =    do_rescale
						__SCREAMING_SNAKE_CASE						       =    rescale_factor
						__SCREAMING_SNAKE_CASE						       =    do_center_crop
						__SCREAMING_SNAKE_CASE						       =    crop_size
						__SCREAMING_SNAKE_CASE						       =    do_flip_channel_order




	def   UpperCAmelCase_				(			self      :    Any      ,      UpperCAmelCase__      :    np.ndarray      ,      UpperCAmelCase__      :    Dict[str, int]      ,      UpperCAmelCase__      :    PILImageResampling = PIL.Image.BILINEAR      ,      UpperCAmelCase__      :    Optional[Union[str, ChannelDimension]] = None      ,      **UpperCAmelCase__      :    Optional[Any]      ,      )	->     np.ndarray:
						__SCREAMING_SNAKE_CASE						       =    get_size_dict(UpperCAmelCase__      ,      default_to_square=UpperCAmelCase__       )
						if "shortest_edge" not in size:
											raise ValueError(F"""The `size` dictionary must contain the key `shortest_edge`. Got {size.keys()}"""       )
						__SCREAMING_SNAKE_CASE						       =    get_resize_output_image_size(UpperCAmelCase__      ,      size=size["shortest_edge"]      ,      default_to_square=UpperCAmelCase__       )
						return resize(UpperCAmelCase__      ,      size=UpperCAmelCase__      ,      resample=UpperCAmelCase__      ,      data_format=UpperCAmelCase__      ,      **UpperCAmelCase__       )




	def   UpperCAmelCase_				(			self      :    str      ,      UpperCAmelCase__      :    np.ndarray      ,      UpperCAmelCase__      :    Dict[str, int]      ,      UpperCAmelCase__      :    Optional[Union[str, ChannelDimension]] = None      ,      **UpperCAmelCase__      :    Any      ,      )	->     np.ndarray:
						__SCREAMING_SNAKE_CASE						       =    get_size_dict(UpperCAmelCase__       )
						if "height" not in size or "width" not in size:
											raise ValueError(F"""The `size` dictionary must contain the keys `height` and `width`. Got {size.keys()}"""       )
						return center_crop(UpperCAmelCase__      ,      size=(size["height"], size["width"])      ,      data_format=UpperCAmelCase__      ,      **UpperCAmelCase__       )




	def   UpperCAmelCase_				(			self      :    Optional[int]      ,      UpperCAmelCase__      :    np.ndarray      ,      UpperCAmelCase__      :    Union[int, float]      ,      UpperCAmelCase__      :    Optional[Union[str, ChannelDimension]] = None      ,      **UpperCAmelCase__      :    Dict      ,      )	->     Dict:
						return rescale(UpperCAmelCase__      ,      scale=UpperCAmelCase__      ,      data_format=UpperCAmelCase__      ,      **UpperCAmelCase__       )




	def   UpperCAmelCase_				(			self      :    Optional[int]      ,      UpperCAmelCase__      :    np.ndarray      ,      UpperCAmelCase__      :    Optional[Union[str, ChannelDimension]] = None       )	->     np.ndarray:
						return flip_channel_order(UpperCAmelCase__      ,      data_format=UpperCAmelCase__       )




	def   UpperCAmelCase_				(			self      :    Optional[int]      ,      UpperCAmelCase__      :    ImageInput      ,      UpperCAmelCase__      :    bool = None      ,      UpperCAmelCase__      :    Dict[str, int] = None      ,      UpperCAmelCase__      :    PILImageResampling = None      ,      UpperCAmelCase__      :    bool = None      ,      UpperCAmelCase__      :    float = None      ,      UpperCAmelCase__      :    bool = None      ,      UpperCAmelCase__      :    Dict[str, int] = None      ,      UpperCAmelCase__      :    bool = None      ,      UpperCAmelCase__      :    Optional[Union[str, TensorType]] = None      ,      UpperCAmelCase__      :    ChannelDimension = ChannelDimension.FIRST      ,      **UpperCAmelCase__      :    str      ,      )	->     PIL.Image.Image:
						__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_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						       =    do_center_crop if do_center_crop is not None else self.do_center_crop
						__SCREAMING_SNAKE_CASE						       =    (
						    do_flip_channel_order if do_flip_channel_order is not None else self.do_flip_channel_order
						)

						__SCREAMING_SNAKE_CASE						       =    size if size is not None else self.size
						__SCREAMING_SNAKE_CASE						       =    get_size_dict(UpperCAmelCase__      ,      default_to_square=UpperCAmelCase__       )
						__SCREAMING_SNAKE_CASE						       =    crop_size if crop_size is not None else self.crop_size
						__SCREAMING_SNAKE_CASE						       =    get_size_dict(UpperCAmelCase__      ,      param_name="crop_size"       )

						__SCREAMING_SNAKE_CASE						       =    make_list_of_images(UpperCAmelCase__       )

						if not valid_images(UpperCAmelCase__       ):
											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_center_crop and crop_size is None:
											raise ValueError("Crop size must be specified if do_center_crop is True."       )

						# All transformations expect numpy arrays.
						__SCREAMING_SNAKE_CASE						       =    [to_numpy_array(UpperCAmelCase__       ) for image in images]

						if do_resize:
											__SCREAMING_SNAKE_CASE						       =    [self.resize(image=UpperCAmelCase__      ,      size=UpperCAmelCase__      ,      resample=UpperCAmelCase__       ) for image in images]

						if do_center_crop:
											__SCREAMING_SNAKE_CASE						       =    [self.center_crop(image=UpperCAmelCase__      ,      size=UpperCAmelCase__       ) for image in images]

						if do_rescale:
											__SCREAMING_SNAKE_CASE						       =    [self.rescale(image=UpperCAmelCase__      ,      scale=UpperCAmelCase__       ) for image in images]

						# the pretrained checkpoints assume images are BGR, not RGB
						if do_flip_channel_order:
											__SCREAMING_SNAKE_CASE						       =    [self.flip_channel_order(image=UpperCAmelCase__       ) for image in images]

						__SCREAMING_SNAKE_CASE						       =    [to_channel_dimension_format(UpperCAmelCase__      ,      UpperCAmelCase__       ) for image in images]

						__SCREAMING_SNAKE_CASE						       =    {"pixel_values": images}
						return BatchFeature(data=UpperCAmelCase__      ,      tensor_type=UpperCAmelCase__       )




	def   UpperCAmelCase_				(			self      :    Optional[Any]      ,      UpperCAmelCase__      :    List[Any]      ,      UpperCAmelCase__      :    List[Tuple] = None       )	->     Optional[int]:
						__SCREAMING_SNAKE_CASE						       =    outputs.logits

						# Resize logits and compute semantic segmentation maps
						if target_sizes is not None:
											if len(UpperCAmelCase__       ) != len(UpperCAmelCase__       ):
																raise ValueError(
																    "Make sure that you pass in as many target sizes as the batch dimension of the logits"       )

											if is_torch_tensor(UpperCAmelCase__       ):
																__SCREAMING_SNAKE_CASE						       =    target_sizes.numpy()

											__SCREAMING_SNAKE_CASE						       =    []

											for idx in range(len(UpperCAmelCase__       )       ):
																__SCREAMING_SNAKE_CASE						       =    torch.nn.functional.interpolate(
																    logits[idx].unsqueeze(dim=0       )      ,      size=target_sizes[idx]      ,      mode="bilinear"      ,      align_corners=UpperCAmelCase__       )
																__SCREAMING_SNAKE_CASE						       =    resized_logits[0].argmax(dim=0       )
																semantic_segmentation.append(UpperCAmelCase__       )
						else:
											__SCREAMING_SNAKE_CASE						       =    logits.argmax(dim=1       )
											__SCREAMING_SNAKE_CASE						       =    [semantic_segmentation[i] for i in range(semantic_segmentation.shape[0]       )]

						return semantic_segmentation
