Anomaly detection involves identifying data patterns that deviate from the anticipated norm. Traditional methods struggle in high-dimensional spaces due to the curse of dimensionality. In recent years, self-supervised learning, particularly through contrastive objectives, has driven advances in anomaly detection. However, vanilla contrastive learning struggles to align with the unique demands of anomaly detection, as it lacks a pretext task tailored to the homogeneous nature of In-Distribution (ID) data and the diversity of Out-of-Distribution (OOD) anomalies. Methods that attempt to address these challenges, such as introducing hard negatives through synthetic outliers, Outlier Exposure (OE), and supervised objectives, often rely on pretext tasks that fail to balance compact clustering of ID samples with sufficient separation from OOD data. In this work, we propose Focused In-distribution Representation Modeling (FIRM), a contrastive learning objective specifically designed for anomaly detection. Unlike existing approaches, FIRM incorporates synthetic outliers into its pretext task in a way that actively shapes the representation space, promoting compact clustering of ID samples while enforcing strong separation from outliers. This formulation addresses the challenges of class collision, enhancing both the compactness of ID representations and the discriminative power of the learned feature space. We show that FIRM surpasses other contrastive methods in standard benchmarks, significantly enhancing anomaly detection compared to both traditional and supervised contrastive learning objectives. Our ablation studies confirm that FIRM consistently improves the quality of representations and shows robustness across a range of scoring methods. The code is available at: https://github.com/willtl/firm.
翻译:异常检测旨在识别偏离预期常态的数据模式。传统方法在高维空间中因维度诅咒而面临困难。近年来,自监督学习,特别是通过对比目标,推动了异常检测领域的进展。然而,传统的对比学习方法难以满足异常检测的特殊需求,因为它缺乏针对分布内数据同质性与分布外异常多样性的定制化前置任务。现有方法尝试通过合成离群点引入困难负样本、离群暴露和监督目标等方式应对这些挑战,但其前置任务往往无法平衡分布内样本的紧致聚类与分布外数据的充分分离。本研究提出聚焦式分布内表征建模,这是一种专门为异常检测设计的对比学习目标。与现有方法不同,FIRM以前置任务形式引入合成离群点,主动塑造表征空间,在促进分布内样本紧致聚类的同时强制实现与离群点的强分离。该框架有效解决了类别碰撞问题,既增强了分布内表征的紧致性,又提升了所学特征空间的判别能力。实验表明,FIRM在标准基准测试中超越其他对比方法,相较于传统及监督对比学习目标显著提升了异常检测性能。消融研究证实,FIRM能持续改善表征质量,并在多种评分方法中展现出鲁棒性。代码已开源:https://github.com/willtl/firm。