armory icon indicating copy to clipboard operation
armory copied to clipboard

WIP: Adapt

Open davidslater opened this issue 2 years ago • 2 comments

davidslater avatar Oct 17 '22 21:10 davidslater

I'm running the following code:

model = cifar10_model()
xy_batches, classes = cifar10_data()
attack = PGD_Linf(model)

for batch in xy_batches:
    x, y = batch
    x_adv = attack(x)

and getting the following error:

Traceback (most recent call last):
  File "run.py", line 9, in <module>
    x_adv = attack(x)
  File "/home/lucas/Desktop/gard/git/twosixlabs/armory/armory/adapt/pytorch.py", line 644, in __call__
    self.gradient()
  File "/home/lucas/Desktop/gard/git/twosixlabs/armory/armory/adapt/pytorch.py", line 582, in gradient
    self.loss = self.loss_fn(self.y_pred, self.y_target)
  File "/home/lucas/miniconda3/envs/armory-adapt/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/lucas/Desktop/gard/git/twosixlabs/armory/armory/adapt/pytorch.py", line 511, in forward
    return super().forward(torch.log(input), target)
  File "/home/lucas/miniconda3/envs/armory-adapt/lib/python3.8/site-packages/torch/nn/modules/loss.py", line 211, in forward
    return F.nll_loss(input, target, weight=self.weight, ignore_index=self.ignore_index, reduction=self.reduction)
  File "/home/lucas/miniconda3/envs/armory-adapt/lib/python3.8/site-packages/torch/nn/functional.py", line 2689, in nll_loss
    return torch._C._nn.nll_loss_nd(input, target, weight, _Reduction.get_enum(reduction), ignore_index)
RuntimeError: 0D or 1D target tensor expected, multi-target not supported

which I think occurs because self.y_target is an array of shape torch.Size([1, 10]) (the same one as self.y_pred) rather than an integer

lcadalzo avatar Oct 24 '22 14:10 lcadalzo

Thanks, @lcadalzo, I hadn't tested with model predictions.

davidslater avatar Oct 24 '22 15:10 davidslater