


"""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,
    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


__SCREAMING_SNAKE_CASE							:      Dict						=      logging.get_logger(__name__)





class        __A       (snake_case__):





							'''simple docstring'''

							__lowercase:						Tuple							 =      ["""pixel_values"""]



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



														"""simple docstring"""



														super().__init__(**UpperCAmelCase_    )
														snake_case_          =						size if size is not None else {"""shortest_edge""": 256}
														snake_case_          =						get_size_dict(UpperCAmelCase_						,    default_to_square=UpperCAmelCase_    )
														snake_case_          =						crop_size if crop_size is not None else {"""height""": 224, """width""": 224}
														snake_case_          =						get_size_dict(UpperCAmelCase_						,    param_name="""crop_size"""    )
														snake_case_          =						do_resize
														snake_case_          =						size
														snake_case_          =						resample
														snake_case_          =						do_center_crop
														snake_case_          =						crop_size
														snake_case_          =						do_rescale
														snake_case_          =						rescale_factor
														snake_case_          =						do_normalize
														snake_case_          =						image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
														snake_case_          =						image_std if image_std is not None else IMAGENET_STANDARD_STD



							def 						lowerCAmelCase    (			self							: Optional[int]						,    UpperCAmelCase_							: np.ndarray						,    UpperCAmelCase_							: Dict[str, int]						,    UpperCAmelCase_							: PILImageResampling = PILImageResampling.BICUBIC						,    UpperCAmelCase_							: Optional[Union[str, ChannelDimension]] = None						,    **UpperCAmelCase_							: Optional[Any]						,    )   ->np.ndarray:



														"""simple docstring"""



														snake_case_          =						get_size_dict(UpperCAmelCase_						,    default_to_square=UpperCAmelCase_    )
														if "shortest_edge" not in size:
																					raise ValueError(F"""The `size` parameter must contain the key `shortest_edge`. Got {size.keys()}"""    )
														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 						lowerCAmelCase    (			self							: Dict						,    UpperCAmelCase_							: np.ndarray						,    UpperCAmelCase_							: Dict[str, int]						,    UpperCAmelCase_							: Optional[Union[str, ChannelDimension]] = None						,    **UpperCAmelCase_							: Union[str, Any]						,    )   ->np.ndarray:



														"""simple docstring"""



														snake_case_          =						get_size_dict(UpperCAmelCase_    )
														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(UpperCAmelCase_						,    size=(size["""height"""], size["""width"""])						,    data_format=UpperCAmelCase_						,    **UpperCAmelCase_    )



							def 						lowerCAmelCase    (			self							: str						,    UpperCAmelCase_							: np.ndarray						,    UpperCAmelCase_							: float						,    UpperCAmelCase_							: Optional[Union[str, ChannelDimension]] = None						,    **UpperCAmelCase_							: Dict    )   ->np.ndarray:



														"""simple docstring"""



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



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



														"""simple docstring"""



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



							def 						lowerCAmelCase    (			self							: Optional[Any]						,    UpperCAmelCase_							: ImageInput						,    UpperCAmelCase_							: Optional[bool] = None						,    UpperCAmelCase_							: Dict[str, int] = None						,    UpperCAmelCase_							: PILImageResampling = None						,    UpperCAmelCase_							: bool = None						,    UpperCAmelCase_							: Dict[str, int] = None						,    UpperCAmelCase_							: Optional[bool] = None						,    UpperCAmelCase_							: Optional[float] = None						,    UpperCAmelCase_							: Optional[bool] = None						,    UpperCAmelCase_							: Optional[Union[float, List[float]]] = None						,    UpperCAmelCase_							: Optional[Union[float, List[float]]] = None						,    UpperCAmelCase_							: Optional[Union[str, TensorType]] = None						,    UpperCAmelCase_							: Union[str, ChannelDimension] = ChannelDimension.FIRST						,    **UpperCAmelCase_							: Any						,    )   ->Optional[Any]:



														"""simple docstring"""



														snake_case_          =						do_resize if do_resize is not None else self.do_resize
														snake_case_          =						size if size is not None else self.size
														snake_case_          =						get_size_dict(UpperCAmelCase_						,    default_to_square=UpperCAmelCase_    )
														snake_case_          =						resample if resample is not None else self.resample
														snake_case_          =						do_center_crop if do_center_crop is not None else self.do_center_crop
														snake_case_          =						crop_size if crop_size is not None else self.crop_size
														snake_case_          =						get_size_dict(UpperCAmelCase_						,    param_name="""crop_size"""    )
														snake_case_          =						do_rescale if do_rescale is not None else self.do_rescale
														snake_case_          =						rescale_factor if rescale_factor is not None else self.rescale_factor
														snake_case_          =						do_normalize if do_normalize is not None else self.do_normalize
														snake_case_          =						image_mean if image_mean is not None else self.image_mean
														snake_case_          =						image_std if image_std is not None else self.image_std

														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_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.
														snake_case_          =						[to_numpy_array(UpperCAmelCase_    ) for image in images]

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

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

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

														if do_normalize:
																					snake_case_          =						[self.normalize(image=UpperCAmelCase_						,    mean=UpperCAmelCase_						,    std=UpperCAmelCase_    ) for image in images]

														snake_case_          =						[to_channel_dimension_format(UpperCAmelCase_						,    UpperCAmelCase_    ) for image in images]

														snake_case_          =						{"""pixel_values""": images}
														return BatchFeature(data=UpperCAmelCase_						,    tensor_type=UpperCAmelCase_    )



							def 						lowerCAmelCase    (			self							: Any						,    UpperCAmelCase_							: Tuple						,    UpperCAmelCase_							: List[Tuple] = None    )   ->Dict:



														"""simple docstring"""



														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_    ):
																												snake_case_          =						target_sizes.numpy()

																					snake_case_          =						[]

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

														return semantic_segmentation







"""simple docstring"""
# NOTE: This file is deprecated and will be removed in a future version.
# It only exists so that temporarely `from diffusers.pipelines import DiffusionPipeline` works

from ...utils import deprecate
from ..controlnet.pipeline_flax_controlnet import FlaxStableDiffusionControlNetPipeline  # noqa: F401


deprecate(
    'stable diffusion controlnet',
    '0.22.0',
    'Importing `FlaxStableDiffusionControlNetPipeline` from diffusers.pipelines.stable_diffusion.flax_pipeline_stable_diffusion_controlnet is deprecated. Please import `from diffusers import FlaxStableDiffusionControlNetPipeline` instead.',
    standard_warn=False,
    stacklevel=3,
)



