Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while running PGD for Object Detection #89

Open
manishgoyal1590 opened this issue Apr 24, 2021 · 1 comment
Open

Error while running PGD for Object Detection #89

manishgoyal1590 opened this issue Apr 24, 2021 · 1 comment

Comments

@manishgoyal1590
Copy link

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant