Skip to content

Adversarial Patch defense using SegmentAndComplete (SAC) & Masked AutoEncoder (MAE)

License

Notifications You must be signed in to change notification settings

Kahsolt/adv-patch-defense

Repository files navigation

adv-patch-defense

Adversarial Patch defense using SegmentAndComplete (SAC) & Masked AutoEncoder (MAE)

Naive defense pipeline to AdvPatch := SAC + MAE

  • Consider image classification and object dectection task
  • AdvPatch puts high-freq color patches on given image (circle/square, ~15%(?) full area)
  • SAC detects adv patches then mask with pure black (round-corner square, nearly cover)
  • MAE recovers the black area

Partial result (limit=256):

| Setting | Accuracy | cmdline | | :-: | :-: | :-: | :-: | | clean | 96.484% | python run_adv_patch.py -L 256 -B 32 | | attack | 44.531% | python run_adv_patch.py -L 256 -B 32 --ap | | attack | 46.484% | python run_adv_patch.py -L 256 -B 32 --ap --ap_pgd | | defense | | python run_adv_patch.py -L 256 -B 4 --ap --sac --mae | | defense | | python run_adv_patch.py -L 256 -B 4 --ap --sac --sac_complete --mae |

⚠ For 12G VRAM, max batch_size for attack/defense is 48/6 separately ⚠ To defend against --ip attack, you must turn on --sac_complete because the pre-generated patches are not that PGD-like noisy

⚪ run error trouble shoot

Q: pip package version issues
A: assure timm==0.3.2, torch>1.7; recommend numpy==1.24.3, torch==2.0.1+cu117, torchvision==0.15.2+cu117

Q: ImportError in site-package timm
A: modify timm/models/layers/helper.py:6 to import collections.abc as container_abcs

Q: deprecation numpy error in local mae repo
A: modify mae/util/pos_embed.py:56, change np.float to np.float32

quick start

  • run repo/init_repos.cmd
  • download MAE weights to repo/mae/models
  • download test data ImageNet-1k
  • run clean test: python run_adv_patch.py
  • run attack test: python run_adv_patch.py --ap or python run_adv_patch.py --ip
  • run defense test
    • batch: python run_adv_patch.py -B 16 -L 16 --ap --sac --mae
    • all: python run_adv_patch.py --ap --sac --mae

pipeline subsitutes:

⚪ adv patch attack
  - AdvPatch (*)
  - ImageNet-Patch
  - DPatch / Robust-DPatch
  - regioned PGD
  - feature_level_adv

⚪ adv patch detect (mask / drop)
  - SAC (*)
  - smoothed-vit
  - PatchCleanser

⚪ high-freq suppress
  - PatchGuard
  - local gradients smoothing
  - unsharp mask (new = low + high * alpha)

⚪ image recover
  - MAE / dMAE (*)
  - MST / ZITS inpainting
  - DDNM (null-space diffusion inpainting)

ImageNet-Patch info

{
  'patch_size': 50, 
  'target_names': {
    804: 'soap dispenser', 
    513: 'cornet', 
    923: 'plate', 
    954: 'banana', 
    968: 'cup', 
    878: 'typewriter keyboard', 
    546: 'electric guitar', 
    585: 'hair spray', 
    806: 'sock', 
    487: 'cellular telephone'}, 
  'patch_type': 'square', 
  'input_shape': (3, 224, 224)
}

reference

⚪ adv attack toolbox

⚪ patch attack

⚪ image recover (patch & inpaint)

⚪ defense


by Armit 2023/03/23

About

Adversarial Patch defense using SegmentAndComplete (SAC) & Masked AutoEncoder (MAE)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published