UniNet: A Contrastive Learning-guided Unified Framework with Feature Selection for Anomaly Detection

Shun Wei, Jielin Jiang, Xiaolong XuCVPR 2025

Abstract

Visual anomaly detection (AD) has traditionally been a fragmented field, with specialized models tailored for specific domains such as industrial inspection, medical imaging, or video surveillance. This "one-model-one-domain" paradigm is limited by significant domain discrepancies and the inherent feature bias of pre-trained networks. We present UniNet, a novel unified framework that leverages a student-teacher architecture enhanced by domain-related feature selection and contrastive learning. UniNet effectively bridges the gap between diverse domains, achieving state-of-the-art results across 12 major benchmarks.

The Challenge of Generalization in Anomaly Detection

Anomaly detection involves identifying patterns that deviate from expected "normal" behavior. However, what constitutes "normal" varies wildly across applications. A scratch on a metal surface is an industrial anomaly, whereas a retinal lesion is a medical one. Most existing AD models rely on networks pre-trained on generic datasets like ImageNet, which often fail to capture the subtle, domain-specific textures necessary for high-precision detection.

Comparison between separate models and the proposed unified framework.

As shown in Figure 5, traditional approaches (a) require separate models for each domain, whereas UniNet (b) proposes a single, unified architecture capable of handling industrial, medical, and video data simultaneously. This unification addresses the fragmentation of the field and reduces the need for domain-specific engineering.

Methodology: Selective Learning and Multi-Scale Context

UniNet's core innovation lies in its ability to adapt its feature extraction to the specific requirements of a target domain. It utilizes a Student-Teacher (S-T) architecture where the student network is guided to learn only the most relevant features from the teacher. Key components include:

  • Multi-Scale Embedding Module (MEM): To capture both local textures and global context, UniNet employs a multi-scale approach in its bottleneck. By using a combination of large (7x7) and small (3x3) kernels, the model maintains contextual awareness—essential for detecting anomalies that are only "abnormal" relative to their surroundings.
  • Domain-Related Feature Selection (DFS): Rather than simple mimicry, DFS acts as a filtering mechanism. It weights the teacher's features, forcing the student to focus on domain-relevant information and ignore generic pre-trained biases.
  • Contrastive and Margin Losses: To sharpen the boundary between normal and anomalous data, UniNet employs a Similarity-Contrastive Loss ($L_{SC}$) to cluster normal features and a Margin Loss ($L_M$) to push anomalies away in the feature space.

Experimental Evaluation

The framework was evaluated across 12 datasets, including MVTec AD (industrial), APTOS and OCT2017 (medical), and Ped2 (video). UniNet consistently outperformed existing state-of-the-art (SOTA) methods across all categories.

AUROC curves for UniNet on the OCT2017 and APTOS medical datasets.

As illustrated in the AUROC curves in Figure 2, UniNet demonstrates exceptional discriminative power. In the medical domain, it achieved a perfect 100% AUROC on the ISIC2018 skin lesion dataset. In industrial settings, it reached 99.90% Image-level AUROC on MVTec AD and significantly improved performance on the challenging MVTec 3D-AD benchmark, hitting 95.76% compared to the previous 88.63% SOTA. On video surveillance data (Ped2), it surpassed the baseline ReContrast model by 2.7%.

Conclusion

UniNet represents a significant step toward a universal anomaly detection system. By moving away from rigid, domain-specific architectures and generic pre-trained biases, it provides a flexible and highly accurate framework for a wide range of real-world applications. While the framework introduces some hyperparameter sensitivity and training overhead, its superior generalization capabilities across industrial, medical, and video domains set a new benchmark for the field.

Summary updated

BibTeX
@inproceedings{wei2025uninet,
  author = {Shun Wei and Jielin Jiang and Xiaolong Xu},
  title = {{UniNet: A Contrastive Learning-guided Unified Framework with Feature Selection for Anomaly Detection}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2025},
  doi = {10.1109/cvpr52734.2025.00934},
}
Figure