Bonus on Adversarial Machine Learning in final project of CS420 in SJTU.
Based on pre-trained model, we apply AdverTorch to attack our classifier and defense.
Particularly, we perform untargeted attack and construct defenses based on preprocessing.
For Linux:
conda install pytorch torchvision cudatoolkit=9.0 -c pytorch
Refer to Pytorch.
pip install advertorch
Refer to AdverTorch
Import packages in python files.
adversarial_defense.py should run first.
- adversarial_defense.py is to perform attack and defense, and generate adversarial as well as defended data files.
- accuracy.py is an accuracy test on all three kinds of data.
- comparison.py is a visulization of prediction and comparison results.
First create a data folder.
Download Facial Expression Recognition Dataset and add fer2013.csv file to data folder.
Run adversarial_defense.py to generate:
- cln_defended.txt: defended clean data;
- adv.txt: adversarial data;
- adv_defended.txt: defended adversarial data.
In models folder, there are pre-trained model and network. Refer to Project.
Thanks to my collaborator JiaYi, course TAs, and our teacher Tu Shikui.