This commit is contained in:
Nataniel Ruiz
2019-12-25 20:23:14 -04:00
parent 75e2ccd8da
commit ff2dfbfee7

View File

@@ -91,32 +91,6 @@ class TestModel(BaseModel):
d = (generated - generated_noattack).norm(float('-inf'))
return l1, l2, l0, d
def attack(self, label, inst, image=None):
# Encode Inputs
image = Variable(image) if image is not None else None
input_label, inst_map, real_image, _ = self.encode_input(Variable(label), Variable(inst), image, infer=True)
# Fake Generation
if self.use_features:
if self.opt.use_encoded_image:
# encode the real image to get feature map
feat_map = self.netE.forward(real_image, inst_map)
else:
# sample clusters from precomputed features
feat_map = self.sample_features(inst_map)
input_concat = torch.cat((input_label, feat_map), dim=1)
else:
input_concat = input_label
# Attack
pgd_attack = attacks.LinfPGDAttack(model=self.netG)
black = np.zeros((1, 3, input_concat.size(2), input_concat.size(3)))
black = torch.FloatTensor(black).cuda()
# print(input_concat.size())
input_adv, perturb = pgd_attack.perturb(input_concat, black)
return input_adv, perturb
def optimize_parameters(self):
"""No optimization for test model."""
pass