""" Hugging Face compatible configuration for existing Space This extends your existing config without breaking it """ try: from transformers import PretrainedConfig TRANSFORMERS_AVAILABLE = True except ImportError: TRANSFORMERS_AVAILABLE = False # Fallback configuration class PretrainedConfig: def __init__(self, **kwargs): for key, value in kwargs.items(): setattr(self, key, value) class HFResNet18DetectorConfig(PretrainedConfig): """ Hugging Face compatible configuration for your existing model Works alongside your existing training config """ model_type = "resnet18-detector" def __init__( self, num_classes: int = 2, image_size: int = 224, architecture: str = "resnet18", dropout_rate: float = 0.5, freeze_backbone: bool = False, pretrained_weights: str = "IMAGENET1K_V1", label_smoothing: float = 0.1, # Anti-overfitting: Label smoothing weight_decay: float = 0.1, # Anti-overfitting: L2 regularization max_grad_norm: float = 1.0, # Anti-overfitting: Gradient clipping **kwargs ): """ Initialize HF compatible config with anti-overfitting parameters """ self.num_classes = num_classes self.image_size = image_size self.architecture = architecture self.dropout_rate = dropout_rate self.freeze_backbone = freeze_backbone self.pretrained_weights = pretrained_weights self.label_smoothing = label_smoothing self.weight_decay = weight_decay self.max_grad_norm = max_grad_norm if TRANSFORMERS_AVAILABLE: super().__init__(**kwargs) else: for key, value in kwargs.items(): setattr(self, key, value) # Register for auto-loading if transformers is available if TRANSFORMERS_AVAILABLE: try: HFResNet18DetectorConfig.register_for_auto_class() except: pass