This repository is the official implementation of Segment Shards: Prompt Batch Adversarial Attack to Segment Anything Model.
To install requirements:
pip install -r requirements.txt
env : Ubuntu 18.04 python 3.8 Pytorch 1.8.1+cu111
To generate the adversarial example(s) in the paper, run this command:
-
PBA
python attack_pba.py --config config/PBA/Apollo_10_816b.yaml
-
SPA
python attack.py --config config/SPA/Apollo_10_816b.yaml
-
PA
python attack.py --config config/PA/Apollo_10_864b.yaml
-
NPA
python attack_npa.py --config config/NPA/Apollo_10_816b.yaml
ps. You can use the config file to change the detial of attacking
To evaluate the adversarial examples generated, run:
# calculate miou
python eval_miou.py --config config/PBA/eval_Apollo_10_816b_816b.yaml
# calculate ssim
python eval_ssim.py --config config/PBA/Apollo_10_816b.yaml
the output of evaluation is a file named *.csv
You can download pretrained models here:
Then, put them into checkpoints directory, your project tree may like:
<root of code>
├── checkpoints
│ ├── sam_vit_b01ec64.pth
│ └── sam_vit_h_4b8939.pth
├── add_permutations.ipynb
├── attack_pba.py
├── attack_npa.py
├── attack.py
|...
You can download datasets from Apollo Dataset link, BDD100k Dataset link, CBCL Dataset link.
You can put these data in advDataset directory. Your project tree may like:
<root of code>
├── checkpoints
│ ├── sam_vit_b01ec64.pth
│ └── sam_vit_h_4b8939.pth
├── advDataset
│ ├── advApollo
│ | └──...
│ └── advBDD
│ └──...
├── add_permutations.ipynb
├── attack_pba.py
├── attack_npa.py
├── attack.py
|...
The Segment Shards project was made with the help of Segment Anything project.