Skip to content

Commit 211e728

Browse files
committed
initial commit denoised_smoothing
1 parent 32f99f3 commit 211e728

27 files changed

+5008
-44
lines changed

research/.idea/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

research/.idea/inspectionProfiles/profiles_settings.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

research/.idea/misc.xml

Lines changed: 0 additions & 7 deletions
This file was deleted.

research/.idea/modules.xml

Lines changed: 0 additions & 8 deletions
This file was deleted.

research/.idea/research.iml

Lines changed: 0 additions & 12 deletions
This file was deleted.

research/.idea/vcs.xml

Lines changed: 0 additions & 7 deletions
This file was deleted.

research/denoised_smoothing

Submodule denoised_smoothing deleted from cc0fe66
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Sayak Paul
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Denoised-Smoothing-TF
2+
Minimal implementation of [Denoised Smoothing: A Provable Defense for Pretrained Classifiers](https://arxiv.org/abs/2003.01908) in TensorFlow.
3+
4+
**Denoised Smoothing** is a simple and elegant way to (provably) robustify pre-trained image classification models (including the cloud APIs with only query access) and _l2_ adversarial attacks. [This blog post](https://www.microsoft.com/en-us/research/blog/denoised-smoothing-provably-defending-pretrained-classifiers-against-adversarial-examples/) provides a nice introduction to the method. The figure below summarizes what Denoised Smoothing is and how it works:
5+
6+
<div align="center">
7+
<img src="https://www.microsoft.com/en-us/research/uploads/prod/2021/02/DenoisedSmoothingFigure4-1024x246.png" width=700></img><br>
8+
<small><a href="https://www.microsoft.com/en-us/research/blog/denoised-smoothing-provably-defending-pretrained-classifiers-against-adversarial-examples/">Source</a></small>
9+
</div><br>
10+
11+
* Take a pre-trained classifier and prepend a pre-trained denoiser with it. Of course, the dataset on which the classifier and the denoiser would need to be trained on the same/similar dataset.
12+
* Apply [Randomized Smoothing](https://arxiv.org/abs/1902.02918).
13+
14+
Randomized Smoothing is a well-tested method to provably defend against _l2_ adversarial attacks under a specific radii. But it assumes that a classifier performs well under Gaussian noisy perturbations which may not always be the case.
15+
16+
**Note**: I utilized many scripts from the [official repository](https://github.com/microsoft/denoised-smoothing) of Denoised Smoothing to develop this repository. My aim with this repository is to provide a template for researchers to conduct certification tests with Keras/TensorFlow models. I encourage the readers to check out the original repository, it's really well-developed.
17+
18+
## Further notes
19+
20+
* The Denoised Smoothing process is demonstrated on the CIFAR-10 dataset.
21+
* You can train a classifier quickly with the [`Train_Classifier.ipynb`](https://colab.research.google.com/github/sayakpaul/Denoised-Smoothing-TF/blob/main/Train_Classifier.ipynb) notebook.
22+
* Training the denoiser is demonstrated in the [`Train_Denoiser.ipynb`](https://colab.research.google.com/github/sayakpaul/Denoised-Smoothing-TF/blob/main/Train_Denoiser.ipynb) notebook.
23+
* Certification tests are in [`Certification_Test.ipynb`](https://colab.research.google.com/github/sayakpaul/Denoised-Smoothing-TF/blob/main/Certification_Test.ipynb) notebook.
24+
25+
All the notebooks can be executed on Colab! You also have the option to train using the free TPUs.
26+
27+
## Results
28+
29+
| Denoiser with stability objective | Denoiser with MSE objective |
30+
| ---------|-------|
31+
| ![](figures/denoiser_stab.png) | ![](figures/denoiser_mse.png) |
32+
33+
As we can see prepending a pre-trained denoiser is extremely helpful for our purpose.
34+
35+
## Models
36+
37+
The models are available inside [`models.tar.gz`](https://github.com/sayakpaul/Denoised-Smoothing-TF/blob/main/models.tar.gz) in the `SavedModel` format. In the interest of reproducibility, the initial model weights are also provided.
38+
39+
## Acknowledgements
40+
41+
* [Hadi Salman](https://hadisalman.com/) (first author of Denoised Smoothing) for fruitful discussions.
42+
* [ML-GDE program](https://developers.google.com/programs/experts/) for providing GCP credits.
43+
44+
## Paper citation
45+
```
46+
@inproceedings{NEURIPS2020_f9fd2624,
47+
author = {Salman, Hadi and Sun, Mingjie and Yang, Greg and Kapoor, Ashish and Kolter, J. Zico},
48+
booktitle = {Advances in Neural Information Processing Systems},
49+
editor = {H. Larochelle and M. Ranzato and R. Hadsell and M. F. Balcan and H. Lin},
50+
pages = {21945--21957},
51+
publisher = {Curran Associates, Inc.},
52+
title = {Denoised Smoothing: A Provable Defense for Pretrained Classifiers},
53+
url = {https://proceedings.neurips.cc/paper/2020/file/f9fd2624beefbc7808e4e405d73f57ab-Paper.pdf},
54+
volume = {33},
55+
year = {2020}
56+
}
57+
```

0 commit comments

Comments
 (0)