Add instructions to download dataset and relevant GLoVe embeddings.

PiperOrigin-RevId: 282954546
This commit is contained in:
Cyprien de Masson d'Autume
2019-11-28 17:42:16 +00:00
committed by Diego de Las Casas
parent cef986bf9c
commit 49e6321d76
6 changed files with 148 additions and 1 deletions
+7 -1
View File
@@ -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:
+33
View File
@@ -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
View File
@@ -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 git@github.com:google/unrestricted-adversarial-examples.git
pip install -e unrestricted-adversarial-examples/bird-or-bicycle
pip install -e unrestricted-adversarial-examples/unrestricted-advex
+58
View File
@@ -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
View File
@@ -0,0 +1,4 @@
absl-py>=0.7.0
numpy>=1.16.4
tensorflow>=1.14
tensorflow-hub>=0.5.0
+21
View File
@@ -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