Mitigating Spurious Negative Pairs for Robust Industrial Anomaly Detection
Hossein Mirzaei, Mojtaba Nafez, Jafar Habibi, Mohammad Sabokrou, Mohammad Hossein Rohban
TL;DR
One-class anomaly detection often lacks anomaly examples, making detectors vulnerable to adversarial perturbations. The authors propose COBRA, combining distribution-aware pseudo-anomaly generation with an anomaly-aware contrastive loss that uses opposite pairs to maximize the margin between normal and anomaly distributions in embedding space under adversarial perturbations bounded by $\epsilon\u007f$. A threshold $lambda$ computed via a k-class classifier and Gaussian Mixture Model on embeddings filters pseudo-anomalies, and the training optimizes a min–max objective with a binary head for scoring. Empirically, COBRA yields up to $26.1\%$ improvements in robust AUROC across multiple datasets and attacks, without requiring external anomaly data, while maintaining competitive clean performance and demonstrating broad applicability to real-world anomaly detection tasks.
Abstract
Despite significant progress in Anomaly Detection (AD), the robustness of existing detection methods against adversarial attacks remains a challenge, compromising their reliability in critical real-world applications such as autonomous driving. This issue primarily arises from the AD setup, which assumes that training data is limited to a group of unlabeled normal samples, making the detectors vulnerable to adversarial anomaly samples during testing. Additionally, implementing adversarial training as a safeguard encounters difficulties, such as formulating an effective objective function without access to labels. An ideal objective function for adversarial training in AD should promote strong perturbations both within and between the normal and anomaly groups to maximize margin between normal and anomaly distribution. To address these issues, we first propose crafting a pseudo-anomaly group derived from normal group samples. Then, we demonstrate that adversarial training with contrastive loss could serve as an ideal objective function, as it creates both inter- and intra-group perturbations. However, we notice that spurious negative pairs compromise the conventional contrastive loss to achieve robust AD. Spurious negative pairs are those that should be closely mapped but are erroneously separated. These pairs introduce noise and misguide the direction of inter-group adversarial perturbations. To overcome the effect of spurious negative pairs, we define opposite pairs and adversarially pull them apart to strengthen inter-group perturbations. Experimental results demonstrate our superior performance in both clean and adversarial scenarios, with a 26.1% improvement in robust detection across various challenging benchmark datasets. The implementation of our work is available at: https://github.com/rohban-lab/COBRA.
