1. Introduction
Industrial visual anomaly detection aims to identify defective samples and localize abnormal regions while using few or no anomalous training examples. Conventional methods model normal appearance through reconstruction, feature distributions, memory banks, distillation, or normalizing flows [
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13]. These approaches are highly effective when anomalies create visible local deviations such as scratches, dents, stains, or deformations. However, industrial inspection also contains
logical anomalies: all parts may appear valid individually, but their presence, count, arrangement, or connection violates the normal logic of the product [
14].
Large vision–language models (VLMs), particularly CLIP [
15], have recently enabled generalizable zero- and few-shot anomaly detection. WinCLIP introduced compositional prompts and window-level CLIP features [
16]; AnomalyCLIP learned object-agnostic normal and abnormal prompts together with dense visual adaptation [
17]; and AA-CLIP strengthened anomaly-aware text anchors and patch-level visual alignment [
18]. PromptAD, AdaCLIP, FiLo, and subsequent prompt-learning methods further improved pixel-level anomaly localization through more discriminative or input-adaptive vision–language prompts [
19,
20,
21,
22,
23]. Nevertheless, these methods still primarily answer the local question:
Does this patch look abnormal with respect to a learned or prompted abnormality concept?However, that perspective is insufficient for logical anomalies. A product may contain valid-looking parts that are misplaced, duplicated, or arranged incorrectly, or it may lack an expected component. Although their local appearance remains consistent with the normal feature manifold, their semantic and spatial relationships can become abnormal. MVTec LOCO AD was introduced to expose this gap by distinguishing structural anomalies from logical anomalies while providing pixel-level annotations for both [
14]. To address this challenge, recent methods explicitly model components, object compositions, correspondences, or natural-language constraints [
24,
25,
26,
27,
28,
29,
30,
31]. Their strong image-level performance highlights the importance of relational reasoning for logical anomaly detection, but these approaches often rely on dedicated segmentation, object extraction, few-shot exemplars, or additional image-level reasoning pipelines, which can limit their applicability.
This work studies a narrower but practically important question: Can the relation information already present inside a CLIP-based anomaly detector improve logical anomaly detection and localization without training a new logical reasoning model? Our answer is Relation Prototype Re-scoring. For an image with patch features F and visual self-attention A, we construct a relation-aware representation . A normal training set defines a category-wise prototype P, and the patch relation score is the Euclidean distance . Attention is therefore not interpreted as an anomaly heatmap by itself. It acts as a message-passing operator that converts local patch features into context-conditioned representations.
Crucially, this context is inherently both semantic and spatial. In vision transformers, positional embeddings are added to patch embeddings before self-attention is computed, allowing the resulting attention graph to encode not only visual similarity but also token identity and spatial arrangement. Furthermore, our normal relation prototype remains indexed by patch position. The relation score therefore asks: “does patch i participate in the normal semantic–spatial configuration of this object?” This formulation is directly relevant to logical anomalies involving missing, duplicated, misplaced, or incorrectly connected parts. It also explains why explicitly appending a separate positional cue did not improve the best-performing relation feature in our ablation study: spatial information is already embedded throughout the transformer via positional embeddings, propagated by self-attention, and preserved by the spatial indexing of the normal prototype.
We investigate two relation formulations. An initial attention-difference variant (V1) directly measures discrepancies between test and normal attention matrices. In contrast, our final feature-relation variant (V2) compares attention-aggregated patch features against normal relation prototypes. The substantial performance gap between V1 and V2 for pixel-level localization indicates that attention weights alone are insufficient; the discriminative signal arises primarily from deviations in spatially indexed feature content, while attention-guided propagation provides an additional gain.
We adopt AnomalyCLIP as the main analysis baseline because its DPAM patch features and separate query–key (q-k) and value–value (v-v) attention branches enable a detailed examination of representation and relation cues. WinCLIP and AA-CLIP are also included to evaluate the generality of the proposed relation prototype across both a training-free baseline and a stronger anomaly-aware baseline. MVTec LOCO AD [
14] serves as the primary benchmark for logical anomaly detection, while CAD-SD [
24] provides external validation on co-occurrence anomalies. Because the AnomalyCLIP and AA-CLIP checkpoints used in this study were trained on VisA [
32], MVTec AD [
3] is used as a benchmark to evaluate the generalization to conventional surface anomalies.
Our objective is not to replace existing logical anomaly detection pipelines. More importantly, we do not convert a CLIP-based baseline into a logical-anomaly-specific detector or alter its learned representation. Instead, we retain the original anomaly map and augment it with a relation map computed from the detector’s existing attention matrices and patch features, using a prototype constructed only from normal images. While the underlying CLIP-based detectors are designed for zero-shot anomaly detection, the proposed relation re-scoring module additionally constructs category-specific relation prototypes from normal reference images of the target category. Therefore, our extension is more accurately characterized as a training-free method using normal reference images rather than a strictly zero-shot method.
The main contributions of this work are summarized as follows:
We formulate logical anomaly detection as a deviation from the normal semantic–spatial compatibility of patch features, rather than from local patch appearance alone. By using self-attention as a relation operator, the proposed representation extends patch-wise anomaly evidence to context-conditioned feature deviation without introducing an explicit component or symbolic relation model.
We propose a lightweight, training-free relation prototype re-scoring module that reuses the attention matrices and patch features already produced by an existing CLIP-based detector. The resulting relation map is fused with the unchanged baseline anomaly map, adding logical-anomaly sensitivity without requiring additional annotations, learnable parameters, retraining, checkpoint modification, or architectural changes.
We investigate two relation formulations—an attention-difference variant (V1) and a feature-relation prototype variant (V2)—and show that spatially indexed feature prototypes provide a strong logical-anomaly cue and that attention-guided feature propagation further improves this representation, whereas attention differences alone remain insufficient.
We demonstrate improved logical-anomaly localization and image-level detection across three representative CLIP-based anomaly detectors (AnomalyCLIP, WinCLIP, and AA-CLIP), together with analyses of relation maps, fusion strategies, score calibration, baseline strength, and anomaly type.
We validate the generality and limitations of the proposed relation cue through additional experiments on MVTec LOCO AD, CAD-SD, and MVTec AD, clarifying when semantic–spatial relation information is beneficial and where its effectiveness is inherently limited.
3. Method
3.1. Problem Formulation
Let
denote the set of normal training images for category
c, and let
x be a test image. A CLIP-based anomaly detector produces a dense anomaly map
together with visual patch features
We additionally extract a head-averaged patch-to-patch self-attention matrix
from the visual encoder, removing the CLS-token row and column before constructing patch relations. The baseline detector remains frozen, and neither its architecture nor its original anomaly map is modified; the proposed module only reads intermediate representations and computes an additional score after the forward pass.
Our goal is to estimate a relation map that is spatially aligned with the detector’s base anomaly map while capturing deviations from the normal semantic–spatial configuration. The final output fuses the proposed relation map with the unchanged base anomaly map. Standalone relation scores are reported only to isolate the contribution of each relation formulation. The relation map is used for both pixel-level localization and image-level anomaly detection, although the corresponding scoring strategies differ.
For pixel-level localization, the base and relation maps are normalized independently because they generally have different numeric ranges:
The normalized maps are then fused according to the strategy described in
Section 3.6:
Image-level anomaly detection follows a separate raw-score pathway described in
Section 3.7.
Figure 1 illustrates the overall framework. The underlying CLIP-based detector produces the base anomaly map, patch features
F, and self-attention matrix
A, while normal training images are used only to construct the category-wise relation prototype. During inference, the resulting relation map is used in two separate pathways: a normalized fusion pathway for dense anomaly localization and a raw-score pathway for image-level anomaly detection. This separation ensures that spatial fusion benefits from per-image normalization while preserving valid score comparisons across different test images.
3.2. Why Relation Re-Scoring Detects Logical Anomalies
Many patch-based anomaly detectors can be abstracted as assigning each patch an anomaly score primarily from its local feature representation, i.e., . This strategy is effective when an anomaly directly perturbs the local appearance encoded in . Logical anomalies, however, often preserve the local appearance of individual components while altering their semantic–spatial relationships through missing, duplicated, misplaced, or incorrectly connected parts. Consequently, the local feature may remain close to the normal feature manifold even though the surrounding object configuration is abnormal.
Our relation representation is defined as
, where the attention matrix
A determines how contextual information is propagated and
F specifies the propagated visual features. Under perturbations
and
, the resulting change becomes
The first term,
, propagates local appearance changes through the normal relation structure. The second term,
, captures changes in semantic–spatial relationships even when the local visual features remain plausible. The final term,
, represents the interaction between appearance and relational changes. Therefore, the relation representation responds jointly to changes in both feature content and inter-patch relations.
This decomposition provides an intuitive explanation for the behavior of relation re-scoring. Changes in component presence, position, or connectivity can perturb the attention structure or its interaction with otherwise plausible patch features, allowing the relation representation to respond even when local appearance remains close to normal. In contrast, for highly localized surface defects, the anomaly is already well represented by the local feature perturbation , while relation aggregation can spread or attenuate that local evidence. Therefore, relation re-scoring should be viewed as a complementary mechanism that is expected to be most effective when anomaly evidence arises from semantic–spatial inconsistency rather than isolated appearance changes. This decomposition provides the theoretical basis for the proposed re-scoring: it extends anomaly evidence from local feature deviation to deviations in the compatibility between visual content and its expected semantic–spatial context.
3.3. Position-Aware Attention and Feature Extraction
Let
denote the visual embedding of patch
i and
its positional embedding. The input token for patch
i is
At transformer layer
ℓ, q-k self-attention is computed as
where the softmax is applied along the key dimension. Because
and
are derived from tokens initialized with both visual and positional embeddings and subsequently updated through repeated self-attention and feed-forward transformations,
encodes appearance-dependent semantic–spatial relations among image patches. This does not imply that the transformer enforces an explicit coordinate-based rule; rather, it indicates that inter-patch affinities are jointly conditioned by visual evidence and the positional structure provided to the transformer.
For each selected layer
ℓ, we first average the attention matrices across heads after removing the CLS-token row and column, resulting in a patch-to-patch attention matrix
. The remaining patch-to-patch attention matrix is then row-normalized so that each patch distributes unit attention over the remaining patch tokens before feature propagation. The relation-aggregated representation is obtained by averaging the propagated features over the selected layers:
where
denotes the set of transformer layers used for relation extraction. In the main AnomalyCLIP experiments,
contains the final five transformer layers.
The feature source is chosen to match the underlying anomaly detector. WinCLIP uses its CLIP patch representations, AnomalyCLIP uses DPAM-enhanced patch features, and AA-CLIP uses its adapted anomaly-aware patch features. For AnomalyCLIP, we construct the relation graph from the original q-k self-attention rather than the DPAM v-v attention, while using the DPAM patch features as the propagated content. This design follows the distinct roles of the transformer components. The q-k attention matrix explicitly represents pairwise attention affinities that determine how information is propagated across patches, making it a natural representation of semantic–spatial relations. In contrast, DPAM v-v attention is designed to enhance dense anomaly features through value-based aggregation. Although it can also define patch affinities, the ablation results show that it is less effective than q-k attention as the relation graph when DPAM features are used as the propagated content.
3.4. V1: Attention-Difference Relation Score
V1 serves as a preliminary ablation to examine whether deviations in attention affinities alone provide sufficient evidence for logical anomaly detection.
For category
c, the normal attention prototype is constructed by averaging the attention matrices of normal training images:
For test patch
i, V1 measures deviations in both its outgoing and incoming attention affinities:
The outgoing term measures how the attention assigned by patch
i to other patches deviates from the normal prototype, whereas the incoming term measures deviations in how other patches attend to patch
i. Therefore, V1 evaluates changes in the attention-based relation structure without considering the visual content transmitted through those relations. It is an attention-difference score rather than a feature-distance score.
3.5. V2: Feature-Relation Prototype
V2 is the final relation formulation, while the proposed detector output is obtained by fusing the V2 relation map with the unchanged baseline anomaly map. It uses self-attention as a relation operator over patch features.
For patch
i, the relation-aggregated feature is defined as
where
determines the contribution of patch
j to the relation representation of patch
i. For simplicity,
denotes the layer-averaged attention defined in Equation (
7). For each category
c, a spatially indexed normal relation prototype is constructed by averaging the relation features of normal training images:
Then, the relation anomaly score for patch
i is computed as the Euclidean distance between the observed relation feature and its corresponding normal prototype:
The resulting patch-level scores are reshaped to the token grid and bilinearly upsampled to the input image resolution. Unless otherwise stated, the relation map is defined as
.
The relation prototype remains sensitive to spatial layout through two complementary mechanisms. First, the attention affinities are derived from transformer tokens that incorporate positional embeddings. Second, the prototype preserves each patch position instead of pooling all relation features into a single order-invariant representation. As a result, each patch is compared with the normal semantic–spatial context expected at the corresponding location, allowing displacement, absence, duplication, and invalid co-occurrence to appear as mismatches from the category-specific configuration.
This spatially indexed formulation assumes approximate spatial correspondence between normal reference and test images and is therefore best suited to controlled industrial inspection settings in which the object occupies a similar position, scale, orientation, and viewpoint. Exact pixel-level registration is not required because the comparison is performed on patch-level relation representations; nevertheless, geometric changes large enough to shift semantic components to different patch locations can increase the relation score even for normal samples. Consequently, robustness may degrade under substantial translation, scale variation, in-plane rotation, viewpoint change, or object misalignment, as discussed in
Section 5.4.
3.6. Relation Map Fusion
The standalone relation map is evaluated to quantify the information supplied by V1 and V2, but it is not intended to replace the base detector. The final method combines V2 with the baseline anomaly map so that logical-relation evidence is added while the detector’s original local-defect response is retained. Let
denote the normalized anomaly map produced by the underlying detector and
the normalized relation map computed by V1 or V2. We consider the general fusion form of Equation (
3). This formulation includes relation-only inference, equal fusion, and weighted combinations as special cases. In particular, we evaluate
,
, and weighted variants:
or
.
The relation map is treated as a substantial source of anomaly evidence rather than merely as a weak refinement term, so its contribution is not assumed a priori to be small. At the same time, fusion remains essential to the proposed formulation because it retains the baseline detector’s appearance-based evidence. We therefore evaluate multiple fusion strategies to determine an appropriate balance between the two cues.
3.7. Map-Based Image-Level Scoring
The proposed relation map is generated after the detector’s forward pass and therefore does not alter the CLS-token representation used by existing image-level classifiers. To evaluate the image-level contribution of the relation map itself, we derive image scores directly from the anomaly maps. Image-level scoring is performed on the raw anomaly maps rather than on the normalized maps used for spatial fusion. Although per-image min–max normalization is suitable for combining spatial maps within an image, it removes the absolute score scale required for comparing anomaly scores across different test images.
For an anomaly map
S, the image score can be computed as
for
, together with the maximum score. In this study, Top-5% (
) is used as the primary image-level score, since logical anomalies typically occupy localized part-level regions rather than appearing as isolated peak responses.
The raw image scores produced by the base and relation maps may follow different category-dependent distributions. We therefore standardize them using category-specific statistics estimated exclusively from normal training images:
The standardized scores are then combined with equal weights:
3.8. Computational Overhead
The proposed relation module requires no additional network training. Relation prototypes are constructed by a single forward pass over the normal training images without backpropagation or parameter optimization. At inference, the attention matrices are already available from the transformer forward pass, so the additional computation is limited to relation-feature aggregation, prototype comparison, and map fusion. The dominant operation is the matrix multiplication , whose computational complexity is for L selected transformer layers, N patch tokens, and feature dimension C.
The relation prototype requires storing one feature matrix per category, resulting in a memory complexity of per category. In the main AnomalyCLIP configuration ( patch tokens), the proposed method introduces only a small computational and memory overhead.
Because it introduces no learnable parameters and requires no retraining, checkpoint modification, or architectural change, the proposed module can be incorporated into existing CLIP-based anomaly detectors as a post hoc plug-in.
4. Experiments
4.1. Experimental Setup
Datasets. MVTec LOCO AD serves as the primary benchmark. It contains five industrial object categories and provides image- and pixel-level annotations for both logical and structural anomalies [
14]. CAD-SD is a single-category screw-assembly dataset introduced with SA-PatchCore [
24]. Following the anomaly definitions provided with the dataset, we regard
Over-coupling and
Lacking as logical anomalies involving incorrect component composition or co-occurrence, whereas
Scratch and
Paint are treated as local surface anomalies. Since CAD-SD does not provide pixel-level ground-truth masks, we report only image-level results on this dataset. MVTec AD contains 15 industrial categories with image- and pixel-level annotations for local surface and structural defects [
3]. It is used as an additional benchmark for measuring generalization to conventional local anomalies.
Baselines and checkpoints. AnomalyCLIP is used as the primary development baseline. We use its official implementation and the checkpoint trained on VisA [
32] that is released through the official repository [
41]. WinCLIP is included as a training-free CLIP-based reference and therefore requires no anomaly-detection checkpoint trained on a source dataset. AA-CLIP is included as a stronger anomaly-aware baseline. Since no official pretrained checkpoint was available, we trained AA-CLIP on VisA using the official implementation [
42]. Unlike its default 32-shot setting, we used the full VisA training set, and the final-epoch checkpoints were used for all experiments. Detailed training settings are provided below.
The VisA-trained AnomalyCLIP and AA-CLIP checkpoints are kept fixed when evaluating MVTec LOCO AD, CAD-SD, and MVTec AD. Thus, no anomalous sample or anomaly annotation from any target benchmark is used for detector training or checkpoint adaptation. For the proposed method, only normal training images from the corresponding target category are used to construct the relation prototypes. Prototype construction requires only forward inference and does not update detector parameters. For CAD-SD, the text prompt category is specified as screw assembly.
Implementation details. AnomalyCLIP and AA-CLIP use the CLIP ViT-L/14@336px backbone, whereas WinCLIP uses ViT-B/16-plus-240 with LAION-400M pretrained weights (laion400m_e31). AnomalyCLIP uses the official VisA-trained checkpoint, while AA-CLIP uses the VisA-trained full-shot adapters described above. Input images are resized using bicubic interpolation and center-cropped to for AnomalyCLIP and AA-CLIP and to for WinCLIP, followed by standard CLIP normalization. These resolutions yield relation-feature grids of , , and , respectively. For V2, the patch features are -normalized, and the relation graph is obtained from the last five visual-transformer blocks; patch-to-patch attention is averaged over heads and row-normalized after removing the class token. The resulting relation maps are bilinearly upsampled, and is used for numerical stability. The original detector-specific anomaly-map computations are retained, including Gaussian smoothing with , and all detector and relation-module settings are fixed across datasets without dataset-specific tuning.
For AA-CLIP, full-shot training uses the official preprocessing and augmentation pipeline. The text and image adapters are trained for 5 and 20 epochs using Adam (, ), with learning rates of and and batch sizes of 16 and 2, respectively; the random seed is fixed to 111. Images are resized to and normalized using the standard CLIP statistics; the official geometric augmentations are applied during adapter training, with additional color augmentation used only for the image adapter.
Normal reference images. The proposed relation module is training-free but uses normal reference images from each target category to construct category-specific relation prototypes. Unless otherwise specified, all normal images in the official training split are used, without limiting the number of prototype samples. MVTec LOCO AD uses 1778 normal reference images across five categories (351 for
breakfast box, 335 for
juice bottle, 372 for
pushpins, 360 for
screw bag, and 360 for
splicing connectors). CAD-SD uses 400 normal images for its single
screw assembly category. MVTec AD uses 3629 normal images across 15 categories, ranging from 60 (
toothbrush) to 391 (
hazelnut) images per category. The sensitivity to the number of normal reference images is analyzed in
Appendix B.1.
Metrics. Dense anomaly localization is evaluated using pixel-level area under the receiver operating characteristic curve (AUROC) and per-region overlap (AUPRO). Image-level detection is evaluated using image AUROC and average precision (AP), where the image anomaly score is computed from the top 5% of the raw anomaly map as described in Equation (
13). Because the proposed relation module modifies dense anomaly maps rather than the detector-specific image scoring functions, both the baseline and the proposed variants are evaluated using a common map-derived image scoring protocol. A common map-derived image score is used for all detectors because their original implementations employ different image-level scoring mechanisms. Using the same aggregation protocol allows the effect of the proposed relation re-scoring to be compared under a unified evaluation criterion rather than being influenced by detector-specific image-score definitions. All metrics are computed separately for each object category and then averaged across object categories. Pixel-level evaluation uses the normalized localization maps in Equation (
3), whereas image-level evaluation uses the raw anomaly scores in Equations (
13)–(
15).
Model-selection protocol. The proposed method contains no learnable parameters. All design choices (attention source, number of attention layers, propagated feature layer, positional cue, image-level aggregation strategy, and fusion formulation/weights) were determined through the design-ablation study using AnomalyCLIP on the MVTec LOCO AD logical split. No separate validation split was created. After fixing a single configuration, the same settings were applied without modification to WinCLIP, AA-CLIP, CAD-SD, and MVTec AD.
4.2. Main Logical-Anomaly Results on AnomalyCLIP
Table 1 reports the category-averaged results of AnomalyCLIP on the logical-anomaly split of MVTec LOCO AD. Here, V1 denotes the attention-difference relation map, whereas V2 denotes the feature-relation map constructed from attention-aggregated patch features. V1 alone achieves only 51.0 pixel AUROC and 11.0 AUPRO, indicating that attention-affinity deviations alone provide limited localization capability. Fusing V1 with the baseline improves the localization performance to 52.4 AUROC and 24.3 AUPRO, but both remain below the baseline results of 53.9 AUROC and 28.7 AUPRO. At the image level, V1 reaches 59.6 AUROC and 60.9 AP, while fusion with the baseline retains 59.6 AUROC but reduces AP to 59.2. These results indicate that attention-difference information can increase the overall anomaly response, but the resulting map remains too spatially diffuse to serve as a reliable dense localization cue.
In contrast, V2 alone achieves 74.2 pixel AUROC and 51.7 AUPRO, substantially outperforming both the baseline and V1. This demonstrates that the proposed feature-relation representation provides a much stronger cue for logical anomaly localization. Combining V2 with the baseline yields the best overall results of 74.4 pixel AUROC, 52.7 AUPRO, and 71.7 image AUROC, corresponding to absolute gains of 20.5, 24.0, and 21.2 percentage points over the baseline, respectively. These gains show that the effect of relation re-scoring is substantial on the primary logical-anomaly task. Although V2 alone achieves a slightly higher image AP than the fused result, the proposed fusion consistently provides the best overall balance between image-level detection and pixel-level localization. Therefore, reporting both “V2 only” and “Baseline + V2” distinguishes the intrinsic capability of the proposed relation scoring from its complementary effect when integrated with the baseline detector.
Category-wise results are provided in
Appendix C.1,
Table A6 and
Table A7. The improvements are observed across multiple object categories rather than being dominated by a single category, while also revealing differences between improvements in global image ranking and dense region localization, particularly for the
screw bag category.
4.3. Generality Across WinCLIP and AA-CLIP
Table 2 evaluates the proposed relation formulation on two additional CLIP-based anomaly detectors, WinCLIP and AA-CLIP. The same post hoc computation is applied across detectors while each detector, its parameters, and its original anomaly map remain unchanged.
For WinCLIP, V2 alone substantially improves logical anomaly detection, increasing pixel AUROC from 51.2 to 70.1, pixel AUPRO from 27.1 to 41.6, and image AUROC from 55.5 to 69.4. Although the fused result remains better than the original baseline, it is slightly inferior to V2 alone in the localization metrics. Compared with AnomalyCLIP, the larger improvement observed for WinCLIP suggests that the proposed relation representation is particularly beneficial when the underlying baseline provides relatively weak patch-wise localization. In this case, the relation cue becomes the dominant source of logical anomaly evidence.
AA-CLIP exhibits a slightly different behavior. V2 alone achieves the highest image-level performance, with 66.4 AUROC and 68.7 AP. At the pixel-level, it preserves a similar pixel AUROC, but substantially reduces pixel AUPRO, indicating less accurate region coverage than the baseline. Integrating V2 with the baseline yields a small numerical increase in pixel AUROC from 62.9 to 63.6, while improving pixel AUPRO from 45.8 to 48.4 and image AUROC from 50.9 to 63.1. Given the small magnitude of the pixel-AUROC difference, we do not interpret this change alone as evidence of a statistically meaningful improvement. In contrast, Baseline + V1 yields only modest gains in AUPRO and the image-level metrics, reduces pixel AUROC, and remains clearly weaker than Baseline + V2 for localization.
Although AA-CLIP achieves the strongest baseline performance on the logical-anomaly split, V2 is less effective with AA-CLIP than with AnomalyCLIP or WinCLIP, both independently and after fusion. This contrast indicates that baseline anomaly-detection performance and compatibility with relation-based modeling are not necessarily correlated. The effectiveness of V2 therefore depends not only on the strength of the underlying detector but also on whether its feature representation preserves information suitable for semantic–spatial relation modeling.
Overall, the results demonstrate that the proposed feature-relation formulation generalizes consistently across different CLIP-based anomaly detectors despite their substantially different localization mechanisms. Complete category-wise localization and image-detection results for WinCLIP and AA-CLIP on the logical-anomaly split of MVTec LOCO AD are provided in
Appendix C,
Table A10,
Table A11,
Table A14, and
Table A15.
4.4. Positioning Against Logical-Anomaly-Specific Methods
Table 3 positions the proposed method relative to recent logical-anomaly-specific approaches in terms of their required supervision, additional resources, and modeling assumptions. Therefore, the reported image-level performance should be interpreted as a qualitative comparison rather than a controlled leaderboard.
PSAD relies on manually annotated component masks to train an additional segmentation network and construct multiple component- and patch-level memory banks. SALAD removes manual component annotation but still requires a pseudo-label generation pipeline based on DINO [
39] and SAM-HQ [
43], training of a component segmentation network, and discriminative learning with synthetic logical anomalies. ObjectCore depends on few-shot support images together with an open-world object detector and a mask-generation model. LogicQA avoids task-specific training and annotation but relies on a large pretrained vision–language model and repeated question-generation and question-answering inference.
These methods explicitly model object composition, component relationships, or logical reasoning, providing strong priors for image-level logical anomaly detection. Therefore, their reported AUROC is obtained under substantially different supervision, reference-data, computational, and modeling assumptions, making direct performance comparison inappropriate.
In contrast, the proposed method introduces no additional annotations, object detectors, mask generators, synthetic logical anomalies, or explicit reasoning modules. Instead, it exploits the semantic–spatial relationships already encoded in pretrained CLIP features and constructs only normal relation prototypes. The objective is not to replace dedicated logical-reasoning systems or convert the baseline into a logical-anomaly-specific model. Instead, the unchanged baseline map is fused with relation evidence extracted from the same transformer, extending sensitivity to logical anomalies while retaining the detector’s original dense anomaly pathway and requiring no separate logical-analysis pipeline.
4.5. Results on Structural Anomalies
Table 4 reports the corresponding results on the structural-anomaly split of MVTec LOCO AD. Unlike logical anomalies, structural defects are typically characterized by localized appearance changes, making accurate local evidence more important than relational context.
For AnomalyCLIP, V1 remains ineffective, achieving only 59.4/12.8 pixel AUROC/AUPRO and 46.9/42.5 image AUROC/AP. Baseline + V1 restores much of the lost local information (71.7/52.2), but still does not reach the baseline performance. V2 alone also substantially degrades region precision. Although Baseline + V2 achieves the best pixel AUROC and image-level performance, it lowers pixel AUPRO compared with the baseline, indicating that relation modeling improves pixel ranking and image-level detection but does not consistently preserve accurate defect regions.
For WinCLIP, the proposed V2 fusion improves both pixel AUROC (77.3 to 80.8) and pixel AUPRO (42.4 to 54.9), demonstrating that relation context can complement a relatively weak local anomaly map. In contrast, Baseline + V1 provides only a modest AUPRO gain and decreases the other three metrics.
AA-CLIP exhibits a different behavior. The baseline already achieves the strongest structural localization (89.7 pixel AUROC and 76.5 AUPRO), while both Baseline + V1 (88.1/68.9) and Baseline + V2 (89.2/73.7) reduce localization performance. Furthermore, both relation-only variants remain substantially below the baseline, indicating limited compatibility between AA-CLIP’s anomaly-aware features and the proposed relation representation for structural defects in this setting.
Appendix C,
Table A8,
Table A9,
Table A12,
Table A13,
Table A16, and
Table A17 provide the complete category-wise results. Overall, the effectiveness of relation modeling is considerably more dependent on the underlying detector for structural anomalies than for logical anomalies. These results also explain why Baseline + V2, rather than V2 only, is the proposed configuration: retaining the baseline map substantially restores local-defect evidence.
This observation is consistent with the nature of the two anomaly types. Structural defects usually produce strong local appearance changes that are already captured by patch-level representations, so replacing or averaging these responses with contextual information can weaken localization accuracy. In contrast, logical anomalies often exhibit only subtle local appearance changes, making deviations in semantic–spatial relationships a more informative cue. These complementary characteristics define the scope of the proposed relation modeling.
4.6. External Validation on CAD-SD
Table 5 reports image-level results on CAD-SD, where
Over-coupling and
Lacking are treated as logical co-occurrence anomalies, while
Scratch and
Paint represent surface defects. The results provide external evidence that relation-based scoring is particularly effective for detecting co-occurrence violations.
For AnomalyCLIP, V2 alone increases logical-anomaly AUROC from 50.0 to 96.0 and AP from 27.8 to 91.5. Baseline + V2 also substantially outperforms the baseline, although it does not retain the full gain of the relation-only score. On the surface subset, all variants achieve nearly saturated performance, making it difficult to assess anomaly-type specificity from AnomalyCLIP alone.
WinCLIP provides the clearest separation between the two anomaly types. V2 alone improves logical AUROC from 36.5 to 98.7 and AP from 22.1 to 97.4. In contrast, its surface AUROC/AP decreases from 76.6/62.6 to 54.8/31.8. Baseline fusion recovers much of the lost surface performance but remains slightly below the baseline. This contrast indicates that relation scoring is highly informative for co-occurrence violations but cannot replace the local appearance evidence required for surface-defect detection.
AA-CLIP exhibits a similar pattern. V2 alone raises logical AUROC from 18.5 to 68.1 and AP from 18.1 to 54.8, while reducing surface AUROC/AP from 91.1/86.7 to 72.6/42.8. Baseline + V2 retains only part of the logical improvement but slightly improves the surface baseline to 93.9 AUROC and 90.9 AP. Together with the WinCLIP results, this consistent pattern indicates that relation-only scoring is particularly effective for co-occurrence anomalies, whereas fusion with the local baseline is important for preserving appearance-based defect evidence.
Overall, the consistent behavior across all three detectors supports the intended role of V2: it captures violations of normal semantic–spatial relationships that may not produce a strong local appearance shift. In contrast, surface anomalies are more directly represented by local feature deviations and therefore benefit less consistently from relation-only scoring. Complete results, including the corresponding V1 variants, are provided in
Appendix D,
Table A18.
4.7. Additional Evaluation on MVTec AD
Table 6 further evaluates the proposed method on MVTec AD, a widely used benchmark that primarily contains structural and surface defects. The results show that relation-only scoring cannot generally replace the local anomaly evidence required for this setting.
For AnomalyCLIP, Baseline + V2 improves pixel AUROC from 88.2 to 89.2 and also increases both image-level metrics. However, pixel AUPRO decreases from 80.5 to 77.5, indicating that the fused response improves overall pixel ranking but produces less precise region-level localization. V2 alone performs substantially below the baseline, further showing that relation context is insufficient as a standalone cue for many MVTec AD defects.
For WinCLIP, relation modeling is consistently beneficial. Even V2 alone outperforms the baseline across all pixel- and image-level metrics, improving pixel AUROC/AUPRO from 83.0/58.9 to 88.3/70.2. Baseline + V2 further increases performance to 90.3/77.5 with corresponding improvements in image AUROC and AP. Unlike the other detectors, these results indicate that relation modeling itself provides a stronger anomaly representation than the original WinCLIP baseline, while baseline fusion further combines complementary local and relational evidence.
AA-CLIP shows a different fusion outcome. Its baseline already achieves 91.0 pixel AUROC and 88.0 AUPRO, whereas Baseline + V2 reduces these metrics to 89.5 and 81.6, respectively, despite improving image-level detection. Together with the decrease in AnomalyCLIP AUPRO and the weak relation-only results, this finding shows that relation context does not consistently improve dense localization when local structural cues are already captured effectively by the transferred baseline.
Overall, the effectiveness of V2 on MVTec AD depends strongly on the underlying detector. For WinCLIP, relation modeling alone already provides a stronger anomaly representation than the original baseline, and fusion further improves performance by combining local and relational cues. In contrast, AnomalyCLIP and AA-CLIP continue to rely primarily on local texture, boundary, and material evidence for accurate dense localization. As detailed by the category-wise results, relation re-scoring is most helpful for categories containing orientation, component, or configuration changes, whereas texture-dominated categories with strong baseline responses show smaller or negative changes. Complete V1/V2 results and category-wise baseline and fusion results are provided in
Appendix E,
Table A19 and
Table A20.
4.8. Ablation Studies and Design Analysis
We evaluate the principal design choices on the logical-anomaly split of MVTec LOCO AD using AnomalyCLIP.
Table 7 summarizes the main comparisons, while complete parameter sweeps are reported in
Appendix B,
Table A1,
Table A2 and
Table A3.
Relation content. The first block of
Table 7 compares four relation representations. The position-only relation replaces semantic feature similarity with patch-coordinate information, so that relation propagation depends only on spatial proximity. The raw-feature prototype directly compares each patch feature
with the normal feature prototype at the same spatial index, without attention-based feature propagation. The attention-propagated feature relation corresponds to the proposed V2 formulation without the additional explicit position term, where the patch features are propagated through the attention graph before constructing the position-indexed normal prototype, whereas the fourth variant combines the attention-propagated semantic features with an explicit coordinate-derived position term. Under the preliminary early-fusion formulation, the position-only configuration achieves 55.7 pixel AUROC and 31.2 AUPRO, providing only a modest improvement over the AnomalyCLIP baseline of 53.9/28.7. The raw-feature prototype substantially improves performance to 63.2/38.2, showing that position-indexed normal feature statistics themselves provide a strong anomaly cue. The attention-propagated feature relation further improves performance to 63.9/39.0. Adding an explicit coordinate-derived positional term produces 63.9/38.7 and therefore does not improve upon the attention-propagated feature result. The complete relation-weight sweep in
Table A1 of
Appendix B shows the same overall ordering.
These results show that position-indexed feature prototypes account for a substantial portion of the improvement, while attention-based feature propagation provides an additional gain. However, explicit coordinates are not the primary source of the gain. Spatial information is already incorporated through the visual transformer: positional embeddings affect attention formation across layers, while the category-specific prototype () retains the expected patch index. Consequently, the attention-propagated feature relation (V2) can characterize deviations from a semantic–spatial relation pattern without an additional absolute-coordinate term. Explicit positional cues may also introduce sensitivity to alignment, scale, or viewpoint variation.
Attention graph. The second block compares the attention representation used to define the relation graph. Using relation maps aggregated from the last five layers, DPAM v-v attention obtains 70.6 pixel AUROC and 46.7 AUPRO, whereas the original q-k attention reaches 74.2/51.7. Because both configurations use V2 only, the difference directly reflects the choice of relation graph rather than its fusion with the baseline.
This comparison supports the use of q-k attention as the semantic–spatial graph for message passing. The q-k representation describes contextual dependencies between patch queries and keys, while DPAM features provide the anomaly-sensitive content propagated through these dependencies. In contrast, using the same v-v mechanism to define the relation affinity and produce the anomaly-aware feature content may yield less complementary information.
Table A2 in
Appendix B further evaluates the number of aggregated attention layers and the feature source. The one-, three-, and five-layer v-v variants remain relatively close, with the best AUROC and AUPRO obtained by different aggregation depths. The selected last-five-layer q-k configuration nevertheless outperforms all evaluated v-v alternatives on both metrics. Using the preceding feature layer instead of the final layer also reduces performance under the v-v setting, supporting the use of late semantic features.
Fusion formulation and weight. The final row of
Table 7 combines the selected q-k relation map with the baseline anomaly map. Equal weighting, corresponding to
in
, achieves the best overall result of 74.4 pixel AUROC and 52.7 AUPRO. This slightly improves upon the relation-only q-k result of 74.2/51.7, indicating that the baseline retains complementary local anomaly evidence.
The complete fusion analysis in
Table A3 of
Appendix B explains the transition from the preliminary to the final formulation. Under
, performance improves continuously as
increases over the evaluated range, showing that the relation score should not be treated as only a small correction to the baseline. After reparameterizing the fusion as
, performance remains stable across a broad range of
, and equal fusion yields the highest observed AUPRO while retaining the best AUROC. We therefore fix
without category-specific tuning.
Overall, the ablations support three design conclusions. First, spatially indexed feature prototypes account for a substantial part of the improvement, while attention propagation provides a further gain; explicit coordinate information alone is considerably less effective and provides little additional benefit when combined with semantic features. Second, original q-k attention provides a more effective relation graph than DPAM v-v similarity in the evaluated configuration. Third, the relation branch provides a major complementary logical-anomaly cue rather than merely a small correction to the baseline, while equal fusion preserves complementary local evidence from the baseline.
4.9. Qualitative Analysis
Figure 2,
Figure 3,
Figure 4 and
Figure 5 present qualitative visualizations of the proposed method on representative logical, structural, co-occurrence, and surface anomalies using AnomalyCLIP. These examples illustrate how semantic–spatial relation modeling influences the anomaly maps and complement the quantitative results presented in the previous sections. The visualizations are interpreted together with the relation formulation in Equations (
10)–(
12), highlighting how deviations from the normal semantic–spatial relations contribute to anomaly localization.
To examine the cross-detector applicability of the proposed relation modeling,
Figure A1 in
Appendix A compares results from AnomalyCLIP, WinCLIP, and AA-CLIP on the same MVTec LOCO AD logical-anomaly examples.
4.9.1. Logical Anomalies on MVTec LOCO AD
Figure 2 compares the AnomalyCLIP baseline, V1 only, V2 only, and their fused variants on representative logical anomalies from MVTec LOCO AD. The examples include missing, misplaced, duplicated, and incorrectly connected components in the
breakfast box,
juice bottle,
pushpins,
screw bag, and
splicing connectors categories. The patch-wise baseline mainly responds to locally unusual appearance and is therefore often weak when the individual components remain visually plausible but violate the expected product configuration through their presence, number, position, or connectivity.
V1 measures changes in the attention-connectivity pattern without considering the feature content propagated through the relation graph. It can respond to broad configurational changes, but its activation is often spatially diffuse or does not align clearly with the component responsible for the logical violation. In contrast, V2 evaluates whether the attention-aggregated feature content is consistent with the normal relation prototype at each patch location. Therefore, it can assign a high anomaly score to a locally plausible component when that component appears at an unexpected location, replaces an expected part, occurs in an incorrect number, or participates in an abnormal spatial relationship.
Figure 2.
Qualitative comparison on representative MVTec LOCO AD logical anomalies using AnomalyCLIP. V1 measures changes in attention-connectivity, whereas V2 measures the L2 deviation between attention-aggregated features and normal relation prototypes. Compared with the patch-wise baseline and V1, V2 more clearly highlights components or expected regions associated with missing, displaced, duplicated, or incorrectly connected parts, while Baseline + V2 preserves complementary local anomaly evidence.
Figure 2.
Qualitative comparison on representative MVTec LOCO AD logical anomalies using AnomalyCLIP. V1 measures changes in attention-connectivity, whereas V2 measures the L2 deviation between attention-aggregated features and normal relation prototypes. Compared with the patch-wise baseline and V1, V2 more clearly highlights components or expected regions associated with missing, displaced, duplicated, or incorrectly connected parts, while Baseline + V2 preserves complementary local anomaly evidence.
This distinction is visible across the examples in
Figure 2. For
breakfast box and
splicing connectors, V2 produces a more coherent response over the component or region involved in the configuration error. For
pushpins and
screw bag, it better reflects changes in component arrangement or count than the patch-wise baseline. In the
juice bottle example, V2 responds more selectively to the small component associated with the logical violation, whereas the baseline mainly produces a broader appearance-driven response. These qualitative observations are consistent with the quantitative results in
Table 1, where V1 provides only limited localization gains, whereas V2 yields substantially stronger pixel-level performance.
Baseline + V2 combines complementary local and relational evidence. The baseline preserves responses to locally unusual appearance, whereas V2 highlights components or expected locations involved in the logical inconsistency. Across several examples, the fused map produces a clearer response than either the baseline or V1-based fusion, although the degree of improvement varies across categories.
4.9.2. Structural Anomalies on MVTec LOCO AD
Figure 3 exhibits a different response pattern from the logical anomalies. Structural defects are typically characterized by localized appearance changes, such as cracks, deformations, or boundary irregularities, which are effectively captured by the patch-wise baseline. Consequently, the baseline generally produces sharper localization than the relation maps for small structural defects.
Figure 3.
Qualitative comparison on representative MVTec LOCO AD structural anomalies using AnomalyCLIP. The baseline responds more precisely to localized appearance changes, whereas V2 primarily captures structural changes that influence semantic–spatial relations across multiple patches. Baseline + V2 combines complementary local appearance and relation cues, with the degree of improvement depending on the spatial extent of the defect.
Figure 3.
Qualitative comparison on representative MVTec LOCO AD structural anomalies using AnomalyCLIP. The baseline responds more precisely to localized appearance changes, whereas V2 primarily captures structural changes that influence semantic–spatial relations across multiple patches. Baseline + V2 combines complementary local appearance and relation cues, with the degree of improvement depending on the spatial extent of the defect.
V1 exhibits a similar tendency to V2 by responding to broader structural changes rather than fine local appearance variations. However, because it measures only changes in attention connectivity, its responses are generally more diffuse and less precisely aligned with the structural defects than the baseline.
V2 evaluates deviations from normal semantic–spatial relations rather than local appearance itself. When a defect is confined to a small portion of a patch, it may not substantially alter the contextual relations between neighboring patches, resulting in a relatively weak relation response. This behavior is evident in the juice bottle and splicing connectors examples, where the baseline localizes the structural defects more precisely than V1 and V2.
In contrast, when the structural anomaly affects a larger semantic region, both V1 and V2 respond more strongly. The breakfast box example shows that V2 produces a more coherent response over the defective food region, indicating that larger structural modifications can also alter the semantic–spatial relations captured by the proposed representation.
These observations are consistent with the quantitative results in
Table 4. The baseline remains more effective for fine local defects, whereas relation modeling provides complementary structural evidence when a structural change affects a broader semantic region or inter-patch geometry. Although the visual effect of fusion is not consistently distinct across these examples, the quantitative results indicate that combining local appearance and relation cues can still benefit particular metrics and categories.
4.9.3. Co-Occurrence and Surface Anomalies on CAD-SD
Figure 4 further illustrates the different behaviors of the proposed relation modeling on co-occurrence and surface anomalies in CAD-SD.
Over-coupling and
Lacking violate the expected relationships between otherwise normal assembly components while largely preserving their local appearance. Consequently, the patch-wise baseline often produces relatively weak or incomplete responses because the individual screw and nut components remain visually plausible.
Figure 4.
Qualitative comparison on representative CAD-SD anomalies using AnomalyCLIP. V2 produces clear responses to co-occurrence anomalies (Over-coupling and Lacking) by highlighting disrupted component relations, whereas surface anomalies (Scratch and Paint) remain primarily characterized by local appearance changes. Baseline + V2 combines complementary local appearance and relation cues.
Figure 4.
Qualitative comparison on representative CAD-SD anomalies using AnomalyCLIP. V2 produces clear responses to co-occurrence anomalies (Over-coupling and Lacking) by highlighting disrupted component relations, whereas surface anomalies (Scratch and Paint) remain primarily characterized by local appearance changes. Baseline + V2 combines complementary local appearance and relation cues.
V1 shows a similar qualitative tendency to V2 by responding to changes in component configuration. However, its responses are generally more diffuse and less focused on the components responsible for the co-occurrence violation. Incorporating the propagated feature content in V2 produces more coherent responses over the altered assembly, making the distinction between normal and abnormal configurations more evident.
As a result, V2 responds strongly to the altered assembly configuration in both
Over-coupling and
Lacking, highlighting the affected components or their expected locations. The fused map exhibits a similar response pattern, indicating that the relation cue dominates the localization of co-occurrence anomalies. These qualitative observations are consistent with the substantial improvement on the logical subset reported in
Table 5.
A different behavior is observed for Scratch and Paint. These anomalies are primarily characterized by localized texture or color changes rather than changes in component relationships. Accordingly, the baseline remains the dominant source of localization, while the relation maps provide relatively weaker responses. The fused maps therefore remain visually similar to the baseline, indicating that relation modeling contributes less when the anomaly is confined to local appearance without altering the underlying component configuration.
4.9.4. Structural and Surface Anomalies on MVTec AD
Figure 5 illustrates the behavior of AnomalyCLIP on MVTec AD together with the proposed V1 and V2 variants. Although MVTec AD is primarily used to evaluate surface anomalies, its defect types are not uniformly limited to local texture or material changes. Some samples also involve changes in object orientation, component arrangement, or structural integrity, making semantic–spatial relation cues potentially informative.
Figure 5.
Qualitative results on MVTec AD using AnomalyCLIP. Although MVTec AD primarily contains surface anomalies, some defects also disrupt object-level configuration or component relations. The baseline remains effective for compact local defects, whereas V2 provides additional responses to relation-sensitive anomalies such as flipped or displaced components. Therefore, their fusion can improve localization when local appearance and semantic–spatial relation cues are complementary.
Figure 5.
Qualitative results on MVTec AD using AnomalyCLIP. Although MVTec AD primarily contains surface anomalies, some defects also disrupt object-level configuration or component relations. The baseline remains effective for compact local defects, whereas V2 provides additional responses to relation-sensitive anomalies such as flipped or displaced components. Therefore, their fusion can improve localization when local appearance and semantic–spatial relation cues are complementary.
For compact local defects, such as the color anomaly in
carpet, the baseline produces a more precise response, whereas both V1 and V2 are relatively diffuse or weak. This behavior is consistent with the lower V2-only AUPRO reported in
Table 6, indicating that relation modeling alone is not well suited to fine-grained surface localization. In contrast, V2 provides meaningful responses for relation-sensitive cases. For example, the flipped
metal nut violates the expected object orientation, while the
transistor sample contains a large component separated from its normal configuration. In these cases, V2 responds to the disrupted object- or component-level relations rather than only to local appearance differences.
The coexistence of compact surface defects and relation-sensitive anomalies explains why fusion can improve several aggregate metrics despite the weaker standalone localization of V2. For purely local defects, the fused map largely follows the baseline response, whereas for samples involving abnormal orientation or component configuration, V2 can contribute complementary evidence. Therefore, the qualitative results support the quantitative improvement of Baseline + V2 in
Table 6: relation modeling does not uniformly improve every MVTec AD sample, but it can improve the overall performance by addressing anomaly patterns that are not fully characterized by local appearance cues.
4.9.5. Interpreting the Relation Maps
The qualitative observations across
Figure 2,
Figure 3,
Figure 4 and
Figure 5 are consistent with the perturbation analysis in Equation (
4). Relation modeling is most effective when an anomaly alters semantic context or the spatial configuration of object components, producing changes in both the propagated feature term,
, and the attention structure term,
. Such behavior is evident for logical anomalies in MVTec LOCO AD and CAD-SD, as well as relation-sensitive samples in MVTec AD, where V2 highlights missing, displaced, flipped, or structurally disconnected components. In contrast, compact local defects primarily produce localized feature perturbations with limited changes in attention structure, reducing the contribution of relation modeling.
The visualizations also support the interpretation that the proposed prototypes encode semantic–spatial rather than purely semantic information. In many examples, V2 responds not only to the anomalous component itself but also to its expected location or surrounding semantic context. This behavior is consistent with the use of positional embeddings in attention computation together with the spatially indexed prototype . It also explains why explicitly appending coordinate information provides little additional benefit, as much of the required layout information is already represented by the attention graph and the position-specific prototypes.
Finally, the qualitative results clarify the complementary roles of local appearance and relation modeling. Relation cues are particularly effective for anomalies involving object configuration or component relationships, whereas the baseline remains more reliable for compact texture and material defects. Consequently, the proposed fusion improves robustness not because either cue is universally superior, but because the two cues respond to different types of anomalous evidence.
5. Discussion
5.1. What the Relation Prototype Represents
The proposed prototype does not encode an explicit symbolic rule, such as “exactly one component must be present” or “part A must be connected to part B.” Instead, it represents the expected attention-aggregated feature at each patch position under normal configurations. Therefore, it models the first-order statistics of semantic–spatially conditioned patch features rather than discrete logical constraints.
Semantic information is introduced through detector-specific patch features and content-dependent attention, while spatial information is retained through transformer positional embeddings and the position-indexed prototype . This representation can capture distributed dependencies involving component identity, expected location, orientation, and surrounding context without requiring component annotations or manually defined rules.
The same property also limits interpretability. The proposed method detects deviations from normal semantic–spatial relations, but it does not explicitly determine whether the underlying violation is caused by absence, duplication, incorrect count, displacement, or an invalid connection. Therefore, methods based on explicit component parsing or visual question answering may remain preferable when exact rule verification or human-readable explanations are required [
25,
28,
29].
5.2. Why Image-Level and Pixel-Level Metrics Can Differ
Image-level and pixel-level metrics evaluate different properties of the anomaly response. Image AUROC measures whether normal and anomalous images can be separated, whereas pixel AUROC, AP, and AUPRO depend on how accurately the response overlaps the anomalous region.
This distinction is particularly evident for V1. Changes in attention connectivity may produce a detectable image-level signal even when the corresponding heatmap is spatially diffuse. As a result, V1 can improve image-level separation without providing comparably accurate localization. V2 produces substantially stronger localization than V1 by evaluating feature deviations against spatially indexed normal prototypes, with attention aggregation providing additional contextualization beyond the raw feature representation, but its performance still depends on the spatial extent and type of anomaly.
Relation-only scoring is particularly effective for anomalies involving missing, displaced, duplicated, flipped, or disconnected components, whereas compact local defects may remain better localized by the baseline. Fusion can improve pixel-level performance when the two maps contain complementary evidence, but its benefit need not be uniform across datasets, backbones, or anomaly types. These observations motivate evaluating both image- and pixel-level performance and interpreting relation modeling as a complementary source of anomaly evidence rather than a replacement for local appearance cues.
5.3. Relation to Attention-Based Prior Work
SA-PatchCore also leverages self-attention to improve the detection of co-occurrence anomalies [
24], but it differs from our method in both the role assigned to attention and the representation on which anomaly scoring is performed. In SA-PatchCore, self-attention is incorporated into a PatchCore-style feature and memory-bank framework to enhance or contextualize patch representations before conventional feature-space matching. Therefore, attention serves primarily as a feature augmentation mechanism, while anomaly detection remains based on distances between the resulting patch features and stored normal features.
Instead, our method treats attention as a semantic–spatial message-passing operator. Given detector-specific CLIP patch features F and an attention matrix A, V2 forms the propagated representation , where each patch receives semantic feature content from other patches according to their learned semantic and positional affinities. Rather than refining appearance features, we explicitly model the distribution of these propagated relation messages under normal conditions and define anomaly scores as deviations from category-wise normal prototypes in this relation space. Consequently, the anomaly representation is fundamentally different from that of SA-PatchCore: the anomaly score is computed from relation-message deviations, not from contextualized appearance features. Although both methods employ self-attention to incorporate contextual information beyond local appearance, SA-PatchCore uses attention to improve feature representations for conventional memory matching, whereas our method uses attention to construct an explicit semantic–spatial relation representation for training-free relation re-scoring in CLIP-based anomaly detectors.
5.4. Limitations and Future Directions
The proposed method relies on spatially indexed relation prototypes, assuming that corresponding semantic components appear at approximately consistent patch locations across normal and test images. This assumption is generally reasonable for controlled industrial inspection, where the camera setup and object placement are constrained. However, translation, scale changes, rotation, viewpoint variation, or object misalignment that moves normal semantic components across patch locations can produce relation deviations even in the absence of a true anomaly, potentially increasing false-positive responses. The current method does not explicitly compensate for such geometric variation. Extending the framework with object-centric alignment, position-tolerant matching, or pose-invariant relation representations would improve its applicability to less constrained environments.
Another limitation is that each spatial relation prototype is represented by a single mean. Although this formulation is simple and training-free, it may not adequately characterize categories with multiple valid layouts, orientations, or component states. Multiple prototypes, non-parametric relation memories, or probabilistic representations could model multimodal normal configurations while also providing an estimate of relation uncertainty. Such uncertainty could further indicate when the relation response is sufficiently reliable to complement the baseline anomaly map.
The method identifies deviations from normal semantic–spatial configurations but does not infer explicit logical rules. It can localize an abnormal component or region without determining whether the underlying cause is an incorrect count, a missing part, displacement, or an invalid connection. Integrating the dense relation map with component-level recognition or vision–language reasoning could support explicit verification of these anomaly types and provide human-readable explanations without discarding the localization capability of the proposed representation.
The current implementation computes dense interactions between patch tokens, resulting in quadratic complexity with respect to the number of patches. This cost can become substantial at high input resolutions, where small anomalies require finer tokenization. Sparse neighborhood propagation, hierarchical token aggregation, or low-rank approximations could reduce the computational burden while retaining the contextual information needed for relation modeling.
The design parameters were selected from a single benchmark rather than a separate validation split. Although the resulting configuration generalized well to different detectors and datasets without further tuning, future work should investigate validation protocols that completely separate configuration selection from the final evaluation.
Finally, the proposed method relies on a fixed fusion weight selected empirically using the alpha- and beta-weighting frameworks presented in
Appendix B. Equal-weight fusion yielded the best overall performance in the AnomalyCLIP-based validation experiments, but a weight selected for a particular backbone and evaluation setting may not generalize optimally across datasets or anomaly types. Therefore, adaptive fusion is an important direction for future work; however, estimating map reliability without anomaly supervision remains a challenging problem in the training-free setting. Moreover, CAD-SD contains only a single object category and does not provide pixel-level annotations, which limits both the statistical characterization of its image-level results and the dense quantitative evaluation of co-occurrence anomalies. Therefore, the reported CAD-SD results should be interpreted as external validation rather than as a comprehensive statistical assessment. Future evaluation on more diverse co-occurrence benchmarks with pixel-level masks and uncertainty estimates would enable a more comprehensive assessment of relation-based localization.
6. Conclusions
We presented a training-free relation prototype re-scoring framework that broadens the sensitivity of existing CLIP-based anomaly detectors to include logical anomalies. The proposed method treats position-aware visual self-attention as a semantic–spatial message-passing operator over detector-specific patch features and measures each patch by its deviation from a category-wise normal relation prototype. Through matched standalone and fusion experiments, we showed that direct attention differences, represented by V1, provide only limited and spatially diffuse anomaly evidence. In contrast, V2 captures deviations in attention-aggregated feature content and therefore provides substantially stronger localization cues for anomalies that disrupt expected component identity, position, orientation, or configuration. The final method combines this relation evidence with the baseline anomaly map using the empirically selected equal-weight fusion.
Experiments with AnomalyCLIP, WinCLIP, and AA-CLIP demonstrate that the proposed relation re-scoring consistently strengthens logical anomaly localization and map-derived image-level detection on MVTec LOCO AD. Results on CAD-SD further confirm its sensitivity to co-occurrence violations, while evaluations on structural and surface anomalies from different benchmarks clarify the complementary roles of local appearance and semantic–spatial relation cues. In particular, the relation map is most effective for configurational abnormalities, whereas the baseline remains important for compact texture and material defects. This anomaly-type dependence is consistent with the intended complementary role of the proposed relation cue: it is designed to supply semantic–spatial evidence that is missing from local anomaly maps, not to replace appearance-based detection for every defect type. Therefore, retaining both maps provides a practical mechanism for adding logical sensitivity while preserving local evidence more effectively than relation-only scoring, although the benefit of fixed fusion remains detector- and category-dependent.
Unlike approaches that require component annotations, explicit object extraction and matching, additional composition-model training, or vision–language rule verification, the proposed framework introduces no learnable parameters and directly exploits relational information already present in CLIP representations. Therefore, it can be incorporated into multiple CLIP-based detectors without changing their architecture, checkpoints, or training procedures. Overall, the results establish attention-guided feature deviation as an effective representation for dense logical anomaly analysis and provide a simple, general plug-in that supplements local appearance modeling with sensitivity to semantic–spatial configuration.