cassidylaidlaw / perceptual-advex

Code and data for the ICLR 2021 paper "Perceptual Adversarial Robustness: Defense Against Unseen Threat Models".
https://arxiv.org/abs/2006.12655
MIT License
54 stars 10 forks source link

Running error tensor and the written-to tensor refer to a single memory location #8

Closed cod3r0k closed 3 years ago

cod3r0k commented 3 years ago

Dear @cassidylaidlaw , I run your code in Google Colab (latest version of each modules). But Ican't run your code. I encountered the following error:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-7-3e325de596ce> in <module>()
     10     lpips_model='alexnet_cifar',
     11 )
---> 12 adv_inputs = attack(inputs, labels)
     13 
     14 # Show the adversarial examples.

2 frames
/usr/local/lib/python3.7/dist-packages/perceptual_advex/perceptual_attacks.py in _attack(self, inputs, labels)
    623                     live[live] = (adv_labels != labels[live]) | (lpips_dists > self.bound)
    624                 else:
--> 625                     live[live] = (adv_labels == labels[live]) | (lpips_dists > self.bound)
    626                 if live.sum() == 0:
    627                     break

RuntimeError: unsupported operation: some elements of the input tensor and the written-to tensor refer to a single memory location. Please clone() the tensor before performing the operation.
cassidylaidlaw commented 3 years ago

Hi @cod3r0k, thanks for your interest in the work! I just uploaded a new version to PyPI that I believe should fix this problem. If you are still getting errors in Colab, you might have to run !pip install --upgrade perceptual-advex.

cassidylaidlaw commented 3 years ago

@cod3r0k did this fix the problem for you? I'll close the issue if I don't hear back from you.