SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2308.02983 · ICCV · 2023

Focus the Discrepancy: Intra-and Inter-Correlation Learning for Image Anomaly Detection

Yan Luo, Xincheng Yao, Chongyang Zhang, Zefeng Qian, Ruoqi Li

arXiv · PDF · Open in the Atlas

Code that ran

10 of 13 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (4 of them constructed an object rather than computing a result; 1 honoured the contract we drafted, 0 violated it and 4 have no contract verdict; 5 failures of our instrument; 3 no recorded run), measured 2026-11-24; 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.02983.json · badge: /api/ran/2308.02983.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
xcyao00/fod canonical (classifier label)
classifier basis: census
6 ran · 1 no recorded run
xcyao00/FOD community
Papers with Code archive
4 ran · 2 no recorded run
FunctionStatusWhere it lives
Embedding2D Ran
ran on a synthesized input · constructed an object; no result was computed
xcyao00/FOD/models/model.py
code served (permissive licence) · get_code("5ed0a100400b50f9")
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 an instance of its own class, Embedding2D: the run constructed the object and did not call it, so no result was computed. 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
import math

torch.manual_seed(0)

# Set up the arguments for Embedding2D.__init__
ARGS = {
    'in_channels': 3,
    'd_model': 8,
    'dropout': 0.1,
    'h': 4,
    'w': 5,
    'with_pos_embed': True,
    'device': torch.device('cpu')
}
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 Embedding2D — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a Embedding2D 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
Encoder Ran
ran on a synthesized input · constructed an object; no result was computed
xcyao00/FOD/models/model.py
code served (permissive licence) · get_code("5ef174bf4fbeea2f")
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 an instance of its own class, Encoder: the run constructed the object and did not call it, so no result was computed. 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)

# Create a minimal encode layer that matches the expected interface
class MinimalEncodeLayer(nn.Module):
    def __init__(self, input_dim, output_dim):
        super(MinimalEncodeLayer, self).__init__()
        self.linear = nn.Linear(input_dim, output_dim)
    
    def forward(self, x, ref_x=None, with_intra=True, with_inter=True):
        x = self.linear(x)
        # Return: x, intra_corrs, intra_targets, inter_corrs, inter_targets
        batch_size = x.shape[0]
        intra_corrs = torch.randn(batch_size, 2)
        intra_targets = torch.randn(batch_size, 2)
        inter_corrs = torch.randn(batch_size, 2)
        inter_targets = torch.randn(batch_size, 2)
        return x, intra_corrs, intra_targets, inter_corrs, inter_targets

# Create encode layers
encode_layers = [
    MinimalEncodeLayer(4, 6),
    MinimalEncodeLayer(6, 8),
]

# Create a simple normalization layer
norm_layer = nn.BatchNorm1d(8)

ARGS = {
    "encode_layers": encode_layers,
    "norm_layer": norm_layer,
}
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 Encoder — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a Encoder 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
EncoderLayer Ran
ran on a synthesized input · constructed an object; no result was computed
xcyao00/FOD/models/model.py
code served (permissive licence) · get_code("69586fc628c7ebb6")
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 an instance of its own class, EncoderLayer: the run constructed the object and did not call it, so no result was computed. 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)

# Create a minimal attention module that satisfies the usage in EncoderLayer
class MinimalAttention(nn.Module):
    def __init__(self, d_model):
        super().__init__()
        self.d_model = d_model
        self.proj = nn.Linear(d_model, d_model)
    
    def forward(self, q, k, v, return_attention=False):
        # Compute attention-like output
        out = self.proj(q)
        
        if return_attention:
            # Return (output, correlation, target) as expected
            batch_size = q.shape[0]
            seq_len = q.shape[1]
            # correlation and target are dummy tensors
            corr = torch.randn(batch_size, seq_len, seq_len)
            target = torch.randn(batch_size, seq_len, self.d_model)
            return out, corr, target
        else:
            return out, None, None

# Create attention modules
d_model = 4
self_attention = MinimalAttention(d_model)
cross_attention = MinimalAttention(d_model)

# Define ARGS dictionary with all required parameters
ARGS = {
    'self_attention': self_attention,
    'cross_attention': cross_attention,
    'd_model': d_model,
    'd_feed_foward': 16,
    'dropout': 0.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 EncoderLayer — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a EncoderLayer 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
PositionalEmbedding Ran
ran on a synthesized input · constructed an object; no result was computed
xcyao00/FOD/models/model.py
code served (permissive licence) · get_code("9aadfb2a17c8c080")
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 an instance of its own class, PositionalEmbedding: the run constructed the object and did not call it, so no result was computed. 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
import math

torch.manual_seed(0)

ARGS = {
    'd_model': 8,
    'h': 4,
    'w': 5,
    'device': torch.device('cpu')
}
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 PositionalEmbedding — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a PositionalEmbedding 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_pro_retrieval_metrics Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
xcyao00/fod/utils/utils.py
pointer only (licence: MIT); the stored copy get_code serves, from hlr7999/rlr, is pointer only (licence: NONE) · get_code("b45f413cb8bb72e2")
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 hlr7999/rlr, 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.

denormalization Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
xcyao00/fod/utils/visualizer.py
pointer only (licence: MIT); the stored copy get_code serves, from hlr7999/rlr, is pointer only (licence: NONE) · get_code("3dcadf77eb559329")
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 hlr7999/rlr, 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.

embedding_concat Ran
ran; our contract draft was wrong, not the code
xcyao00/fod/utils/utils.py
pointer only (licence: MIT); the stored copy get_code serves, from hlr7999/rlr, is pointer only (licence: NONE) · get_code("ef0e6b962918f4b4")
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 hlr7999/rlr, 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.

entropy_loss Ran
ran; our contract draft was wrong, not the code
xcyao00/fod/losses.py
code served (permissive licence) · get_code("d6ada2dc4e5d3719")
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)

# p should be a probability distribution tensor
# The function expects:
# - p to be a tensor with shape (batch_size, ..., num_classes)
# - Operations: -p * torch.log(p + 0.0001), torch.sum(dim=-1), torch.mean(dim=1)
# - So we need at least 2 dimensions for the final torch.mean(entropy, dim=1)

# Create a tensor with shape (batch=2, sequence=3, classes=4) to have meaningful dims
# This way: sum over dim=-1 (classes) gives (2, 3), mean over dim=1 (sequence) gives (2,)
p = torch.rand(2, 3, 4)
# Normalize to make it a valid probability distribution
p = p / p.sum(dim=-1, keepdim=True)

ARGS = {
    "p": p
}
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
idx_1d_to_pos_2d Ran
ran, honoured the contract we drafted
xcyao00/fod/create_distance_maps.py
code served (permissive licence) · get_code("11596f92ff71fb9a")
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 1, dtype family int; 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 torch

torch.manual_seed(0)

ARGS = {
    "idx": 5,
    "width": 16,
}
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, ndim 1, dtype family int — 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
to_var Ran
ran; our contract draft was wrong, not the code
xcyao00/fod/utils/utils.py
pointer only (licence: MIT); the stored copy get_code serves, from TheZino/Image_captioning_SATell, is pointer only (licence: NONE) · get_code("502c50812b7f31ab")
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 TheZino/Image_captioning_SATell, 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.

Attention2D Not yet run
unverified (harvested, no recorded run)
xcyao00/FOD/models/model.py
code served (permissive licence) · get_code("36da03ed71d4d479")
How it ran

no invocation recorded.

FOD Not yet run
unverified (harvested, no recorded run)
xcyao00/FOD/models/model.py
code served (permissive licence) · get_code("de8248efbce530f7")
How it ran

no invocation recorded.

kl_loss Not yet run
unverified (harvested, no recorded run)
xcyao00/fod/losses.py
code served (permissive licence) · get_code("a2f6a358aed78f39")
How it ran

no invocation recorded.

Also present in other papers' code

Of 13 samples lifted from this paper's linked repositories, 13 carry a function identity and 0 do not. Of the 13 distinct functions with an identity, 4 are also present in other papers whose code we hold (1 with at least one paper dated earlier, 0 the same month, 4 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
to_var 9 other papers
7 dated earlier, 2 later · 1 only as an assembly brick
1502.03044 (2015-02)
Show, Attend and Tell: Neural Image Caption Generation with Visual Attention
1511.06349 (2015-11)
Generating Sentences from a Continuous Space
1704.03162 (2017-04)
Show, Ask, Attend, and Answer: A Strong Baseline For Visual Question Answering
and 6 more not named here
compute_pro_retrieval_metrics 1 other paper
1 later
2403.11561 (2024-03)
Learning Unified Reference Representation for Unsupervised Multi-class Anomaly Detection
denormalization 1 other paper
1 later
2403.11561 (2024-03)
Learning Unified Reference Representation for Unsupervised Multi-class Anomaly Detection
embedding_concat 1 other paper
1 later
2403.11561 (2024-03)
Learning Unified Reference Representation for Unsupervised Multi-class Anomaly Detection

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-24.

Repositories linked to this paper

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

Abstract

Humans recognize anomalies through two aspects: larger patch-wise representation discrepancies and weaker patch-to-normal-patch correlations. However, the previous AD methods didn't sufficiently combine the two complementary aspects to design AD models. To this end, we find that Transformer can ideally satisfy the two aspects as its great power in the unified modeling of patchwise representations and patch-to-patch correlations. In this paper, we propose a novel AD framework: FOcusthe-Discrepancy (FOD), which can simultaneously spot the patch-wise, intra-and inter-discrepancies of anomalies. The major characteristic of our method is that we renovate the self-attention maps in transformers to Intra-Inter-Correlation (I2Correlation). The I2Correlation contains a two-branch structure to first explicitly establish intraand inter-image correlations, and then fuses the features of two-branch to spotlight the abnormal patterns. To learn the intra-and inter-correlations adaptively, we propose the RBF-kernel-based target-correlations as learning targets for self-supervised learning. Besides, we introduce an entropy constraint strategy to solve the mode collapse issue in optimization and further amplify the normal-abnormal distinguishability. Extensive experiments on three unsupervised real-world AD benchmarks show the superior performance of our approach. Code will be available at https: //github.com/xcyao00/FOD.

For agents

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

get_harvested_code_for_paper("2308.02983")
get_code_for_paper("2308.02983")
have("2308.02983")

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

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

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

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

Connect an agent — have() is free.