Skip to content

Commit 49e6321

Browse files
Cyprien de Masson d'Autumediegolascasas
authored andcommitted
Add instructions to download dataset and relevant GLoVe embeddings.
PiperOrigin-RevId: 282954546
1 parent cef986b commit 49e6321

File tree

6 files changed

+148
-1
lines changed

6 files changed

+148
-1
lines changed

scratchgan/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@ The data contains:
3939

4040
## Running
4141

42-
Place the data files in the directory specified by `data_dir` flag.
42+
Download the data and place it in the directory specified by `data_dir` flag:
43+
44+
mkdir -p /tmp/emnlp2017
45+
curl https://storage.googleapis.com/deepmind-scratchgan-data/train.json --output /tmp/emnlp2017/train.json
46+
curl https://storage.googleapis.com/deepmind-scratchgan-data/valid.json --output /tmp/emnlp2017/valid.json
47+
curl https://storage.googleapis.com/deepmind-scratchgan-data/test.json --output /tmp/emnlp2017/test.json
48+
curl https://storage.googleapis.com/deepmind-scratchgan-data/glove_emnlp2017.txt --output /tmp/emnlp2017/glove_emnlp2017.txt
4349

4450
Create and activate a virtual environment if needed:
4551

unrestricted_advx/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Unrestricted Adversarial Challenge
2+
3+
This is a submission for the unrestricted adversarial challenge: Phase I. The
4+
entry is uses a pretrained ImageNet model with Local Linearity Regularizer, then
5+
adversarially trained using birds-or-bicycles dataset (train and extras) as
6+
provided by the challenge.
7+
8+
> Tom B. Brown et al
9+
*Unrestricted Adversarial Examples*. [\[arXiv\]](https://arxiv.org/pdf/1809.08352).
10+
> Chongli Qin et al
11+
*Adversarial Robustness through Local Linearization*. NEURIPS 2019. [\[arXiv\]](https://arxiv.org/abs/1907.02610)
12+
13+
14+
## Contents
15+
16+
The code contains:
17+
18+
- a main file (`main.py`) for our submission.
19+
20+
## Running
21+
22+
Install requirements please follow instructions on
23+
[Unrestricted Adversarial Challenge.](https://github.com/google/unrestricted-adversarial-examples/blob/master/warmup.md)
24+
25+
You can do this by running:
26+
27+
./unrestricted_advx/install_dependencies.sh
28+
29+
You can run the main script by:
30+
31+
./unrestricted_advx/run.sh
32+
33+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/sh
2+
# Copyright 2019 Deepmind Technologies Limited.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# Usage:
17+
# user@host:/path/to/deepmind_research$ unrestricted_advx/run.sh
18+
19+
# Sets up virtual environment, install dependencies, and runs evaluation script
20+
python3 -m venv unrestricted_venv
21+
source unrestricted_venv/bin/activate
22+
pip install -r unrestricted_advx/requirements.txt
23+
git clone [email protected]:google/unrestricted-adversarial-examples.git
24+
pip install -e unrestricted-adversarial-examples/bird-or-bicycle
25+
pip install -e unrestricted-adversarial-examples/unrestricted-advex

unrestricted_advx/main.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Copyright 2019 Deepmind Technologies Limited.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Submission to Unrestricted Adversarial Challenge."""
16+
from __future__ import absolute_import
17+
from __future__ import division
18+
from __future__ import print_function
19+
import tensorflow as tf
20+
import tensorflow_hub as hub
21+
from unrestricted_advex import eval_kit
22+
23+
24+
def _preprocess_image(image):
25+
image = tf.image.central_crop(image, central_fraction=0.875)
26+
image = tf.image.resize_bilinear(image, [224, 224], align_corners=False)
27+
return image
28+
29+
30+
def test_preprocess(image):
31+
image = _preprocess_image(image)
32+
image = tf.subtract(image, 0.5)
33+
image = tf.multiply(image, 2.0)
34+
return image
35+
36+
37+
def main():
38+
g = tf.Graph()
39+
with g.as_default():
40+
input_tensor = tf.placeholder(tf.float32, (None, 224, 224, 3))
41+
x_np = test_preprocess(input_tensor)
42+
raw_module_1 = hub.Module(
43+
"https://tfhub.dev/deepmind/llr-pretrain-adv/latents/1")
44+
raw_module_2 = hub.Module(
45+
"https://tfhub.dev/deepmind/llr-pretrain-adv/linear/1")
46+
latents = raw_module_1(dict(inputs=x_np, decay_rate=0.1))
47+
logits = raw_module_2(dict(inputs=latents))
48+
logits = tf.squeeze(logits, axis=[1, 2])
49+
two_class_logits = tf.concat([tf.nn.relu(-logits[:, 1:]),
50+
tf.nn.relu(logits[:, 1:])], axis=1)
51+
sess = tf.train.SingularMonitoredSession()
52+
def model(x_np):
53+
return sess.run(two_class_logits, feed_dict={input_tensor: x_np})
54+
55+
eval_kit.evaluate_bird_or_bicycle_model(model, model_name="llr_resnet")
56+
57+
if __name__ == "__main__":
58+
main()

unrestricted_advx/requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
absl-py>=0.7.0
2+
numpy>=1.16.4
3+
tensorflow>=1.14
4+
tensorflow-hub>=0.5.0

unrestricted_advx/run.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/sh
2+
# Copyright 2019 Deepmind Technologies Limited.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# Usage:
17+
# user@host:/path/to/deepmind_research$ unrestricted_advx/run.sh
18+
19+
# Runs evaluation script
20+
source unrestricted_venv/bin/activate
21+
python3 -m unrestricted_advx.main

0 commit comments

Comments
 (0)