Skip to content

Commit

Permalink
Fix travis tests (#34)
Browse files Browse the repository at this point in the history
* Fix num_batches for py27

* Skip MNIST tests when no GPU is available

* Update travis
  • Loading branch information
nottombrown authored Sep 19, 2018
1 parent e349634 commit f5248ea
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
11 changes: 2 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,12 @@ install:
pip install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.8.0-cp35-cp35m-linux_x86_64.whl;
fi
- time pip install -q -e "bird-or-bicycle"
- time pip install -q -e "unrestricted-advex[test]"

# workaround for version incompatibility between the scipy version in conda
# and the system-provided /usr/lib/x86_64-linux-gnu/libstdc++.so.6
# by installing a conda-provided libgcc and adding it to the load path
- conda install libgcc
- export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/travis/miniconda/envs/test-environment/lib

# command to run tests
script:
# exit on first error
- set -e
- time pip install -q -e "bird-or-bicycle"
- time pip install -q -e "unrestricted-advex[test]"

# Accuracy tests are slow so we run them after finishing all the other tests
- pytest -s -k "not two_class_mnist_accuracy"
Expand Down
2 changes: 1 addition & 1 deletion unrestricted-advex/unrestricted_advex/eval_kit.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def evaluate_two_class_unambiguous_model(

if attack._stop_after_n_datapoints is not None:
batch_size = len(data_iter[0][0])
n_batches = math.ceil(float(attack._stop_after_n_datapoints) / batch_size)
n_batches = int(math.ceil(float(attack._stop_after_n_datapoints) / batch_size))
attack_data_iter = data_iter[:n_batches]
else:
attack_data_iter = data_iter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def two_class_iter(images, labels, num_datapoints, batch_size,
which = (labels == class1) | (labels == class2)
images_2class = images[which].astype(np.float32)
labels_2class = labels[which]
num_batches = math.ceil(num_datapoints / batch_size)
num_batches = int(math.ceil(num_datapoints / batch_size))

idxs = range(int(num_batches))
if cycle:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
import tensorflow as tf
from unrestricted_advex import eval_kit, attacks

from unrestricted_advex.mnist_baselines import mnist_utils

model_dir = '/tmp/two-class-mnist/test'
Expand Down Expand Up @@ -36,6 +37,8 @@ def train_overfit_classifier(num_batches, batch_size):
return mnist_utils.np_two_class_mnist_model(model_dir)


@pytest.mark.skipif(not tf.test.is_gpu_available(),
reason="Running attacks on MNIST currently requires a GPU :( ")
def test_two_class_mnist_accuracy():
""" Train an mnist model on a subset of mnist and then evaluate it
on small attacks *on the training set*.
Expand Down

0 comments on commit f5248ea

Please sign in to comment.