./Backdoor-Example/
├── data
│ ├── bd_data
│ │ └── bd_test.h5 // this is the test data with backdoor trigger inserted
│ ├── clean_data
│ │ ├── test.h5 // this is clean data used for testing (validation)
│ │ └── train.h5 // this is clean data used for training the network
│ └── sun_glass_trigger.png
├── eval.py // this is the evaluation script
├── gen_backdoor.py // this is script you should modify to generate your backdoored data
└── model
└── bd_net
└── bd_net.h5
Training/Test data and example code for backdoor trigger generation and network evaluation can be found here.
- Python 3.6.8
- Keras 2.2.4
- Numpy 1.16.3
- Matplotlib 2.2.2
- H5py 2.9.0
- PIL 6.0.0
-
In
data/gen_backdoor.py
, change thepoison_data
function and specify thetarget_label
. -
Execute the python script by running
python ./gen_backdoor.py <trigger filename> <clean test data filename>
.E.g.,
python ./gen_backdoor.py ./data/sun_glass_trigger.png ./data/clean_data/test.h5
. -
The poisoned data will be stored under
data/bd_data
directory.
-
Store your model in
model/bd_net
directory. -
In
eval.py
, change thedata_preprocessing
function with your own preprocessing and execute the script by runningpython ./eval.py <clean test data filename> <backdoored test data filename> <backdoored model filename>
.E.g.,
python ./eval.py ./data/clean_data/test.h5 ./data/bd_data/bd_test.h5 ./model/bd_net/bd_net.h5
. -
Clean data classification accuracy and backdoored data attack success rate will be printed.