Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Semantic Robustness #259

Merged
merged 109 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
ece832f
Add batch_c15n for [0,1] image input and imagenet-normalized input.
mzweilin May 2, 2024
726a0af
Turn off inference mode before creating perturbations.
mzweilin May 2, 2024
b0c3079
Switch to training mode before running LightningModule.training_step().
mzweilin May 2, 2024
eba3c2b
Add utils for config instantiation.
mzweilin May 2, 2024
dd10c79
Add mart.utils.Get() to extract a value from kwargs dict.
mzweilin May 2, 2024
43d63f5
Upgrade Lightning from 2.0 to 2.1.
mzweilin May 2, 2024
f4f1f1a
Move most dependencies to optional groups.
mzweilin May 2, 2024
a18b691
Avoid importing everything in mart.
mzweilin May 2, 2024
6c8a99d
Make a separate naming space mart.transforms.objdet for object detect…
mzweilin May 2, 2024
e0dc984
Comment
mzweilin May 14, 2024
b51d3be
Merge branch 'main' into mzweilin/instantiate_config
mzweilin May 15, 2024
f4e9acc
Clean up.
mzweilin May 15, 2024
b283bf1
Move to mart.nn.Get().
mzweilin May 15, 2024
976f77e
Merge branch 'mzweilin/instantiate_config' into mzweilin/get_value_fr…
mzweilin May 15, 2024
4c0de4f
Merge branch 'mzweilin/get_value_from_kwargs' into mzweilin/upgrade_l…
mzweilin May 15, 2024
b96a99a
Revert changes in transforms.
mzweilin May 15, 2024
89eea77
Revert changes in __init__.py
mzweilin May 15, 2024
9491cc4
Revert changes in pyproject.toml.
mzweilin May 15, 2024
ec63b73
Skip object detection tests if pycocotools is not installed.
mzweilin May 15, 2024
e063944
Simplify dependency with newer lightning 2.1+.
mzweilin May 15, 2024
63286d0
Clean up comments.
mzweilin May 15, 2024
d725ea3
Remove the version constraint on rich, due to the conflict with Anoma…
mzweilin May 15, 2024
8d19d9b
Make a package anomalib_adversary
mzweilin May 15, 2024
94d4d44
Add two model configs for Anomalib.
mzweilin May 15, 2024
b85aaf1
Add README.
mzweilin May 15, 2024
3c0f172
Update README
mzweilin May 15, 2024
101940d
Replace Anomalib config files with command lines.
mzweilin May 16, 2024
d71cfd5
Merge branch 'main' into mzweilin/example_anomalib_adversary
mzweilin May 17, 2024
ed21be6
Add an empty configs folder, because mart.generate_config requires a …
mzweilin May 17, 2024
f74c293
Point dependency to MART@main.
mzweilin May 17, 2024
061b502
Parameterize module step function in AdversaryConnector
dxoigmn May 18, 2024
ceb7ccb
HACK: Gain function that clones it target
dxoigmn May 18, 2024
310186e
Update README with WinClip example
dxoigmn May 18, 2024
72ea76e
Add shape parameter to Perturber
dxoigmn May 21, 2024
0ab1c89
Add shape tests
dxoigmn May 21, 2024
5ff278f
Perturber shape overrides
dxoigmn May 21, 2024
7b0da36
Fix shape type annotation
dxoigmn May 21, 2024
96c6907
Update docstring
dxoigmn May 21, 2024
1c8e376
More shape tests
dxoigmn May 21, 2024
163b7ee
Add Semantic composer module
dxoigmn May 21, 2024
1698ed6
Undo syntax change
dxoigmn May 21, 2024
eed1ced
Break Adversary
dxoigmn May 21, 2024
8e92455
Barebone SemanticAdversary callback
dxoigmn May 22, 2024
280ab46
Add semantic perturbation logic
dxoigmn May 22, 2024
f1a8bb2
Revert changes to composer and perturber
dxoigmn May 22, 2024
5124c47
cleanup
dxoigmn May 22, 2024
cbc0a90
cleanup
dxoigmn May 22, 2024
4105f4d
Save metrics
dxoigmn May 22, 2024
fc13254
cleanup
dxoigmn May 22, 2024
9297b06
Add attack progress bar
dxoigmn May 23, 2024
1a0fdf3
Output gain in progress bar
dxoigmn May 23, 2024
39fdbe7
Derotate anomaly_map
dxoigmn May 23, 2024
ae1e2f2
Major refactor
dxoigmn May 23, 2024
f1ef7c4
Convert gain to loss
dxoigmn May 23, 2024
f28c9cf
Parameterize metrics
dxoigmn May 23, 2024
4b83dd1
Use full_like and friends
dxoigmn May 23, 2024
42b8f74
Close progress bar before printing
dxoigmn May 23, 2024
ac46559
Less memory use
dxoigmn May 23, 2024
226d13d
Clone before manipulation
dxoigmn May 23, 2024
8dee640
cleanup logic
dxoigmn May 23, 2024
dd037d7
Add perturb_image test
dxoigmn May 24, 2024
43a57cd
Add metric/loss saving logic
dxoigmn May 24, 2024
e203fa4
Seed for random restarts
dxoigmn May 24, 2024
cf748de
Always return best perturbed sample
dxoigmn May 24, 2024
6c9296f
Remove F1Score and image metrics
dxoigmn May 24, 2024
97a1c1d
cleanup
dxoigmn May 24, 2024
f259b34
cleanup
dxoigmn May 24, 2024
d35877a
cleanup
dxoigmn May 24, 2024
6874772
print mean and std
dxoigmn May 24, 2024
704d0b1
Use on_test_batch_start
dxoigmn May 28, 2024
0a0e444
Use test step
dxoigmn May 28, 2024
77be10c
Chasing memory issues
dxoigmn May 28, 2024
b963a48
More memory cleanup
dxoigmn May 28, 2024
b8cf698
Cleanup
dxoigmn May 29, 2024
3240103
Log best parameters to results.pt
dxoigmn May 29, 2024
e66ea8e
comment
dxoigmn May 29, 2024
cdfff75
Keep track of best batch
dxoigmn May 29, 2024
1a97278
bugfix
dxoigmn May 29, 2024
47d3253
Take step immediately after loss computation
dxoigmn May 29, 2024
96ec91e
Accumulate in adv_batch
dxoigmn May 29, 2024
4c52b3f
Move batch to cpu after backwards
dxoigmn May 29, 2024
5a83aac
bugfix
dxoigmn May 29, 2024
7407e19
Add support for 0-dim tensors
dxoigmn May 29, 2024
a3fa533
Log batch history
dxoigmn May 29, 2024
b357ef9
Keep batch on GPU when computing metrics but history on CPU
dxoigmn May 30, 2024
3e507de
Log batch_pAUROC
dxoigmn May 30, 2024
aa3fa52
Match loss
dxoigmn May 30, 2024
4aa8f8f
comment
dxoigmn May 30, 2024
9db3db2
Save best metrics to history
dxoigmn May 30, 2024
2c8c276
Add torch-rotation to requirements.txt
dxoigmn Jun 4, 2024
faefb8e
Fix comment
dxoigmn Jun 4, 2024
f76cf61
Fix comment
dxoigmn Jun 4, 2024
85e85bb
Fix comment
dxoigmn Jun 4, 2024
187ac53
Update MART dependency.
mzweilin Jun 5, 2024
e0117ae
Mordenize packaging with pyproject.toml.
mzweilin Jun 5, 2024
3b016d0
Revert "Parameterize module step function in AdversaryConnector"
mzweilin Jun 5, 2024
4fb0690
Revert "HACK: Gain function that clones it target"
mzweilin Jun 5, 2024
7500539
Revert "Update README with WinClip example"
mzweilin Jun 5, 2024
6cc6df6
Update README.
mzweilin Jun 5, 2024
bc3e4bb
Merge branch 'mzweilin/example_anomalib_adversary' into dxoigmn/seman…
mzweilin Jun 5, 2024
585c3ad
Change flake8 styling rule from W503 to W504.
mzweilin Jun 5, 2024
1d5008d
Move anomalib callback code to the standalone package.
mzweilin Jun 5, 2024
2621460
Add a comma to make consistent lines.
mzweilin Jun 5, 2024
72cff14
Merge branch 'mzweilin/example_anomalib_adversary' into dxoigmn/seman…
mzweilin Jun 5, 2024
6ef940b
Update README.
mzweilin Jun 5, 2024
0b87e4f
Add CLI instruction for running SemanticAdversary in Anomalib.
mzweilin Jun 5, 2024
4c3415e
Lock to earlier Anomalib to get WinClip gradients.
mzweilin Jun 5, 2024
59e8e2b
Update WinClip results under attack.
mzweilin Jun 6, 2024
7ab3f36
Merge branch 'main' into dxoigmn/semantic_robustness
mzweilin Jun 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions examples/anomalib_adversary/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ pip install -e .
ln -s {PATH_TO_ANOMALIB_REPO}/datasets .
```

### Model: STFPM

1. Train a model. We add an EarlyStopping callback in command line.

```sh
Expand Down Expand Up @@ -94,3 +96,55 @@ CUDA_VISIBLE_DEVICES=0 anomalib test \
│ pixel_F1Score │ 0.0955422893166542 │
└───────────────────────────┴───────────────────────────┘
```

### Model: WinCLIP

1. Evaluate the pre-trained model without adversary as baseline.

```sh
CUDA_VISIBLE_DEVICES=0 \
anomalib test \
--data anomalib.data.MVTec \
--data.category hazelnut \
--model WinClip \
--data.init_args.image_size [240,240] \
--data.init_args.eval_batch_size 16 \
--metrics.pixel=[F1Score,AUROC]
```

```console
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Test metric ┃ DataLoader 0 ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ image_AUROC │ 0.9074999690055847 │
│ image_F1Score │ 0.882758617401123 │
│ pixel_AUROC │ 0.9510707855224609 │
│ pixel_F1Score │ 0.37700045108795166 │
└───────────────────────────┴───────────────────────────┘
```

2. Run attack.

```sh
CUDA_VISIBLE_DEVICES=0 \
anomalib test \
--data anomalib.data.MVTec \
--data.category hazelnut \
--model WinClip \
--data.init_args.image_size [240,240] \
--data.init_args.eval_batch_size 16 \
--metrics.pixel=[F1Score,AUROC] \
--trainer.callbacks anomalib_adversary.callbacks.SemanticAdversary \
--trainer.callbacks.seed 2024
```

```console
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Test metric ┃ DataLoader 0 ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ image_AUROC │ 0.1875 │
│ image_F1Score │ 0.7283236980438232 │
│ pixel_AUROC │ 0.8381223678588867 │
│ pixel_F1Score │ 0.07936933636665344 │
└───────────────────────────┴───────────────────────────┘
```
Loading
Loading