-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Description
I'm using the following code:
for x, y in self.test_loader:
x, y = x.to(self.device), y.to(self.device)
x_pgd = projected_gradient_descent(
self.model,
x,
self.epsilon,
self.step_size,
self.iterations,
np.inf,
clip_min=self.clip_min,
clip_max=self.clip_max,
)
adv_input.append(x_pgd.detach().cpu().numpy())
labels.append(y.detach().cpu().numpy())
Where:
self.modelis a standard VGG modelself.test_loaderis a DataLoader created fromtorchvision.datasets.CIFAR10self.clip_minis 0.0self.clip_maxis 1.0self.epsilonis 0.01self.step_sizeis 0.01self.iterationsis 40
I get the following error:
File ".../.venv/lib/python3.11/site-packages/cleverhans/torch/attacks/projected_gradient_descent.py", line 152, in projected_gradient_descent
assert np.all(asserts)
^^^^^^^^^^^^^^^
File ".../.venv/lib/python3.11/site-packages/numpy/core/fromnumeric.py", line 2504, in all
return _wrapreduction(a, np.logical_and, 'all', axis, None, out,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../.venv/lib/python3.11/site-packages/numpy/core/fromnumeric.py", line 88, in _wrapreduction
return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../.venv/lib/python3.11/site-packages/torch/_tensor.py", line 1087, in __array__
return self.numpy()
^^^^^^^^^^^^
TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
The error goes away when I do not use the clip_min and clip_max arguments.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels