Create a virtual environment

September 15, 2026 · View on GitHub

⚒️ Revisiting Adversarial Patch Defenses on Object Detectors: Unified Evaluation, Large-Scale Dataset, and New Insights

License: MIT Python Pytorch GitHub stars

English | 中文

Note: This project focuses on the research of adversarial patch attacks and defenses for Object Detectors, providing a complete pipeline for attacks, defenses, and evaluation.

This is the official repository for the paper Revisiting Adversarial Patch Defenses on Object Detectors: Unified Evaluation, Large-Scale Dataset, and New Insights accepted by ICCV2025.

📅 Roadmap & To-Do List

The current development plan is as follows, and we will continue to update this list:

  • 1. Detector Evaluation Framework

    • Integrate mainstream detector interfaces (YOLOv2/3/4/5/7, Faster R-CNN, SSD, CenterNet, ...).
    • Provide standardized robustness evaluation metrics (mAP under Attack, Attack Success Rate).
  • 2. APDE Dataset

    • Release the Adversarial Patch Defense Evaluation dataset download link.
    • Provide dataset readers, integrity checks, and Hugging Face download/processing examples.
  • 3. Retrained Defense

    • Release retrained defense weights (SAC, Adyolo, NAPGuard).
    • Provide Model Zoo table comparing Adv mAP before and after retraining.
  • 4. Continuous Updates

    • Attack Codes: Integrate the latest attack algorithms (T-SEA, ...).
    • Patches: Update adversarial patches to provide references for new defense works.

🚀 Introduction

With the application of deep learning in autonomous driving and security surveillance, the safety of object detectors has attracted significant attention. This repository aims to provide a unified platform for:

  1. Generating high-quality adversarial samples (Adversarial Patch Attacks).
  2. Evaluating the vulnerability of existing detectors when facing attacks.
  3. Improving model defense capabilities through the APDE dataset and adversarial training.

🛠️ Installation

# Clone the repository
git clone https://github.com/Gandolfczjh/APDE.git
cd APDE

# Create a virtual environment
conda create -n APDE python=3.10
conda activate APDE

# Install dependencies
pip install -r requirements.txt

APDE dataset

The reconstructed dataset is complete and validated: 94 patch types, 94,000 patched images, with one mask and annotation file per image. The full dataset is available on Hugging Face. This Git repository includes the patch originals and reader tools. Follow the download and usage examples below; see the dataset card for formats, sources, and evaluation details.

SplitPatch typesPatched images
Train5757,000
Test3737,000
Total9494,000

This is a reconstruction, not the exact original dataset used for the paper. The paper reports 56,400/37,600 images; this release keeps each 1,000-image patch type entirely in one split. Clean sources are shared across patch types, including across train/test. Split isolation applies to patch types, not source photographs.

The source pool contains 1,000 positives (81 INRIA Test + 919 COCO val2017) sampled without replacement from 288 + 2,693 positive candidates, and 1,000 annotation-negative backgrounds (162 INRIA + 838 COCO). Images are padded/resized to 416×416. Masks are lossless binary PNG (0/255); annotation rows are person x1 y1 x2 y2 and patch x1 y1 x2 y2 in pixel coordinates. Patch right/bottom coordinates are exclusive.

Download and use APDE from Hugging Face

Dataset: Gandolfczjh/APDE

Install the data dependencies from this repository:

python -m pip install -r requirements-data.txt
ConfigurationSplitsContents
patched (default)train: 57,000; test: 37,000Patched images, binary masks, TXT annotations and metadata
cleanpositive: 1,000; negative: 1,000Clean source images and person boxes
patchesall: 94Original patches and train/test assignments

Load online

from datasets import load_dataset

data = load_dataset("Gandolfczjh/APDE", "patched")
assert len(data["train"]) == 57000
assert len(data["test"]) == 37000
sample = data["test"][0]

clean = load_dataset("Gandolfczjh/APDE", "clean")
patches = load_dataset("Gandolfczjh/APDE", "patches", split="all")

The first call downloads and prepares the selected configuration in the Hugging Face cache; subsequent calls reuse it. For a quick preview without downloading the entire configuration first, use streaming:

stream = load_dataset("Gandolfczjh/APDE", "patched", split="test", streaming=True)
sample = next(iter(stream))

Download all files and load locally

The complete release contains 97 Parquet files and is about 20 GB. Allow extra disk space for the prepared cache or extracted images. Run from the cloned code repository; APDE below is a data subdirectory:

hf download Gandolfczjh/APDE --repo-type dataset --local-dir APDE
python tools/verify_apde_hf.py APDE

Repeat the download command to resume an interrupted download. Once downloaded, load the local Parquet files:

from datasets import load_dataset

data = load_dataset("parquet", data_files={
    "train": "APDE/data/train/*.parquet",
    "test": "APDE/data/test/*.parquet",
})
sample = data["test"][0]

The HF release embeds image, mask and annotation contents in Parquet. Its data/train, data/test, clean and patches folders differ from the original PNG/JSONL layout below. Use load_dataset() for downloaded HF files; APDEDataset("APDE") expects the original layout with train.jsonl and test.jsonl.

Process images, masks and annotations

from pathlib import Path
import numpy as np
from apde_data.dataset import parse_labels

image = sample["image"].convert("RGB")  # PIL image, 416 x 416
mask = sample["mask"].convert("L")      # 0 = background, 255 = patch
boxes = parse_labels(sample["labels"])
person_boxes = boxes["person_boxes"]   # pixel-coordinate [x1, y1, x2, y2]
patch_boxes = boxes["patch_boxes"]

image_array = np.asarray(image, dtype=np.float32) / 255.0  # H x W x 3
mask_array = (np.asarray(mask) > 0).astype(np.uint8)        # H x W, values 0/1

# Export one sample to ordinary PNG/TXT files.
image.save("sample.png")
mask.save("sample_mask.png")
Path("sample.txt").write_text(sample["labels"], encoding="utf-8")

Each row also includes id, source_id, patch_id, method, detector, attack_goal and split. For clean-source rows, parse person_boxes_json with json.loads(). Apply geometric transforms consistently to images, masks and boxes, and use nearest-neighbor interpolation for masks. Preserve the supplied patch-type split when training and evaluating.

See the official HF loading guide and download guide.

Directory layout

APDE/
├── clean/
│   ├── positive/{images,labels}/        # 1,000 clean positive samples
│   └── negative/{images,labels}/        # 1,000 clean negative samples
├── groups/<method>/<detector>/
│   ├── images/                         # 1,000 RGB PNGs per patch type
│   ├── masks/                          # 1,000 binary PNG masks
│   ├── labels/                         # 1,000 TXT annotations
│   ├── patch.png                       # Frozen patch used for this group
│   ├── samples.jsonl                   # Paths, split, and hashes
│   └── complete.json
├── images/<method>/<detector>/          # Compatibility symlink to groups
├── annotations/<method>/
│   ├── <detector>_label/                # Compatibility symlink
│   └── <detector>_mask/                 # Compatibility symlink
├── train.jsonl                         # 57,000 sample records
├── test.jsonl                          # 37,000 sample records
├── split_plan.json
├── positive_sources.json
├── negative_sources.json
├── source_report.json
├── build_report.json
├── audit_report.json
├── pipeline_status.json
├── code_snapshot/
└── preview.jpg

The eight matrix families (advpatch, TCEGA, tsea-pgd, tsea-mim, TCA, tsea, GNAP, DM-NAP) each cover 11 detectors: yolov2, yolov3, yolov4, yolov5, yolov7, ssd, centernet, retinanet, mask_rcnn, faster_rcnn, ddetr.

The remaining six types are test-only: AdvCloak/yolov2, AdvCloak/yolov3, AdvTshirt/yolov2, AA/yolov2, AdvSticker/yolov3, and UPC/yolov3. The train/test JSONL manifests define the split; there are no duplicated train/test image directories.

All previews use a height of 96 pixels and preserve their original aspect ratios. Click a patch to view the original. Each caption identifies the detector and train/test assignment.

AdvPatch

advpatch/yolov2 patch
YOLOv2
Test
advpatch/yolov3 patch
YOLOv3
Test
advpatch/yolov4 patch
YOLOv4
Train
advpatch/yolov5 patch
YOLOv5
Train
advpatch/yolov7 patch
YOLOv7
Train
advpatch/ssd patch
SSD
Train
advpatch/centernet patch
CenterNet
Train
advpatch/retinanet patch
RetinaNet
Train
advpatch/mask_rcnn patch
Mask R-CNN
Test
advpatch/faster_rcnn patch
Faster R-CNN
Train
advpatch/ddetr patch
D-DETR
Test

TC-EGA

TCEGA/yolov2 patch
YOLOv2
Train
TCEGA/yolov3 patch
YOLOv3
Train
TCEGA/yolov4 patch
YOLOv4
Train
TCEGA/yolov5 patch
YOLOv5
Train
TCEGA/yolov7 patch
YOLOv7
Test
TCEGA/ssd patch
SSD
Train
TCEGA/centernet patch
CenterNet
Test
TCEGA/retinanet patch
RetinaNet
Test
TCEGA/mask_rcnn patch
Mask R-CNN
Train
TCEGA/faster_rcnn patch
Faster R-CNN
Train
TCEGA/ddetr patch
D-DETR
Test

T-SEA-PGD

tsea-pgd/yolov2 patch
YOLOv2
Train
tsea-pgd/yolov3 patch
YOLOv3
Train
tsea-pgd/yolov4 patch
YOLOv4
Train
tsea-pgd/yolov5 patch
YOLOv5
Test
tsea-pgd/yolov7 patch
YOLOv7
Test
tsea-pgd/ssd patch
SSD
Train
tsea-pgd/centernet patch
CenterNet
Test
tsea-pgd/retinanet patch
RetinaNet
Train
tsea-pgd/mask_rcnn patch
Mask R-CNN
Train
tsea-pgd/faster_rcnn patch
Faster R-CNN
Train
tsea-pgd/ddetr patch
D-DETR
Train

T-SEA-MIM

tsea-mim/yolov2 patch
YOLOv2
Train
tsea-mim/yolov3 patch
YOLOv3
Train
tsea-mim/yolov4 patch
YOLOv4
Test
tsea-mim/yolov5 patch
YOLOv5
Test
tsea-mim/yolov7 patch
YOLOv7
Train
tsea-mim/ssd patch
SSD
Train
tsea-mim/centernet patch
CenterNet
Train
tsea-mim/retinanet patch
RetinaNet
Train
tsea-mim/mask_rcnn patch
Mask R-CNN
Test
tsea-mim/faster_rcnn patch
Faster R-CNN
Train
tsea-mim/ddetr patch
D-DETR
Test

TCA

TCA/yolov2 patch
YOLOv2
Train
TCA/yolov3 patch
YOLOv3
Train
TCA/yolov4 patch
YOLOv4
Test
TCA/yolov5 patch
YOLOv5
Train
TCA/yolov7 patch
YOLOv7
Train
TCA/ssd patch
SSD
Test
TCA/centernet patch
CenterNet
Train
TCA/retinanet patch
RetinaNet
Train
TCA/mask_rcnn patch
Mask R-CNN
Train
TCA/faster_rcnn patch
Faster R-CNN
Test
TCA/ddetr patch
D-DETR
Test

T-SEA

tsea/yolov2 patch
YOLOv2
Test
tsea/yolov3 patch
YOLOv3
Train
tsea/yolov4 patch
YOLOv4
Train
tsea/yolov5 patch
YOLOv5
Test
tsea/yolov7 patch
YOLOv7
Train
tsea/ssd patch
SSD
Train
tsea/centernet patch
CenterNet
Test
tsea/retinanet patch
RetinaNet
Test
tsea/mask_rcnn patch
Mask R-CNN
Train
tsea/faster_rcnn patch
Faster R-CNN
Train
tsea/ddetr patch
D-DETR
Train

GNAP

GNAP/yolov2 patch
YOLOv2
Train
GNAP/yolov3 patch
YOLOv3
Train
GNAP/yolov4 patch
YOLOv4
Train
GNAP/yolov5 patch
YOLOv5
Train
GNAP/yolov7 patch
YOLOv7
Test
GNAP/ssd patch
SSD
Test
GNAP/centernet patch
CenterNet
Train
GNAP/retinanet patch
RetinaNet
Train
GNAP/mask_rcnn patch
Mask R-CNN
Train
GNAP/faster_rcnn patch
Faster R-CNN
Test
GNAP/ddetr patch
D-DETR
Test

DM-NAP

DM-NAP/yolov2 patch
YOLOv2
Train
DM-NAP/yolov3 patch
YOLOv3
Train
DM-NAP/yolov4 patch
YOLOv4
Test
DM-NAP/yolov5 patch
YOLOv5
Test
DM-NAP/yolov7 patch
YOLOv7
Train
DM-NAP/ssd patch
SSD
Test
DM-NAP/centernet patch
CenterNet
Test
DM-NAP/retinanet patch
RetinaNet
Train
DM-NAP/mask_rcnn patch
Mask R-CNN
Train
DM-NAP/faster_rcnn patch
Faster R-CNN
Train
DM-NAP/ddetr patch
D-DETR
Train

Six test-only patches

AdvCloak/yolov2 patch
AdvCloak / YOLOv2
Test
AdvCloak/yolov3 patch
AdvCloak / YOLOv3
Test
AdvTshirt/yolov2 patch
AdvTshirt / YOLOv2
Test
AA/yolov2 patch
AA / YOLOv2
Test
AdvSticker/yolov3 patch
AdvSticker / YOLOv3
Test
UPC/yolov3 patch
UPC / YOLOv3
Test

Read the local dataset

python -m pip install Pillow
from apde_data import APDEDataset

data = APDEDataset("APDE", split="test")
sample = data[0]
image, mask = sample["image"], sample["mask"]  # RGB / L PIL images
person_boxes, patch_boxes = sample["person_boxes"], sample["patch_boxes"]

The reader works with PyTorch DataLoader; supply a transform and a custom collate function for variable-length boxes. For downloaded HF files, follow the download and usage examples.

Provenance and limits

Four missing GNAP combinations were retrained with corrected settings. AdvCloak/YOLOv3 was recovered from its original paper's embedded patch figure. AA, AdvSticker, and UPC are newly trained detector adaptations; UPC is weak under the small-patch placement used here. These are not recovered original-author checkpoints. Detailed provenance and diagnostic results are in the dataset card.

The defense scores below belong to the published paper and have not been rerun on this reconstruction.

🧠 Retrained Defense

To verify the effectiveness of the APDE Dataset, we performed retraining on three mainstream defense methods (SAC, Adyolo, NAPGuard) using this dataset.

The table below shows the detection performance (mAP) before and after retraining under various adversarial patch attacks. It is worth noting that the AdvCloak and AdvTshirt attacks in the last two rows were NOT included in our retraining set (Out-of-Domain / Unseen). Experimental results show that retraining with APDE not only improves defense against known attacks but also significantly enhances generalization capabilities against unknown (out-of-domain) patches.

Attack MethodSAC
(Original / Retrained)
Adyolo
(Original / Retrained)
NAPGuard
(Original / Retrained)
T-SEA51.82 / 71.6166.61 / 72.4783.61 / 86.31
TC-EGA58.16 / 71.3663.49 / 70.9168.51 / 85.30
Advpatch56.53 / 73.2965.54 / 72.0778.45 / 85.10
GNAP70.03 / 76.8672.94 / 78.5278.96 / 85.42
DM-NAP68.50 / 76.4869.26 / 76.8371.37 / 85.71
Out-of-Domain (Unseen)
AdvCloak4.17 / 71.2918.29 / 22.3652.21 / 73.16
AdvTshirt34.27 / 64.478.19 / 37.5350.21 / 70.89

Weights Download:

Google Drive Google Drive Includes weights for SAC-Retrained, Adyolo-Retrained, NAPGuard-Retrained, etc.

This repository integrates the following three typical defense methods and provides the corresponding retrained weights:

  • SAC (Segment and Complete): Locates adversarial patches via a segmentation network, removes them, and uses image inpainting technology to restore the background, thereby recovering detector performance.

  • Adyolo (Adversarial YOLO): Introduces a new "adversarial patch" class during the training phase, enabling the detector to actively identify and ignore adversarial patches in the scene, preventing them from interfering with normal object detection.

  • NAPGuard: Specifically designed for naturalistic adversarial patches, it distinguishes generated adversarial textures from natural objects by analyzing texture and pixel distribution features.