Beyond Feature Direction: Magnitude-Aware Matching of Patches and Spatial Contexts for Training-Free Anomaly Detection
Abstract
In this paper, we introduce a training-free anomaly detection framework that exploits both feature magnitude and local spatial context in pretrained DINOv2 representations. Existing nearest-neighbor-based anomaly detection methods commonly rely on normalized patch features, emphasizing feature direction while leaving the magnitude information of the original representation largely unused. They also often compare individual patches independently, which can overlook anomalies that are better characterized by abnormal local spatial configurations. To address these limitations, we construct a magnitude-aware patch representation by combining the direction of the post-LayerNorm feature with the centered magnitude of its pre-LayerNorm counterpart. The magnitude is normalized using statistics from normal reference patches and softly incorporated through square-root scaling, preserving semantic direction while retaining relative feature strength. We further represent each patch together with its ordered neighborhood to capture local spatial configurations without introducing any learnable parameters. Separate normal memory banks are constructed for individual patches and spatial contexts, and anomaly scores are obtained through nearest-neighbor distances in the two representation spaces and combined at inference time. The proposed method requires neither additional training nor anomaly validation data and can be directly applied under few-shot normal-reference settings. Experiments on MVTec AD and VisA under 1-, 2-, and 4-shot settings demonstrate consistent gains over the AnomalyDINO baseline at both image and pixel levels. These results suggest that feature magnitude and spatial context provide complementary normality cues for training-free industrial anomaly detection.
Then back it, or bet against it.
Related papers
Open the market on this paper to see 7 more related papers.