Skip to content

Commit 8be52c9

Browse files
committed
addressed comments
1 parent aa0c5b7 commit 8be52c9

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

art/attacks/carlini.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ def generate(self, x, **kwargs):
210210
y = get_labels_np_array(self.classifier.predict(x, logits=False))
211211

212212
for j, (ex, target) in enumerate(zip(x_adv, y)):
213-
logger.debug('Processing sample %i out of %i' % (j, x_adv.shape[0]))
214-
image = ex.copy().astype(NUMPY_DTYPE)
213+
logger.debug('Processing sample %i out of %i', j, x_adv.shape[0])
214+
image = ex.copy()
215215

216216
# The optimization is performed in tanh space to keep the
217217
# adversarial images bounded from clip_min and clip_max.
@@ -228,7 +228,7 @@ def generate(self, x, **kwargs):
228228

229229
for bss in range(self.binary_search_steps):
230230
lr = self.learning_rate
231-
logger.debug('Binary search step %i out of %i (c==%f)' % (bss, self.binary_search_steps, c))
231+
logger.debug('Binary search step %i out of %i (c==%f)', bss, self.binary_search_steps, c)
232232

233233
# Initialize perturbation in tanh space:
234234
adv_image = image
@@ -238,15 +238,15 @@ def generate(self, x, **kwargs):
238238
overall_attack_success = attack_success
239239

240240
for it in range(self.max_iter):
241-
logger.debug('Iteration step %i out of %i' % (it, self.max_iter))
241+
logger.debug('Iteration step %i out of %i', it, self.max_iter)
242242
logger.debug('Total Loss: %f', loss)
243243
logger.debug('L2Dist: %f', l2dist)
244244
logger.debug('Margin Loss: %f', loss-l2dist)
245245

246246
if attack_success:
247247
logger.debug('Margin Loss <= 0 --> Attack Success!')
248248
if l2dist < best_l2dist:
249-
logger.debug('New best L2Dist: %f (previous=%f)' % (l2dist, best_l2dist))
249+
logger.debug('New best L2Dist: %f (previous=%f)', l2dist, best_l2dist)
250250
best_l2dist = l2dist
251251
best_adv_image = adv_image
252252

@@ -263,7 +263,7 @@ def generate(self, x, **kwargs):
263263

264264
halving = 0
265265
while loss >= prev_loss and halving < self.max_halving:
266-
logger.debug('Apply gradient with learning rate %f (halving=%i)' % (lr, halving))
266+
logger.debug('Apply gradient with learning rate %f (halving=%i)', lr, halving)
267267
new_adv_image_tanh = adv_image_tanh + lr * perturbation_tanh
268268
new_adv_image = self._tanh_to_original(new_adv_image_tanh, clip_min, clip_max)
269269
_, l2dist, loss = self._loss(image, new_adv_image, target, c)
@@ -284,7 +284,7 @@ def generate(self, x, **kwargs):
284284
while loss <= prev_loss and doubling < self.max_doubling:
285285
prev_loss = loss
286286
lr *= 2
287-
logger.debug('Apply gradient with learning rate %f (doubling=%i)' % (lr, doubling))
287+
logger.debug('Apply gradient with learning rate %f (doubling=%i)', lr, doubling)
288288
doubling += 1
289289
new_adv_image_tanh = adv_image_tanh + lr * perturbation_tanh
290290
new_adv_image = self._tanh_to_original(new_adv_image_tanh, clip_min, clip_max)
@@ -311,7 +311,7 @@ def generate(self, x, **kwargs):
311311
if attack_success:
312312
logger.debug('Margin Loss <= 0 --> Attack Success!')
313313
if l2dist < best_l2dist:
314-
logger.debug('New best L2Dist: %f (previous=%f)' % (l2dist, best_l2dist))
314+
logger.debug('New best L2Dist: %f (previous=%f)', l2dist, best_l2dist)
315315
best_l2dist = l2dist
316316
best_adv_image = adv_image
317317

0 commit comments

Comments
 (0)