THUYimingLi / BackdoorBox

The open-sourced Python toolbox for backdoor attacks and defenses.
GNU General Public License v2.0
433 stars 70 forks source link

Bug in WaNET attack #68

Closed ReniKoci closed 6 months ago

ReniKoci commented 6 months ago

Hi, this is some amazing work and is really helpful for people just starting out. I think I might have found a bug and wanted to let you know.

In attacks -> WaNET.py -> add_trigger(self, img, noise=False)

Im also attaching an image

Screenshot 2024-02-24 150651

THUYimingLi commented 6 months ago

Hi, this is some amazing work and is really helpful for people just starting out. I think I might have found a bug and wanted to let you know.

In attacks -> WaNET.py -> add_trigger(self, img, noise=False)

  • If there is noise, the grid is calculated as: grid = self.grid + ins / self.h
  • However, in the next line grid is recalculated as: grid = torch.clamp(self.grid + ins / self.h, -1, 1)

Im also attaching an image

Screenshot 2024-02-24 150651

Hi, AcronRK,

Thanks for using our toolbox and nice words. In general, I would say it is not a bug but a code redundancy. Specifically, the torch.clamp is to ensure that all elements are within [-1, 1]. Unless we have a misunderstanding about the range of grid, it should work well. But as I said, there is a redundancy, I think you can delete the line 'grid = self.grid + ins / self.h' and also run the code with the same results.

Anyway, thanks for your notification!

ReniKoci commented 6 months ago

Ah thank you for the clarification :)