TCFMAD: Tri-Consistency Foundation Model-Based Few-Shot Manufacturing Anomaly Detection
Abstract
Anomaly detection (AD) aims to distinguish anomalous samples from normal ones and localize the corresponding anomalous regions in real-world manufacturing environments. Benefiting from the strong visual priors of foundation models (FMs), few-shot FM-based methods can rapidly adapt to new manufacturing categories using only a small support set. However, existing methods still suffer from triple inconsistencies: inconsistency between synthetic and real anomalies before training, inconsistency in anomaly evidence across patch tokens from different FM layers during training, and inconsistency between image-level and pixel-level assessments during evaluation. Consequently, AD models may correctly distinguish anomalous samples at the image level while still mislocalizing the anomalous regions at the pixel level. Detection performance further degrades markedly when adapting to other manufacturing datasets under the sparse few-shot setting. To address these inconsistencies, we propose TCFMAD, a tri-consistency FM-based few-shot AD pipeline that enforces consistency in anomaly synthesis, cross-layer anomaly evidence, and fine-grained label construction throughout training and evaluation. TCFMAD adapts the anomaly detector using a few normal support images together with an equally small class-specific anomalous-patch bank. Specifically, realistic anomaly synthesis (RAS) uses this anomalous-patch bank, matched to the 1/2/4-shot normal-support budget, to generate realistic synthetic anomalous samples and alleviate the inconsistency between synthetic and real anomalies. During training, cross-layer evidence agreement (CLEA) optimizes the anomaly predictor with a consistency regularization loss to learn stable anomaly evidence from multi-layer patch tokens of DINOv3. CLEA strengthens the consistency of anomaly evidence extraction. For PKU-Market-PCB, weakly-constrained bootstrapping (WCB) operates offline to refine weak bounding boxes into masks for anomalous-patch extraction and fixed fine-grained localization assessment; it is not part of the anomaly detector or its online inference path. TCFMAD achieves state-of-the-art performance on the human-mask-based public benchmarks and strong relative performance on PKU-Market-PCB under a shared WCB-refined pseudo-mask protocol. Code is available at: https://github.com/GingerCohle/TCFMAD Note to Practitioners—In real-world manufacturing inspection, anomaly detection models often need to adapt to a new product category using highly limited support data while still providing reliable defect localization for quality control. In practice, existing few-shot anomaly detection methods may report strong image-level performance, yet still produce unstable or misleading localization results because the synthesized anomalies used for training are unrealistic, anomaly evidence varies across different foundation-model layers, and dense pixel-level annotations are often unavailable for evaluation. This article presents a tri-consistency framework to address these practical issues at three stages of deployment. Specifically, the proposed method improves the realism of synthetic anomalies before training, stabilizes anomaly evidence across multiple DINOv3 layers during training, and refines fine-grained masks from weak annotations during evaluation. These properties are especially relevant to industrial scenarios such as PCB inspection and other manufacturing tasks where annotation cost is high and rapid adaptation is required. Practitioners should note that TCFMAD is not a strictly normal-only adaptation method. In addition to a few normal reference images, RAS requires an equally small set of class-specific anomalous patches. WCB further uses limited dense annotations and weak bounding boxes offline to extract the PKU-Market-PCB patch bank and construct fixed evaluation masks; it does not increase online detector inference cost. Nevertheless, it provides a practical way to improve both anomaly discrimination and localization reliability in sparse-data manufacturing scenarios.