From 982d09fe8427cc8694f4292260cc2a70463ad870 Mon Sep 17 00:00:00 2001 From: Nataniel Ruiz Date: Thu, 26 Dec 2019 09:57:29 -0400 Subject: [PATCH] next --- cyclegan/models/test_model.py | 2 +- cyclegan/util/attacks.py | 2 +- stargan/solver.py | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cyclegan/models/test_model.py b/cyclegan/models/test_model.py index 915f330..4c3be38 100644 --- a/cyclegan/models/test_model.py +++ b/cyclegan/models/test_model.py @@ -77,7 +77,7 @@ class TestModel(BaseModel): pgd_attack = attacks.LinfPGDAttack(model=self.netG) black = np.zeros((1, 3, image.size(2), image.size(3))) black = torch.FloatTensor(black).cuda() - input_adv, perturb = pgd_attack.perturb(image, image) + input_adv, perturb = pgd_attack.perturb(image, black) return input_adv, perturb diff --git a/cyclegan/util/attacks.py b/cyclegan/util/attacks.py index cd2d38a..559d910 100644 --- a/cyclegan/util/attacks.py +++ b/cyclegan/util/attacks.py @@ -7,7 +7,7 @@ import torch import torch.nn as nn class LinfPGDAttack(object): - def __init__(self, model=None, epsilon=0.15, k=40, a=0.01): + def __init__(self, model=None, epsilon=0.05, k=1, a=0.01): self.model = model self.epsilon = epsilon self.k = k diff --git a/stargan/solver.py b/stargan/solver.py index e460d87..c85162c 100644 --- a/stargan/solver.py +++ b/stargan/solver.py @@ -609,8 +609,8 @@ class Solver(object): # Translate images. x_fake_list = [x_real] - # if i == 0: - # x_adv, perturb = pgd_attack.perturb(x_real, x_real, c_trg_list[0]) + if i == 0: + x_adv, perturb = pgd_attack.perturb(x_real, x_real, c_trg_list[0]) for c_trg in c_trg_list: with torch.no_grad(): @@ -639,6 +639,8 @@ class Solver(object): l0_error += (gen - gen_noattack).norm(0) min_dist += (gen - gen_noattack).norm(float('-inf')) n_samples += 1 + + break # Save the translated images. x_concat = torch.cat(x_fake_list, dim=3)