






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 (
    center_crop,
    convert_to_rgb,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    OPENAI_CLIP_MEAN,
    OPENAI_CLIP_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


UpperCamelCase__     =	logging.get_logger(__name__)


if is_vision_available():
					import PIL

class     __SCREAMING_SNAKE_CASE   (       __lowerCamelCase    ):
							snake_case       : Dict         =    ['pixel_values']






							def __init__(  self					,	__lowerCAmelCase = True					,	__lowerCAmelCase = None					,	__lowerCAmelCase = PILImageResampling.BICUBIC					,	__lowerCAmelCase = True					,	__lowerCAmelCase = None					,	__lowerCAmelCase = True					,	__lowerCAmelCase = 1 / 255					,	__lowerCAmelCase = True					,	__lowerCAmelCase = None					,	__lowerCAmelCase = None					,	__lowerCAmelCase = True					,	**__lowerCAmelCase					,	):
														super().__init__(**UpperCamelCase_					)
														UpperCamelCase__			       =     size if size is not None else {"""shortest_edge""": 224}
														UpperCamelCase__			       =     get_size_dict(UpperCamelCase_					,	default_to_square=UpperCamelCase_					)
														UpperCamelCase__			       =     crop_size if crop_size is not None else {"""height""": 224, """width""": 224}
														UpperCamelCase__			       =     get_size_dict(UpperCamelCase_					,	default_to_square=UpperCamelCase_					,	param_name="""crop_size"""					)

														UpperCamelCase__			       =     do_resize
														UpperCamelCase__			       =     size
														UpperCamelCase__			       =     resample
														UpperCamelCase__			       =     do_center_crop
														UpperCamelCase__			       =     crop_size
														UpperCamelCase__			       =     do_rescale
														UpperCamelCase__			       =     rescale_factor
														UpperCamelCase__			       =     do_normalize
														UpperCamelCase__			       =     image_mean if image_mean is not None else OPENAI_CLIP_MEAN
														UpperCamelCase__			       =     image_std if image_std is not None else OPENAI_CLIP_STD
														UpperCamelCase__			       =     do_convert_rgb






							def 			_lowerCamelCase						(  self					,	__lowerCAmelCase					,	__lowerCAmelCase					,	__lowerCAmelCase = PILImageResampling.BICUBIC					,	__lowerCAmelCase = None					,	**__lowerCAmelCase					,	):
														UpperCamelCase__			       =     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()}"""					)
														UpperCamelCase__			       =     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					,	__lowerCAmelCase					,	__lowerCAmelCase					,	__lowerCAmelCase = None					,	**__lowerCAmelCase					,	):
														UpperCamelCase__			       =     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, width). Got {size.keys()}"""					)
														return center_crop(UpperCamelCase_					,	size=(size["""height"""], size["""width"""])					,	data_format=UpperCamelCase_					,	**UpperCamelCase_					)






							def 			_lowerCamelCase						(  self					,	__lowerCAmelCase					,	__lowerCAmelCase					,	__lowerCAmelCase = None					,	**__lowerCAmelCase					,	):
														return rescale(UpperCamelCase_					,	scale=UpperCamelCase_					,	data_format=UpperCamelCase_					,	**UpperCamelCase_					)






							def 			_lowerCamelCase						(  self					,	__lowerCAmelCase					,	__lowerCAmelCase					,	__lowerCAmelCase					,	__lowerCAmelCase = None					,	**__lowerCAmelCase					,	):
														return normalize(UpperCamelCase_					,	mean=UpperCamelCase_					,	std=UpperCamelCase_					,	data_format=UpperCamelCase_					,	**UpperCamelCase_					)







							def 			_lowerCamelCase						(  self					,	__lowerCAmelCase					,	__lowerCAmelCase = None					,	__lowerCAmelCase = None					,	__lowerCAmelCase = None					,	__lowerCAmelCase = None					,	__lowerCAmelCase = None					,	__lowerCAmelCase = None					,	__lowerCAmelCase = None					,	__lowerCAmelCase = None					,	__lowerCAmelCase = None					,	__lowerCAmelCase = None					,	__lowerCAmelCase = None					,	__lowerCAmelCase = None					,	__lowerCAmelCase = ChannelDimension.FIRST					,	**__lowerCAmelCase					,	):
														UpperCamelCase__			       =     do_resize if do_resize is not None else self.do_resize
														UpperCamelCase__			       =     size if size is not None else self.size
														UpperCamelCase__			       =     get_size_dict(UpperCamelCase_					,	param_name="""size"""					,	default_to_square=UpperCamelCase_					)
														UpperCamelCase__			       =     resample if resample is not None else self.resample
														UpperCamelCase__			       =     do_center_crop if do_center_crop is not None else self.do_center_crop
														UpperCamelCase__			       =     crop_size if crop_size is not None else self.crop_size
														UpperCamelCase__			       =     get_size_dict(UpperCamelCase_					,	param_name="""crop_size"""					,	default_to_square=UpperCamelCase_					)
														UpperCamelCase__			       =     do_rescale if do_rescale is not None else self.do_rescale
														UpperCamelCase__			       =     rescale_factor if rescale_factor is not None else self.rescale_factor
														UpperCamelCase__			       =     do_normalize if do_normalize is not None else self.do_normalize
														UpperCamelCase__			       =     image_mean if image_mean is not None else self.image_mean
														UpperCamelCase__			       =     image_std if image_std is not None else self.image_std
														UpperCamelCase__			       =     do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

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

														# PIL RGBA images are converted to RGB
														if do_convert_rgb:
																					UpperCamelCase__			       =     [convert_to_rgb(UpperCamelCase_					) for image in images]

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

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

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

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

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

														UpperCamelCase__			       =     [to_channel_dimension_format(UpperCamelCase_					,	UpperCamelCase_					) for image in images]

														UpperCamelCase__			       =     {"""pixel_values""": images}
														return BatchFeature(data=UpperCamelCase_					,	tensor_type=UpperCamelCase_					)











import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..auto.configuration_auto import CONFIG_MAPPING


UpperCamelCase__     =	logging.get_logger(__name__)

class     __SCREAMING_SNAKE_CASE   (       _a    ):
							snake_case       : List[Any]         =    """upernet"""






							def __init__(  self					,	__lowerCAmelCase=None					,	__lowerCAmelCase=512					,	__lowerCAmelCase=0.02					,	__lowerCAmelCase=[1, 2, 3, 6]					,	__lowerCAmelCase=True					,	__lowerCAmelCase=0.4					,	__lowerCAmelCase=384					,	__lowerCAmelCase=256					,	__lowerCAmelCase=1					,	__lowerCAmelCase=False					,	__lowerCAmelCase=255					,	**__lowerCAmelCase					,	):
														super().__init__(**__lowerCAmelCase					)

														if backbone_config is None:
																					logger.info("""`backbone_config` is `None`. Initializing the config with the default `ResNet` backbone."""					)
																					UpperCamelCase__			       =     CONFIG_MAPPING["""resnet"""](out_features=["""stage1""", """stage2""", """stage3""", """stage4"""]					)
														elif isinstance(__lowerCAmelCase					,	__lowerCAmelCase					):
																					UpperCamelCase__			       =     backbone_config.get("""model_type"""					)
																					UpperCamelCase__			       =     CONFIG_MAPPING[backbone_model_type]
																					UpperCamelCase__			       =     config_class.from_dict(__lowerCAmelCase					)

														UpperCamelCase__			       =     backbone_config
														UpperCamelCase__			       =     hidden_size
														UpperCamelCase__			       =     initializer_range
														UpperCamelCase__			       =     pool_scales
														UpperCamelCase__			       =     use_auxiliary_head
														UpperCamelCase__			       =     auxiliary_loss_weight
														UpperCamelCase__			       =     auxiliary_in_channels
														UpperCamelCase__			       =     auxiliary_channels
														UpperCamelCase__			       =     auxiliary_num_convs
														UpperCamelCase__			       =     auxiliary_concat_input
														UpperCamelCase__			       =     loss_ignore_index







							def 			_lowerCamelCase						(  self					):
														UpperCamelCase__			       =     copy.deepcopy(self.__dict__					)
														UpperCamelCase__			       =     self.backbone_config.to_dict()
														UpperCamelCase__			       =     self.__class__.model_type
														return output




