SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2407.20337 · 2024

Contrasting Deepfakes Diffusion via Contrastive Learning and Global-Local Similarities

arXiv · PDF · Open in the Atlas

Code that ran

7 of 8 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, 1 violated it and 0 have no contract verdict; 4 failures of our instrument; 1 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/2407.20337.json · badge: /api/ran/2407.20337.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
aimagelab/code canonical (classifier label)
classifier basis: census
7 ran · 1 no recorded run
FunctionStatusWhere it lives
custom_range Ran
ran, honoured the contract we drafted
aimagelab/code/src/dataset/CustomTransform.py
code served (permissive licence) · get_code("76293afb49fb8256")
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 (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

torch.manual_seed(0)

ARGS = {
    "min": 0.0,
    "max": 10.0,
    "steps": 5
}
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 (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
cv2_jpg Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
aimagelab/code/src/dataset/standardtransform.py
code served (permissive licence) · get_code("86961d87fd5fab69")
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 3, dtype family int, shape (4, 3, 3) 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 cv2
import numpy as np

# Create a valid image array in BGR format (as expected by cv2)
# Image shape: (height, width, channels) with values in uint8 range [0, 255]
img = np.random.randint(0, 256, size=(4, 3, 3), dtype=np.uint8)

# Compression quality value (JPEG quality, typically 0-100)
compress_val = 80

ARGS = {
    'img': img,
    'compress_val': compress_val
}
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 ndarray, ndim 3, dtype family int, shape (4, 3, 3) — shape (4, 3, 3) 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
load_all_dictionary Ran
ran; our contract draft was wrong, not the code
aimagelab/code/src/data_download/download_elsa_v2.py
code served (permissive licence) · get_code("2d3091c8c8848b77")
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 defaultdict. 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 tempfile
from pathlib import Path
from collections import defaultdict
import pickle
import os

# Create temporary directory structure for the test
tmpdir = tempfile.mkdtemp()
data_dir = Path(tmpdir)

# Create the necessary directory structure and pickle files
world_size = 3
offset_rank_folder = 0

for i in range(world_size):
    rank_dir = data_dir / f'data_d3/job-{i + offset_rank_folder}'
    rank_dir.mkdir(parents=True, exist_ok=True)
    
    # Create sample data dictionaries for each rank
    sample_dict = {
        'key1': [f'value_{i}_1', f'value_{i}_2'],
        'key2': [f'value_{i}_3'],
        'key3': [f'value_{i}_4', f'value_{i}_5', f'value_{i}_6'],
    }
    
    # Pickle the dictionary
    with open(rank_dir / 'data_dictionary.pkl', 'wb') as f:
        pickle.dump(sample_dict, f)

# Create a simple args object with required attributes
class Args:
    def __init__(self, world_size, offset_rank_folder, data_dir):
        self.world_size = world_size
        self.offest_rank_folder = offset_rank_folder  # Note: typo in original function
        self.data_dir = data_dir

ARGS = {
    'args': Args(
        world_size=world_size,
        offset_rank_folder=offset_rank_folder,
        data_dir=data_dir
    )
}
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 defaultdict — a defaultdict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a defaultdict 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
load_faulty_parquet Ran
ran; our contract draft was wrong, not the code
aimagelab/code/src/data_download/download_elsa_v2.py
code served (permissive licence) · get_code("ca7e7f75bdff0684")
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 2, 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 pickle
import tempfile
from pathlib import Path

# Create a temporary directory structure for testing
temp_dir = tempfile.mkdtemp()
data_dir = Path(temp_dir)

# Create the directory structure that the function expects
world_size = 2
offset_rank_folder = 0

for i in range(world_size):
    rank_dir = data_dir / f'data_d3/job-{i + offset_rank_folder}'
    rank_dir.mkdir(parents=True, exist_ok=True)
    
    # Create incomplete_images.txt for each rank
    incomplete_images_content = f"image_rank{i}_1.jpg\nimage_rank{i}_2.jpg"
    with open(rank_dir / 'incomplete_images.txt', 'w') as f:
        f.write(incomplete_images_content)
    
    # Create faulted_parquet.pkl for each rank
    faulted_parquet_data = [f"parquet_rank{i}_1.parquet", f"parquet_rank{i}_2.parquet"]
    with open(rank_dir / 'faulted_parquet.pkl', 'wb') as f:
        pickle.dump(faulted_parquet_data, f)

# Create a simple args class
class Args:
    def __init__(self, data_dir, world_size, offset_rank_folder):
        self.data_dir = data_dir
        self.world_size = world_size
        self.offest_rank_folder = offset_rank_folder  # Note: typo in original function

args_obj = Args(data_dir=data_dir, world_size=world_size, offset_rank_folder=offset_rank_folder)

ARGS = {
    'args': args_obj
}
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 tuple, ndim 2, 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
np_images Ran
ran, honoured the contract we drafted
aimagelab/code/src/data_download/wds_creation.py
code served (permissive licence) · get_code("5113cb3c7498031a")
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 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 numpy as np
from PIL import Image
import tempfile
import os

# Create temporary directory with dummy image files
temp_dir = tempfile.mkdtemp()

# Create 7 dummy RGB images and save them
def create_dummy_image(filepath):
    img_array = np.random.randint(0, 256, (10, 10, 3), dtype=np.uint8)
    img = Image.fromarray(img_array, 'RGB')
    img.save(filepath)

image_paths = []
for i in range(7):
    filepath = os.path.join(temp_dir, f"image_{i}.jpg")
    create_dummy_image(filepath)
    image_paths.append(filepath)

# Build data_dictionary with required structure
data_dictionary = {
    "sample_key": image_paths
}

ARGS = {
    "data_dictionary": data_dictionary,
    "key": "sample_key",
    "extension": "jpg"
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
PIL, 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 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
pil_jpg Ran
ran; our contract draft was wrong, not the code
aimagelab/code/src/dataset/standardtransform.py
code served (permissive licence) · get_code("5632d030545bf59a")
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 3, dtype family int, shape (4, 3, 3) 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 PIL import Image
from io import BytesIO

def pil_jpg(img, compress_val):
    out = BytesIO()
    img = Image.fromarray(img)
    img.save(out, format='jpeg', quality=compress_val)
    img = Image.open(out)
    img = np.array(img)
    out.close()
    return img

# Create a small test image as numpy array
# Shape: (height=4, width=3, channels=3) for RGB image
test_img = np.random.randint(0, 256, (4, 3, 3), dtype=np.uint8)

# compress_val should be an integer between 1 and 95 for JPEG quality
compress_val = 85

ARGS = {
    "img": test_img,
    "compress_val": compress_val
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
PIL, numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type ndarray, ndim 3, dtype family int, shape (4, 3, 3) — shape (4, 3, 3) 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
sample_discrete Ran
ran, violated the contract we drafted
aimagelab/code/src/dataset/standardtransform.py
code served (permissive licence) · get_code("e3287363e619218a")
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 int, ndim 0, dtype family int, 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.

from random import random, choice

# sample_discrete takes a parameter 's' which is used with:
# - len(s) to check if length is 1
# - s[0] to access first element if length is 1
# - choice(s) to pick a random element from the sequence
# So 's' must be a sequence (list, tuple, etc.)

# Test case 1: list with single element
s_single = [42]

# Test case 2: list with multiple elements
s_multiple = [1, 2, 3, 4, 5]

# We'll use the multiple element case as it exercises both branches
ARGS = {
    "s": s_multiple
}
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 int, ndim 0, dtype family int, 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
tar_creation Not yet run
unverified (harvested, no recorded run)
aimagelab/code/src/data_download/wds_creation.py
code served (permissive licence) · get_code("e151f6cecae4a02d")
How it ran

no invocation recorded.

Also present in other papers' code

Of 8 samples lifted from this paper's linked repositories, 8 carry a function identity and 0 do not. Of the 8 distinct functions with an identity, 3 are also present in other papers whose code we hold (2 with at least one paper dated earlier, 0 the same month, 2 later) and 5 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
cv2_jpg 3 other papers
2 dated earlier, 1 later
2008.04115 (2020-08)
T-GD: Transferable GAN-generated Images Detection Framework
2402.12927 (2024-02)
CLIPping the Deception: Adapting Vision-Language Models for Universal Deepfake Detection
2503.18286 (2025-03)
CO-SPY: Combining Semantic and Pixel Features to Detect Synthetic Images by AI
pil_jpg 1 other paper
1 later
2503.18286 (2025-03)
CO-SPY: Combining Semantic and Pixel Features to Detect Synthetic Images by AI
sample_discrete 1 other paper
1 dated earlier
2402.01123 (2024-02)
A Single Simple Patch is All You Need for AI-generated Image 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-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

Discerning between authentic content and that generated by advanced AI methods has become increasingly challenging. While previous research primarily addresses the detection of fake faces, the identification of generated natural images has only recently surfaced. This prompted the recent exploration of solutions that employ foundation vision-and-language models, like CLIP. However, the CLIP embedding space is optimized for global image-to-text alignment and is not inherently designed for deepfake detection, neglecting the potential benefits of tailored training and local image features. In this study, we propose CoDE (Contrastive Deepfake Embeddings), a novel embedding space specifically designed for deepfake detection. CoDE is trained via contrastive learning by additionally enforcing global-local similarities. To sustain the training of our model, we generate a comprehensive dataset that focuses on images generated by diffusion models and encompasses a collection of 9.2 million images produced by using four different generators. Experimental results demonstrate that CoDE achieves state-of-the-art accuracy on the newly collected dataset, while also showing excellent generalization capabilities to unseen image generators. Our source code, trained models, and collected dataset are publicly available at: https://github.com/aimagelab/CoDE.

For agents

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

get_harvested_code_for_paper("2407.20337")
get_code_for_paper("2407.20337")
have("2407.20337")

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

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

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

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

Connect an agent — have() is free.