Skip to content

Commit 83f81f5

Browse files
committed
Adding code for adversarially trained ImageNet models
1 parent 2243d30 commit 83f81f5

File tree

5 files changed

+894
-0
lines changed

5 files changed

+894
-0
lines changed

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
adversarial_crypto/* @dave-andersen
22
adversarial_text/* @rsepassi
3+
adv_imagenet_models/* @AlexeyKurakin
34
attention_ocr/* @alexgorban
45
audioset/* @plakal @dpwe
56
autoencoders/* @snurkabill

adv_imagenet_models/README.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Adversarially trained ImageNet models
2+
3+
Pre-trained ImageNet models from the following papers:
4+
5+
* [Adversarial Machine Learning at Scale](https://arxiv.org/abs/1611.01236)
6+
* [Ensemble Adversarial Training: Attacks and Defenses](https://arxiv.org/abs/1705.07204)
7+
8+
## Contact
9+
10+
Author: Alexey Kurakin,
11+
github: [AlexeyKurakin](https://github.com/AlexeyKurakin)
12+
13+
## Pre-requesites and installation
14+
15+
Ensure that you have installed TensorFlow 1.1 or greater
16+
([instructions](https://www.tensorflow.org/install/)).
17+
18+
You also need copy of ImageNet dataset if you want to run provided example.
19+
Follow
20+
[Preparing the dataset](https://github.com/tensorflow/models/tree/master/slim#Data)
21+
instructions in TF-Slim library to get and preprocess ImageNet data.
22+
23+
## Available models
24+
25+
Following pre-trained models are available:
26+
27+
Network Architecture | Adversarial training | Checkpoint
28+
---------------------|----------------------|----------------
29+
Inception v3 | Step L.L. | [adv_inception_v3_2017_08_18.tar.gz](http://download.tensorflow.org/models/adv_inception_v3_2017_08_18.tar.gz)
30+
Inception v3 | Step L.L. on ensemble of 3 models | [ens3_adv_inception_v3_2017_08_18.tar.gz](http://download.tensorflow.org/models/ens3_adv_inception_v3_2017_08_18.tar.gz)
31+
Inception v3 | Step L.L. on ensemble of 4 models| [ens4_adv_inception_v3_2017_08_18.tar.gz](http://download.tensorflow.org/models/ens4_adv_inception_v3_2017_08_18.tar.gz)
32+
Inception ResNet v2 | Step L.L. on ensemble of 3 models | [ens_adv_inception_renset_v2_2017_08_18.tar.gz](http://download.tensorflow.org/models/ens_adv_inception_renset_v2_2017_08_18.tar.gz)
33+
34+
All checkpoints are compatible with
35+
[TF-Slim](https://github.com/tensorflow/models/tree/master/slim)
36+
implementation of Inception v3 and Inception Resnet v2.
37+
38+
## How to evaluate models on ImageNet test data
39+
40+
Python script `eval_on_adversarial.py` allow you to evaluate provided models
41+
on white-box adversarial examples generated from ImageNet test set.
42+
43+
Usage is following:
44+
45+
```bash
46+
# ${MODEL_NAME} - type of network architecture,
47+
# either "inception_v3" or "inception_resnet_v2"
48+
# ${CHECKPOINT_PATH} - path to model checkpoint
49+
# ${DATASET_DIR} - directory with ImageNet test set
50+
# ${ADV_METHOD} - which method to use to generate adversarial images,
51+
# supported method:
52+
# "none" - use clean images from the dataset
53+
# "stepll" - one step towards least likely class method (StepLL),
54+
# see https://arxiv.org/abs/1611.01236 for details
55+
# "stepllnoise" - RAND+StepLL method from https://arxiv.org/abs/1705.07204
56+
# ${ADV_EPS} - size of adversarial perturbation, ignored when method is none
57+
python eval_on_adversarial.py \
58+
--model_name=${MODEL_NAME} \
59+
--checkpoint_path=${CHECKPOINT_PATH} \
60+
--dataset_dir=${DATASET_DIR} \
61+
--batch_size=50 \
62+
--adversarial_method=${ADV_METHOD} \
63+
--adversarial_eps=${ADV_EPS}
64+
```
65+
66+
Below is an example how to evaluate one of the models on RAND+StepLL adversarial
67+
examples:
68+
69+
```bash
70+
# Download checkpoint
71+
CHECKPOINT_DIR=/tmp/checkpoints
72+
mkdir ${CHECKPOINT_DIR}
73+
wget http://download.tensorflow.org/models/ens_adv_inception_renset_v2_2017_08_18.tar.gz
74+
tar -xvf ens_adv_inception_renset_v2_2017_08_18.tar.gz
75+
mv ens_adv_inception_renset_v2.ckpt* ${CHECKPOINT_DIR}
76+
rm ens_adv_inception_renset_v2_2017_08_18.tar.gz
77+
78+
# Run evaluation
79+
python eval_on_adversarial.py \
80+
--model_name=inception_v3 \
81+
--checkpoint_path=${CHECKPOINT_DIR}/ens_adv_inception_renset_v2.ckpt \
82+
--dataset_dir=${DATASET_DIR} \
83+
--batch_size=50 \
84+
--adversarial_method=stepllnoise \
85+
--adversarial_eps=16
86+
```

0 commit comments

Comments
 (0)