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

Add the EAD attack to torchattacks and bug fix #137

Closed rikonaka closed 1 year ago

rikonaka commented 1 year ago

PR Type and Checklist

What kind of change does this PR introduce?

rikonaka commented 1 year ago

On 64 CIFAR10 test datasets, the EADL1 untargeted attack accuracy drop to 1.56%, and the EADEN untargeted attack accuracy also drop to 1.56%.

image

I did not see any target attack method in paper...the value $t$ is not used in the Algorithm 1...but I still supported targeted attack in code, even though the accuracy rate would only drop to 64%. 🤨

codecov-commenter commented 1 year ago

Codecov Report

Merging #137 (c9e9531) into master (9a22433) will increase coverage by 1.83%. The diff coverage is 90.70%.

:exclamation: Current head c9e9531 differs from pull request most recent head 5fe65ec. Consider uploading reports for the commit 5fe65ec to get more accurate results

:mega: This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #137      +/-   ##
==========================================
+ Coverage   71.25%   73.09%   +1.83%     
==========================================
  Files          41       43       +2     
  Lines        3500     3787     +287     
  Branches      500      535      +35     
==========================================
+ Hits         2494     2768     +274     
- Misses        852      857       +5     
- Partials      154      162       +8     
Impacted Files Coverage Δ
torchattacks/attack.py 47.98% <16.00%> (+0.05%) :arrow_up:
torchattacks/attacks/square.py 52.98% <33.33%> (ø)
torchattacks/attacks/pixle.py 58.12% <60.00%> (+0.91%) :arrow_up:
torchattacks/attacks/upgd.py 62.82% <75.00%> (ø)
torchattacks/attacks/eaden.py 95.55% <95.55%> (ø)
torchattacks/attacks/eadl1.py 97.08% <97.08%> (ø)
torchattacks/__init__.py 100.00% <100.00%> (ø)
torchattacks/attacks/apgd.py 76.30% <100.00%> (ø)
torchattacks/attacks/apgdt.py 86.25% <100.00%> (ø)
torchattacks/attacks/autoattack.py 81.25% <100.00%> (ø)
... and 27 more

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 9a22433...5fe65ec. Read the comment docs.

Harry24k commented 1 year ago

I'm surprised that you were already fixed the normalization part 😄. The current validation check process has some issues when we use normalized_used=True, such as ValueError: Input must have a range [0, 1] (max: 1.0, min: -2.9802322387695312e-08). I'm working on it.

BTW, there is an error during the coverage check. Could you fix the problem? :

code_coverage/test_atks.py::test_atks_on_cifar10[OnePixel]
  /home/runner/work/adversarial-attacks-pytorch/adversarial-attacks-pytorch/torchattacks/attacks/_differential_evolution.py:592: RuntimeWarning: divide by zero encountered in double_scalars
    convergence=self.tol / convergence) is True):
rikonaka commented 1 year ago

Hi @Harry24k , I could not reproduce the same error that caused when I run OnePixel attack 😂.

It's looks like an error in the _differential_evolution.py file not OnePixel.

Harry24k commented 1 year ago

I cannot find the cause of the error, so I merge it and will update it!

rikonaka commented 1 year ago

Hi @Harry24k , I found the problem, in the line of _differential_evolution.py, the value of convergence could be 0 when run the OnePixel attack.

image

I modified the code so that the value is set to inf when it is divided by 0.

image