Papers › Toward Generalist Anomaly Detection via In-context Residual Learning with Few-shot...

Toward Generalist Anomaly Detection via In-context Residual Learning with Few-shot Sample Prompts

11 Mar 2024CVPR 2024 1arXiv:2403.06495archive 2025-07-28

Jiawen Zhu, Guansong Pang

This paper explores the problem of Generalist Anomaly Detection (GAD), aiming to train one single detection model that can generalize to detect anomalies in diverse datasets from different application domains without any further training on the target data. Some recent studies have shown that large pre-trained Visual-Language Models (VLMs) like CLIP have strong generalization capabilities on detecting industrial defects from various datasets, but their methods rely heavily on handcrafted text prompts about defects, making them difficult to generalize to anomalies in other applications, e.g., medical image anomalies or semantic anomalies in natural images. In this work, we propose to train a GAD model with few-shot normal images as sample prompts for AD on diverse datasets on the fly. To this end, we introduce a novel approach that learns an in-context residual learning model for GAD, termed InCTRL. It is trained on an auxiliary dataset to discriminate anomalies from normal samples based on a holistic evaluation of the residuals between query images and few-shot normal sample prompts. Regardless of the datasets, per definition of anomaly, larger residuals are expected for anomalies than normal samples, thereby enabling InCTRL to generalize across different domains without further training. Comprehensive experiments on nine AD datasets are performed to establish a GAD benchmark that encapsulate the detection of industrial defect anomalies, medical anomalies, and semantic anomalies in both one-vs-all and multi-class setting, on which InCTRL is the best performer and significantly outperforms state-of-the-art competing methods. Code is available at https://github.com/mala-lab/InCTRL.

PaperPDFConference PDFCodeCode Syntology ran

In Syntology Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.

For agents, Syntology's MCP tool lists every function and class Syntology harvested from this paper and whether it ran (how to connect): get_harvested_code_for_paper(arxiv_id="2403.06495")

Code

Syntology Ran 12 of 21 code samples harvested from 2 repositories linked to this paper; 9 have no recorded run. Of those that ran: 1 ran · violated contract; 2 ran · our draft was wrong; 9 ran with no contract checked.

By repository: official repository: 21 samples from 2 repositories, 12 ran. The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

mala-lab/inctrl officialmentioned in papermentioned on GitHubpytorchApache-2.0 report
mala-lab/winclip officialmentioned in paperpytorchGPL-3.0 report

Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.

Code Syntology ran Syntology

21 samples harvested; 12 ran; 0 honoured the contract we drafted; 9 have no recorded run. Read from Syntology's graph 2026-09-24; that is when this build read the record, not when the samples ran.

1ran · violated contract
2ran · our draft was wrong
9ran
9unverified

Licence: 15 of the 21 samples are pointer only, meaning Syntology does not serve that copy's text. This page shows no code text for any sample; each one links to its file in the repository.

Harvested from 2 repositories linked to this paper, official or community; each sample names its own and says which. “Ran” means the sample executed on a synthesized input. It does not mean the output is correct, and nothing here reproduces the paper's results. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself; “our draft was wrong” and “fixture could not drive it” are failures of Syntology's instrument, not of the code.

Each sample ends with its code_sha256, Syntology's identity for that exact code. An agent fetches the stored sample with Syntology's MCP tool get_code(code_sha256="…") (how to connect); click an identity to copy that call.

Repository labels, per sample. official repository: The archive marks this repository official for the paper. named in the paper: The archive records that the paper mentions this repository; it is not marked official. community (archive-listed): In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper. found in paper text by Syntology: Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted. community: Not in the archive's code links for this paper; a community repository Syntology harvested. Samples from a repository marked official are listed first. Licence labels name the repository's licence as recorded at harvest. “Pointer only” means Syntology does not serve that copy's text, for one of four reasons: no licence file was found; the licence was not identified; the licence is recorded as permissive but that copy's record is not marked cleared; or the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar). Some licences outside that list permit redistribution, such as WTFPL, and GPL-3.0 under its conditions; they are simply not on the list. Hover a licence label for the reason. File links open the file on GitHub at the default branch, which may have changed since the harvest.

convert_to_custom_text_state_dict mala-lab/WinCLIP/open_clip/model.py official repository ran · violated contract GPL-3.0 (copyleft) · pointer only · f19962ebb134b3d7 · report
eval_epoch mala-lab/inctrl/engine_IC.py official repository ran Apache-2.0 (permissive) · 4405aae96cb9935e · report
get_cast_dtype mala-lab/WinCLIP/open_clip/model.py official repository ran · our draft was wrong GPL-3.0 (copyleft) · pointer only · dcd422d66b0581d8 · report
get_input_dtype mala-lab/WinCLIP/open_clip/model.py official repository ran · our draft was wrong GPL-3.0 (copyleft) · pointer only · b476c8cfbf0f1f47 · report
get_inputs mala-lab/WinCLIP/datasets/mvtec_dataset.py official repository ran GPL-3.0 (copyleft) · pointer only · 8be46af3c88f4a4a · report
get_texts mala-lab/inctrl/open_clip/model.py official repository ran fingerprinted Apache-2.0 (permissive) · b45d9bb956858415 · report
img_batch_tensor2numpy mala-lab/WinCLIP/datasets/mvtec_dataset.py official repository ran GPL-3.0 (copyleft) · pointer only · 86643f692da7dfe4 · report
img_tensor2numpy mala-lab/WinCLIP/datasets/mvtec_dataset.py official repository ran GPL-3.0 (copyleft) · pointer only · 356af6b8fba23d25 · report
load_state_dict mala-lab/WinCLIP/open_clip/factory.py official repository ran GPL-3.0 (copyleft) · pointer only · 4b3a4d17e1df3140 · report
multiple_samples_collate mala-lab/inctrl/datasets/loader.py official repository ran Apache-2.0 (permissive) · 89796902ab9c77c5 · report
replace_linear mala-lab/WinCLIP/open_clip/new_utils.py official repository ran GPL-3.0 (copyleft) · pointer only · d50f37a336cfbd4c · report
tile_image mala-lab/inctrl/datasets/IC_dataset_new.py official repository ran Apache-2.0 (permissive) · ef6be348d60ab9c4 · report
aucPerformance mala-lab/inctrl/engine_IC.py official repository unverified Apache-2.0 (permissive) · cd7be40e5f2e4888 · report
construct_loader mala-lab/inctrl/datasets/loader.py official repository unverified Apache-2.0 (permissive) · c061f59d4b035f46 · report
freeze_batch_norm_2d mala-lab/WinCLIP/open_clip/new_utils.py official repository unverified GPL-3.0 (copyleft) · pointer only · 9b5765523c6d17fd · report
gather_features mala-lab/WinCLIP/open_clip/loss.py official repository unverified GPL-3.0 (copyleft) · pointer only · ddcbd45e940484ee · report
get_model_config mala-lab/WinCLIP/open_clip/factory.py official repository unverified GPL-3.0 (copyleft) · pointer only · 5c7cf820e99443ff · report
get_tokenizer mala-lab/WinCLIP/open_clip/factory.py official repository unverified GPL-3.0 (copyleft) · pointer only · f34d8f34635af394 · report
load_openai_model mala-lab/WinCLIP/open_clip/openai.py official repository unverified GPL-3.0 (copyleft) · pointer only · 8811c5d06f3a2eaa · report
prepare_inputs_for_generation mala-lab/WinCLIP/open_clip/coca_model.py official repository unverified GPL-3.0 (copyleft) · pointer only · fb651d0a97fd4d3f · report
register_pooler mala-lab/WinCLIP/open_clip/hf_model.py official repository unverified GPL-3.0 (copyleft) · pointer only · 2a377da4a76a2d44 · report

Tasks

Anomaly Detection

Results from the paper archive 2025-07-28

No leaderboard rows for this paper in the archive.

Methods

CLIPFAVOR+Performer

Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections