Harry24k / adversarial-attacks-pytorch

PyTorch implementation of adversarial attacks [torchattacks]
https://adversarial-attacks-pytorch.readthedocs.io/en/latest/index.html
MIT License
1.9k stars 352 forks source link

Cannot set requires_grad in deepfool #2

Closed zhxgj closed 4 years ago

zhxgj commented 4 years ago

The deepfool method fails due the error below

  File "/dccstor/ddig/jbtang/tools/anaconda3/envs/python3/lib/python3.6/site-packages/torchattacks/attacks/deepfool.py", line 29, in forward
    image.requires_grad = True
RuntimeError: you can only change requires_grad flags of leaf variables.
Harry24k commented 4 years ago

Thank you for noticing me. That error arises because of 'break' in iterations. I solved this error with adding '.detach()' . Please refer https://github.com/Harry24k/adversairal-attacks-pytorch/commit/b0510b54f04990467fca127c2e5ab19e1288ee3a.

zhxgj commented 4 years ago

Thank you @Harry24k for your quick fix!