Papers › AnomalyDiffusion: Few-Shot Anomaly Image Generation with Diffusion Model

AnomalyDiffusion: Few-Shot Anomaly Image Generation with Diffusion Model

10 Dec 2023arXiv:2312.05767archive 2025-07-28

Teng Hu, Jiangning Zhang, Ran Yi, Yuzhen Du, Xu Chen, Liang Liu, Yabiao Wang, Chengjie Wang

Anomaly inspection plays an important role in industrial manufacture. Existing anomaly inspection methods are limited in their performance due to insufficient anomaly data. Although anomaly generation methods have been proposed to augment the anomaly data, they either suffer from poor generation authenticity or inaccurate alignment between the generated anomalies and masks. To address the above problems, we propose AnomalyDiffusion, a novel diffusion-based few-shot anomaly generation model, which utilizes the strong prior information of latent diffusion model learned from large-scale dataset to enhance the generation authenticity under few-shot training data. Firstly, we propose Spatial Anomaly Embedding, which consists of a learnable anomaly embedding and a spatial embedding encoded from an anomaly mask, disentangling the anomaly information into anomaly appearance and location information. Moreover, to improve the alignment between the generated anomalies and the anomaly masks, we introduce a novel Adaptive Attention Re-weighting Mechanism. Based on the disparities between the generated anomaly image and normal sample, it dynamically guides the model to focus more on the areas with less noticeable generated anomalies, enabling generation of accurately-matched anomalous image-mask pairs. Extensive experiments demonstrate that our model significantly outperforms the state-of-the-art methods in generation authenticity and diversity, and effectively improves the performance of downstream anomaly inspection tasks. The code and data are available in https://github.com/sjtuplayer/anomalydiffusion.

PaperPDFCodeCode 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="2312.05767")

Code

Syntology Ran 3 of 10 code samples harvested from 1 repository linked to this paper; 7 have no recorded run. Of those that ran: 2 ran · honoured contract; 1 ran with no contract checked.

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

sjtuplayer/anomalydiffusion officialmentioned in papermentioned on GitHubpytorchMIT 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

10 samples harvested; 3 ran; 2 honoured the contract we drafted; 7 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.

2ran · honoured contract
1ran
7unverified

Licence: 0 of the 10 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 sjtuplayer/anomalydiffusion. “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.

check_mask sjtuplayer/anomalydiffusion/generate_mask.py official repository ran MIT (permissive) · 1398a2cb64d8b5aa · report
gaussian sjtuplayer/anomalydiffusion/unet_utils/loss.py official repository ran · honoured contract fingerprinted MIT (permissive) · c56b7ef16f309a45 · report
get_lr sjtuplayer/anomalydiffusion/test-classification.py official repository ran · honoured contract MIT (permissive) · 7337f1f5ff01dcd0 · report
collect_anomaly_scores sjtuplayer/anomalydiffusion/unet_utils/au_pro_util.py official repository unverified MIT (permissive) · 18c9bfa7e94951e9 · report
compute_pro sjtuplayer/anomalydiffusion/unet_utils/au_pro_util.py official repository unverified MIT (permissive) · 49b5692178958afe · report
create_window sjtuplayer/anomalydiffusion/unet_utils/loss.py official repository unverified MIT (permissive) · 443341084ce76798 · report
make_batch sjtuplayer/anomalydiffusion/generate_mask.py official repository unverified MIT (permissive) · c23b317a405ae12c · report
nondefault_trainer_args sjtuplayer/anomalydiffusion/train_mask.py official repository unverified MIT (permissive) · 87fbedd0c27cf378 · report
ssim sjtuplayer/anomalydiffusion/unet_utils/loss.py official repository unverified MIT (permissive) · bff794bd9bd73f94 · report
trapezoid sjtuplayer/anomalydiffusion/unet_utils/au_pro_util.py official repository unverified MIT (permissive) · 9d72c1f1f0d6dea4 · report

Tasks

Image Generation

Results from the paper archive 2025-07-28

No leaderboard rows for this paper in the archive.

Methods

DiffusionFocusLatent Diffusion Model

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