This commit is contained in:
Nataniel Ruiz
2019-12-30 14:13:43 -04:00
parent 8233dde691
commit 0737326238
2 changed files with 4 additions and 4 deletions
+2 -2
View File
@@ -7,7 +7,7 @@ import torch
import torch.nn as nn
class LinfPGDAttack(object):
def __init__(self, model=None, device=None, epsilon=0.05, k=1, a=0.05, feat = None):
def __init__(self, model=None, device=None, epsilon=0.05, k=1, a=0.01, feat = None):
self.model = model
self.epsilon = epsilon
self.k = k
@@ -24,7 +24,7 @@ class LinfPGDAttack(object):
X = X_nat.clone().detach_()
for i in range(self.k):
# print(i)
print(i)
X.requires_grad = True
output, feats = self.model(X, c_trg)
+2 -2
View File
@@ -611,7 +611,6 @@ class Solver(object):
# x_advs = []
if i == 0:
print(i)
_, perturb = pgd_attack.perturb(x_real, black, c_trg_list[0])
# for idx, c_trg in enumerate(c_trg_list):
# x_adv, perturb = pgd_attack.perturb(x_real, black, c_trg)
@@ -624,7 +623,8 @@ class Solver(object):
# Attack
# x_adv, perturb = pgd_attack.perturb(x_real, black, c_trg)
# _, perturb = x_advs[idx]
x_adv = x_real + perturb
# x_adv = x_real + perturb
x_adv = torch.clamp(x_real + perturb, min=-1, max=1)
# x_adv = self.blur_tensor(x_adv)
# Metrics