See the paper here.
Python 3, NumPy, and TensorFlow
A makefile is included for training and evaluating the ensembles described in the paper.
First train an ensemble:
make train DATASET=x
where x is eithermnist
orcifar
Then generate some adversarial examples targeting it:
make gen DATASET=x ATTACK=y
where y isFGS
,BI
,DF
,CW
, orRAND
Then evaluate it against the generated examples:
make eval DATASET=x
Read below if you wish to experiment with different parameters.
The file train.py
can be used to train an ensemble from scratch.
Some important parameters:
-n, --ensemble_size
to set the number of ensemble members--learning_rate
to set the initial learning rate--eta
to set the eta parameter to control random perturbation-d, --dataset
to choose between MNIST and CIFAR10
See the file for other parameters.
python3 train.py -n 5 --dataset MNIST --learning_rate 0.1 --max_steps 100000 --eta 0.1 --model_dir models/myensemble
The file gen_adv.py
can be used to generate adversarial examples using the following methods:
- 0: Fast gradient sign
- 1: Basic iterative
- 2: DeepFool
- 3: C&W l2
- 4: Random noise
Use -t
or --type
to choose the attack method by its numeric index shown above.
Use --direct
to save the adversarial examples directly in adv_examples/
See the file for other parameters.
python3 gen_adv.py -n 5 --dataset MNIST --model_dir models/myensemble --attack 0 --epsilon 0.1
The file eval.py
can be used to evaluate an ensemble's performance against both clean and adversarial examples.
Some parameters:
-rt, --rank_threshold
to set the detection parameter tau-s, --set
to choose between the test and validation sets
See the file for other parameters.
python3 eval.py -n 5 --dataset MNIST --model_dir models/myensemble --rank_threshold 2