Skip to content

Commit

Permalink
Update spsa.py (#1176)
Browse files Browse the repository at this point in the history
Change the dependency of spsa.py on the deprecated tf.contrib
  • Loading branch information
gamaleldin committed Jul 9, 2020
1 parent 0bea6b8 commit 4b5ce54
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions cleverhans/attacks/spsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import numpy as np
from six.moves import xrange
import tensorflow as tf
import tensorflow_addons as tfa

from cleverhans.attacks.attack import Attack
from cleverhans.compat import reduce_mean, reduce_sum, reduce_max
Expand Down Expand Up @@ -505,19 +506,19 @@ def _apply_transformation(inputs):

# Apply rotation
angle *= np.pi / 180
x = tf.contrib.image.rotate(x, angle, interpolation='BILINEAR')
x = tfa.image.rotate(x, angle, interpolation='BILINEAR')

# Apply translation
dx_in_px = -dx * height
dy_in_px = -dy * width
translation = tf.convert_to_tensor([dx_in_px, dy_in_px])

try:
x = tf.contrib.image.translate(x, translation, interpolation='BILINEAR')
x = tfa.image.translate(x, translation, interpolation='BILINEAR')
except AttributeError as e:
print("WARNING: SpatialAttack requires tf 1.6 or higher")
raise e
x = tf.contrib.image.translate(x, translation, interpolation='BILINEAR')
x = tfa.image.translate(x, translation, interpolation='BILINEAR')
return tf.image.resize_image_with_crop_or_pad(x, height, width)


Expand Down Expand Up @@ -677,7 +678,7 @@ def projected_optimization(loss_fn,
input_image, clip_min=clip_min,
clip_max=clip_max)
init_optim_state = optimizer.init_state([init_perturbation])
nest = tf.contrib.framework.nest
nest = tf.nest

def loop_body(i, perturbation, flat_optim_state):
"""Update perturbation to input image."""
Expand Down

0 comments on commit 4b5ce54

Please sign in to comment.