SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2108.09135 · 2021

PatchCleanser: Certifiably Robust Defense against Adversarial Patches for Any Image Classifier

arXiv · PDF · Open in the Atlas

Code that ran

4 of 6 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 4 have no contract verdict; 0 failures of our instrument; 2 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/2108.09135.json · badge: /api/ran/2108.09135.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
inspire-group/PatchCleanser canonical (classifier label)
classifier basis: census
4 ran · 2 no recorded run
FunctionStatusWhere it lives
double_masking_precomputed Ran
ran on a synthesized input
inspire-group/PatchCleanser/utils/defense.py
code served (permissive licence) · get_code("06cd86197cddda59")
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 int64, 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.

import numpy as np

# Create a prediction_map that is a 2D numpy array
# The function extracts the diagonal, gets unique values and their counts,
# and uses these to determine a prediction label
# Let's create a scenario where there's disagreement in diagonal predictions

prediction_map = np.array([
    [1, 0, 0, 0],
    [1, 2, 0, 0],
    [1, 1, 1, 0],
    [2, 2, 2, 2]
], dtype=np.int64)

ARGS = {
    "prediction_map": prediction_map
}
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 int64, 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
gen_mask_set_mr Ran
ran on a synthesized input
inspire-group/PatchCleanser/misc/pc_mr_experimental.py
code served (permissive licence) · get_code("512589c1670e79f2")
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 argparse

torch.manual_seed(0)

# Create a minimal args object with required attributes
args = argparse.Namespace()
args.mask_stride = 8
args.pa = 0
args.pb = 0
args.patch_size = 16

# Create a minimal ds_config dict with required structure
ds_config = {
    'input_size': [1, 64, 64]  # [batch, height, width]
}

# Define ARGS mapping all parameters
ARGS = {
    'args': args,
    'ds_config': ds_config,
    'mr': 2
}
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
process_minority_report Ran
ran on a synthesized input
inspire-group/PatchCleanser/misc/pc_mr_experimental.py
code served (permissive licence) · get_code("e08babe721b045e2")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned tuple, ndim 4, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import numpy as np

# Create small test arrays
# prediction_map: shape [num_img, num_pred, num_pred]
# confidence_map: shape [num_img, num_pred, num_pred, num_classes]
# The function uses these to create voting grids

num_img = 2
num_pred = 5
num_classes = 3

# Create prediction_map - integer predictions
prediction_map = np.random.randint(0, num_classes, size=(num_img, num_pred, num_pred), dtype=int)

# Create confidence_map - confidence scores for each class at each position
# Shape: [num_img, num_pred, num_pred, num_classes]
confidence_map = np.random.rand(num_img, num_pred, num_pred, num_classes).astype(np.float32)

# Minority report parameter
mr = 2

ARGS = {
    "prediction_map": prediction_map,
    "confidence_map": confidence_map,
    "mr": mr
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 4, dtype family float — a tuple output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
provable_detection Ran
ran on a synthesized input
inspire-group/PatchCleanser/misc/pc_mr.py
code served (permissive licence) · get_code("9dd0b4ae4528945e")
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 numpy as np

# Create numpy arrays for prediction_map and confidence_map
# prediction_map: contains predicted labels
prediction_map = np.array([1, 1, 2, 2])

# confidence_map: contains confidence scores
confidence_map = np.array([0.9, 0.8, 0.7, 0.6])

# label: the true label
label = 1

# orig_pred: the original prediction
orig_pred = 1

# tau: confidence threshold
tau = 0.75

ARGS = {
    "prediction_map": prediction_map,
    "confidence_map": confidence_map,
    "label": label,
    "orig_pred": orig_pred,
    "tau": tau
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 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
double_masking Not yet run
unverified (harvested, no recorded run)
inspire-group/PatchCleanser/utils/defense.py
code served (permissive licence) · get_code("eec1dffb030e6ea0")
How it ran

no invocation recorded.

gen_mask_set Not yet run
unverified (harvested, no recorded run)
inspire-group/PatchCleanser/utils/defense.py
code served (permissive licence) · get_code("03785e97d143efc7")
How it ran

no invocation recorded.

Also present in other papers' code

Of 6 samples lifted from this paper's linked repositories, 6 carry a function identity and 0 do not. Of the 6 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 6 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.

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

The adversarial patch attack against image classification models aims to inject adversarially crafted pixels within a restricted image region (i.e., a patch) for inducing model misclassification. This attack can be realized in the physical world by printing and attaching the patch to the victim object; thus, it imposes a real-world threat to computer vision systems. To counter this threat, we design PatchCleanser as a certifiably robust defense against adversarial patches. In PatchCleanser, we perform two rounds of pixel masking on the input image to neutralize the effect of the adversarial patch. This image-space operation makes PatchCleanser compatible with any state-of-the-art image classifier for achieving high accuracy. Furthermore, we can prove that PatchCleanser will always predict the correct class labels on certain images against any adaptive white-box attacker within our threat model, achieving certified robustness. We extensively evaluate PatchCleanser on the ImageNet, ImageNette, CIFAR-10, CIFAR-100, SVHN, and Flowers-102 datasets and demonstrate that our defense achieves similar clean accuracy as state-of-the-art classification models and also significantly improves certified robustness from prior works. Remarkably, PatchCleanser achieves 83.9% top-1 clean accuracy and 62.1% top-1 certified robust accuracy against a 2%-pixel square patch anywhere on the image for the 1000-class ImageNet dataset.

For agents

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

get_harvested_code_for_paper("2108.09135")
get_code_for_paper("2108.09135")
have("2108.09135")

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

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

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

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

Connect an agent — have() is free.