Skip to content

Commit

Permalink
Enable Travis tests for unsupervised_adversarial_training
Browse files Browse the repository at this point in the history
* Pin the version of Tensorflow at >= 1.15. This allows us to remove a workaround that causes breakages for newer versions (we get errors if `AddV2` already has a registered gradient).
* Pin the version of Tensorflow at < 2 since cleverhans <= 3.1.0 doesn't properly support TF2
* Pin the version of cleverhans between 3.0.1 and 3.1.0. Versions newer than 3.1.0 will no longer support TF1.
* Comment out the dependency on `tensorflow-gpu` as it's not a strict requirement, and it does nothing for us on Travis.

PiperOrigin-RevId: 368241595
  • Loading branch information
alimuldal authored and diegolascasas committed Apr 13, 2021
1 parent b37b4ec commit edcd3f3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ env:
- PROJECT="transporter"
- PROJECT="tvt"
# - PROJECT="unrestricted_advx" # TODO(b/184862249): Fix and enable
- PROJECT="unsupervised_adversarial_training"
before_script:
- sudo apt-get update -qq
- pip install --upgrade pip
Expand Down
5 changes: 0 additions & 5 deletions unsupervised_adversarial_training/quick_eval_cifar.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
from cleverhans import attacks
import numpy as np
import tensorflow.compat.v1 as tf
from tensorflow.python.ops import math_grad
import tensorflow_hub as hub

UAT_HUB_URL = ('https://tfhub.dev/deepmind/unsupervised-adversarial-training/'
Expand Down Expand Up @@ -80,10 +79,6 @@ def eval_cifar():
_, data_test = tf.keras.datasets.cifar10.load_data()
data = _build_dataset(data_test, batch_size=batch_size, shuffle=False)

# Necessary for backwards-compatibility
# Earlier versions of TF don't have a registered gradient for the AddV2 op
tf.RegisterGradient('AddV2')(math_grad._AddGrad) # pylint: disable=protected-access

# Generate adversarial images.
if attack_fn_name == 'fgsm':
attack = attacks.MadryEtAl(cleverhans_model)
Expand Down
6 changes: 3 additions & 3 deletions unsupervised_adversarial_training/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
absl-py>=0.7.0
cleverhans>=3.0.1
cleverhans>=3.0.1,<=3.1.0
numpy>=1.16.4
pillow>=4.3.0
tensorflow>=1.14
tensorflow-gpu >= 1.11.0 # GPU version of TensorFlow.
tensorflow>=1.15,<2
# tensorflow-gpu >= 1.15.0,<2 # GPU version of TensorFlow.
tensorflow-hub>=0.5.0
8 changes: 5 additions & 3 deletions unsupervised_adversarial_training/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
# user@host:/path/to/deepmind_research$ unsupervised_adversarial_training/run.sh

# Sets up virtual environment, install dependencies, and runs evaluation script
python3 -m venv uat_venv
source uat_venv/bin/activate
python3 -m venv /tmp/uat_venv
source /tmp/uat_venv/bin/activate
pip install -U pip
pip install -r unsupervised_adversarial_training/requirements.txt

python -m unsupervised_adversarial_training.quick_eval_cifar \
--attack_fn_name=fgsm
--attack_fn_name=fgsm \
--num_batches=1

0 comments on commit edcd3f3

Please sign in to comment.