





'''simple docstring'''







import copy

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


snake_case_     :       int						=  logging.get_logger(__name__)

snake_case_     :       str						=  {
    "SenseTime/deformable-detr": "https://huggingface.co/sensetime/deformable-detr/resolve/main/config.json",
    # See all Deformable DETR models at https://huggingface.co/models?filter=deformable-detr
}


class 					__a      (lowerCamelCase     ):
							__a					:   Optional[Any]									=       "deformable_detr"
							__a					:   Optional[Any]									=       {
							    "hidden_size": "d_model",
							    "num_attention_heads": "encoder_attention_heads",
							}

							def __init__(							self							:     List[Any]       ,     __magic_name__							:     str=True       ,     __magic_name__							:     Tuple=None       ,     __magic_name__							:     Optional[Any]=3       ,     __magic_name__							:     int=3_00       ,     __magic_name__							:     str=10_24       ,     __magic_name__							:     List[Any]=6       ,     __magic_name__							:     Dict=10_24       ,     __magic_name__							:     Optional[int]=8       ,     __magic_name__							:     List[Any]=6       ,     __magic_name__							:     Dict=10_24       ,     __magic_name__							:     int=8       ,     __magic_name__							:     Tuple=0.0       ,     __magic_name__							:     Tuple=True       ,     __magic_name__							:     Tuple="relu"       ,     __magic_name__							:     Union[str, Any]=2_56       ,     __magic_name__							:     Dict=0.1       ,     __magic_name__							:     Optional[int]=0.0       ,     __magic_name__							:     Optional[int]=0.0       ,     __magic_name__							:     int=0.0_2       ,     __magic_name__							:     Dict=1.0       ,     __magic_name__							:     Dict=True       ,     __magic_name__							:     str=False       ,     __magic_name__							:     str="sine"       ,     __magic_name__							:     List[Any]="resnet50"       ,     __magic_name__							:     List[str]=True       ,     __magic_name__							:     Optional[int]=False       ,     __magic_name__							:     List[str]=4       ,     __magic_name__							:     List[Any]=4       ,     __magic_name__							:     Optional[Any]=4       ,     __magic_name__							:     List[str]=False       ,     __magic_name__							:     Tuple=3_00       ,     __magic_name__							:     List[str]=False       ,     __magic_name__							:     Optional[int]=1       ,     __magic_name__							:     int=5       ,     __magic_name__							:     Union[str, Any]=2       ,     __magic_name__							:     Optional[int]=1       ,     __magic_name__							:     Tuple=1       ,     __magic_name__							:     Optional[Any]=5       ,     __magic_name__							:     Optional[int]=2       ,     __magic_name__							:     Optional[Any]=0.1       ,     __magic_name__							:     Dict=0.2_5       ,     __magic_name__							:     Tuple=False       ,     **__magic_name__							:     List[Any]       ,     )					->       Tuple:







													"""simple docstring"""
													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.'''   )
																									UpperCAmelCase_			:      Tuple     						=  CONFIG_MAPPING['''resnet'''](out_features=['''stage4''']   )
																			elif isinstance(__magic_name__       ,     __magic_name__   ):
																									UpperCAmelCase_			:      Tuple     						=  backbone_config.get('''model_type'''   )
																									UpperCAmelCase_			:      Optional[int]     						=  CONFIG_MAPPING[backbone_model_type]
																									UpperCAmelCase_			:      Any     						=  config_class.from_dict(__magic_name__   )
													UpperCAmelCase_			:      Dict     						=  use_timm_backbone
													UpperCAmelCase_			:      List[str]     						=  backbone_config
													UpperCAmelCase_			:      Union[str, Any]     						=  num_channels
													UpperCAmelCase_			:      int     						=  num_queries
													UpperCAmelCase_			:      Optional[Any]     						=  max_position_embeddings
													UpperCAmelCase_			:      Dict     						=  d_model
													UpperCAmelCase_			:      Tuple     						=  encoder_ffn_dim
													UpperCAmelCase_			:      List[Any]     						=  encoder_layers
													UpperCAmelCase_			:      Any     						=  encoder_attention_heads
													UpperCAmelCase_			:      List[Any]     						=  decoder_ffn_dim
													UpperCAmelCase_			:      Optional[Any]     						=  decoder_layers
													UpperCAmelCase_			:      Any     						=  decoder_attention_heads
													UpperCAmelCase_			:      Optional[int]     						=  dropout
													UpperCAmelCase_			:      Union[str, Any]     						=  attention_dropout
													UpperCAmelCase_			:      Tuple     						=  activation_dropout
													UpperCAmelCase_			:      Optional[int]     						=  activation_function
													UpperCAmelCase_			:      Dict     						=  init_std
													UpperCAmelCase_			:      int     						=  init_xavier_std
													UpperCAmelCase_			:      List[str]     						=  encoder_layerdrop
													UpperCAmelCase_			:      List[Any]     						=  auxiliary_loss
													UpperCAmelCase_			:      Optional[int]     						=  position_embedding_type
													UpperCAmelCase_			:      Union[str, Any]     						=  backbone
													UpperCAmelCase_			:      Optional[Any]     						=  use_pretrained_backbone
													UpperCAmelCase_			:      Dict     						=  dilation
													# deformable attributes
													UpperCAmelCase_			:      Optional[int]     						=  num_feature_levels
													UpperCAmelCase_			:      str     						=  encoder_n_points
													UpperCAmelCase_			:      Tuple     						=  decoder_n_points
													UpperCAmelCase_			:      Dict     						=  two_stage
													UpperCAmelCase_			:      Optional[int]     						=  two_stage_num_proposals
													UpperCAmelCase_			:      Dict     						=  with_box_refine
													if two_stage is True and with_box_refine is False:
																			raise ValueError('''If two_stage is True, with_box_refine must be True.'''   )
													# Hungarian matcher
													UpperCAmelCase_			:      Union[str, Any]     						=  class_cost
													UpperCAmelCase_			:      List[str]     						=  bbox_cost
													UpperCAmelCase_			:      Dict     						=  giou_cost
													# Loss coefficients
													UpperCAmelCase_			:      Tuple     						=  mask_loss_coefficient
													UpperCAmelCase_			:      int     						=  dice_loss_coefficient
													UpperCAmelCase_			:      Optional[Any]     						=  bbox_loss_coefficient
													UpperCAmelCase_			:      Any     						=  giou_loss_coefficient
													UpperCAmelCase_			:      List[Any]     						=  eos_coefficient
													UpperCAmelCase_			:      Dict     						=  focal_alpha
													UpperCAmelCase_			:      int     						=  disable_custom_kernels
													super().__init__(is_encoder_decoder=__magic_name__       ,     **__magic_name__   )

							@property
							def     UpperCAmelCase__	(							self							:     List[Any]   )					->       int:







													"""simple docstring"""
													return self.encoder_attention_heads

							@property
							def     UpperCAmelCase__	(							self							:     List[Any]   )					->       int:







													"""simple docstring"""
													return self.d_model



							def     UpperCAmelCase__	(							self							:     Optional[Any]   )					->       str:







													"""simple docstring"""
													UpperCAmelCase_			:      int     						=  copy.deepcopy(self.__dict__   )
													if self.backbone_config is not None:
																			UpperCAmelCase_			:      str     						=  self.backbone_config.to_dict()
													UpperCAmelCase_			:      List[Any]     						=  self.__class__.model_type
													return output












'''simple docstring'''







from typing import List, Optional, Union

import numpy as np
import PIL.Image

from ...image_processing_utils import BaseImageProcessor, BatchFeature
from ...image_transforms import rescale, resize, to_channel_dimension_format
from ...image_utils import (
    ChannelDimension,
    PILImageResampling,
    get_image_size,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, logging


snake_case_     :       Union[str, Any]						=  logging.get_logger(__name__)


class 					__a      (lowerCamelCase     ):
							__a					:   Tuple									=       ["pixel_values"]

							def __init__(							self							:     List[Any]       ,     __magic_name__							:     bool = True       ,     __magic_name__							:     int = 32       ,     __magic_name__							:     Union[str, Any]=PILImageResampling.BILINEAR       ,     __magic_name__							:     bool = True       ,     **__magic_name__							:     List[str]       ,     )					->       None:







													"""simple docstring"""
													UpperCAmelCase_			:      int     						=  do_resize
													UpperCAmelCase_			:      Tuple     						=  do_rescale
													UpperCAmelCase_			:      List[Any]     						=  size_divisor
													UpperCAmelCase_			:      Any     						=  resample
													super().__init__(**__magic_name__   )

							def     UpperCAmelCase__	(							self							:     Optional[Any]       ,     __magic_name__							:     np.ndarray       ,     __magic_name__							:     int       ,     __magic_name__							:     str       ,     __magic_name__							:     Optional[ChannelDimension] = None       ,     **__magic_name__							:     Tuple   )					->       np.ndarray:







													"""simple docstring"""
													UpperCAmelCase_						,       UpperCAmelCase_			:      List[str]     						=  get_image_size(__magic_name__   )
													# Rounds the height and width down to the closest multiple of size_divisor
													UpperCAmelCase_			:      Dict     						=  height // size_divisor * size_divisor
													UpperCAmelCase_			:      Dict     						=  width // size_divisor * size_divisor
													UpperCAmelCase_			:      Any     						=  resize(__magic_name__       ,     (new_h, new_w)       ,     resample=__magic_name__       ,     data_format=__magic_name__       ,     **__magic_name__   )
													return image

							def     UpperCAmelCase__	(							self							:     int       ,     __magic_name__							:     np.ndarray       ,     __magic_name__							:     float       ,     __magic_name__							:     Optional[ChannelDimension] = None       ,     **__magic_name__							:     Optional[Any]   )					->       np.ndarray:







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



							def     UpperCAmelCase__	(							self							:     str       ,     __magic_name__							:     Union["PIL.Image.Image", TensorType, List["PIL.Image.Image"], List[TensorType]]       ,     __magic_name__							:     Optional[bool] = None       ,     __magic_name__							:     Optional[int] = None       ,     __magic_name__							:     Any=None       ,     __magic_name__							:     Optional[bool] = None       ,     __magic_name__							:     Optional[Union[TensorType, str]] = None       ,     __magic_name__							:     ChannelDimension = ChannelDimension.FIRST       ,     **__magic_name__							:     Tuple       ,     )					->       BatchFeature:







													"""simple docstring"""
													UpperCAmelCase_			:      Dict     						=  do_resize if do_resize is not None else self.do_resize
													UpperCAmelCase_			:      str     						=  do_rescale if do_rescale is not None else self.do_rescale
													UpperCAmelCase_			:      Any     						=  size_divisor if size_divisor is not None else self.size_divisor
													UpperCAmelCase_			:      Dict     						=  resample if resample is not None else self.resample

													if do_resize and size_divisor is None:
																			raise ValueError('''size_divisor is required for resizing'''   )

													UpperCAmelCase_			:      Optional[int]     						=  make_list_of_images(__magic_name__   )

													if not valid_images(__magic_name__   ):
																			raise ValueError('''Invalid image(s)'''   )

													# All transformations expect numpy arrays.
													UpperCAmelCase_			:      List[str]     						=  [to_numpy_array(__magic_name__   ) for img in images]

													if do_resize:
																			UpperCAmelCase_			:      str     						=  [self.resize(__magic_name__       ,     size_divisor=__magic_name__       ,     resample=__magic_name__   ) for image in images]

													if do_rescale:
																			UpperCAmelCase_			:      Tuple     						=  [self.rescale(__magic_name__       ,     scale=1 / 2_55   ) for image in images]

													UpperCAmelCase_			:      Union[str, Any]     						=  [to_channel_dimension_format(__magic_name__       ,     __magic_name__   ) for image in images]

													UpperCAmelCase_			:      int     						=  {'''pixel_values''': images}
													return BatchFeature(data=__magic_name__       ,     tensor_type=__magic_name__   )





