SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2308.06748 · 2023

Target before Shooting: Accurate Anomaly Detection and Localization under One Millisecond via Cascade Patch Retrieval

arXiv · PDF · Open in the Atlas

Code that ran

9 of 11 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; 2 honoured the contract we drafted, 0 violated it and 0 have no contract verdict; 7 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/2308.06748.json · badge: /api/ran/2308.06748.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
flyinghu123/cpr canonical (classifier label)
classifier basis: census
9 ran · 2 no recorded run
FunctionStatusWhere it lives
compute_image_auc Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
flyinghu123/cpr/metrics.py
code served (permissive licence) · get_code("9904f18fa913eb37")
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 float, 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 numpy as np
from sklearn import metrics

# Create small binary labels and prediction scores
np.random.seed(0)
N = 10

# Binary ground truth labels (0 or 1)
gts = np.array([0, 1, 0, 1, 1, 0, 1, 0, 1, 0])

# Prediction scores (higher = more anomalous)
preds = np.array([0.1, 0.9, 0.2, 0.8, 0.85, 0.15, 0.7, 0.3, 0.95, 0.05])

ARGS = {
    "gts": gts,
    "preds": preds,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, sklearn — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type float, 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
entropy_pytorch Ran
ran; our contract draft was wrong, not the code
flyinghu123/cpr/models/grb.py
code served (permissive licence) · get_code("afd1fd4c67e83001")
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 Tensor, ndim 1, dtype family float, shape (2,) 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)

# Create small probability tensors for pk and qk
# pk: probability distribution (shape: 4,)
# qk: reference probability distribution (shape: 4,)
pk = torch.tensor([0.25, 0.25, 0.25, 0.25], dtype=torch.float32)
qk = torch.tensor([0.1, 0.2, 0.3, 0.4], dtype=torch.float32)

# Alternative: 2D tensors to test dim parameter
# pk shape (2, 4) - 2 samples, 4 classes
pk = torch.softmax(torch.randn(2, 4), dim=1)
qk = torch.softmax(torch.randn(2, 4), dim=1)

ARGS = {
    "pk": pk,
    "qk": qk,
    "dim": 1
}
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 Tensor, ndim 1, dtype family float, shape (2,) — shape (2,) 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
fix_seeds Ran
ran; our contract draft was wrong, not the code
flyinghu123/cpr/utils.py
code served (permissive licence) · get_code("0c3e0e613af57ee1")
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 function. The image it ran in was not recorded. The code mentions cuda, and the harness aliases cuda to the CPU for every sample; whether this run needed that is not recorded. If your copy returns the same type 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 random
import numpy as np
import torch

torch.manual_seed(0)

ARGS = {
    "seed": 42,
    "with_torch": True,
    "with_cuda": False,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type function — a function output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a function output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
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
generate_fractal_noise_2d Ran
ran; our contract draft was wrong, not the code
flyinghu123/cpr/libs/perlin.py
pointer only (licence: MIT); the stored copy get_code serves, from anindyasdas/adl4vad, is pointer only (licence: NONE) · get_code("293a2b1189b747fd")
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 anindyasdas/adl4vad, 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.

generate_perlin_noise_2d Ran
ran; our contract draft was wrong, not the code
flyinghu123/cpr/libs/perlin.py
pointer only (licence: MIT); the stored copy get_code serves, from anindyasdas/adl4vad, is pointer only (licence: NONE) · get_code("ed9e127befc02046")
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 anindyasdas/adl4vad, 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.

get_grb Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
flyinghu123/cpr/models/grb.py
code served (permissive licence) · get_code("c05bbe23123f3bf7")
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 GlobalRetrievalBranch. The image it ran in was not recorded. The code mentions cuda, and the harness aliases cuda to the CPU for every sample; whether this run needed that is not recorded. If your copy returns the same type 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
import numpy as np
from sklearn.cluster import KMeans

torch.manual_seed(0)

# Create small train_features tensor
# Shape: (B, C, H, W) = (2, 4, 8, 8)
# B=2 (batch), C=4 (channels), H=8 (height), W=8 (width)
train_features = torch.randn(2, 4, 8, 8)

ARGS = {
    "train_features": train_features
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, sklearn, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type GlobalRetrievalBranch — a GlobalRetrievalBranch output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a GlobalRetrievalBranch output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
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
lerp_np Ran
ran, honoured the contract we drafted
flyinghu123/cpr/libs/perlin.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("4de91a4627a51ea2")
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.

pixel_params_verify Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
flyinghu123/cpr/metrics.py
code served (permissive licence) · get_code("fc87506f23fa4651")
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 tuple, ndim 4, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim 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 numpy as np

# Create ground truth data: 3D array (num_samples=2, height=4, width=3)
# Values should be binary after thresholding (0 or 1)
gts = np.array([
    [[1, 0, 1], [0, 1, 0], [1, 1, 0], [0, 0, 1]],
    [[0, 1, 0], [1, 0, 1], [0, 1, 1], [1, 0, 0]]
], dtype=np.float32)

# Create predictions data: 3D array (num_samples=2, height=4, width=3)
# Values are floats representing probabilities
preds = np.array([
    [[0.9, 0.1, 0.8], [0.2, 0.7, 0.3], [0.95, 0.85, 0.1], [0.15, 0.05, 0.88]],
    [[0.1, 0.92, 0.2], [0.88, 0.15, 0.75], [0.05, 0.91, 0.82], [0.87, 0.12, 0.06]]
], dtype=np.float32)

ARGS = {
    'gts': gts,
    'preds': preds
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 4, dtype family float — a tuple output has no array shape of its own; none is stated
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
save_dependencies_files Ran
ran, honoured the contract we drafted
flyinghu123/cpr/utils.py
code served (permissive licence) · get_code("3eec1fa82531e363")
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 list, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim 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 os
import tempfile
import shutil

# Create a temporary directory to serve as root_path
temp_dir = tempfile.mkdtemp()

# The function takes one parameter: root_path, which should be a valid directory path
# The function will save dependency files into this directory
root_path = temp_dir

ARGS = {
    "root_path": root_path
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 1, dtype family float — a list output has no array shape of its own; none is stated
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
compute_image_auc_torch Not yet run
unverified (harvested, no recorded run)
flyinghu123/cpr/metrics.py
code served (permissive licence) · get_code("aa3eaa45e0fc06c6")
How it ran

no invocation recorded.

get_feb Not yet run
unverified (harvested, no recorded run)
flyinghu123/cpr/models/feb.py
code served (permissive licence) · get_code("c0449268a49c4f3d")
How it ran

no invocation recorded.

Also present in other papers' code

Of 11 samples lifted from this paper's linked repositories, 11 carry a function identity and 0 do not. Of the 11 distinct functions with an identity, 3 are also present in other papers whose code we hold (3 with at least one paper dated earlier, 0 the same month, 3 later) and 8 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
lerp_np 8 other papers
2 dated earlier, 6 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
2403.05897 (2024-03)
RealNet: A Feature Selection Network with Realistic Synthetic Anomaly for Anomaly Detection
and 5 more not named here
generate_fractal_noise_2d 5 other papers
2 dated earlier, 3 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
2406.07487 (2024-06)
GLAD: Towards Better Reconstruction with Global and Local Adaptive Diffusion Models for Unsupervised Anomaly Detection
and 2 more not named here
generate_perlin_noise_2d 5 other papers
2 dated earlier, 3 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
2406.07487 (2024-06)
GLAD: Towards Better Reconstruction with Global and Local Adaptive Diffusion Models for Unsupervised Anomaly Detection
and 2 more not named here

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

In this work, by re-examining the "matching" nature of Anomaly Detection (AD), we propose a new AD framework that simultaneously enjoys new records of AD accuracy and dramatically high running speed. In this framework, the anomaly detection problem is solved via a cascade patch retrieval procedure that retrieves the nearest neighbors for each test image patch in a coarse-to-fine fashion. Given a test sample, the top-K most similar training images are first selected based on a robust histogram matching process. Secondly, the nearest neighbor of each test patch is retrieved over the similar geometrical locations on those "global nearest neighbors", by using a carefully trained local metric. Finally, the anomaly score of each test image patch is calculated based on the distance to its "local nearest neighbor" and the "non-background" probability. The proposed method is termed "Cascade Patch Retrieval" (CPR) in this work. Different from the conventional patch-matching-based AD algorithms, CPR selects proper "targets" (reference images and locations) before "shooting" (patch-matching). On the well-acknowledged MVTec AD, BTAD and MVTec-3D AD datasets, the proposed algorithm consistently outperforms all the comparing SOTA methods by remarkable margins, measured by various AD metrics. Furthermore, CPR is extremely efficient. It runs at the speed of 113 FPS with the standard setting while its simplified version only requires less than 1 ms to process an image at the cost of a trivial accuracy drop. The code of CPR is available at https://github.com/flyinghu123/CPR.

For agents

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

get_harvested_code_for_paper("2308.06748")
get_code_for_paper("2308.06748")
have("2308.06748")

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

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

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

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

Connect an agent — have() is free.