Abstract
Adversarial attacks exploit the vulnerabilities of convolutional neural networks by introducing imperceptible perturbations that lead to misclassifications, exposing weaknesses in feature representations and decision boundaries. This paper presents a novel framework combining supervised contrastive learning and margin-based contrastive loss to enhance adversarial robustness. Supervised contrastive learning improves the structure of the feature space by clustering embeddings of samples within the same class and separating those from different classes. Margin-based contrastive loss, inspired by support vector machines, enforces explicit constraints to create robust decision boundaries with well-defined margins. Experiments on the CIFAR-100 dataset with a ResNet-18 backbone demonstrate robustness performance improvements in adversarial accuracy under Fast Gradient Sign Method attacks.
Introduction
Deep learning models are notoriously brittle; tiny, imperceptible changes to an input image—known as adversarial attacks—can cause state-of-the-art models to confidently misidentify objects. This vulnerability often stems from standard training practices. Traditional Cross-Entropy (CE) loss prioritizes classification accuracy on clean data but does not explicitly optimize the geometric organization of features. Consequently, models may rely on spurious patterns or shortcuts that are easily manipulated by small perturbations. This research seeks a fundamental solution: improving the geometric structure of feature representations to make them inherently more robust.
Methodology
The proposed framework utilizes a dual-objective training strategy to restructure the internal feature space of the model.
Supervised Contrastive Learning (SCL)
Unlike standard self-supervised contrastive learning, SCL leverages label information to pull samples of the same class together in the latent space while pushing different classes apart. This creates tighter, more distinct class clusters.
Margin-Based Contrastive Loss
Inspired by Support Vector Machines (SVMs), a novel margin-based loss function is introduced. This function penalizes the model if the distance between classes is insufficient or if intra-class clusters are not tight enough, effectively creating a "buffer zone" around decision boundaries to absorb adversarial noise.
Architecture and Dataset
The framework employs a dual-stream architecture with shared weights based on a ResNet-18 backbone. The model outputs projection vectors for both the contrastive loss and the traditional classification loss. Experiments were conducted on the CIFAR-100 dataset, which contains 60,000 images across 100 classes.
Results and Discussion
The models were evaluated against the Fast Gradient Sign Method (FGSM) attack at various perturbation magnitudes ($\epsilon$).
Adversarial Performance
In scenarios without data augmentation, the SCL-trained model consistently outperformed the baseline. At $\epsilon = 0.01$, the SCL model achieved 20.4% accuracy compared to the baseline's 19.7%. The Margin-Based SCL model provided the most stable defense, achieving 12.6% accuracy at $\epsilon = 0.02$, surpassing the baseline's 12.0%.
Training Dynamics
Analysis of the loss curves reveals that while the task-specific classification loss drops rapidly, the contrastive loss provides a steady regularizing signal throughout the 200 training epochs. This continuous refinement helps in learning more invariant and robust features.
Key Insights
A significant finding was that "refining" a pre-trained model with contrastive loss post-hoc was less effective than joint training. In some instances, post-hoc refinement led to worse performance under attack, suggesting that robust features must be integrated into the learning process from the beginning.
Conclusion
This work demonstrates that supervised contrastive learning with margin-based constraints can effectively harden DNNs against adversarial perturbations by improving feature space geometry. Future research will focus on evaluating the framework against more potent iterative attacks like Projected Gradient Descent (PGD) and optimizing joint-training schedules to better balance classification and contrastive objectives.
Summary updated