Skip to content

Commit

Permalink
Closes cleverhans-lab#744 (PGD wrapper issue)
Browse files Browse the repository at this point in the history
  • Loading branch information
goodfeli committed Oct 10, 2018
1 parent ab38939 commit 83e4fe1
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests_tf/test_projected_gradient_descent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""Tests for the ProjectGradientDescent attack
"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from nose.tools import assert_raises
import tensorflow as tf

from cleverhans.attacks import ProjectedGradientDescent

def test_callable_no_softmax():
batch_size = 2
nb_classes = 3
def model(x):
return tf.ones((batch_size, nb_classes)) / nb_classes
sess = tf.Session()
attack = ProjectedGradientDescent(model, sess=sess)
x = tf.ones((batch_size, 3))
# Currently ProjectedGradientDescent treats the output of a callable
# as probs rather than logits.
# Since our callable does not use a softmax, it is impossible to get
# the logits back. The test confirms that this causes an error.
assert_raises(TypeError, attack.generate, x)

if __name__ == "__main__":
test_callable()

0 comments on commit 83e4fe1

Please sign in to comment.