SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2403.05897 · CVPR · 2024

RealNet: A Feature Selection Network with Realistic Synthetic Anomaly for Anomaly Detection

Min Xu, Xiuzhuang Zhou, Ximiao Zhang

arXiv · PDF · Open in the Atlas

Code that ran

10 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; 2 honoured the contract we drafted, 0 violated it and 0 have no contract verdict; 8 failures of our instrument; 0 no recorded run), measured 2026-11-22; 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/2403.05897.json · badge: /api/ran/2403.05897.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
cnulab/RealNet canonical (classifier label)
classifier basis: census
10 ran · 0 no recorded run
FunctionStatusWhere it lives
SDAS_sample Ran
ran; our contract draft was wrong, not the code
cnulab/RealNet/train_diffusion.py
code served (permissive licence) · get_code("c46ea6fc2bd50337")
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. 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 torch.nn as nn

torch.manual_seed(0)

# Define a minimal model that accepts noise and class labels
class DummyModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 4)
    
    def forward(self, x, t, y=None):
        # x: noise tensor, t: timestep, y: class labels
        return self.linear(x)

# Define a minimal sampler with required methods
class DummySampler:
    def p_sample_loop(self, model, noise, device, s, model_kwargs):
        # Return tensor with same shape as noise
        return noise
    
    def ddim_reverse_sample_loop(self, model, x, clip_denoised, device, model_kwargs):
        # Return dict with 'sample' key
        return {'sample': x}
    
    def ddim_sample_loop(self, model, noise, eta, device, model_kwargs):
        # Return tensor with same shape as noise
        return noise

# Create instances
model = DummyModel()
sampler = DummySampler()

# Create tiny tensors: batch=2, channels=4, height=3, width=5
imgs = torch.randn(2, 4, 3, 5)
class_labels = torch.randint(0, 10, (2,))

ARGS = {
    'imgs': imgs,
    'class_labels': class_labels,
    'model': model,
    'sampler': sampler
}
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 tuple — a tuple output has no array shape of its own; none is 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
build_image_reader Ran
ran; our contract draft was wrong, not the code
cnulab/RealNet/datasets/image_reader.py
code served (permissive licence) · get_code("02edfca0848f4ad3")
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 OpenCVReader. The image it ran in was 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 os
import cv2
import tempfile
import numpy as np

# Create a temporary directory with test images
temp_dir = tempfile.mkdtemp()

# Create a simple test image (BGR format as OpenCV uses)
test_image = np.random.randint(0, 256, (100, 100, 3), dtype=np.uint8)
test_image_path = os.path.join(temp_dir, "test_image.jpg")
cv2.imwrite(test_image_path, test_image)

# Create a test mask image (grayscale)
test_mask = np.random.randint(0, 256, (100, 100), dtype=np.uint8)
test_mask_path = os.path.join(temp_dir, "test_mask.jpg")
cv2.imwrite(test_mask_path, test_mask)

# Define configuration for OpenCV reader
cfg_reader = {
    'type': 'opencv',
    'kwargs': {
        'image_dir': temp_dir,
        'color_mode': 'RGB'
    }
}

ARGS = {
    'cfg_reader': cfg_reader
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
cv2, numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type OpenCVReader — a OpenCVReader output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a OpenCVReader 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
compute_top_k Ran
ran; our contract draft was wrong, not the code
cnulab/RealNet/train_classifier.py
code served (permissive licence) · get_code("f85c45c8d1765da4")
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 torch

torch.manual_seed(0)

# Create small tensors for testing
batch_size = 2
num_classes = 4
k = 2

# logits: shape (batch_size, num_classes) - raw model outputs
logits = torch.randn(batch_size, num_classes)

# labels: shape (batch_size,) - ground truth class indices
labels = torch.tensor([1, 3])

# k: number of top predictions to check
k_val = k

# reduction: how to aggregate the results
reduction = 'mean'

ARGS = {
    'logits': logits,
    'labels': labels,
    'k': k_val,
    'reduction': reduction
}
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 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
lerp_np Ran
ran, honoured the contract we drafted
cnulab/RealNet/datasets/realnet_dataset.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.

rand_perlin_2d_np Ran
ran; our contract draft was wrong, not the code
cnulab/RealNet/datasets/realnet_dataset.py
code served (permissive licence) · get_code("4bb5faf95cfc1665")
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 ndarray, ndim 2, dtype family float, shape (16, 20) 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
import math

# Analyze the function to understand its parameters and usage:
# - shape: tuple of 2 integers, used for indexing and array operations
# - res: tuple of 2 integers, used for dividing and creating grids
# - fade: callable function, default is a lambda that takes t and returns fade values

# The function creates Perlin noise by:
# 1. Computing delta from res and shape
# 2. Creating a grid based on shape and res
# 3. Generating random gradients based on res
# 4. Computing dot products and lerping

# Set seed for reproducibility
np.random.seed(0)

# Create valid arguments
shape = (16, 20)  # Small shape tuple (distinct dimensions)
res = (4, 5)      # Small resolution tuple (distinct dimensions)

# Default fade function - using the provided lambda
fade = lambda t: 6 * t ** 5 - 15 * t ** 4 + 10 * t ** 3

ARGS = {
    "shape": shape,
    "res": res,
    "fade": fade
}
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 ndarray, ndim 2, dtype family float, shape (16, 20) — shape (16, 20) 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
random_between_a_and_b Ran
ran, honoured the contract we drafted
cnulab/RealNet/sample.py
code served (permissive licence) · get_code("38a9840dccf671bd")
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 random

def random_between_a_and_b(a, b):
    assert b >= a
    return random.random() * (b - a) + a

ARGS = {
    "a": 5.0,
    "b": 10.0
}
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 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
update_config Ran
ran; our contract draft was wrong, not the code
cnulab/RealNet/train_realnet.py
code served (permissive licence) · get_code("3e33555f9dc00ec5")
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 Config. The image it ran in was 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 torch.nn as nn

torch.manual_seed(0)

class Layer:
    def __init__(self, idx):
        self.idx = idx

class Block:
    def __init__(self, layers):
        self.layers = layers

class NetConfig:
    def __init__(self, kwargs=None):
        self.kwargs = kwargs if kwargs is not None else {}
    
    def get(self, key, default=None):
        return self.kwargs.get(key, default)

class DatasetMeta:
    def __init__(self, meta_file, sdas_dir=None):
        self.meta_file = meta_file
        self.sdas_dir = sdas_dir if sdas_dir is not None else ""

class DatasetSplit:
    def __init__(self, meta_file, sdas_dir=None):
        self.meta_file = meta_file
        self.sdas_dir = sdas_dir if sdas_dir is not None else ""

class Dataset:
    def __init__(self, train, test):
        self.train = train
        self.test = test

class Config:
    def __init__(self, structure, net, dataset):
        self.structure = structure
        self.net = net
        self.dataset = dataset

class Args:
    def __init__(self, class_name):
        self.class_name = class_name

# Build the config structure
block1 = Block([Layer(0), Layer(1)])
block2 = Block([Layer(1), Layer(2)])
structure = [block1, block2]

net_config_0 = NetConfig({'some_param': 'value'})
net_config_1 = NetConfig({'other_param': 'value'})
net = [net_config_0, net_config_1]

train_split = DatasetSplit(
    meta_file='path/train_{}.txt',
    sdas_dir='sdas/train_{}'
)
test_split = DatasetSplit(
    meta_file='path/test_{}.txt',
    sdas_dir='sdas/test_{}'
)
dataset = Dataset(train=train_split, test=test_split)

config = Config(structure=structure, net=net, dataset=dataset)
args = Args(class_name='dog')

ARGS = {
    'config': config,
    'args': args
}
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 Config — a Config output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Config 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
update_config Ran
ran; our contract draft was wrong, not the code
cnulab/RealNet/sample.py
code served (permissive licence) · get_code("4102f1fdf8eafea4")
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 Config. The image it ran in was 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 math

class ConfigDataset:
    def __init__(self):
        self.H = 64
        self.W = 64
        self.batch_size = 32

class ConfigUnet:
    def __init__(self):
        self.use_fp16 = True
        self.image_size = None

class ConfigClassifier:
    def __init__(self):
        self.image_size = None

class Config:
    def __init__(self):
        self.dataset = ConfigDataset()
        self.unet = ConfigUnet()
        self.classifier = ConfigClassifier()
        self.sample_number = 1000
        self.iter_number = None

config = Config()
world_size = 4

ARGS = {
    "config": config,
    "world_size": world_size
}
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 Config — a Config output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Config 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
update_config Ran
ran; our contract draft was wrong, not the code
cnulab/RealNet/train_classifier.py
code served (permissive licence) · get_code("0402f903a58abc8a")
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 Config. The image it ran in was 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

# Create a minimal config object with the required attributes
class Config:
    def __init__(self):
        self.dataset = DatasetConfig()
        self.classifier = ClassifierConfig()

class DatasetConfig:
    def __init__(self):
        self.input_size = [224, 224]  # tuple-like size specification
        self.class_name_list = []

class ClassifierConfig:
    def __init__(self):
        self.image_size = None

# Create args object with class_name_list
class Args:
    def __init__(self):
        self.class_name_list = ["cat", "dog", "bird"]

config = Config()
args = Args()

ARGS = {
    "config": config,
    "args": args
}
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 Config — a Config output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Config 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
update_config Ran
ran; our contract draft was wrong, not the code
cnulab/RealNet/train_diffusion.py
code served (permissive licence) · get_code("39f7b5d3324b349c")
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 Config. The image it ran in was 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

class ConfigDataset:
    def __init__(self):
        self.class_name_list = None
        self.input_size = [256, 256]

class ConfigUnet:
    def __init__(self):
        self.image_size = None
        self.use_fp16 = False

class ConfigTrainer:
    def __init__(self):
        self.use_fp16 = True

class Config:
    def __init__(self):
        self.dataset = ConfigDataset()
        self.unet = ConfigUnet()
        self.trainer = ConfigTrainer()

config = Config()
args_class_name_list = ['class_a', 'class_b', 'class_c']

class Args:
    def __init__(self, class_name_list):
        self.class_name_list = class_name_list

args = Args(args_class_name_list)

ARGS = {
    'config': config,
    'args': args
}
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 Config — a Config output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Config 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

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, 1 are also present in other papers whose code we hold (1 with at least one paper dated earlier, 0 the same month, 1 later) and 9 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
3 dated earlier, 5 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
2308.06748 (2023-08)
Target before Shooting: Accurate Anomaly Detection and Localization under One Millisecond via Cascade Patch Retrieval
and 5 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-22.

Repositories linked to this paper

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

Abstract

Self-supervised feature reconstruction methods have shown promising advances in industrial image anomaly detection and localization. Despite this progress, these methods still face challenges in synthesizing realistic and diverse anomaly samples, as well as addressing the feature redundancy and pre-training bias of pre-trained feature. In this work, we introduce RealNet, a feature reconstruction network with realistic synthetic anomaly and adaptive feature selection. It is incorporated with three key innovations: First, we propose Strength-controllable Diffusion Anomaly Synthesis (SDAS), a diffusion process-based synthesis strategy capable of generating samples with varying anomaly strengths that mimic the distribution of real anomalous samples. Second, we develop Anomaly-aware Features Selection (AFS), a method for selecting representative and discriminative pre-trained feature subsets to improve anomaly detection performance while controlling computational costs. Third, we introduce Reconstruction Residuals Selection (RRS), a strategy that adaptively selects discriminative residuals for comprehensive identification of anomalous regions across multiple levels of granularity. We assess RealNet on four benchmark datasets, and our results demonstrate significant improvements in both Image AU-ROC and Pixel AUROC compared to the current state-ofthe-art methods. The code, data, and models are available at https://github.com/cnulab/RealNet.

For agents

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

get_harvested_code_for_paper("2403.05897")
get_code_for_paper("2403.05897")
have("2403.05897")

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

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

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

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

Connect an agent — have() is free.