





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,
    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,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_torch_available, is_torch_tensor, logging


if is_torch_available():
							import torch


UpperCAmelCase_							=				logging.get_logger(__name__)
class     UpperCamelCase__					(     __lowercase				):






		'''simple docstring'''






		__a       :       int       =	["""pixel_values"""]






		def __init__(							self,   snake_case__ = True,   snake_case__ = None,   snake_case__ = PILImageResampling.BILINEAR,   snake_case__ = True,   snake_case__ = None,   snake_case__ = True,   snake_case__ = 1 / 2_55,   snake_case__ = True,   snake_case__ = None,   snake_case__ = None,   **snake_case__,   )       -> Tuple:






									"""simple docstring"""
									super().__init__(**SCREAMING_SNAKE_CASE_  )
									lowercase_	:   Optional[Any]  				=     size if size is not None else {"""shortest_edge""": 2_56}
									lowercase_	:   Union[str, Any]  				=     get_size_dict(SCREAMING_SNAKE_CASE_,   default_to_square=SCREAMING_SNAKE_CASE_  )
									lowercase_	:   List[Any]  				=     crop_size if crop_size is not None else {"""height""": 2_24, """width""": 2_24}
									lowercase_	:   Optional[int]  				=     get_size_dict(SCREAMING_SNAKE_CASE_,   param_name="""crop_size"""  )
									lowercase_	:   Optional[Any]  				=     do_resize
									lowercase_	:   Optional[Any]  				=     size
									lowercase_	:   str  				=     resample
									lowercase_	:   Optional[Any]  				=     do_center_crop
									lowercase_	:   Union[str, Any]  				=     crop_size
									lowercase_	:   Any  				=     do_rescale
									lowercase_	:   Optional[int]  				=     rescale_factor
									lowercase_	:   int  				=     do_normalize
									lowercase_	:   str  				=     image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
									lowercase_	:   Union[str, Any]  				=     image_std if image_std is not None else IMAGENET_STANDARD_STD






		def 						snake_case__				(							self,   snake_case__,   snake_case__,   snake_case__ = PILImageResampling.BICUBIC,   snake_case__ = None,   **snake_case__,   )       -> Optional[int]:






									"""simple docstring"""
									lowercase_	:   int  				=     get_size_dict(SCREAMING_SNAKE_CASE_,   default_to_square=SCREAMING_SNAKE_CASE_  )
									if "shortest_edge" not in size:
																raise ValueError(f"""The `size` parameter must contain the key `shortest_edge`. Got {size.keys()}"""  )
									lowercase_	:   Union[str, Any]  				=     get_resize_output_image_size(SCREAMING_SNAKE_CASE_,   size=size["""shortest_edge"""],   default_to_square=SCREAMING_SNAKE_CASE_  )
									return resize(SCREAMING_SNAKE_CASE_,   size=SCREAMING_SNAKE_CASE_,   resample=SCREAMING_SNAKE_CASE_,   data_format=SCREAMING_SNAKE_CASE_,   **SCREAMING_SNAKE_CASE_  )






		def 						snake_case__				(							self,   snake_case__,   snake_case__,   snake_case__ = None,   **snake_case__,   )       -> Union[str, Any]:






									"""simple docstring"""
									lowercase_	:   Tuple  				=     get_size_dict(SCREAMING_SNAKE_CASE_  )
									if "height" not in size or "width" not in size:
																raise ValueError(f"""The `size` parameter must contain the keys `height` and `width`. Got {size.keys()}"""  )
									return center_crop(SCREAMING_SNAKE_CASE_,   size=(size["""height"""], size["""width"""]),   data_format=SCREAMING_SNAKE_CASE_,   **SCREAMING_SNAKE_CASE_  )






		def 						snake_case__				(							self,   snake_case__,   snake_case__,   snake_case__ = None,   **snake_case__  )       -> Any:






									"""simple docstring"""
									return rescale(SCREAMING_SNAKE_CASE_,   scale=SCREAMING_SNAKE_CASE_,   data_format=SCREAMING_SNAKE_CASE_,   **SCREAMING_SNAKE_CASE_  )






		def 						snake_case__				(							self,   snake_case__,   snake_case__,   snake_case__,   snake_case__ = None,   **snake_case__,   )       -> Optional[int]:






									"""simple docstring"""
									return normalize(SCREAMING_SNAKE_CASE_,   mean=SCREAMING_SNAKE_CASE_,   std=SCREAMING_SNAKE_CASE_,   data_format=SCREAMING_SNAKE_CASE_,   **SCREAMING_SNAKE_CASE_  )






		def 						snake_case__				(							self,   snake_case__,   snake_case__ = None,   snake_case__ = None,   snake_case__ = None,   snake_case__ = None,   snake_case__ = None,   snake_case__ = None,   snake_case__ = None,   snake_case__ = None,   snake_case__ = None,   snake_case__ = None,   snake_case__ = None,   snake_case__ = ChannelDimension.FIRST,   **snake_case__,   )       -> int:






									"""simple docstring"""
									lowercase_	:   int  				=     do_resize if do_resize is not None else self.do_resize
									lowercase_	:   Union[str, Any]  				=     size if size is not None else self.size
									lowercase_	:   List[str]  				=     get_size_dict(SCREAMING_SNAKE_CASE_,   default_to_square=SCREAMING_SNAKE_CASE_  )
									lowercase_	:   Any  				=     resample if resample is not None else self.resample
									lowercase_	:   Optional[int]  				=     do_center_crop if do_center_crop is not None else self.do_center_crop
									lowercase_	:   str  				=     crop_size if crop_size is not None else self.crop_size
									lowercase_	:   Union[str, Any]  				=     get_size_dict(SCREAMING_SNAKE_CASE_,   param_name="""crop_size"""  )
									lowercase_	:   Optional[int]  				=     do_rescale if do_rescale is not None else self.do_rescale
									lowercase_	:   Union[str, Any]  				=     rescale_factor if rescale_factor is not None else self.rescale_factor
									lowercase_	:   str  				=     do_normalize if do_normalize is not None else self.do_normalize
									lowercase_	:   Any  				=     image_mean if image_mean is not None else self.image_mean
									lowercase_	:   List[str]  				=     image_std if image_std is not None else self.image_std

									lowercase_	:   Tuple  				=     make_list_of_images(SCREAMING_SNAKE_CASE_  )

									if not valid_images(SCREAMING_SNAKE_CASE_  ):
																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_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."""  )

									# All transformations expect numpy arrays.
									lowercase_	:   List[str]  				=     [to_numpy_array(SCREAMING_SNAKE_CASE_  ) for image in images]

									if do_resize:
																lowercase_	:   Union[str, Any]  				=     [self.resize(image=SCREAMING_SNAKE_CASE_,   size=SCREAMING_SNAKE_CASE_,   resample=SCREAMING_SNAKE_CASE_  ) for image in images]

									if do_center_crop:
																lowercase_	:   int  				=     [self.center_crop(image=SCREAMING_SNAKE_CASE_,   size=SCREAMING_SNAKE_CASE_  ) for image in images]

									if do_rescale:
																lowercase_	:   int  				=     [self.rescale(image=SCREAMING_SNAKE_CASE_,   scale=SCREAMING_SNAKE_CASE_  ) for image in images]

									if do_normalize:
																lowercase_	:   Union[str, Any]  				=     [self.normalize(image=SCREAMING_SNAKE_CASE_,   mean=SCREAMING_SNAKE_CASE_,   std=SCREAMING_SNAKE_CASE_  ) for image in images]

									lowercase_	:   List[str]  				=     [to_channel_dimension_format(SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_  ) for image in images]

									lowercase_	:   Any  				=     {"""pixel_values""": images}
									return BatchFeature(data=SCREAMING_SNAKE_CASE_,   tensor_type=SCREAMING_SNAKE_CASE_  )






		def 						snake_case__				(							self,   snake_case__,   snake_case__ = None  )       -> str:






									"""simple docstring"""
									lowercase_	:   Optional[Any]  				=     outputs.logits

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

																if is_torch_tensor(SCREAMING_SNAKE_CASE_  ):
																							lowercase_	:   Union[str, Any]  				=     target_sizes.numpy()

																lowercase_	:   Union[str, Any]  				=     []

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

									return semantic_segmentation

"""simple docstring"""




from ..utils import (
    OptionalDependencyNotAvailable,
    is_flax_available,
    is_scipy_available,
    is_torch_available,
    is_torchsde_available,
)


try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						from ..utils.dummy_pt_objects import *  # noqa F403
else:
						from .scheduling_consistency_models import CMStochasticIterativeScheduler
						from .scheduling_ddim import DDIMScheduler
						from .scheduling_ddim_inverse import DDIMInverseScheduler
						from .scheduling_ddim_parallel import DDIMParallelScheduler
						from .scheduling_ddpm import DDPMScheduler
						from .scheduling_ddpm_parallel import DDPMParallelScheduler
						from .scheduling_deis_multistep import DEISMultistepScheduler
						from .scheduling_dpmsolver_multistep import DPMSolverMultistepScheduler
						from .scheduling_dpmsolver_multistep_inverse import DPMSolverMultistepInverseScheduler
						from .scheduling_dpmsolver_singlestep import DPMSolverSinglestepScheduler
						from .scheduling_euler_ancestral_discrete import EulerAncestralDiscreteScheduler
						from .scheduling_euler_discrete import EulerDiscreteScheduler
						from .scheduling_heun_discrete import HeunDiscreteScheduler
						from .scheduling_ipndm import IPNDMScheduler
						from .scheduling_k_dpm_2_ancestral_discrete import KDPMaAncestralDiscreteScheduler
						from .scheduling_k_dpm_2_discrete import KDPMaDiscreteScheduler
						from .scheduling_karras_ve import KarrasVeScheduler
						from .scheduling_pndm import PNDMScheduler
						from .scheduling_repaint import RePaintScheduler
						from .scheduling_sde_ve import ScoreSdeVeScheduler
						from .scheduling_sde_vp import ScoreSdeVpScheduler
						from .scheduling_unclip import UnCLIPScheduler
						from .scheduling_unipc_multistep import UniPCMultistepScheduler
						from .scheduling_utils import KarrasDiffusionSchedulers, SchedulerMixin
						from .scheduling_vq_diffusion import VQDiffusionScheduler

try:
						if not is_flax_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						from ..utils.dummy_flax_objects import *  # noqa F403
else:
						from .scheduling_ddim_flax import FlaxDDIMScheduler
						from .scheduling_ddpm_flax import FlaxDDPMScheduler
						from .scheduling_dpmsolver_multistep_flax import FlaxDPMSolverMultistepScheduler
						from .scheduling_karras_ve_flax import FlaxKarrasVeScheduler
						from .scheduling_lms_discrete_flax import FlaxLMSDiscreteScheduler
						from .scheduling_pndm_flax import FlaxPNDMScheduler
						from .scheduling_sde_ve_flax import FlaxScoreSdeVeScheduler
						from .scheduling_utils_flax import (
						    FlaxKarrasDiffusionSchedulers,
						    FlaxSchedulerMixin,
						    FlaxSchedulerOutput,
						    broadcast_to_shape_from_left,
						)


try:
						if not (is_torch_available() and is_scipy_available()):
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						from ..utils.dummy_torch_and_scipy_objects import *  # noqa F403
else:
						from .scheduling_lms_discrete import LMSDiscreteScheduler

try:
						if not (is_torch_available() and is_torchsde_available()):
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						from ..utils.dummy_torch_and_torchsde_objects import *  # noqa F403
else:
						from .scheduling_dpmsolver_sde import DPMSolverSDEScheduler