SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2207.00278 · 2022

BadHash: Invisible Backdoor Attacks against Deep Hashing with Clean Label

arXiv · PDF · Open in the Atlas

Code that ran

10 of 12 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; 0 honoured the contract we drafted, 0 violated it and 8 have no contract verdict; 2 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/2207.00278.json · badge: /api/ran/2207.00278.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
cgcl-codes/badhash canonical (classifier label)
classifier basis not recorded on the link
10 ran · 2 no recorded run
FunctionStatusWhere it lives
CalcHammingDist Ran
ran on a synthesized input
cgcl-codes/badhash/utils/hamming_matching.py
code served (permissive licence) · get_code("fec8bc71986e9775")
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 (2, 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

# B1 and B2 are binary matrices (or any numeric matrices)
# The function computes Hamming distance using dot product
# B1 shape: (n_samples_1, q) where q is number of bits
# B2 shape: (n_samples_2, q) where q is number of bits
# Result shape: (n_samples_1, n_samples_2)

B1 = np.array([
    [1, 0, 1, 0],
    [0, 1, 1, 1]
], dtype=np.float32)

B2 = np.array([
    [1, 1, 0, 0],
    [0, 0, 1, 1],
    [1, 0, 1, 0]
], dtype=np.float32)

ARGS = {
    "B1": B1,
    "B2": B2
}
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 (2, 3) — shape (2, 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
CalcMap Ran
ran on a synthesized input
cgcl-codes/badhash/utils/hamming_matching.py
code served (permissive licence) · get_code("0d0f5f9ab369ac01")
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 float64, ndim 0, 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

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

# Create small binary matrices for hashing
# qB: query binary codes (num_query x code_length)
# rB: retrieval binary codes (num_retrieval x code_length)
num_query = 2
num_retrieval = 3
code_length = 4

qB = np.random.randint(0, 2, size=(num_query, code_length)).astype(np.float32)
rB = np.random.randint(0, 2, size=(num_retrieval, code_length)).astype(np.float32)

# queryL: query labels (num_query x num_classes)
# retrievalL: retrieval labels (num_retrieval x num_classes)
num_classes = 5

queryL = np.random.randint(0, 2, size=(num_query, num_classes)).astype(np.float32)
retrievalL = np.random.randint(0, 2, size=(num_retrieval, num_classes)).astype(np.float32)

# Ensure at least some positive labels to avoid division by zero
queryL[0, 0] = 1
retrievalL[0, 0] = 1
retrievalL[1, 0] = 1

ARGS = {
    "qB": qB,
    "rB": rB,
    "queryL": queryL,
    "retrievalL": retrievalL,
}
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 float64, ndim 0, dtype family float — no output shape is stated: observe_signature.py recorded float ndim 0, which disagrees with the fixture run
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
CalcSim Ran
ran on a synthesized input
cgcl-codes/badhash/model/utils.py
code served (permissive licence) · get_code("a1703482ab911f6a")
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 2, dtype family float, shape (2, 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 torch

torch.manual_seed(0)

# CalcSim takes two label tensors and computes similarity via matrix multiplication
# batch_label: tensor of shape (batch_size, num_features)
# train_label: tensor of shape (num_train, num_features)
# The function does: batch_label.mm(train_label.t()) which requires both to be 2D

batch_label = torch.randint(0, 2, (2, 4)).float()
train_label = torch.randint(0, 2, (3, 4)).float()

ARGS = {
    "batch_label": batch_label,
    "train_label": train_label,
}
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 2, dtype family float, shape (2, 3) — shape (2, 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
compute_result Ran
ran on a synthesized input
cgcl-codes/badhash/utils/hamming_matching.py
code served (permissive licence) · get_code("e41e957d5b40db30")
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)

# Build a minimal net that satisfies the function's usage:
# - net.eval() is called
# - net(img.cuda()) is called, so it needs __call__
# - The output has .data.cpu(), so it returns a tensor
class MinimalNet(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 3)
    
    def forward(self, x):
        return self.linear(x)

net = MinimalNet()

# Build a dataloader: list of (img, cls, _) tuples
# img: batch of images, shape (2, 4) - batch_size=2, feature_dim=4
# cls: class labels, shape (2,) - batch_size=2
# _: unused third element
dataloader = [
    (torch.randn(2, 4), torch.tensor([0, 1]), None),
    (torch.randn(2, 4), torch.tensor([1, 0]), None),
]

ARGS = {
    "dataloader": dataloader,
    "net": net,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch, tqdm — 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
get_scheduler Ran
ran; our contract draft was wrong, not the code
cgcl-codes/badhash/model/module.py
code served (permissive licence) · get_code("0427d9736d5128bb")
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 LambdaLR. 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
from torch.optim import Adam

torch.manual_seed(0)

# Create a minimal model
model = nn.Linear(4, 3)

# Create an optimizer
optimizer = Adam(model.parameters(), lr=0.001)

# Create a minimal options class with required attributes
class Options:
    def __init__(self, lr_policy='linear'):
        self.lr_policy = lr_policy
        self.epoch_count = 0
        self.n_epochs = 10
        self.n_epochs_decay = 10
        self.lr_decay_iters = 5

# Test with 'linear' policy
opt = Options(lr_policy='linear')

ARGS = {
    'optimizer': optimizer,
    'opt': opt
}
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 LambdaLR — a LambdaLR output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a LambdaLR 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
l2normalize Ran
ran; our contract draft was wrong, not the code
cgcl-codes/badhash/model/spectral_norm.py
pointer only (licence: MIT); the stored copy get_code serves, from xxxliu95/RA_FA_Cardiac, is pointer only (licence: NONE) · get_code("bedff51745d2cf84")
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 xxxliu95/RA_FA_Cardiac, 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.

load_label Ran
ran on a synthesized input
cgcl-codes/badhash/utils/data_provider.py
code served (permissive licence) · get_code("8edd0019ee4ece92")
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 (4,) 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 os
import torch
import numpy as np
import tempfile

# Create a temporary directory and file for testing
temp_dir = tempfile.mkdtemp()
temp_filename = "test_labels.txt"
temp_filepath = os.path.join(temp_dir, temp_filename)

# Write some sample label data to the temporary file
sample_labels = np.array([0, 1, 2, 1], dtype=np.int64)
np.savetxt(temp_filepath, sample_labels, fmt='%d')

ARGS = {
    "filename": temp_filename,
    "data_dir": temp_dir,
}
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 Tensor, ndim 1, dtype family float, shape (4,) — shape (4,) 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
log_trick Ran
ran on a synthesized input
cgcl-codes/badhash/model/utils.py
code served (permissive licence) · get_code("62659c288a716208")
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 2, dtype family float, shape (2, 4) as a later run recorded it. 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, 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 torch.autograd import Variable

torch.manual_seed(0)

# Create a small tensor for testing
x = torch.randn(2, 4)

ARGS = {
    "x": x
}
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 2, dtype family float, shape (2, 4) — shape (2, 4) 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
smooth_one_hot Ran
ran on a synthesized input
cgcl-codes/badhash/model/utils.py
code served (permissive licence) · get_code("52dca59d4bef58a4")
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 2, dtype family float, shape (2, 4) 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 a batch of 2 samples with 4 classes
# true_labels should be one-hot encoded or suitable for torch.max
batch_size = 2
num_classes = 4
true_labels = torch.zeros(batch_size, num_classes)
true_labels[0, 1] = 1.0  # First sample: class 1
true_labels[1, 3] = 1.0  # Second sample: class 3

classes = 4
smoothing = 0.1

ARGS = {
    "true_labels": true_labels,
    "classes": classes,
    "smoothing": smoothing,
}
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 2, dtype family float, shape (2, 4) — shape (2, 4) 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
spectral_norm Ran
ran on a synthesized input
cgcl-codes/badhash/model/spectral_norm.py
code served (permissive licence) · get_code("80dbe040cd85c98b")
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 SimpleModule. 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
from torch.nn import Parameter

torch.manual_seed(0)

# Create a simple module with a weight parameter
class SimpleModule(nn.Module):
    def __init__(self):
        super().__init__()
        # Create a weight parameter with shape (4, 3) - distinct dimensions
        self.weight = Parameter(torch.randn(4, 3))
    
    def forward(self, x):
        return x

# Instantiate the module
module = SimpleModule()

# Define the arguments dict
ARGS = {
    'module': module
}
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 SimpleModule — a SimpleModule output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a SimpleModule 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
get_data Not yet run
unverified (harvested, no recorded run)
cgcl-codes/badhash/utils/data_provider.py
code served (permissive licence) · get_code("a3c3e950fd3ba00c")
How it ran

no invocation recorded.

remove_spectral_norm Not yet run
unverified (harvested, no recorded run)
cgcl-codes/badhash/model/spectral_norm.py
code served (permissive licence) · get_code("b68aa157100e24b9")
How it ran

no invocation recorded.

Also present in other papers' code

Of 12 samples lifted from this paper's linked repositories, 12 carry a function identity and 0 do not. Of the 12 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, 2 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
l2normalize 27 other papers
15 dated earlier, 10 later, 2 same year, order not determinable · 2 only as an assembly brick
1703.09452 (2017-03)
SEGAN: Speech Enhancement Generative Adversarial Network
1802.05957 (2018-02)
Spectral Normalization for Generative Adversarial Networks
1806.03589 (2018-06)
Free-Form Image Inpainting with Gated Convolution
and 24 more not named here
get_scheduler 6 other papers
4 dated earlier, 2 later
1909.08313 (2019-09)
Unsupervised Sketch-to-Photo Synthesis
2110.02516 (2021-10)
Attack as the Best Defense: Nullifying Image-to-image Translation GANs via Limit-aware Adversarial Attack
2112.09343 (2021-12)
Domain Adaptation on Point Clouds via Geometry-Aware Implicits
and 3 more not named here
CalcHammingDist 1 other paper
1 dated earlier
1702.00758 (2017-02)
HashNet: Deep Learning to Hash by Continuation

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

Due to its powerful feature learning capability and high efficiency, deep hashing has achieved great success in large-scale image retrieval. Meanwhile, extensive works have demonstrated that deep neural networks (DNNs) are susceptible to adversarial examples, and exploring adversarial attack against deep hashing has attracted many research efforts. Nevertheless, backdoor attack, another famous threat to DNNs, has not been studied for deep hashing yet. Although various backdoor attacks have been proposed in the field of image classification, existing approaches failed to realize a truly imperceptive backdoor attack that enjoys invisible triggers and clean label setting simultaneously, and they also cannot meet the intrinsic demand of image retrieval backdoor. In this paper, we propose BadHash, the first generative-based imperceptible backdoor attack against deep hashing, which can effectively generate invisible and input-specific poisoned images with clean label. Specifically, we first propose a new conditional generative adversarial network (cGAN) pipeline to effectively generate poisoned samples. For any given benign image, it seeks to generate a natural-looking poisoned counterpart with a unique invisible trigger. In order to improve the attack effectiveness, we introduce a label-based contrastive learning network LabCLN to exploit the semantic characteristics of different labels, which are subsequently used for confusing and misleading the target model to learn the embedded trigger. We finally explore the mechanism of backdoor attacks on image retrieval in the hash space. Extensive experiments on multiple benchmark datasets verify that BadHash can generate imperceptible poisoned samples with strong attack ability and transferability over state-of-the-art deep hashing schemes.

For agents

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

get_harvested_code_for_paper("2207.00278")
get_code_for_paper("2207.00278")
have("2207.00278")

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

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

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

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

Connect an agent — have() is free.