Skip to content

Commit

Permalink
Add instructions to download dataset and relevant GLoVe embeddings.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 282954546
  • Loading branch information
Cyprien de Masson d'Autume authored and diegolascasas committed Dec 11, 2019
1 parent cef986b commit 49e6321
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 1 deletion.
8 changes: 7 additions & 1 deletion scratchgan/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ The data contains:

## Running

Place the data files in the directory specified by `data_dir` flag.
Download the data and place it in the directory specified by `data_dir` flag:

mkdir -p /tmp/emnlp2017
curl https://storage.googleapis.com/deepmind-scratchgan-data/train.json --output /tmp/emnlp2017/train.json
curl https://storage.googleapis.com/deepmind-scratchgan-data/valid.json --output /tmp/emnlp2017/valid.json
curl https://storage.googleapis.com/deepmind-scratchgan-data/test.json --output /tmp/emnlp2017/test.json
curl https://storage.googleapis.com/deepmind-scratchgan-data/glove_emnlp2017.txt --output /tmp/emnlp2017/glove_emnlp2017.txt

Create and activate a virtual environment if needed:

Expand Down
33 changes: 33 additions & 0 deletions unrestricted_advx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Unrestricted Adversarial Challenge

This is a submission for the unrestricted adversarial challenge: Phase I. The
entry is uses a pretrained ImageNet model with Local Linearity Regularizer, then
adversarially trained using birds-or-bicycles dataset (train and extras) as
provided by the challenge.

> Tom B. Brown et al
*Unrestricted Adversarial Examples*. [\[arXiv\]](https://arxiv.org/pdf/1809.08352).
> Chongli Qin et al
*Adversarial Robustness through Local Linearization*. NEURIPS 2019. [\[arXiv\]](https://arxiv.org/abs/1907.02610)


## Contents

The code contains:

- a main file (`main.py`) for our submission.

## Running

Install requirements please follow instructions on
[Unrestricted Adversarial Challenge.](https://github.com/google/unrestricted-adversarial-examples/blob/master/warmup.md)

You can do this by running:

./unrestricted_advx/install_dependencies.sh

You can run the main script by:

./unrestricted_advx/run.sh


25 changes: 25 additions & 0 deletions unrestricted_advx/install_dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh
# Copyright 2019 Deepmind Technologies Limited.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Usage:
# user@host:/path/to/deepmind_research$ unrestricted_advx/run.sh

# Sets up virtual environment, install dependencies, and runs evaluation script
python3 -m venv unrestricted_venv
source unrestricted_venv/bin/activate
pip install -r unrestricted_advx/requirements.txt
git clone [email protected]:google/unrestricted-adversarial-examples.git
pip install -e unrestricted-adversarial-examples/bird-or-bicycle
pip install -e unrestricted-adversarial-examples/unrestricted-advex
58 changes: 58 additions & 0 deletions unrestricted_advx/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Copyright 2019 Deepmind Technologies Limited.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Submission to Unrestricted Adversarial Challenge."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import tensorflow as tf
import tensorflow_hub as hub
from unrestricted_advex import eval_kit


def _preprocess_image(image):
image = tf.image.central_crop(image, central_fraction=0.875)
image = tf.image.resize_bilinear(image, [224, 224], align_corners=False)
return image


def test_preprocess(image):
image = _preprocess_image(image)
image = tf.subtract(image, 0.5)
image = tf.multiply(image, 2.0)
return image


def main():
g = tf.Graph()
with g.as_default():
input_tensor = tf.placeholder(tf.float32, (None, 224, 224, 3))
x_np = test_preprocess(input_tensor)
raw_module_1 = hub.Module(
"https://tfhub.dev/deepmind/llr-pretrain-adv/latents/1")
raw_module_2 = hub.Module(
"https://tfhub.dev/deepmind/llr-pretrain-adv/linear/1")
latents = raw_module_1(dict(inputs=x_np, decay_rate=0.1))
logits = raw_module_2(dict(inputs=latents))
logits = tf.squeeze(logits, axis=[1, 2])
two_class_logits = tf.concat([tf.nn.relu(-logits[:, 1:]),
tf.nn.relu(logits[:, 1:])], axis=1)
sess = tf.train.SingularMonitoredSession()
def model(x_np):
return sess.run(two_class_logits, feed_dict={input_tensor: x_np})

eval_kit.evaluate_bird_or_bicycle_model(model, model_name="llr_resnet")

if __name__ == "__main__":
main()
4 changes: 4 additions & 0 deletions unrestricted_advx/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
absl-py>=0.7.0
numpy>=1.16.4
tensorflow>=1.14
tensorflow-hub>=0.5.0
21 changes: 21 additions & 0 deletions unrestricted_advx/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh
# Copyright 2019 Deepmind Technologies Limited.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Usage:
# user@host:/path/to/deepmind_research$ unrestricted_advx/run.sh

# Runs evaluation script
source unrestricted_venv/bin/activate
python3 -m unrestricted_advx.main

0 comments on commit 49e6321

Please sign in to comment.