





'''simple docstring'''







import logging
import os
import threading
import time


try:
					import warnings
except ImportError:
					lowerCAmelCase_					:    Dict      	=			None

try:
					import msvcrt
except ImportError:
					lowerCAmelCase_					:    Union[str, Any]      	=			None

try:
					import fcntl
except ImportError:
					lowerCAmelCase_					:    Optional[Any]      	=			None


# Backward compatibility
# ------------------------------------------------
try:
					TimeoutError
except NameError:
					lowerCAmelCase_					:    str      	=			OSError


# Data
# ------------------------------------------------
lowerCAmelCase_					:    List[Any]      	=			[
    'Timeout',
    'BaseFileLock',
    'WindowsFileLock',
    'UnixFileLock',
    'SoftFileLock',
    'FileLock',
]

lowerCAmelCase_					:    Union[str, Any]      	=			'3.0.12'


lowerCAmelCase_					:    Any      	=			None






def  _lowerCamelCase				( )	->	Dict:
				global _logger
				_a								= _logger or logging.getLogger(__name__						)
				return _logger
class 				__SCREAMING_SNAKE_CASE  (lowerCamelCase_      ):






				"""simple docstring"""







				def __init__(  self     :					Dict					,				__a     :					List[str]					):
								_a								= lock_file
								return None




				def __str__(  self     :					Optional[Any]					):
								_a								= f'The file lock \'{self.lock_file}\' could not be acquired.'
								return temp


class 				__SCREAMING_SNAKE_CASE  :






				"""simple docstring"""







				def __init__(  self     :					Any					,				__a     :					Optional[Any]					):
								_a								= lock
								return None




				def __enter__(  self     :					Union[str, Any]					):
								return self.lock




				def __exit__(  self     :					List[str]					,				__a     :					Union[str, Any]					,				__a     :					str					,				__a     :					Union[str, Any]					):
								self.lock.release()
								return None


class 				__SCREAMING_SNAKE_CASE  :






				"""simple docstring"""







				def __init__(  self     :					Optional[Any]					,				__a     :					int					,				__a     :					List[Any]=-1					,				__a     :					List[str]=None					):
								_a								= max_filename_length if max_filename_length is not None else 2_55
								# Hash the filename if it's too long
								_a								= self.hash_filename_if_too_long(__a					,				__a					)
								# The path to the lock file.
								_a								= lock_file

								# The file descriptor for the *_lock_file* as it is returned by the
								# os.open() function.
								# This file lock is only NOT None, if the object currently holds the
								# lock.
								_a								= None

								# The default timeout value.
								_a								= timeout

								# We use this lock primarily for the lock counter.
								_a								= threading.Lock()

								# The lock counter is used for implementing the nested locking
								# mechanism. Whenever the lock is acquired, the counter is increased and
								# the lock is only released, when this value is 0 again.
								_a								= 0
								return None




				@property
				def   UpperCamelCase__   (  self     :					Optional[Any]					):
								return self._lock_file




				@property
				def   UpperCamelCase__   (  self     :					str					):
								return self._timeout




				@timeout.setter
				def   UpperCamelCase__   (  self     :					Union[str, Any]					,				__a     :					Optional[Any]					):
								_a								= float(__a					)
								return None




				def   UpperCamelCase__   (  self     :					List[str]					):
								raise NotImplementedError()




				def   UpperCamelCase__   (  self     :					Optional[Any]					):
								raise NotImplementedError()




				@property
				def   UpperCamelCase__   (  self     :					List[str]					):
								return self._lock_file_fd is not None




				def   UpperCamelCase__   (  self     :					Dict					,				__a     :					Any=None					,				__a     :					Union[str, Any]=0.05					):
								# Use the default timeout, if no timeout is provided.
								if timeout is None:
												_a								= self.timeout

								# Increment the number right at the beginning.
								# We can still undo it, if something fails.
								with self._thread_lock:
												self._lock_counter += 1

								_a								= id(self					)
								_a								= self._lock_file
								_a								= time.time()
								try:
												while True:
																with self._thread_lock:
																				if not self.is_locked:
																								logger().debug(f'Attempting to acquire lock {lock_id} on {lock_filename}'					)
																								self._acquire()

																if self.is_locked:
																				logger().debug(f'Lock {lock_id} acquired on {lock_filename}'					)
																				break
																elif timeout >= 0 and time.time() - start_time > timeout:
																				logger().debug(f'Timeout on acquiring lock {lock_id} on {lock_filename}'					)
																				raise Timeout(self._lock_file					)
																else:
																				logger().debug(
																				    f'Lock {lock_id} not acquired on {lock_filename}, waiting {poll_intervall} seconds ...'					)
																				time.sleep(__a					)
								except:  # noqa
												# Something did go wrong, so decrement the counter.
												with self._thread_lock:
																_a								= max(0					,				self._lock_counter - 1					)

												raise
								return _Acquire_ReturnProxy(lock=self					)




				def   UpperCamelCase__   (  self     :					Optional[int]					,				__a     :					Optional[int]=False					):
								with self._thread_lock:
												if self.is_locked:
																self._lock_counter -= 1

																if self._lock_counter == 0 or force:
																				_a								= id(self					)
																				_a								= self._lock_file

																				logger().debug(f'Attempting to release lock {lock_id} on {lock_filename}'					)
																				self._release()
																				_a								= 0
																				logger().debug(f'Lock {lock_id} released on {lock_filename}'					)

								return None




				def __enter__(  self     :					List[Any]					):
								self.acquire()
								return self




				def __exit__(  self     :					List[str]					,				__a     :					str					,				__a     :					str					,				__a     :					Optional[int]					):
								self.release()
								return None




				def __del__(  self     :					Union[str, Any]					):
								self.release(force=__a					)
								return None




				def   UpperCamelCase__   (  self     :					str					,				__a     :					str					,				__a     :					int					):
								_a								= os.path.basename(__a					)
								if len(__a					) > max_length and max_length > 0:
												_a								= os.path.dirname(__a					)
												_a								= str(hash(__a					)					)
												_a								= filename[: max_length - len(__a					) - 8] + "..." + hashed_filename + ".lock"
												return os.path.join(__a					,				__a					)
								else:
												return path


class 				__SCREAMING_SNAKE_CASE  (lowerCamelCase_      ):






				"""simple docstring"""







				def __init__(  self     :					Tuple					,				__a     :					Tuple					,				__a     :					Union[str, Any]=-1					,				__a     :					List[str]=None					):
								from .file_utils import relative_to_absolute_path

								super().__init__(__a					,				timeout=__a					,				max_filename_length=__a					)
								_a								= "\\\\?\\" + relative_to_absolute_path(self.lock_file					)




				def   UpperCamelCase__   (  self     :					Optional[int]					):
								_a								= os.O_RDWR | os.O_CREAT | os.O_TRUNC

								try:
												_a								= os.open(self._lock_file					,				__a					)
								except OSError:
												pass
								else:
												try:
																msvcrt.locking(__a					,				msvcrt.LK_NBLCK					,				1					)
												except OSError:
																os.close(__a					)
												else:
																_a								= fd
								return None




				def   UpperCamelCase__   (  self     :					int					):
								_a								= self._lock_file_fd
								_a								= None
								msvcrt.locking(__a					,				msvcrt.LK_UNLCK					,				1					)
								os.close(__a					)

								try:
												os.remove(self._lock_file					)
								# Probably another instance of the application
								# that acquired the file lock.
								except OSError:
												pass
								return None


class 				__SCREAMING_SNAKE_CASE  (lowerCamelCase_      ):






				"""simple docstring"""







				def __init__(  self     :					Optional[Any]					,				__a     :					List[Any]					,				__a     :					str=-1					,				__a     :					List[Any]=None					):
								_a								= os.statvfs(os.path.dirname(__a					)					).f_namemax
								super().__init__(__a					,				timeout=__a					,				max_filename_length=__a					)




				def   UpperCamelCase__   (  self     :					Any					):
								_a								= os.O_RDWR | os.O_CREAT | os.O_TRUNC
								_a								= os.open(self._lock_file					,				__a					)

								try:
												fcntl.flock(__a					,				fcntl.LOCK_EX | fcntl.LOCK_NB					)
								except OSError:
												os.close(__a					)
								else:
												_a								= fd
								return None




				def   UpperCamelCase__   (  self     :					Dict					):
								# Do not remove the lockfile:
								#
								#   https://github.com/benediktschmitt/py-filelock/issues/31
								#   https://stackoverflow.com/questions/17708885/flock-removing-locked-file-without-race-condition
								_a								= self._lock_file_fd
								_a								= None
								fcntl.flock(__a					,				fcntl.LOCK_UN					)
								os.close(__a					)
								return None


class 				__SCREAMING_SNAKE_CASE  (lowerCamelCase_      ):






				"""simple docstring"""







				def   UpperCamelCase__   (  self     :					int					):
								_a								= os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_TRUNC
								try:
												_a								= os.open(self._lock_file					,				__a					)
								except OSError:
												pass
								else:
												_a								= fd
								return None




				def   UpperCamelCase__   (  self     :					Any					):
								os.close(self._lock_file_fd					)
								_a								= None

								try:
												os.remove(self._lock_file					)
								# The file is already deleted and that's what we want.
								except OSError:
												pass
								return None


lowerCAmelCase_					:    Tuple      	=			None

if msvcrt:
					lowerCAmelCase_					:    Union[str, Any]      	=			WindowsFileLock
elif fcntl:
					lowerCAmelCase_					:    Tuple      	=			UnixFileLock
else:
					lowerCAmelCase_					:    Tuple      	=			SoftFileLock

					if warnings is not None:
										warnings.warn('only soft file lock is available')







'''simple docstring'''







import copy

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


lowerCAmelCase_					:    Dict      	=			logging.get_logger(__name__)

lowerCAmelCase_					:    Optional[int]      	=			{
    'ut/deta': 'https://huggingface.co/ut/deta/resolve/main/config.json',
}
class 				__SCREAMING_SNAKE_CASE  (lowerCamelCase_      ):






				"""simple docstring"""







				__a            ='deta'
				__a            ={
				    'hidden_size': 'd_model',
				    'num_attention_heads': 'encoder_attention_heads',
				}




				def __init__(  self     :					List[str]					,				__a     :					List[str]=None					,				__a     :					Dict=9_00					,				__a     :					str=20_48					,				__a     :					Tuple=6					,				__a     :					List[str]=20_48					,				__a     :					str=8					,				__a     :					Union[str, Any]=6					,				__a     :					int=10_24					,				__a     :					List[Any]=8					,				__a     :					Dict=0.0					,				__a     :					Tuple=True					,				__a     :					Optional[Any]="relu"					,				__a     :					Tuple=2_56					,				__a     :					Optional[Any]=0.1					,				__a     :					int=0.0					,				__a     :					List[Any]=0.0					,				__a     :					Optional[int]=0.02					,				__a     :					str=1.0					,				__a     :					Dict=True					,				__a     :					Dict=False					,				__a     :					Optional[int]="sine"					,				__a     :					Any=5					,				__a     :					List[str]=4					,				__a     :					Optional[int]=4					,				__a     :					List[str]=True					,				__a     :					str=3_00					,				__a     :					int=True					,				__a     :					int=True					,				__a     :					Tuple=1					,				__a     :					Optional[int]=5					,				__a     :					Tuple=2					,				__a     :					Dict=1					,				__a     :					Optional[int]=1					,				__a     :					Any=5					,				__a     :					Optional[int]=2					,				__a     :					Dict=0.1					,				__a     :					str=0.25					,				**__a     :					Tuple					,				):
								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=["stage2", "stage3", "stage4"]					)
								else:
												if isinstance(__a					,				__a					):
																_a								= backbone_config.pop("model_type"					)
																_a								= CONFIG_MAPPING[backbone_model_type]
																_a								= config_class.from_dict(__a					)

								_a								= backbone_config
								_a								= num_queries
								_a								= max_position_embeddings
								_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								= auxiliary_loss
								_a								= position_embedding_type
								# deformable attributes
								_a								= num_feature_levels
								_a								= encoder_n_points
								_a								= decoder_n_points
								_a								= two_stage
								_a								= two_stage_num_proposals
								_a								= with_box_refine
								_a								= assign_first_stage
								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
								_a								= class_cost
								_a								= bbox_cost
								_a								= giou_cost
								# Loss coefficients
								_a								= mask_loss_coefficient
								_a								= dice_loss_coefficient
								_a								= bbox_loss_coefficient
								_a								= giou_loss_coefficient
								_a								= eos_coefficient
								_a								= focal_alpha
								super().__init__(is_encoder_decoder=__a					,				**__a					)




				@property
				def   UpperCamelCase__   (  self     :					Optional[Any]					):
								return self.encoder_attention_heads




				@property
				def   UpperCamelCase__   (  self     :					Dict					):
								return self.d_model




				def   UpperCamelCase__   (  self     :					List[str]					):
								_a								= copy.deepcopy(self.__dict__					)
								_a								= self.backbone_config.to_dict()
								_a								= self.__class__.model_type
								return output
