|
| 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 | +|  |  | |
| 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