SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2312.05767 · 2023

AnomalyDiffusion: Few-Shot Anomaly Image Generation with Diffusion Model

arXiv · PDF · Open in the Atlas

Code that ran

8 of 10 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 3 honoured the contract we drafted, 0 violated it and 0 have no contract verdict; 5 failures of our instrument; 2 no recorded run), measured 2026-11-23; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2312.05767.json · badge: /api/ran/2312.05767.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
sjtuplayer/anomalydiffusion canonical (classifier label)
classifier basis: census
8 ran · 2 no recorded run
FunctionStatusWhere it lives
check_mask Ran
ran; our contract draft was wrong, not the code
sjtuplayer/anomalydiffusion/generate_mask.py
code served (permissive licence) · get_code("1398a2cb64d8b5aa")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned bool, ndim 0, dtype family float, shape () as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

# Construct a mask tensor
# The function checks edges of a 3D tensor at indices 0 and w-1
# mask shape: (batch, width, height) where width = height = w
# We'll make a small mask with w=4, batch=2
w = 4
mask = torch.zeros(2, w, w, dtype=torch.uint8)

# Ensure the edge conditions pass by keeping nonzero counts <= w/3
# For w=4, w/3 ≈ 1.33, so we can have at most 1 nonzero per edge check
# Each edge check looks at: mask[:, 0, :], mask[:, w-1, :], mask[:, :, 0], mask[:, :, w-1]
# These are all shape (2, 4), so 8 elements total per edge
# Count nonzero across the batch dimension - if any edge has > w/3 nonzeros, return False

# Create a mask where edges are mostly zeros
# Set just one element in each edge region to keep counts low
mask[0, 0, 0] = 1  # First edge, first position
# Keep other edges empty to ensure they pass the w/3 threshold

ARGS = {
    "mask": mask
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type bool, ndim 0, dtype family float, shape () — shape () as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
collect_anomaly_scores Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
sjtuplayer/anomalydiffusion/unet_utils/au_pro_util.py
pointer only (licence: MIT); the stored copy get_code serves, from Chhro123/fast-foreground-aware-anomaly-synthesis, is pointer only (licence: NONE) · get_code("18c9bfa7e94951e9")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from Chhro123/fast-foreground-aware-anomaly-synthesis, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

compute_pro Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
sjtuplayer/anomalydiffusion/unet_utils/au_pro_util.py
pointer only (licence: MIT); the stored copy get_code serves, from Chhro123/fast-foreground-aware-anomaly-synthesis, is pointer only (licence: NONE) · get_code("49b5692178958afe")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from Chhro123/fast-foreground-aware-anomaly-synthesis, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

create_window Ran
ran, honoured the contract we drafted
sjtuplayer/anomalydiffusion/unet_utils/loss.py
pointer only (licence: MIT); the stored copy get_code serves, from Chhro123/fast-foreground-aware-anomaly-synthesis, is pointer only (licence: NONE) · get_code("443341084ce76798")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from Chhro123/fast-foreground-aware-anomaly-synthesis, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

gaussian Ran
ran, honoured the contract we drafted
sjtuplayer/anomalydiffusion/unet_utils/loss.py
code served (permissive licence) · get_code("c56b7ef16f309a45")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned Tensor, ndim 1, dtype family float, shape (5,) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
from math import exp

torch.manual_seed(0)

ARGS = {
    "window_size": 5,
    "sigma": 1.0,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 1, dtype family float, shape (5,) — shape (5,) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_lr Ran
ran, honoured the contract we drafted
sjtuplayer/anomalydiffusion/test-classification.py
pointer only (licence: MIT); the stored copy get_code serves, from yjzhang96/UTI-VFI, is pointer only (licence: NONE) · get_code("7337f1f5ff01dcd0")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from yjzhang96/UTI-VFI, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

ssim Ran
ran; our contract draft was wrong, not the code
sjtuplayer/anomalydiffusion/unet_utils/loss.py
pointer only (licence: MIT); the stored copy get_code serves, from Chhro123/fast-foreground-aware-anomaly-synthesis, is pointer only (licence: NONE) · get_code("bff794bd9bd73f94")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from Chhro123/fast-foreground-aware-anomaly-synthesis, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

trapezoid Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
sjtuplayer/anomalydiffusion/unet_utils/au_pro_util.py
pointer only (licence: MIT); the stored copy get_code serves, from Chhro123/fast-foreground-aware-anomaly-synthesis, is pointer only (licence: NONE) · get_code("9d72c1f1f0d6dea4")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from Chhro123/fast-foreground-aware-anomaly-synthesis, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

make_batch Not yet run
unverified (harvested, no recorded run)
sjtuplayer/anomalydiffusion/generate_mask.py
pointer only (licence: MIT); the stored copy get_code serves, from Chhro123/fast-foreground-aware-anomaly-synthesis, is pointer only (licence: NONE) · get_code("c23b317a405ae12c")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from Chhro123/fast-foreground-aware-anomaly-synthesis, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. No invocation recorded.

nondefault_trainer_args Not yet run
unverified (harvested, no recorded run)
sjtuplayer/anomalydiffusion/train_mask.py
pointer only (licence: MIT); the stored copy get_code serves, from yangling0818/sgdiff, is pointer only (licence: NONE) · get_code("87fbedd0c27cf378")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from yangling0818/sgdiff, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. No invocation recorded.

Also present in other papers' code

Of 10 samples lifted from this paper's linked repositories, 10 carry a function identity and 0 do not. Of the 10 distinct functions with an identity, 9 are also present in other papers whose code we hold (8 with at least one paper dated earlier, 2 the same month, 9 later) and 1 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
gaussian 160 other papers
53 dated earlier, 8 the same month, 97 later, 2 same year, order not determinable · 7 only as an assembly brick
1812.11941 (2018-12)
High Quality Monocular Depth Estimation via Transfer Learning
1904.01538 (2019-04)
Spatial Attentive Single-Image Deraining with a High Quality Real Rain Dataset
1907.11628 (2019-07)
Unsupervised Learning for Optical Flow Estimation Using Pyramid Convolution LSTM
and 157 more not named here
get_lr 25 other papers
21 dated earlier, 4 later · 2 only as an assembly brick
1605.07148 (2016-05)
Backprop KF: Learning Discriminative Deterministic State Estimators
1606.00915 (2016-06)
DeepLab: Semantic Image Segmentation with Deep Convolutional Nets, Atrous Convolution, and Fully Connected CRFs
1904.01355 (2019-04)
FCOS: Fully Convolutional One-Stage Object Detection
and 22 more not named here
create_window 19 other papers
10 dated earlier, 9 later
1812.11941 (2018-12)
High Quality Monocular Depth Estimation via Transfer Learning
Zavrtanik_DRAEM_-_A_Discriminatively_Trained_Reconstruction_Embedding_for_Surface_Anomaly_ICCV_2021_paper (2021 (year only))
DRAEM -A discriminatively trained reconstruction embedding for surface anomaly detection
2108.07610 (2021-08)
DRAEM -- A discriminatively trained reconstruction embedding for surface anomaly detection
and 16 more not named here
nondefault_trainer_args 8 other papers
5 dated earlier, 1 the same month, 2 later
2005.10242 (2020-05)
Understanding Contrastive Representation Learning through Alignment and Uniformity on the Hypersphere
2112.10752 (2021-12)
High-Resolution Image Synthesis with Latent Diffusion Models
2211.13319 (2022-11)
Make-A-Story: Visual Memory Conditioned Consistent Story Generation
and 5 more not named here
ssim 5 other papers
3 dated earlier, 2 later
Zavrtanik_DRAEM_-_A_Discriminatively_Trained_Reconstruction_Embedding_for_Surface_Anomaly_ICCV_2021_paper (2021 (year only))
DRAEM -A discriminatively trained reconstruction embedding for surface anomaly detection
2108.07610 (2021-08)
DRAEM -- A discriminatively trained reconstruction embedding for surface anomaly detection
2302.08769 (2023-02)
Collaborative Discrepancy Optimization for Reliable Image Anomaly Localization
and 2 more not named here
collect_anomaly_scores 3 other papers
2 dated earlier, 1 later
2203.05550 (2022-03)
Back to the Feature: Classical 3D Features are (Almost) All You Need for 3D Anomaly Detection
2303.00601 (2023-03)
Multimodal Industrial Anomaly Detection via Hybrid Fusion
2509.20295 (2025-09)
FAST: Foreground-aware Diffusion with Accelerated Sampling Trajectory for Segmentation-oriented Anomaly Synthesis
compute_pro 3 other papers
2 dated earlier, 1 later
2203.05550 (2022-03)
Back to the Feature: Classical 3D Features are (Almost) All You Need for 3D Anomaly Detection
2303.00601 (2023-03)
Multimodal Industrial Anomaly Detection via Hybrid Fusion
2509.20295 (2025-09)
FAST: Foreground-aware Diffusion with Accelerated Sampling Trajectory for Segmentation-oriented Anomaly Synthesis
trapezoid 3 other papers
2 dated earlier, 1 later
2203.05550 (2022-03)
Back to the Feature: Classical 3D Features are (Almost) All You Need for 3D Anomaly Detection
2303.00601 (2023-03)
Multimodal Industrial Anomaly Detection via Hybrid Fusion
2509.20295 (2025-09)
FAST: Foreground-aware Diffusion with Accelerated Sampling Trajectory for Segmentation-oriented Anomaly Synthesis
make_batch 1 other paper
1 later
2509.20295 (2025-09)
FAST: Foreground-aware Diffusion with Accelerated Sampling Trajectory for Segmentation-oriented Anomaly Synthesis

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-23.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

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.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2312.05767")
get_code_for_paper("2312.05767")
have("2312.05767")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2312.05767.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2312.05767.svg)](https://syntology.ai/paper/2312.05767)

Connect an agent — have() is free.