Manuscript Offprint
arXiv:2611.12023TIRAD: Text-guided Image Residual Learning for Generalist Anomaly Detection
Seongsu Lee®, Seunghyun Oh®, Seungjae Moon®, and Youngmin Ro*
Machine Intelligence Laboratory,
Dept. of Artificial Intelligence, University of Seoul, Korea
{ssulee0206, osh1795, msj0243, youngmin.ro}@uos.ac.kr
Abstract. Recent anomaly detection studies have shown that residual features, which model the discrepancy between normal and abnormal patterns, provide strong generalization to anomalies unseen during training. However, existing residual-based approaches mainly rely on visual discrepancies derived from image representations, while semantic discrepancies that can be explicitly expressed through language remain largely underexplored. To address this problem, we propose TIRAD, Text-guided Image Residual Learning for Generalist Anomaly Detection, a multimodal residual learning framework that defines the discrepancy between textual representations of normal and abnormal states as a Text Residual Feature and uses it to guide the Image Residual Feature. Specifically, a Text Fusion Module converts patch-level text residuals into a gate that modulates the image residual of each patch. The gate retains the visual discrepancies that the text residual identifies as defect-related and attenuates the others, leading to more discriminative anomaly representations. Extensive experiments on industrial benchmarks and industrial-to-medical transfer demonstrate that the proposed method outperforms existing image-centric residual learning methods.
Keywords: Anomaly Detection · Vision Language Model · Multimodal Learning
1 Introduction
Anomaly Detection (AD) [5, 8, 19, 32] aims to identify abnormal patterns that deviate from normal observations and has been widely adopted in industrial inspection and medical diagnosis [17,34,35,45]. Since anomalous samples are inherently rare, diverse, and often unpredictable, collecting sufficient defect data for every possible abnormal scenario is impractical. This difficulty becomes more severe in real-world deployment, where new object categories, unseen defect types, and domain shifts continuously appear. Consequently, recent studies have increasingly focused on Generalist Anomaly Detection (GAD) [36, 39, 49], which seeks to develop a unified model [37, 41] capable of detecting previously unseen anomalies across diverse object categories and domains without category-specific
- Corresponding author.
Lee et al.

Fig. 1: (a) Illustration of the text residual: subtracting the normal text embedding from the abnormal one yields a text residual that markedly reduces the normal-abnormal similarity. (b) Comparison of text features: raw normal and abnormal embeddings are highly similar and entangled, whereas the text residual features separate normal from abnormal consistently across object classes in the t-SNE projection.
retraining. Unlike conventional AD settings that mainly assume the same category distribution between training and testing, GAD requires a model trained on known categories to generalize to unseen target categories and unseen anomaly types.
A key challenge in GAD is to learn anomaly-relevant representations that are less dependent on object-specific appearance. Recent studies address this issue from the perspective of residual learning. In anomaly detection, a residual can be interpreted as the discrepancy between a normal state and an abnormal state. Instead of representing an object by its absolute visual appearance, residual features emphasize how the query deviates from normality. By suppressing category-specific characteristics, residual representations provide transferable cues for detecting unseen anomalies.
Building on this idea, representative residual-based methods [36, 39, 40, 49] exploit image residual features by comparing query image features with normal reference features or by modeling normal-abnormal visual discrepancies, and demonstrate strong generalization to unseen categories. This line of research indicates that residual learning is a promising direction for building generalist anomaly detectors.
However, existing residual-based anomaly detection methods define residuals only in the image feature space. In other words, they assume that abnormality can be sufficiently represented by visual discrepancies between normal and abnormal image features. Although image residuals are effective for many appearance-level defects, they respond to any deviation from the reference features, including variations in texture, pose, or imaging conditions that are not defects. Whether a visual discrepancy is actually anomalous is a semantic judgment, and the defect concepts needed for this judgment, such as a crack, a scratch, or a missing part, can be explicitly described through language. Relying only on image residuals therefore leaves the model without a semantic criterion for deciding which discrepancies correspond to true anomalies, particularly when it must generalize to unseen categories and domains.
Meanwhile, several AD methods based on Vision-Language Models (VLMs) have attempted to incorporate textual information through handcrafted prompts [19, 33] or learnable text representations [21, 47, 48]. However, these methods typically use the resulting text embeddings as semantic references and compute anomaly scores through image-text similarity [3, 13]. Such direct reliance on text embeddings is suboptimal for anomaly detection because VLMs are primarily trained for category-level image-text alignment rather than fine-grained discrimination between normal and abnormal states. As a result, normal and abnormal textual descriptions may remain entangled in the original text feature space, limiting their ability to provide reliable anomaly-aware cues. More importantly, although residual learning has been extensively studied in the image feature space, textual residuals remain largely underexplored in anomaly detection.
To address this gap, we introduce the Text Residual Feature. Given a set of normal and abnormal text candidates, each query patch is softly matched to the candidates, and a normal text anchor is subtracted from the matched text feature. The resulting residual is close to zero for patches consistent with normality and otherwise points toward the defect semantics most consistent with the patch. Removing the shared normal component leaves the part of the text feature that differs from normality. As illustrated in Fig. 1(a), this subtraction sharply reduces the similarity between normal and abnormal descriptions (cosine similarity 0.921 → 0.230). Since defect concepts are often shared across different object categories and domains, text residuals are more transferable for generalist anomaly detection. As further shown in Fig. 1(b), while raw normal and abnormal text features remain entangled, text residual features separate the two consistently across object classes in the t-SNE projection.
Based on this idea, we propose TIRAD (Text-guided Image Residual learning for generalist Anomaly Detection), a multimodal residual learning framework in which text serves as a semantic refinement of image residuals. The image branch computes patch-level image residuals by measuring the discrepancy between query image features and normal reference features, following a nearest-neighbor residual formulation. In parallel, the text branch computes a text residual for each patch by soft matching over multiple normal and abnormal candidates. This text residual is converted into a scalar gate that multiplicatively modulates the image residual of the same patch, producing a text-guided residual score that is merged with the image-only residual score for the final prediction. Because the gate can only attenuate or preserve the image residual, the text branch does not localize anomalies on its own; it retains the visual discrepancies that the text residual identifies as defect-related and attenuates the others, without any per-category parameter.
The main contributions of this work are summarized as follows:
– We introduce the Text Residual Feature, a semantic residual representation that explicitly models the discrepancy between normal and abnormal textual features, addressing the largely underexplored use of residual cues in the textual domain for generalist anomaly detection.
Lee et al.
– We propose TIRAD, a multimodal residual learning framework that leverages text residual features to guide image residual features. Through a Text Fusion Module, our method effectively combines semantic transferability with visual sensitivity.
– Extensive experiments on diverse anomaly detection benchmarks show that our method improves generalization to unseen categories and anomaly types including a challenging cross-domain, industrial-to-medical transfer setting and outperforms existing image-centric residual learning approaches.
Vision-Language Models for Anomaly Detection. Vision-language models such as CLIP [31] have been widely adopted for anomaly detection through textual descriptions of normal and abnormal states. WinCLIP applies hand-crafted prompt ensembles for zero-/few-shot detection [4, 19, 23], while later work learns object-agnostic or normal-only prompts to better separate normal and abnormal semantics [3, 21, 46–48]. Beyond prompt design, recent methods incorporate large vision-language models or defect-aware supervision for finer anomaly understanding [13, 29, 33], and some approaches even revisit vision-only foundation features for language-free detection [15, 37]. However, these methods use the resulting text embeddings as static semantic anchors and score anomalies through image-text similarity. Because vision-language models are pre-trained for category-level image-text alignment rather than fine-grained normal/abnormal discrimination, normal and abnormal descriptions often remain entangled in the original text space. Consequently, although residual learning has been extensively studied for image features, computing residuals within the text feature space remains largely underexplored. Our work explores this direction by using patch-level text residuals to guide image residuals, combining the transferability of semantic residuals with the localization ability of visual matching.

Fig. 2: Overview of the proposed framework. The image branch uses memory-bank-based nearest-neighbor search to compute an image anomaly score map from query and normal reference features. In parallel, the text branch constructs text residual features from normal and abnormal prompts, and the Text Fusion Module converts them into a gate that semantically modulates image residual features to produce a text-guided score map . The two score maps are merged into the final anomaly score map , which is used for both image-level anomaly detection and pixel-level anomaly localization.
3 Method
We propose TIRAD, a text residual-based framework for generalist anomaly detection. Given a query image and a few normal reference images from the target category, our goal is to produce both an image-level anomaly score and a pixel-level anomaly localization map without updating the frozen image backbone at test time. The key idea is to complement conventional image residuals with text residuals, which describe patch-wise semantic deviations from the normal textual state. While image residuals capture visual discrepancies between the query and normal references, text residuals provide defect-aware semantic guidance that suppresses visually inconsistent but semantically normal variations.
As illustrated in Fig. 2, our framework comprises two complementary branches. The image branch (Sec. 3.2) produces a training-free anomaly map from a normal reference memory bank, while the text branch (Sec. 3.3) derives a text residual that the Text Fusion Module converts into a gate, modulating the image residual to yield a text-guided map . The two maps are merged by a learnable weight (Sec. 3.4) into the final anomaly map for both image-level detection and pixel-level localization.
Lee et al.
3.1 Problem Formulation
We consider a generalist anomaly detection setting where a model is trained on known source categories and evaluated on unseen target categories. Let denote the source training set, where is an image, is the image-level anomaly label, and is the pixel-level anomaly mask. Normal images have and an all-zero mask. During training, each episode consists of a query image , its label , mask , and a set of normal reference images sampled from the source normal images.
At test time, the model is evaluated on unseen target categories that are not used during training. For each target query image, only a few normal reference images from the same target category are provided. No target-category fine-tuning is performed. The objective is to learn a category-generalizable anomaly scoring function , where denotes the category name, is the anomaly localization map, and is the image-level anomaly score.
3.2 Image Branch
The image branch aims to capture patch-level visual discrepancies between a query image and a few normal reference images. Given a query image and normal reference images , we first extract patch-level visual features using a frozen vision encoder [20,30] as with , where denotes the number of image patches. The same encoder is applied to each normal reference image, and all reference patch features are collected to construct a normal memory bank [32,39] .
For each query patch feature , we retrieve its nearest normal reference feature from the memory bank by cosine similarity, , where denotes cosine similarity. The retrieved feature represents the closest normal appearance corresponding to the query patch. We then define the image residual feature as the difference between the query patch feature and its nearest normal reference feature, . We further apply a lightweight image projector to obtain the projected image residual , which is later modulated by the text-derived gate in the text branch.
The image residual feature describes how the local visual pattern of the query image deviates from normal reference appearances. For normal regions, the query patch is expected to be close to at least one normal reference patch, leading to a small residual. In contrast, anomalous regions are likely to produce larger residuals because their visual patterns cannot be well matched by the normal memory bank.
We also compute an image score map using the cosine distance between each query patch and its nearest normal reference patch, for , which yields the image score map . The image branch therefore provides two outputs: the projected image residual features , which are later modulated by the text branch via the Text Fusion Module, and the score map , which is used in the final merge. Since this prior is based solely on visual matching, we further introduce a text branch to incorporate semantic residual cues into the scoring process.
3.3 Text Branch
The text branch provides semantic guidance for image residual features. While the image branch measures visual deviations from normal reference images, the text branch estimates whether each query patch is semantically closer to a normal state or an abnormal state. To this end, it derives a patch-wise text residual and, through the Text Fusion Module, turns this residual into a gate that modulates the image residual and produces a text-guided score; the following paragraphs detail each component.
Given the category name, we construct two sets of predefined text prompts: normal-state prompts and abnormal-state prompts. The normal prompts describe defect-free conditions of the object, such as perfect and flawless. The abnormal prompts describe defect types such as scratch, crack, broken, missing, and other anomaly-related states. We denote the resulting normal and abnormal text features as and , respectively.
Since frozen text embeddings are not directly optimized for patch-level anomaly discrimination, we use a lightweight text projector to adapt them to the residual-based anomaly detection objective, yielding and . We obtain a normal text anchor by aggregating the projected normal text features, . The projected normal and abnormal text features are then used as semantic candidates for patch-wise text matching.
For each query patch feature , we compare it with the projected text candidates and softly match each patch to the most relevant textual state. The matching weights are obtained by applying a temperature-scaled softmax, with temperature , over the cosine similarities between the patch feature and all projected candidates. The matched text representation for the -th patch is then computed as the weighted average of the projected candidates under these matching weights.
We define the text residual feature as the discrepancy between the matched text representation and the normal text anchor:
This residual represents how far the semantic state of a patch deviates from the normal textual state. If a patch is normal, its matched text representation is expected to be close to the normal anchor, resulting in a small text residual. If a patch contains a defect, the matched representation tends to move toward abnormal text candidates, producing a larger semantic residual.
The text residual feature is then used to guide the image residual feature. Specifically, we map the text residual through a lightweight gating module followed by a sigmoid to obtain a patch-wise gate . This gate modulates the projected image residual in an element-wise manner:
Lee et al.
The modulated residual feature is then passed through a lightweight scoring head to produce the text-guided score , which yields the text score map .
In this way, the text branch does not act as an independent text-image similarity classifier. Instead, it computes text residual features from normal and abnormal textual states and uses them to guide patch-level image residuals. This design preserves the localization ability of image residual matching while incorporating semantic cues from defect-related textual descriptions.
3.4 Anomaly Score Aggregation
The final patch-level anomaly score is obtained by merging the image score and the text-guided score:
where is a learnable scalar weight that balances the two scores. The patch-level score map is reshaped to the spatial resolution and upsampled to the input image resolution by bilinear interpolation to obtain the final localization map . For image-level anomaly detection, we aggregate the highest-scoring patches by averaging the anomaly scores of the top 1% patches in the map, which yields the image-level score .
3.5 Training Objective
We train both pixel-level and image-level supervision. Given the predicted anomaly map and the ground-truth mask , we downsample to the patch resolution and supervise the localization output with a segmentation loss. Since anomalous regions typically occupy only a small fraction of the image, the pixel-level labels are highly imbalanced. We therefore combine a focal loss [25], which down-weights easy normal pixels and focuses training on hard anomalous ones, with a dice loss [22], which directly optimizes the region-level overlap between the prediction and the ground-truth mask:
The image-level anomaly score s is supervised by binary cross-entropy:
We further use a patch-text alignment loss to encourage patch features to be closer to the corresponding normal or abnormal text prototype. For each patch feature , we compute a two-way text prediction over the mean projected normal and abnormal text features and (Sec. 3.3):
(6) where is a temperature. The alignment loss is then defined as the mean two-way cross-entropy over all patches:
where is the downsampled patch-level anomaly label. This loss is part of the text branch rather than an auxiliary term, as it shapes the projected text space in which the patch-wise matching and the gate are computed.
The final objective is a weighted sum of the segmentation, classification, and alignment terms:
3.6 Inference
At inference, all learned modules are frozen and no target-category adaptation is performed. For each unseen target category, we build the normal memory bank from the few reference images and instantiate the text prompts from the category name. The final localization map and image-level score are then obtained by the merging and aggregation procedure in Sec. 3.4.
4 Experiments
4.1 Experimental Setup
Datasets and Evaluation Protocol. We evaluate on MVTec AD [2], VisA [50], and BraTS [28] following the BMAD benchmark [1]. MVTec AD and VisA are industrial anomaly detection benchmarks, while BraTS is used to examine industrial-to-medical transfer. Following the generalist anomaly detection setting, we train the model on a source dataset and directly test it on a different target dataset without category-specific retraining. We consider three transfer settings: MVTec AD → VisA, VisA → MVTec AD, and MVTec AD → BraTS.
During training, normal images, abnormal images, and pixel-level ground-truth masks are used. During inference, only a few normal reference images from the target dataset are provided. We report results under 1-shot, 2-shot, and 4-shot settings. Image-level performance is measured by AUROC, AP, and F1-max, while pixel-level localization is evaluated by AUROC, F1-max, and PRO. All metrics are reported in percentage.
Implementation Details. We use DINOv2-Txt [20,30] with a ViT-L/14 [7,10] backbone as the frozen image-text foundation model. The image encoder and text encoder are fixed during training, and only lightweight modules for residual projection, scoring, and merging are optimized. All images are resized to . The model is trained for 20 epochs using AdamW [26] with a learning rate of , weight decay of , and batch size of 32. The loss weights are set to and . All reported results are averaged over three random seeds.
Lee et al.
Table 1: Main results on MVTec AD and VisA under 1-, 2-, 4-shot settings. Results marked with * are based on our re-implementation under the same DINOv2-Txt backbone, while the remaining results are taken from [36]. Best results are in bold, and second-best results are underlined.
| Shot | Method | MVTec AD | VisA | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Image-level | Pixel-level | Image-level | Pixel-level | ||||||||||
| AUROC | AP | F1 | AUROC | F1 | PRO | AUROC | AP | F1 | AUROC | F1 | PRO | ||
| 1-shot | PatchCore | 83.4 | 92.2 | 90.5 | 92.0 | 50.4 | 79.7 | 79.9 | 82.8 | 81.7 | 95.4 | 38.0 | 80.5 |
| WinCLIP | 93.1 | 96.5 | 93.7 | 95.2 | 55.9 | 87.1 | 83.8 | 85.1 | 83.1 | 96.4 | 41.3 | 85.1 | |
| AnomalyDINO* | 95.4 | 97.6 | 94.9 | 93.8 | 52.2 | 86.0 | 85.6 | 88.3 | 82.9 | 95.6 | 36.4 | 87.3 | |
| ResAD* | 92.8 | 95.5 | 93.9 | 94.9 | 55.4 | 92.1 | 89.3 | 91.2 | 87.2 | 96.5 | 38.7 | 87.7 | |
| NAGL* | 96.0 | 97.8 | 95.4 | 95.8 | 55.7 | 92.7 | 90.1 | 91.6 | 86.6 | 97.1 | 38.9 | 89.7 | |
| TIRAD(Ours) | 97.1 | 98.4 | 96.2 | 95.9 | 56.2 | 92.6 | 91.5 | 92.4 | 87.7 | 97.4 | 41.5 | 89.9 | |
| 2-shot | PatchCore | 86.3 | 93.8 | 92.0 | 93.3 | 53.0 | 82.3 | 81.6 | 84.8 | 82.5 | 96.1 | 41.0 | 82.6 |
| WinCLIP | 94.4 | 97.0 | 94.4 | 96.0 | 58.4 | 88.4 | 84.6 | 85.8 | 83.0 | 96.8 | 43.5 | 86.2 | |
| InCTRL | 94.0 | 96.9 | - | - | - | - | 85.8 | 87.7 | - | - | - | - | |
| AnomalyDINO* | 95.9 | 97.8 | 95.4 | 94.2 | 54.8 | 92.5 | 87.4 | 89.8 | 84.4 | 96.8 | 34.2 | 88.1 | |
| ResAD* | 94.5 | 96.7 | 94.7 | 95.8 | 55.5 | 92.4 | 90.9 | 91.5 | 87.8 | 96.7 | 39.5 | 89.9 | |
| NAGL* | 96.7 | 98.1 | 96.1 | 96.0 | 56.9 | 93.1 | 91.6 | 92.6 | 87.7 | 97.3 | 40.3 | 90.7 | |
| TIRAD(Ours) | 97.6 | 98.7 | 97.1 | 96.2 | 55.9 | 92.8 | 93.1 | 93.4 | 89.1 | 97.8 | 42.1 | 90.8 | |
| 4-shot | PatchCore | 88.8 | 94.5 | 92.3 | 94.3 | 55.0 | 84.3 | 85.3 | 87.5 | 84.3 | 96.8 | 43.9 | 84.9 |
| WinCLIP | 95.2 | 97.3 | 94.7 | 96.2 | 59.5 | 89.0 | 87.3 | 88.8 | 84.2 | 97.2 | 47.0 | 87.6 | |
| InCTRL | 94.5 | 97.2 | - | - | - | - | 87.7 | 90.2 | - | - | - | - | |
| AnomalyDINO* | 96.9 | 98.3 | 96.2 | 94.3 | 53.4 | 86.8 | 89.1 | 91.3 | 85.9 | 97.0 | 35.2 | 88.6 | |
| ResAD* | 95.5 | 97.5 | 95.5 | 95.1 | 56.8 | 92.3 | 92.6 | 92.8 | 89.0 | 96.8 | 40.3 | 90.7 | |
| NAGL* | 97.6 | 98.5 | 96.4 | 96.2 | 57.6 | 93.2 | 93.1 | 93.6 | 89.1 | 97.6 | 41.5 | 91.2 | |
| TIRAD(Ours) | 98.2 | 99.2 | 97.7 | 96.5 | 57.9 | 93.4 | 93.9 | 94.3 | 89.5 | 98.1 | 43.1 | 91.8 | |
4.2 Main Results
Comparison with Existing Methods. Table 1 reports the main results on MVTec AD and VisA. Against the strongest re-implemented baseline NAGL* [36], image-level AUROC improves by 1.1/0.9/0.6 points on MVTec AD and 1.4/1.5/0.8 points on VisA under the 1-, 2-, and 4-shot settings, with F1 gains of up to 1.4 points, while ResAD* [39] and AnomalyDINO* [6] are outperformed by clear margins. These consistent gains indicate that text residual cues sharpen the object-level normal/abnormal decision, where purely visual residuals have largely saturated. For localization, our method attains the best pixel-level AUROC across all shots on both datasets, improves VisA pixel-level F1 over NAGL* by 2.6/1.8/1.6 points with the best PRO in every setting, and remains best or comparable on MVTec AD. The image-level improvement is thus the more decisive gap, while the clearest pixel-level gains emerge in the cross-domain setting discussed next.
Cross-Domain Transfer. Table 2 evaluates industrial-to-medical transfer, where all methods share the same DINOv2-Txt backbone and are trained on MVTec AD without any BraTS fine-tuning. Here the benefit of text residuals is most evident. The image-level AUROC improves over the second-best method by 0.9, 2.9, and 3.3 points under the 1-, 2-, and 4-shot settings, and the pixel-level
Table 2: Cross-domain results on BraTS under 1-, 2-, and 4-shot settings. All competing methods are reproduced under the same DINov2-Txt backbone, where models are trained on MVTec AD and directly evaluated on BraTS without target-domain fine-tuning. Best results are in bold, and second-best results are underlined.
| Shot | Method | Image-level | Pixel-level | ||||
|---|---|---|---|---|---|---|---|
| AUROC | AP | F1 | AUROC | F1 | PRO | ||
| 1-shot | AnomalyDINO | 71.83 | 91.03 | 91.13 | 94.69 | 39.18 | 76.43 |
| ResAD | 71.95 | 90.47 | 91.07 | 95.32 | 37.47 | 76.29 | |
| NAGL | 72.79 | 91.05 | 91.34 | 95.36 | 42.66 | 77.30 | |
| TIRAD(Ours) | 73.69 | 92.12 | 91.55 | 95.81 | 46.44 | 76.14 | |
| 2-shot | AnomalyDINO | 76.77 | 92.32 | 91.40 | 95.36 | 42.69 | 77.78 |
| ResAD | 76.05 | 91.51 | 91.82 | 96.19 | 48.09 | 78.01 | |
| NAGL | 76.96 | 92.46 | 91.89 | 95.62 | 44.51 | 78.29 | |
| TIRAD(Ours) | 79.83 | 94.04 | 92.10 | 96.53 | 51.06 | 78.50 | |
| 4-shot | AnomalyDINO | 79.36 | 93.29 | 91.52 | 95.79 | 45.38 | 79.13 |
| ResAD | 79.76 | 92.47 | 92.06 | 95.73 | 46.31 | 78.92 | |
| NAGL | 80.53 | 93.56 | 92.23 | 96.07 | 47.23 | 79.22 | |
| TIRAD(Ours) | 83.80 | 95.39 | 92.38 | 96.97 | 54.32 | 79.76 | |
Table 3: Ablation study on text residual modeling under the 1-shot setting on MVTec AD. “matched” directly uses the matched text feature, while “residual” uses the text residual feature computed with respect to the normal text anchor.
| Configuration | Image-level | Pixel-level | ||||
|---|---|---|---|---|---|---|
| AUROC | AP | F1 | AUROC | F1 | PRO | |
| 93.79 | 96.60 | 94.77 | 95.61 | 54.21 | 91.48 | |
| (matched) | 95.47 | 97.50 | 95.56 | 95.67 | 54.82 | 91.98 |
| (residual) | 97.06 | 98.39 | 96.21 | 95.87 | 56.19 | 92.63 |
F1 by 3.8, 3.0, and 7.1 points. Notably, the image-level margin grows steadily as more reference images become available, suggesting that semantic text residuals become increasingly effective at suppressing domain-specific visual variation once sufficient normal context is provided.
4.3 Ablation Study
We conduct ablation studies to validate the contribution of the proposed components. Table 3 analyzes the effect of text residual modeling. While the matched text feature already improves over the image-only baseline, the residual formulation yields a substantially larger gain, indicating that the semantic discrepancy relative to the normal anchor rather than the absolute matched embedding is the primary driver of the improvement.
Table 4 studies the effect of the text projector and image projector. The results show that the text projector improves performance by mapping text
Lee et al.
Table 4: Ablation study on the effect of the text and image projectors. We compare configurations that include or remove the learnable projectors, isolating the contribution of each projector and showing which configuration is most beneficial.
| Text Proj | Image Proj | Image-level | Pixel-level | ||||
|---|---|---|---|---|---|---|---|
| AUROC | AP | F1 | AUROC | F1 | PRO | ||
| ✗ | ✗ | 95.18 | 97.27 | 95.08 | 95.76 | 55.39 | 92.19 |
| ✓ | ✗ | 95.98 | 97.95 | 95.35 | 95.83 | 55.87 | 92.36 |
| ✗ | ✓ | 96.75 | 98.22 | 96.10 | 95.85 | 56.18 | 92.66 |
| ✓ | ✓ | 97.06 | 98.39 | 96.21 | 95.87 | 56.19 | 92.63 |
Table 5: Ablation study on the merge weight in , evaluated as a post-hoc sweep on the trained checkpoint (learned ).
| Image-level | Pixel-level | |||||
|---|---|---|---|---|---|---|
| AUROC | AP | F1 | AUROC | F1 | PRO | |
| 0.0 | 93.79 | 96.60 | 94.77 | 95.61 | 54.21 | 91.48 |
| 0.2 | 96.86 | 98.24 | 96.11 | 95.64 | 55.26 | 92.21 |
| 0.4 | 96.08 | 97.81 | 95.97 | 95.71 | 54.60 | 92.06 |
| 0.6 | 96.00 | 97.61 | 95.77 | 95.68 | 53.86 | 92.03 |
| 0.8 | 95.33 | 96.95 | 95.16 | 95.43 | 52.79 | 91.72 |
(a) Raw
(b) Adapted
(c) Adapted + Residual

Fig. 3: t-SNE visualization of text features across three stages: (a) raw features from the frozen encoder, (b) adapted features after the learned text projector, and (c) the resulting text residual features. Separation between normal and abnormal semantic states improves progressively from (a) to (c), and remains consistent across different object classes.
residual features into a more discriminative space for anomaly scoring. The image projector also contributes by transforming image residual features before they are modulated by the text-derived gate. When both projectors are used together, the model achieves the best overall balance, indicating that the two projectors play complementary roles in aligning semantic and visual residual cues.
Table 5 evaluates the effect of the merge weight . Relying only on the image residual score limits the benefit of semantic information, while assigning an excessively large weight to the text residual score weakens visual localization reliability. The best performance is obtained with a moderate merge weight, showing that text residual features are most effective when used as complementary guidance rather than as a replacement for image residual features.
4.4 Analysis
Fig. 3 visualizes the text feature distributions across three stages: raw features, projector-adapted features, and text residual features. The raw text features from

Fig. 4: Qualitative anomaly localization on MVTec AD and VisA. From left to right: input image, ground-truth mask, text-residual gate, image residual response, and the fused anomaly map. The text-residual gate modulates the image residual, and the resulting fused map localizes anomalies more accurately than the image residual alone.
the frozen encoder show relatively weak separation between normal and abnormal semantic states, indicating that frozen textual embeddings are not directly optimized for anomaly discrimination. After the text projector, the distribution becomes more structured, suggesting that the projector reshapes textual representations toward the anomaly detection objective; notably, despite originating from different object classes, the adapted features form more coherent clusters organized by normal and abnormal states rather than by class. The text residual features exhibit the clearest separation of the three, demonstrating that residual semantic directions provide class-agnostic cues for anomaly discrimination.
4.5 Qualitative Results
Fig. 4 and Fig. 5 present qualitative anomaly localization results. In Fig. 4, the gate maps show that the text branch selectively modulates visually suspicious regions, suppressing irrelevant activations while emphasizing regions that are semantically consistent with abnormality. By applying this gate to the image residual, the fused map yields more focused and coherent localization than the image residual alone, aligning more closely with the ground-truth anomalous regions and reducing false activations in normal background areas.
Fig. 5 further compares the anomaly maps of our method with those of competing methods. Our results produce sharper and better-localized responses on the ground-truth anomalous regions, whereas the baselines tend to yield more diffuse activations or miss subtle defects.
Lee et al.

Fig. 5: Qualitative comparison of anomaly maps produced by different methods, each following the setting in Sec. 4.
5 Conclusion
We presented TIRAD, a generalist few-shot anomaly detection framework that complements conventional image residuals with text residuals. Rather than treating text as a static similarity anchor, our method computes residuals in the text feature space and uses them to gate patch-level image residuals, refining which visual discrepancies correspond to true anomalies while preserving the localization ability of visual matching. Built on a frozen backbone with only lightweight modules trained, it transfers to unseen categories without target-category fine-tuning, and yields consistent gains over strong same-backbone baselines across industrial benchmarks and industrial-to-medical transfer, with the largest improvements in the cross-domain regime. These results suggest that modeling semantic differences between normal and abnormal descriptions is a promising, underexplored direction for generalist anomaly detection.
A key limitation arises when a single patch contains both normal and abnormal regions: the mixed patch is assigned an ambiguous label that lies between the normal and abnormal textual states, which weakens the text residual and blurs boundary localization. Addressing such mixed patches, for example through finer-grained or soft patch-level supervision, is an important direction for future work.
Acknowledgments. This work was supported by the National Research Foundation (NRF) grant funded by the Korea government (MSIT) [RS-2025-00562400] and [RS-2022-NR068754].
References
-
Bao, J., Sun, H., Deng, H., He, Y., Zhang, Z., Li, X.: Bmad: Benchmarks for medical anomaly detection. In: Proceedings of the IEEE/CVF conference on computer vision and pattern recognition. pp. 4042–4053 (2024)
-
Bergmann, P., Fauser, M., Sattlegger, D., Steger, C.: MVTec AD – a comprehensive real-world dataset for unsupervised anomaly detection. In: CVPR (2019)
-
Cao, Y., Zhang, J., Frittoli, L., Cheng, Y., Shen, W., Boracchi, G.: AdaCLIP: Adapting CLIP with hybrid learnable prompts for zero-shot anomaly detection. In: ECCV (2024)
-
Chen, X., Han, Y., Zhang, J.: A zero-/few-shot anomaly classification and segmentation method for cvpr 2023 vand workshop challenge tracks 1&2: 1st place on zero-shot ad and 4th place on few-shot ad. ArXiv abs/2305.17382 (2023)
-
Cohen, N., Hoshen, Y.: Sub-image anomaly detection with deep pyramid correspondences. ArXiv abs/2005.02357 (2020)
-
Damm, S., Laszkiewicz, M., Lederer, J., Fischer, A.: Anomalydino: Boosting patch-based few-shot anomaly detection with dinov2. In: 2025 IEEE/CVF Winter Conference on Applications of Computer Vision (WACV). pp. 1319–1329. IEEE (2025)
-
Darcet, T., Oquab, M., Mairal, J., Bojanowski, P.: Vision transformers need registers. ICLR (2023)
-
Defard, T., Setkov, A., Loesch, A., Audigier, R.: PaDiM: A patch distribution modeling framework for anomaly detection and localization. In: ICPR (2021)
-
Deng, H., Li, X.: Anomaly detection via reverse distillation from one-class embedding. In: CVPR (2022)
-
Dosovitskiy, A.: An image is worth 16x16 words: Transformers for image recognition at scale. ICLR (2020)
-
Gao, B.B.: Learning to detect multi-class anomalies with just one normal image prompt. In: ECCV (2025)
-
Gao, B.B., Zhou, Y., Yan, J., Cai, Y., Zhang, W., Wang, M., Liu, J., Liu, Y., Wang, L., Wang, C.: Adaptclip: Adapting clip for universal visual anomaly detection. In: Proceedings of the AAAI Conference on Artificial Intelligence. vol. 40, pp. 4095–4103 (2026)
-
Gu, Z., Zhu, B., Zhu, G., Chen, Y., Tang, M., Wang, J.: Anomalygpt: Detecting industrial anomalies using large vision-language models. In: Proceedings of the AAAI conference on artificial intelligence. vol. 38, pp. 1932–1940 (2024)
-
Gudovskiy, D., Ishizaka, S., Kozuka, K.: CFLOW-AD: Real-time unsupervised anomaly detection with localization via conditional normalizing flows. In: WACV (2022)
-
Hou, Y., Li, P., Liu, Z., Wang, Y., Ruan, Y., Qiu, J., Xu, K.: Visualad: Language-free zero-shot anomaly detection via vision transformer. In: Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition. pp. 21346–21356 (2026)
-
Huang, C., Guan, H., Jiang, A., Zhang, Y., Spratling, M., Wang, Y.F.: Registration based few-shot anomaly detection. In: European conference on computer vision. pp. 303–319. Springer (2022)
-
Huang, C., Jiang, A., Feng, J., Zhang, Y., Wang, X., Wang, Y.: Adapting visual-language models for generalizable anomaly detection in medical images. In: IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR) (2024)
Lee et al.
-
Hyun, J., Kim, S., Jeon, G., Kim, S.H., Bae, K., Kang, B.: Reconpatch : Contrastive patch representation learning for industrial anomaly detection. In: IEEE Workshop/Winter Conference on Applications of Computer Vision (2023). https://doi.org/10.1109/WACV57701.2024.00205
-
Jeong, J., Zou, Y., Kim, T., Zhang, D., Ravichandran, A., Dabeer, O.: WinCLIP: Zero-/few-shot anomaly classification and segmentation. In: CVPR (2023)
-
Jose, C., Moutakanni, T., Kang, D., Baldassarre, F., Darcet, T., Xu, H., Li, D., Szafraniec, M., Ramamonjisoa, M., Oquab, M., et al.: Dinov2 meets text: A unified framework for image-and pixel-level vision-language alignment. In: Proceedings of the Computer Vision and Pattern Recognition Conference. pp. 24905–24916 (2025)
-
Li, X., Zhang, Z., Tan, X., Chen, C., Qu, Y., Xie, Y., Ma, L.: PromptAD: Learning prompts with only normal samples for few-shot anomaly detection. In: CVPR (2024)
-
Li, X., Sun, X., Meng, Y., Liang, J., Wu, F., Li, J.: Dice loss for data-imbalanced nlp tasks. In: ACL (2020)
-
Li, X., Huang, Z., Xue, F., Zhou, Y.: MuSc: Zero-shot industrial anomaly classification and segmentation with mutual scoring of the unlabeled images. In: ICLR (2024)
-
Li, Y., Zhang, S., Li, K., Lao, Q.: One-to-Normal: Anomaly personalization for few-shot anomaly detection. In: NeurIPS (2024)
-
Lin, T.Y., Goyal, P., Girshick, R., He, K., Dollár, P.: Focal loss for dense object detection. In: ICCV (2017)
-
Loshchilov, I., Hutter, F.: Decoupled weight decay regularization. In: ICLR (2019)
-
Lv, W., Su, Q., Xu, W.: One-for-all few-shot anomaly detection via instance-induced prompt learning. In: ICLR (2025)
-
Menze, B.H., Jakab, A., Bauer, S., Kalpathy-Cramer, J., Farahani, K., Kirby, J., et al.: The multimodal brain tumor image segmentation benchmark (BRATS). IEEE Trans. Med. Imaging 34(10), 1993–2024 (2014)
-
Oh, S., Lee, S., Chae, S., Ro, Y.: Aulora: Anomaly understanding with low-rank adaptation for zero-shot anomaly detection. IEEE Access (2025)
-
Oquab, M., Darcet, T., Moutakanni, T., Vo, H.V., Szafraniec, M., Khalidov, V., Fernandez, P., HAZIZA, D., Massa, F., El-Nouby, A., Assran, M., Ballas, N., Galuba, W., Howes, R., Huang, P.Y., Li, S.W., Misra, I., Rabbat, M., Sharma, V., Synnaeve, G., Xu, H., Jegou, H., Mairal, J., Labatut, P., Joulin, A., Bojanowski, P.: DINOv2: Learning robust visual features without supervision. Transactions on Machine Learning Research (2024)
-
Radford, A., Kim, J.W., Hallacy, C., Ramesh, A., Goh, G., Agarwal, S., Sastry, G., Askell, A., Mishkin, P., Clark, J., Krueger, G., Sutskever, I.: Learning transferable visual models from natural language supervision. In: ICML (2021)
-
Roth, K., Pemula, L., Zepeda, J., Schölkopf, B., Brox, T., Gehler, P.: Towards total recall in industrial anomaly detection. In: CVPR (2022)
-
Sadikaj, Y., Zhou, H., Halilaj, L., Schmid, S., Staab, S., Plant, C.: Multiads: Defect-aware supervision for multi-type anomaly detection and segmentation in zero-shot learning. In: Proceedings of the IEEE/CVF International Conference on Computer Vision. pp. 22978–22988 (2025)
-
Schulthess, N., Konukoglu, E.: Anomaly detection by clustering dino embeddings using a dirichlet process mixture. In: International Conference on Medical Image Computing and Computer-Assisted Intervention. pp. 46–56. Springer (2025)
-
Shiri, M., Beyan, C., Murino, V.: Madclip: Few-shot medical anomaly detection with clip (2025), https://arxiv.org/abs/2506.23810
-
Wang, Y., Wang, X., Gong, Y., Xiao, J.: Normal-abnormal guided generalist anomaly detection. NIPS (2026)
-
Wei, S., Jiang, J., Xu, X.: Uninet: A contrastive learning-guided unified framework with feature selection for anomaly detection. In: Proceedings of the Computer Vision and Pattern Recognition Conference. pp. 9994–10003 (2025)
-
Xie, G., Wang, J., Liu, J., Jin, Y., Zheng, F.: Pushing the limits of fewshot anomaly detection in industry vision: Graphcore. In: ICLR (2023)
-
Yao, X., Chen, Z., Gao, C., Zhai, G., Zhang, C.: Resad: A simple framework for class generalizable anomaly detection. Advances in Neural Information Processing Systems 37, 125287–125311 (2024)
-
Yao, X., Luo, Y., Qian, Z., Zhang, C.: Adpretrain: Advancing industrial anomaly detection via anomaly representation pretraining. Advances in Neural Information Processing Systems 38, 122977–123005 (2026)
-
You, Z., Cui, L., Shen, Y., Yang, K., Lu, X., Zheng, Y., Le, X.: A unified model for multi-class anomaly detection. In: NeurIPS (2022)
-
Yu, J., Zheng, Y., Wang, X., Li, W., Wu, Y., Zhao, R., Wu, L.: FastFlow: Unsupervised anomaly detection and localization via 2d normalizing flows. arXiv preprint arXiv:2111.07677 (2021)
-
Zavrtanik, V., Kristan, M., Skočaj, D.: DRAEM-a discriminatively trained reconstruction embedding for surface anomaly detection. In: ICCV (2021)
-
Zhang, H., Wu, Z., Wang, Z., Chen, Z., Jiang, Y.G.: Prototypical residual networks for anomaly detection and localization. In: CVPR (2023)
-
Zhang, X., Xu, M., Qiu, D., Yan, R., Lang, N., Zhou, X.: Mediclip: Adapting clip for few-shot medical image anomaly detection. In: International Conference on Medical Image Computing and Computer-Assisted Intervention. pp. 458–468. Springer (2024)
-
Zhou, K., Yang, J., Loy, C.C., Liu, Z.: Conditional prompt learning for vision-language models. In: CVPR (2022)
-
Zhou, K., Yang, J., Loy, C.C., Liu, Z.: Learning to prompt for vision-language models. International Journal of Computer Vision 130(9), 2337–2348 (2022)
-
Zhou, Q., Pang, G., Tian, Y., He, S., Chen, J.: AnomalyCLIP: Object-agnostic prompt learning for zero-shot anomaly detection. In: ICLR (2024)
-
Zhu, J., Pang, G.: Toward generalist anomaly detection via in-context residual learning with few-shot sample prompts. In: CVPR (2024)
-
Zou, Y., Jeong, J., Pemula, L., Zhang, D., Dabeer, O.: Spot-the-difference self-supervised pre-training for anomaly detection and segmentation. In: ECCV (2022)
Lee et al.
Supplementary Material
TIRAD: Text-guided Image Residual Learning for Generalist Anomaly Detection
A Prompt Taxonomy
We provide the full set of text prompts used by the text branch. For each domain, we use a list of normal-state prompts and, for every defect type, a list of abnormal-state prompts. All prompts are wrapped by the shared template ensemble below, and the resulting embeddings are averaged per state before projection.
A.1 Provenance
Prompt engineering is not a contribution of this work. For the industrial domains (MVTec AD and VisA), we directly adopt the defect-aware prompt taxonomy of MultiADS [33]: the normal-state list, the template ensemble, and the per-defect-type prompt sets are taken from its knowledge base for anomalies without modification. This choice is deliberate: reusing an off-the-shelf prompt set isolates our contribution to the residual formulation and the text-guided gate rather than to prompt design.
For the medical domain (BraTS), no comparable public prompt set covers brain MRI, so we construct the prompts ourselves, mirroring the structure of the industrial taxonomy (one normal-state list plus per-anomaly-type descriptor lists). These descriptors denote generic semantic states that may appear in brain MRI; they are not diagnostic labels and are not derived from any prior medical anomaly-detection method. In the BraTS-based benchmark the ground-truth anomaly is tumor presence, whereas the abnormal prompts intentionally span a superset of brain-anomaly descriptors so that the patch-level soft matching can select the closest semantic state.
A.2 Template Ensemble
Every state prompt is expanded by the following 35-way template ensemble (shared across all domains, following [33]); { } is replaced by the filled state string:
a bad photo of a [cls], a low resolution photo of the [cls], a bad photo of the [cls], a cropped photo of the [cls], a bright photo of a [cls], a dark photo of the [cls], a photo of my [cls], a photo of the cool [cls], a close-up photo of a [cls], a black and white photo of the [cls], a bright photo of the [cls], a cropped photo of a [cls], a jpeg corrupted photo of a [cls], a blurry photo of the [cls], a photo of the [cls], a good photo of
TIRAD 19
Table A1: Normal-state prompt templates for the three evaluation domains. The industrial lists follow the taxonomy of MultiADS [33]; the medical list is constructed by us (Sec. A.1). [cls] is replaced by the category name.
| MVTec AD | VisA | BraTS (medical) | |
|---|---|---|---|
| 1 | [cls] | [cls] | [cls] |
| 2 | flawless [cls] | flawless [cls] | healthy [cls] |
| 3 | perfect [cls] | perfect [cls] | normal [cls] |
| 4 | unblemished [cls] | unblemished [cls] | intact [cls] |
| 5 | [cls] without flaw | [cls] without flaw | [cls] without abnormality |
| 6 | [cls] without defect | [cls] without defect | [cls] without lesion |
| 7 | [cls] without damage | [cls] without damage | [cls] without any anomaly |
| 8 | [cls] in ideal condition | [cls] in pristine condition | [cls] in normal condition |
| 9 | [cls] with immaculate quality | [cls] with no imperfections | [cls] with normal appearance |
| 10 | [cls] without any imperfections | [cls] with ideal quality | [cls] with no pathological region |
the [cls].., a photo of one [cls].., a close-up photo of the [cls].., a photo of a [cls].., a low resolution photo of a [cls].., a photo of a large [cls].., a blurry photo of a [cls].., a jpeg corrupted photo of the [cls].., a good photo of a [cls].., a photo of the small [cls].., a photo of the large [cls].., a black and white photo of a [cls].., a dark photo of a [cls].., a photo of a cool [cls].., a photo of a small [cls].., there is a [cls] in the scene.., there is the [cls] in the scene.., this is a [cls] in the scene.., this is the [cls] in the scene.., this is one [cls] in the scene.
A.3 Normal-State Prompts
A.4 Industrial Defect-Aware Prompts
Tables A2 and A3 list the complete defect-aware prompts for MVTec AD and VisA. Each dataset uses a superset of defect types across all of its categories; at test time the category name fills [cls].
Table A2: Defect-aware prompts for MVTec AD (20 defect states, superset over 15 categories), adopted from the MultiADS knowledge base [33].
| Defect type | Prompts ([cls] = category name) |
|---|---|
| bent | [cls] has a bent defect; flawed [cls] with a bent; a bend found in [cls]; [cls] with noticeable bending; a bent edge on [cls]; [cls] has a slight curve defect |
Lee et al.
| Defect type | Prompts |
|---|---|
| broken | [cls] has a broken defect; flawed [cls] with breakage; visible breakage on [cls]; [cls] with broken areas; [cls] shows signs of breaking; cracked or broken spots on [cls] |
| color | [cls] has a color defect; inconsistent color on [cls]; [cls] with color discrepancies; [cls] has a noticeable color difference; [cls] with irregular coloring; [cls] has off-color patches |
| combined | [cls] has a combined defect; multiple issues with [cls]; [cls] with mixed defects; [cls] showing multiple imperfections; several flaws found on [cls]; [cls] with combined defect types |
| contamination | [cls] has a contamination defect; foreign particles on [cls]; [cls] is contaminated; [cls] contains contaminants; [cls] has impurity issues; traces of contamination on [cls] |
| crack | [cls] has a crack defect; a crack is present on [cls]; cracked area on [cls]; [cls] with noticeable cracking; fine cracks found on [cls]; [cls] shows surface cracks |
| cut | [cls] has a cut defect; cut marks on [cls]; [cls] with visible cuts; a cut detected on [cls]; [cls] is sliced or cut; surface cut seen on [cls] |
| fabric | [cls] has a fabric defect; [cls] has a fabric border defect; [cls] has a fabric interior defect; fabric quality issues on [cls]; [cls] with textile irregularities; fabric borders on [cls] show defects |
| faulty imprint | [cls] has a faulty imprint defect; [cls] has a print defect; incorrect printing on [cls]; misaligned print on [cls]; printing errors present on [cls]; [cls] has a blurred print defect |
| glue | [cls] has a glue defect; [cls] has a glue strip defect; excess glue on [cls]; [cls] with uneven glue application; [cls] has visible glue spots; misplaced glue seen on [cls] |
| hole | [cls] has a hole defect; a hole on [cls]; visible hole on [cls]; [cls] with punctures; small hole found in [cls]; perforations present on [cls] |
| missing | [cls] has a missing defect; flawed [cls] with something missing; [cls] has missing components; missing parts on [cls]; [cls] shows absent pieces; certain parts missing from [cls] |
| poke | [cls] has a poke defect; [cls] has a poke insulation defect; visible poke mark on [cls]; [cls] has puncture marks; a poke flaw on [cls]; small poke defect on [cls] |
| Defect type | Prompts |
|---|---|
| rough | [cls] has a rough defect; rough texture on [cls]; uneven surface on [cls]; [cls] is coarser than expected; surface roughness seen on [cls]; texture defects on [cls] |
| scratch | [cls] has a scratch defect; flawed [cls] with a scratch; visible scratches on [cls]; [cls] with surface scratches; minor scratches seen on [cls]; [cls] shows scratch marks |
| squeeze | [cls] has a squeeze defect; flawed [cls] with a squeeze; squeezed area on [cls]; [cls] has compression marks; [cls] appears squeezed; flattened areas on [cls] |
| thread | [cls] has a thread defect; flawed [cls] with a thread; loose threads on [cls]; [cls] has visible threads; untrimmed threads on [cls]; threads sticking out on [cls] |
| liquid | [cls] has a liquid defect; flawed [cls] with liquid; [cls] with oil; liquid marks on [cls]; [cls] with liquid residue; stains from liquid on [cls] |
| misplaced | [cls] has a misplaced defect; flawed [cls] with misplacing; [cls] shows misalignment; misplaced parts on [cls]; [cls] with incorrect positioning; positioning defects on [cls] |
| damaged | [cls] has a damaged defect; flawed [cls] with damage; [cls] with visible damage; damaged areas on [cls]; physical damage seen on [cls]; noticeable wear on [cls] |
Table A3: Defect-aware prompts for VisA (18 defect states, superset over 12 categories), adopted from the MultiADS knowledge base [33].
| Defect type | Prompts ([cls] = category name) |
|---|---|
| damage | [cls] has a damaged defect; flawed [cls] with damage; [cls] shows signs of damage; damage found on [cls]; [cls] with visible wear and tear; [cls] with structural damage |
| scratch | [cls] has a scratch defect; flawed [cls] with a scratch; scratches visible on [cls]; [cls] has surface scratches; small scratches found on [cls]; [cls] with scratch marks |
| breakage | [cls] with a breakage defect; broken [cls]; [cls] with broken defect; [cls] shows breakage; broken or cracked areas on [cls]; visible breakage on [cls] |
Lee et al.
| Defect type | Prompts |
|---|---|
| burnt | [cls] with a burnt defect; [cls] shows burn marks; burnt areas on [cls]; [cls] with signs of burning; scorch marks on [cls]; [cls] appears slightly burnt |
| weird wick | [cls] with a weird wick defect; [cls] has an unusual wick; the wick on [cls] appears odd; [cls] with a strangely shaped wick; irregular wick found on [cls]; odd wick defect on [cls] |
| stuck | [cls] with a stuck defect; [cls] stuck together; [cls] has stuck parts; adhesive issue causing [cls] to stick; [cls] is partially stuck; [cls] with adhesion defect |
| crack | [cls] with a crack defect; [cls] has a visible crack; cracked areas on [cls]; [cls] with surface cracking; fine cracks found on [cls]; [cls] shows crack lines |
| wrong place | [cls] with defect that something on wrong place; [cls] has a misplaced defect; flawed [cls] with misplacing; misaligned part on [cls]; [cls] shows parts out of place; misplacement detected on [cls] |
| partical | [cls] with particles defect; [cls] has foreign particles; small particles on [cls]; [cls] with unwanted particles; contaminants found on [cls]; [cls] with visible particles |
| bubble | [cls] with bubbles defect; bubbles seen on [cls]; [cls] with bubble marks; air bubbles in [cls]; [cls] contains bubble defects; small bubbles on [cls] surface |
| melded | [cls] with melded defect; melded parts on [cls]; [cls] has fused areas; fused spots on [cls]; melded areas on [cls]; [cls] with melded material |
| hole | [cls] has a hole defect; a hole on [cls]; visible hole on [cls]; [cls] has small punctures; [cls] shows perforations; hole present on [cls] |
| melt | [cls] with melt defect; melted areas on [cls]; [cls] shows melting; signs of melting on [cls]; [cls] with melted spots; [cls] has a melted appearance |
| bent | [cls] has a bent defect; flawed [cls] with a bent; bent areas on [cls]; [cls] with visible bending; [cls] shows curvature issues; noticeable bend in [cls] |
| spot | [cls] with spot defect; spots visible on [cls]; flawed [cls] with spots; [cls] with visible spotting; [cls] shows small spots; surface spots on [cls] |
| Defect type | Prompts |
|---|---|
| extra | [cls] with extra thing; [cls] has a defect with extra thing; extra material on [cls]; [cls] contains additional pieces; [cls] with extra component defect; unwanted additions on [cls] |
| chip | [cls] with chip defect; [cls] with fragment broken defect; chipped areas on [cls]; [cls] with chipped parts; broken fragments on [cls]; chip marks found on [cls] |
| missing | [cls] with a missing defect; flawed [cls] with something missing; [cls] has missing parts; missing components on [cls]; absent pieces in [cls]; [cls] is incomplete |
A.5 Medical Anomaly-State Prompts
Table A4 lists the brain-MRI prompts described in Sec. A.1. Here [cls] is fixed to brain.
Table A4: Anomaly-state prompts for the BraTS (brain MRI) domain. These are semantic state descriptors constructed by us, mirroring the industrial taxonomy; they are not diagnostic labels and are not adopted from prior medical work.
| Defect type | Prompts ([cls] = category name) |
|---|---|
| lesion | [cls] has a lesion; a lesion is present on [cls]; abnormal lesion in [cls]; [cls] with a visible lesion; lesion region found in [cls]; [cls] shows a focal lesion |
| tumor | [cls] has a tumor; a tumor is present in [cls]; tumor region in [cls]; [cls] with an abnormal mass; [cls] shows tumor tissue; abnormal growth detected in [cls] |
| hemorrhage | [cls] has a hemorrhage; bleeding region in [cls]; [cls] with hemorrhagic area; [cls] shows signs of bleeding; hemorrhage found in [cls]; abnormal bleeding in [cls] |
| edema | [cls] has edema; edema region in [cls]; [cls] with swelling; [cls] shows abnormal fluid accumulation; swollen area in [cls]; edematous region found in [cls] |
| mass | [cls] has an abnormal mass; a mass is present in [cls]; mass region in [cls]; [cls] with an abnormal mass effect; [cls] shows a mass; abnormal mass detected in [cls] |
| anomaly | [cls] has an anomaly; an abnormal region in [cls]; [cls] with abnormal tissue; [cls] shows an abnormality; abnormal area found in [cls]; [cls] with a pathological region |
Lee et al.
B Implementation Details
B.1 Backbone and training
We use DINOv2-Txt [20] with a ViT-L/14 backbone as the frozen image-text foundation model; both the image encoder and the text encoder are fixed, and only the lightweight residual-projection, gating, scoring, and merge modules are trained. All images are resized to . We train for 20 epochs with AdamW [26] (learning rate , weight decay , batch size 32). The loss weights are set to and . All reported numbers are averaged over three random seeds.
B.2 Text prompts
For each category we encode the normal-state prompts (Table A1) and average them into a single normal text anchor used for the text-residual subtraction. In parallel, each defect type is encoded and averaged into one abnormal candidate, giving abnormal candidates ( for MVTec AD, for VisA, for BraTS). The patch-wise soft matching in Sec. 3.3 is performed over the union of the projected normal candidates and the projected abnormal candidates, with softmax temperature .
B.3 Module specification
The image and text projectors are lightweight linear maps in the backbone embedding space, with initialized to the identity. The gate is a patch-wise linear head () followed by a sigmoid, with bias initialized to ; the scoring head maps the gated residual to a scalar.
B.4 Score aggregation and objective
The two score maps are merged as with a learnable scalar initialized to 0.2; after training it converges to . The merge-weight ablation in the main paper is a post-hoc sweep of on this single trained checkpoint rather than a re-training sweep, which isolates it from optimization variance; the learned value matches the optimum measured there. Image-level scores use the mean of the top 1% patch scores. The training objective follows Sec. 3.5, , with .
C Dataset Details
We evaluate on two industrial benchmarks and one medical benchmark under the generalist setting, training on a source dataset and testing on a different target dataset without category-specific retraining. MVTec AD [2] contains 15 object and texture categories. VisA [50] contains 12 object categories. BraTS [28] is a publicly available brain-MRI benchmark; we use its reorganization into a binary anomaly-detection task (normal slices vs. slices containing tumor) [1]. We follow the patient-level split of BraTS2021 provided by BMAD, so no patient appears in both the training and test sets. All three datasets are publicly available and contain no personally identifying information. We consider three transfer settings: MVTec AD → VisA, VisA → MVTec AD, and MVTec AD → BraTS. During training, normal images, abnormal images, and pixel-level masks are available; at inference only a few normal reference images from the target dataset are provided, under 1-, 2-, and 4-shot settings. Image-level performance uses AUROC, AP, and F1-max; pixel-level localization uses AUROC, F1-max, and PRO.
D Per-Class Results
For completeness we report per-category results (mean±std) under the 1-, 2-, and 4-shot settings. MVTec AD and VisA are given in Tables D5 and D6, respectively; each table stacks the 1-, 2-, and 4-shot settings. BraTS is single-class under the BMAD reorganization [1] and thus has no per-category breakdown; its dataset-level result is given in Table D7. Unless noted otherwise, statistics are computed as the sample standard deviation over three seeds; for the Mean rows, the per-category scores are first averaged within each seed and the standard deviation is then taken across the three seed-level averages.
Table D5: Per-category results on MVTec AD under the 1-, 2-, and 4-shot settings, averaged over three random seeds (mean±std).
| Category | Image-level | Pixel-level | |||||
|---|---|---|---|---|---|---|---|
| AUROC | AP | F1 | AUROC | F1 | PRO | ||
| 1-shot | bottle | 99.92±0.11 | 99.97±0.06 | 99.60±0.57 | 98.78±0.31 | 79.62±0.48 | 96.64±0.08 |
| cable | 95.57±0.44 | 97.90±0.41 | 91.01±0.14 | 93.55±0.22 | 65.37±0.21 | 86.63±0.91 | |
| capsule | 92.96±0.37 | 98.97±0.35 | 94.93±0.33 | 95.37±0.06 | 45.41±0.56 | 95.33±0.23 | |
| carpet | 99.80±0.25 | 99.91±0.07 | 99.15±0.41 | 99.03±0.02 | 61.46±0.52 | 97.56±0.21 | |
| grid | 100.00±0.00 | 100.00±0.00 | 100.00±0.00 | 99.18±0.21 | 43.34±0.37 | 96.07±0.14 | |
| hazelnut | 99.98±0.03 | 99.99±0.02 | 99.65±0.50 | 99.25±0.04 | 74.17±1.48 | 96.72±0.80 | |
| leather | 100.00±0.00 | 100.00±0.00 | 100.00±0.00 | 99.03±0.04 | 43.00±0.04 | 98.70±0.01 | |
| metal_nut | 99.71±0.07 | 99.93±0.13 | 98.91±0.01 | 95.23±0.98 | 70.59±4.78 | 93.35±0.91 | |
| pill | 98.70±0.18 | 99.77±0.14 | 97.16±0.45 | 91.48±0.16 | 50.22±0.46 | 96.47±0.16 | |
| screw | 83.85±0.23 | 93.29±0.57 | 89.02±0.42 | 98.25±0.21 | 49.90±0.11 | 93.56±1.07 | |
| tile | 100.00±0.00 | 100.00±0.00 | 100.00±0.00 | 95.64±0.25 | 64.88±0.12 | 90.48±0.35 | |
| toothbrush | 94.61±0.17 | 97.93±0.47 | 93.22±0.16 | 96.92±0.81 | 35.30±4.14 | 93.35±1.07 | |
| transistor | 92.15±0.38 | 88.76±0.94 | 84.14±0.49 | 87.34±1.97 | 43.72±2.98 | 68.98±2.38 | |
| wood | 99.30±0.62 | 99.78±0.19 | 97.87±1.70 | 93.76±0.73 | 62.61±0.59 | 94.28±0.19 | |
| zipper | 99.31±0.15 | 99.63±0.25 | 98.52±0.32 | 95.29±0.02 | 53.32±0.95 | 91.26±0.48 | |
| Mean | 97.06±0.15 | 98.39±0.19 | 96.21±0.07 | 95.87±0.02 | 56.19±0.48 | 92.63±0.03 | |
| 2-shot | bottle | 99.92±0.11 | 99.97±0.04 | 99.81±0.28 | 99.05±0.37 | 78.06±0.77 | 96.57±0.47 |
| cable | 97.33±1.67 | 98.08±1.08 | 93.22±2.39 | 93.80±2.72 | 58.89±1.70 | 85.75±3.08 | |
| capsule | 95.61±0.17 | 99.27±0.36 | 96.22±0.91 | 96.17±0.34 | 45.89±0.35 | 95.62±0.71 | |
| carpet | 99.84±0.17 | 99.95±0.05 | 99.64±0.08 | 99.15±0.12 | 61.19±0.18 | 97.44±0.45 | |
| grid | 100.00±0.00 | 100.00±0.00 | 100.00±0.00 | 99.20±0.01 | 42.55±0.18 | 96.50±0.04 | |
| hazelnut | 99.98±0.03 | 99.99±0.01 | 99.70±0.43 | 99.20±0.03 | 71.77±0.71 | 97.25±0.08 | |
| leather | 100.00±0.00 | 100.00±0.00 | 100.00±0.00 | 99.56±0.59 | 43.05±0.57 | 98.71±0.08 | |
| metal_nut | 99.80±0.07 | 99.95±0.05 | 99.20±0.37 | 96.43±0.18 | 74.38±0.28 | 93.69±0.78 | |
| pill | 98.71±0.08 | 99.72±0.08 | 97.39±0.27 | 91.69±0.13 | 52.55±0.52 | 96.09±0.32 | |
| screw | 84.15±0.59 | 92.53±1.04 | 89.15±0.80 | 98.37±0.64 | 47.79±1.85 | 92.47±1.93 | |
Lee et al.
Table D5 – continued from previous page
| Category | Image-level | Pixel-level | |||||
|---|---|---|---|---|---|---|---|
| AUROC | AP | F1 | AUROC | F1 | PRO | ||
| tile | |||||||
| toothbrush | |||||||
| transistor | |||||||
| wood | |||||||
| zipper | |||||||
| Mean | |||||||
| bottle | |||||||
| cable | |||||||
| capsule | |||||||
| carpet | |||||||
| grid | |||||||
| hazelnut | |||||||
| leather | |||||||
| metal_nut | |||||||
| pill | |||||||
| screw | |||||||
| tile | |||||||
| toothbrush | |||||||
| transistor | |||||||
| wood | |||||||
| zipper | |||||||
| Mean | |||||||
Table D6: Per-category results on VisA under the 1-, 2-, and 4-shot settings, averaged over three random seeds (mean±std).
| Category | Image-level | Pixel-level | |||||
|---|---|---|---|---|---|---|---|
| AUROC | AP | F1 | AUROC | F1 | PRO | ||
| 1-shot | candle | ||||||
| capsules | |||||||
| cashew | |||||||
| chewinggum | |||||||
| fryum | |||||||
| macaroni1 | |||||||
| macaroni2 | |||||||
| pcb1 | |||||||
| pcb2 | |||||||
| pcb3 | |||||||
| pcb4 | |||||||
| pipe_fryum | |||||||
| Mean | |||||||
| 2-shot | candle | ||||||
| capsules | |||||||
| cashew | |||||||
| chewinggum | |||||||
| fryum | |||||||
| macaroni1 | |||||||
| macaroni2 | |||||||
| pcb1 | |||||||
| pcb2 | |||||||
| pcb3 | |||||||
| pcb4 | |||||||
| pipe_fryum | |||||||
| Mean | |||||||
Table D6 – continued from previous page
| Category | Image-level | Pixel-level | ||||
|---|---|---|---|---|---|---|
| AUROC | AP | F1 | AUROC | F1 | PRO | |
| candle | ||||||
| capsules | ||||||
| cashew | ||||||
| chewinggum | ||||||
| fryum | ||||||
| macaroni1 | ||||||
| macaroni2 | ||||||
| pcb1 | ||||||
| pcb2 | ||||||
| pcb3 | ||||||
| pcb4 | ||||||
| pipe_fryum | ||||||
| Mean | ||||||
Table D7: Cross-domain results on BraTS under the 1-, 2-, and 4-shot settings, averaged over three random seeds (mean±std). BraTS is single-class in the BMAD reorganization [1], so no per-category breakdown applies.
| Setting | Image-level | Pixel-level | ||||
|---|---|---|---|---|---|---|
| AUROC | AP | F1 | AUROC | F1 | PRO | |
| 1-shot | ||||||
| 2-shot | ||||||
| 4-shot | ||||||
E Additional Ablations
Table E8 reports control experiments on VisA → MVTec AD under the 1-shot setting, averaged over three seeds. All trained rows share the same backbone and differ from (g) only in the stated component; the rows are not cumulative.
Where the gain comes from. Row (a) is a capacity-matched control: identical , and identical losses, including , with the gate fixed to . It accounts for only a small part of the gain over , so the improvement is attributable to the gate rather than to added trainable capacity or mask supervision. Row (f) shows that is not an independent route to discriminative patch features: without the gate the model barely moves, consistent with its role as a precondition for the patch-wise matching.
What the gate exploits. Row (b) collapses the candidate set to and falls below the gateless control, so a fixed single direction contributes nothing; the
Lee et al.
Table E8: Control experiments (VisA → MVTec AD, 1-shot, three seeds). Rows are not cumulative.
| Configuration | Image-level | Pixel-level | ||||
|---|---|---|---|---|---|---|
| AUROC | AP | F1 | AUROC | F1 | PRO | |
| only (training-free) | 93.79 | 96.60 | 94.77 | 95.61 | 54.21 | 91.48 |
| (a) gate ≡ 1 | 93.99 | 96.58 | 94.61 | 95.03 | 54.91 | 92.22 |
| (b) single direction () | 93.93 | 96.60 | 94.45 | 95.44 | 54.18 | 92.04 |
| (c) generic prompts | 95.09 | 97.56 | 95.86 | 95.64 | 54.82 | 91.69 |
| (d) wrong-dataset taxonomy | 95.32 | 97.45 | 95.47 | 95.81 | 55.09 | 92.15 |
| (e) mean-centering | 97.05 | 98.39 | 96.17 | 95.87 | 56.19 | 92.63 |
| (f) w/o | 95.52 | 97.37 | 95.19 | 95.74 | 55.08 | 92.26 |
| (g) ours | 97.06 | 98.39 | 96.21 | 95.87 | 56.19 | 92.63 |
gain lies in soft matching over many candidates. Row (e) replaces the normal anchor with the mean of all text candidates and matches (g), indicating that subtracting a fixed reference direction is what matters rather than the identity of the anchor. That (d) is not below (c) further shows that incorrect defect terms do not mislead the gate: what it exploits is the spread of the candidate set away from the anchor, not the correctness of any single term.
Robustness to generic prompts. Row (c) restricts the abnormal prompts to generic descriptors such as “damaged”, “defective” and “anomalous”. A substantial part of the gain survives without any fine-grained defect vocabulary, although the margin shrinks. The same holds in the cross-domain setting: on MVTec AD → BraTS with generic prompts and the terms “tumor”, “lesion” and “mass” removed, TIRAD reaches 73.03/78.84/82.19 image-level AUROC at 1-/2-/4-shot, against 72.79/76.96/80.53 for the best baseline; the ordering holds at every shot count.
F Limitations and Broader Impact
Structural limitation of multiplicative gating. The text branch modulates the image residual multiplicatively, with . Consequently the gate can only attenuate or preserve spatial signal already present in the image residual; it cannot introduce response in regions where the image residual is near zero. Localization gains from the text branch are therefore bounded by the spatial support of the image branch, and the method is best understood as semantic refinement of visual residuals rather than an independent localizer. This is consistent with our finding that the clearest gains appear at the image level and in the cross-domain regime.
Prompt dependence. The size of the gain depends on the abnormal prompt set. With generic descriptors alone the ordering against the baselines is preserved but the margins shrink (Sec. E), so reducing this dependence, for example by generating candidates without a predefined taxonomy, remains open. We also note that the control experiments in Sec. E are reported as three-seed means without paired uncertainty estimates.
Mixed patches. As noted in the main paper, a patch containing both normal and abnormal regions receives an ambiguous label between the normal and abnormal textual states, weakening the text residual and blurring boundary localization; finer-grained or soft patch-level supervision is a natural direction.
Single medical benchmark. Our cross-domain evidence rests on one medical dataset (BraTS). Broader validation across additional medical modalities and other domain shifts is needed to establish the generality of the semantic-prior claim; we regard the current result as indicative rather than conclusive.
Broader impact. The medical prompts are generic semantic descriptors used only to form the normal and abnormal text features; they are not diagnostic statements, and the method is a research prototype not intended for clinical use. All datasets used are publicly available and contain no personally identifying information.
G Additional Qualitative Results
Figures G1, G2, and G3 show additional qualitative results on MVTec AD, VisA, and BraTS. For each example, from left to right, we show the input image, the ground-truth anomaly mask, and the predicted anomaly map.
Lee et al.

Fig. G1: Additional qualitative results on MVTec AD.

Fig. G2: Additional qualitative results on VisA.

Fig. G3: Additional qualitative results on BraTS.