next
This commit is contained in:
+2
-2
@@ -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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user