BorealisAI / advertorch

A Toolbox for Adversarial Robustness Research
GNU Lesser General Public License v3.0
1.29k stars 194 forks source link

Error while running PGD for Object Detection #89

Open manishgoyal1590 opened 3 years ago

manishgoyal1590 commented 3 years ago

I'm trying to perform PGD attack on YOLOv3 model pretrained on PASCAL VOC dataset. As soon as i pass image and label to perturb function, I get an error AttributeError: 'tuple' object has no attribute 'size'. Now, I pass the target and labels as tensor so I'm not sure why are they being converted back to tuples. Here is code that i'm executing and attached is the error:

from advertorch.attacks import LinfPGDAttack import torch.nn as nn import numpy as np

use_cuda = torch.cuda.is_available() device = torch.device("cuda" if use_cuda else "cpu")

print(use_cuda)

model.to(device) torch.cuda.empty_cache();

model = model.eval()

x = torch.from_numpy(train_image[0].asnumpy())

y = torch.from_numpy(class_ids[0])

x = torch.Tensor(batch[0][0].asnumpy()) y = torch.Tensor(batch[6][0].asnumpy())

y = batch[6][0]

print(type(x))

print("x = ",batch[0][0])

print(type(y))

print("y = ",batch[6][0])

adversary = LinfPGDAttack( model, loss_fn=nn.BCEWithLogitsLoss(reduction="none"), eps=0.3, nb_iter=40, eps_iter=0.01, rand_init=False, clip_min=0.0, clip_max=1.0, targeted=False)

nn.CrossEntropyLoss(reduction="sum")

x = torch.unsqueeze(x,0)

adv_untargeted = adversary.perturb(x, y) Capture

manishgoyal1590 commented 3 years ago

Also attaching the current image and target passed to the perturb function. Capture Capture_2