Harry24k / adversarial-attacks-pytorch

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

[BUG] Bugs in the f function of cw.py #184

Open EthanChu7 opened 1 month ago

EthanChu7 commented 1 month ago

✨ Short description of the bug [tl;dr]

Bugs in the f function of cw.py when facing negative logits

πŸ’¬ Detailed code and results

In f function of cw.py, the real and other are computed by

other = torch.max((1 - one_hot_labels) * outputs, dim=1)[0]
real = torch.max(one_hot_labels * outputs, dim=1)[0]

Howerver, when facing negative logits(negative other label logits in other and negative target label in real), the other and real become zero.

I suggest to make the following modifications:

other = torch.max((1 - one_hot_labels) * outputs - one_hot_labels * 1e4, dim=1)[0] 
real = torch.sum(one_hot_labels*outputs, dim=1)
rikonaka commented 1 month ago

Hi @EthanChu7 , good question, this bug already fix by this pull https://github.com/Harry24k/adversarial-attacks-pytorch/pull/168, but it’s has not been merged into the main line yet. πŸ‘πŸ‘πŸ‘

EthanChu7 commented 1 month ago

thx for the reply, i m satisfied with the modifications in pull #168, looking forward to see them in the main branch.