


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


A				:       List[Any]      =  logging.get_logger(__name__)


if is_vision_available():
	import PIL






class      UpperCamelCase(	UpperCamelCase__ ):
					snake_case_		:					str    					=						["""pixel_values"""]


					def __init__(    self						:		List[Any]  ,     SCREAMING_SNAKE_CASE						:		Tuple = True  ,     SCREAMING_SNAKE_CASE						:		str = None  ,     SCREAMING_SNAKE_CASE						:		int = PILImageResampling.BICUBIC  ,     SCREAMING_SNAKE_CASE						:		List[Any] = True  ,     SCREAMING_SNAKE_CASE						:		Tuple = None  ,     SCREAMING_SNAKE_CASE						:		List[Any] = True  ,     SCREAMING_SNAKE_CASE						:		List[Any] = 1 / 2_5_5  ,     SCREAMING_SNAKE_CASE						:		Union[str, Any] = True  ,     SCREAMING_SNAKE_CASE						:		Any = None  ,     SCREAMING_SNAKE_CASE						:		Union[str, Any] = None  ,     SCREAMING_SNAKE_CASE						:		Union[str, Any] = True  ,     **SCREAMING_SNAKE_CASE						:		List[Any]  ,     )      ->						List[str]:




											'''simple docstring'''

											super().__init__(**__lowerCamelCase    )
											__snake_case				=		size if size is not None else {"shortest_edge": 2_2_4}
											__snake_case				=		get_size_dict(__lowerCamelCase  ,     default_to_square=__lowerCamelCase    )
											__snake_case				=		crop_size if crop_size is not None else {"height": 2_2_4, "width": 2_2_4}
											__snake_case				=		get_size_dict(__lowerCamelCase  ,     default_to_square=__lowerCamelCase  ,     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 OPENAI_CLIP_MEAN
											__snake_case				=		image_std if image_std is not None else OPENAI_CLIP_STD
											__snake_case				=		do_convert_rgb


					def 				SCREAMING_SNAKE_CASE_	(    self						:		Tuple  ,     SCREAMING_SNAKE_CASE						:		int  ,     SCREAMING_SNAKE_CASE						:		Dict  ,     SCREAMING_SNAKE_CASE						:		Optional[Any] = PILImageResampling.BICUBIC  ,     SCREAMING_SNAKE_CASE						:		List[str] = None  ,     **SCREAMING_SNAKE_CASE						:		int  ,     )      ->						List[str]:




											'''simple docstring'''

											__snake_case				=		get_size_dict(__lowerCamelCase  ,     default_to_square=__lowerCamelCase    )
											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(__lowerCamelCase  ,     size=size["shortest_edge"]  ,     default_to_square=__lowerCamelCase    )
											return resize(__lowerCamelCase  ,     size=__lowerCamelCase  ,     resample=__lowerCamelCase  ,     data_format=__lowerCamelCase  ,     **__lowerCamelCase    )


					def 				SCREAMING_SNAKE_CASE_	(    self						:		Tuple  ,     SCREAMING_SNAKE_CASE						:		Any  ,     SCREAMING_SNAKE_CASE						:		str  ,     SCREAMING_SNAKE_CASE						:		int = None  ,     **SCREAMING_SNAKE_CASE						:		Dict  ,     )      ->						Optional[Any]:




											'''simple docstring'''

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


					def 				SCREAMING_SNAKE_CASE_	(    self						:		List[Any]  ,     SCREAMING_SNAKE_CASE						:		List[Any]  ,     SCREAMING_SNAKE_CASE						:		int  ,     SCREAMING_SNAKE_CASE						:		Dict = None  ,     **SCREAMING_SNAKE_CASE						:		Optional[Any]  ,     )      ->						Tuple:




											'''simple docstring'''

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


					def 				SCREAMING_SNAKE_CASE_	(    self						:		List[str]  ,     SCREAMING_SNAKE_CASE						:		Optional[Any]  ,     SCREAMING_SNAKE_CASE						:		str  ,     SCREAMING_SNAKE_CASE						:		Union[str, Any]  ,     SCREAMING_SNAKE_CASE						:		Union[str, Any] = None  ,     **SCREAMING_SNAKE_CASE						:		Tuple  ,     )      ->						Optional[int]:




											'''simple docstring'''

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






					def 				SCREAMING_SNAKE_CASE_	(    self						:		List[str]  ,     SCREAMING_SNAKE_CASE						:		Optional[int]  ,     SCREAMING_SNAKE_CASE						:		int = None  ,     SCREAMING_SNAKE_CASE						:		List[str] = None  ,     SCREAMING_SNAKE_CASE						:		Dict = None  ,     SCREAMING_SNAKE_CASE						:		Tuple = None  ,     SCREAMING_SNAKE_CASE						:		Union[str, Any] = None  ,     SCREAMING_SNAKE_CASE						:		Optional[Any] = None  ,     SCREAMING_SNAKE_CASE						:		Union[str, Any] = None  ,     SCREAMING_SNAKE_CASE						:		Optional[int] = None  ,     SCREAMING_SNAKE_CASE						:		int = None  ,     SCREAMING_SNAKE_CASE						:		Tuple = None  ,     SCREAMING_SNAKE_CASE						:		Union[str, Any] = None  ,     SCREAMING_SNAKE_CASE						:		Dict = None  ,     SCREAMING_SNAKE_CASE						:		Union[str, Any] = ChannelDimension.FIRST  ,     **SCREAMING_SNAKE_CASE						:		Optional[Any]  ,     )      ->						List[str]:




											'''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(__lowerCamelCase  ,     param_name="size"  ,     default_to_square=__lowerCamelCase    )
											__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(__lowerCamelCase  ,     param_name="crop_size"  ,     default_to_square=__lowerCamelCase    )
											__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				=		do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

											__snake_case				=		make_list_of_images(__lowerCamelCase    )

											if not valid_images(__lowerCamelCase    ):
																	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:
																	__snake_case				=		[convert_to_rgb(__lowerCamelCase    ) for image in images]

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

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

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

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

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

											__snake_case				=		[to_channel_dimension_format(__lowerCamelCase  ,     __lowerCamelCase    ) for image in images]

											__snake_case				=		{"pixel_values": images}
											return BatchFeature(data=__lowerCamelCase  ,     tensor_type=__lowerCamelCase    )












import copy
from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging
from ..auto import CONFIG_MAPPING


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

a__: Any							   =						{
    'microsoft/conditional-detr-resnet-50': (
        'https://huggingface.co/microsoft/conditional-detr-resnet-50/resolve/main/config.json'
    ),
}




class        SCREAMING_SNAKE_CASE__					(		UpperCamelCase__ ):
 __SCREAMING_SNAKE_CASE							=      '''conditional_detr'''
 __SCREAMING_SNAKE_CASE							=      ['''past_key_values''']
 __SCREAMING_SNAKE_CASE							=      {
     '''hidden_size''': '''d_model''',
     '''num_attention_heads''': '''encoder_attention_heads''',
 }



 def __init__(				self,__lowerCamelCase=True,__lowerCamelCase=None,__lowerCamelCase=3,__lowerCamelCase=300,__lowerCamelCase=6,__lowerCamelCase=2048,__lowerCamelCase=8,__lowerCamelCase=6,__lowerCamelCase=2048,__lowerCamelCase=8,__lowerCamelCase=0.0,__lowerCamelCase=0.0,__lowerCamelCase=True,__lowerCamelCase="relu",__lowerCamelCase=256,__lowerCamelCase=0.1,__lowerCamelCase=0.0,__lowerCamelCase=0.0,__lowerCamelCase=0.02,__lowerCamelCase=1.0,__lowerCamelCase=False,__lowerCamelCase="sine",__lowerCamelCase="resnet50",__lowerCamelCase=True,__lowerCamelCase=False,__lowerCamelCase=2,__lowerCamelCase=5,__lowerCamelCase=2,__lowerCamelCase=1,__lowerCamelCase=1,__lowerCamelCase=2,__lowerCamelCase=5,__lowerCamelCase=2,__lowerCamelCase=0.25,**__lowerCamelCase,):
        if backbone_config is not None and use_timm_backbone:
               raise ValueError('''You can\'t specify both `backbone_config` and `use_timm_backbone`.'''					)

        if not use_timm_backbone:
               if backbone_config is None:
                      logger.info('''`backbone_config` is `None`. Initializing the config with the default `ResNet` backbone.'''					)
                      A__		   =		CONFIG_MAPPING['''resnet'''](out_features=['''stage4''']					)
               elif isinstance(__lowerCamelCase,__lowerCamelCase					):
                      A__		   =		backbone_config.get('''model_type'''					)
                      A__		   =		CONFIG_MAPPING[backbone_model_type]
                      A__		   =		config_class.from_dict(__lowerCamelCase					)

        A__		   =		use_timm_backbone
        A__		   =		backbone_config
        A__		   =		num_channels
        A__		   =		num_queries
        A__		   =		d_model
        A__		   =		encoder_ffn_dim
        A__		   =		encoder_layers
        A__		   =		encoder_attention_heads
        A__		   =		decoder_ffn_dim
        A__		   =		decoder_layers
        A__		   =		decoder_attention_heads
        A__		   =		dropout
        A__		   =		attention_dropout
        A__		   =		activation_dropout
        A__		   =		activation_function
        A__		   =		init_std
        A__		   =		init_xavier_std
        A__		   =		encoder_layerdrop
        A__		   =		decoder_layerdrop
        A__		   =		encoder_layers
        A__		   =		auxiliary_loss
        A__		   =		position_embedding_type
        A__		   =		backbone
        A__		   =		use_pretrained_backbone
        A__		   =		dilation
        # Hungarian matcher
        A__		   =		class_cost
        A__		   =		bbox_cost
        A__		   =		giou_cost
        # Loss coefficients
        A__		   =		mask_loss_coefficient
        A__		   =		dice_loss_coefficient
        A__		   =		cls_loss_coefficient
        A__		   =		bbox_loss_coefficient
        A__		   =		giou_loss_coefficient
        A__		   =		focal_alpha
        super().__init__(is_encoder_decoder=__lowerCamelCase,**__lowerCamelCase					)



 @property
 def 							UpperCamelCase     (				self					):
        return self.encoder_attention_heads



 @property
 def 							UpperCamelCase     (				self					):
        return self.d_model




 def 							UpperCamelCase     (				self					):
        A__		   =		copy.deepcopy(self.__dict__					)
        if self.backbone_config is not None:
               A__		   =		self.backbone_config.to_dict()
        A__		   =		self.__class__.model_type
        return output




class        SCREAMING_SNAKE_CASE__					(		UpperCamelCase__ ):
 __SCREAMING_SNAKE_CASE							=      version.parse('''1.11''' )



 @property
 def 							UpperCamelCase     (				self					):
        return OrderedDict(
            [
                ('''pixel_values''', {0: '''batch''', 1: '''num_channels''', 2: '''height''', 3: '''width'''}),
                ('''pixel_mask''', {0: '''batch'''}),
            ]					)



 @property
 def 							UpperCamelCase     (				self					):
        return 1E-5




 @property
 def 							UpperCamelCase     (				self					):
        return 12





