SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2409.17874 · NeurIPS · 2024

DarkSAM: Fooling Segment Anything Model to Segment Nothing

Zhang, Yu Leo, Hai Jin, Xianlong Wang, Ziqi Zhou, Minghui Li, Shengshan Hu, Yufei Song, Dezhong Yao

arXiv · PDF · Open in the Atlas

Code that ran

3 of 9 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; 1 failure of our instrument; 6 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/2409.17874.json · badge: /api/ran/2409.17874.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/darksam canonical (classifier label)
classifier basis: classifier_2025
2 ran · 3 no recorded run
CGCL-codes/DarkSAM canonical (classifier label)
classifier basis: census
1 ran · 3 no recorded run
FunctionStatusWhere it lives
collate_fn Ran
ran, honoured the contract we drafted
cgcl-codes/darksam/darksam_test.py
code served (permissive licence) · get_code("8a851dec75e212d9")
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) and returned tuple. 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 sample batch items
# Each item is a tuple of (image, prompts_list, mask_gt_list, sample_id)

image_1 = torch.randn(3, 4, 4)  # 3 channels, 4x4 spatial
prompts_1 = ["a cat", "a dog"]
mask_gt_1 = [torch.randint(0, 2, (4, 4)), torch.randint(0, 2, (4, 4))]
sample_id_1 = "sample_001"

image_2 = torch.randn(3, 4, 4)
prompts_2 = ["a bird"]
mask_gt_2 = [torch.randint(0, 2, (4, 4))]
sample_id_2 = "sample_002"

# Create batch as list of tuples
batch = [
    (image_1, prompts_1, mask_gt_1, sample_id_1),
    (image_2, prompts_2, mask_gt_2, sample_id_2),
]

ARGS = {
    "batch": batch
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
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
collate_fn Ran
ran, honoured the contract we drafted
cgcl-codes/darksam/darksam_attack.py
code served (permissive licence) · get_code("f02f45ccf025a2e5")
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) and returned tuple. 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 sample batch items
# Each item is a tuple of (image, mask_gt, prompt, sample_id)
batch_item_1 = (
    torch.randn(3, 4, 4),  # image: 3 channels, 4x4
    [torch.randn(1, 4, 4)],  # mask_gt_list: list of masks
    ["a dog"],  # prompts_list: list of text prompts
    "sample_001"  # sample_id: string identifier
)

batch_item_2 = (
    torch.randn(3, 4, 4),  # image: 3 channels, 4x4
    [torch.randn(1, 4, 4)],  # mask_gt_list: list of masks
    ["a cat"],  # prompts_list: list of text prompts
    "sample_002"  # sample_id: string identifier
)

# Create batch as list of tuples
batch = [batch_item_1, batch_item_2]

ARGS = {
    "batch": batch
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
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
timer Ran
ran; our contract draft was wrong, not the code
CGCL-codes/DarkSAM/utils.py
code served (permissive licence) · get_code("e170e4ed166e28a1")
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 function. 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 time import time

def timer(fn):
    def wrapper(*args, **kwargs):
        start = time()
        r = fn(*args, **kwargs)
        end = time()
        print(f'[Timer]: {fn.__name__} took {end - start:.3f}s')
        return r
    return wrapper

# Create a simple test function to be decorated
@timer
def sample_function(x, y):
    """A simple function that performs some computation."""
    total = 0
    for i in range(1000):
        total += x + y
    return total

# Set up arguments for timer
fn = sample_function
args = ()
kwargs = {}

ARGS = {
    'fn': fn
}
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 function — a function output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a function 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
generate_random_point Not yet run
unverified (harvested, no recorded run)
CGCL-codes/DarkSAM/atk_setting.py
code served (permissive licence) · get_code("e681a0661da4fa67")
How it ran

no invocation recorded.

make_print_to_file Not yet run
unverified (harvested, no recorded run)
cgcl-codes/darksam/darksam_test.py
code served (permissive licence) · get_code("7360acc0d742b347")
How it ran

no invocation recorded.

resize_mask Not yet run
unverified (harvested, no recorded run)
CGCL-codes/DarkSAM/dataset.py
code served (permissive licence) · get_code("06594a11399a956f")
How it ran

no invocation recorded.

resize_mask_and_box Not yet run
unverified (harvested, no recorded run)
CGCL-codes/DarkSAM/dataset.py
code served (permissive licence) · get_code("0b61a02c26a64a88")
How it ran

no invocation recorded.

run Not yet run
unverified (harvested, no recorded run)
cgcl-codes/darksam/darksam_test.py
code served (permissive licence) · get_code("d38920053ef4af89")
How it ran

no invocation recorded.

run Not yet run
unverified (harvested, no recorded run)
cgcl-codes/darksam/darksam_attack.py
code served (permissive licence) · get_code("39f859ed093b3e78")
How it ran

no invocation recorded.

Also present in other papers' code

Of 9 samples lifted from this paper's linked repositories, 9 carry a function identity and 0 do not. Of the 9 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 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.

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

Segment Anything Model (SAM) has recently gained much attention for its outstanding generalization to unseen data and tasks. Despite its promising prospect, the vulnerabilities of SAM, especially to universal adversarial perturbation (UAP) have not been thoroughly investigated yet. In this paper, we propose DarkSAM, the first prompt-free universal attack framework against SAM, including a semantic decoupling-based spatial attack and a texture distortion-based frequency attack. We first divide the output of SAM into foreground and background. Then, we design a shadow target strategy to obtain the semantic blueprint of the image as the attack target. DarkSAM is dedicated to fooling SAM by extracting and destroying crucial object features from images in both spatial and frequency domains. In the spatial domain, we disrupt the semantics of both the foreground and background in the image to confuse SAM. In the frequency domain, we further enhance the attack effectiveness by distorting the high-frequency components (i.e., texture information) of the image. Consequently, with a single UAP, DarkSAM renders SAM incapable of segmenting objects across diverse images with varying prompts. Experimental results on four datasets for SAM and its two variant models demonstrate the powerful attack capability and transferability of DarkSAM. Our codes are available at: https://github.com/CGCL-codes/DarkSAM.

For agents

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

get_harvested_code_for_paper("2409.17874")
get_code_for_paper("2409.17874")
have("2409.17874")

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

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

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

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

Connect an agent — have() is free.