Skip to content

Commit

Permalink
Add TGR attack docs
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerwooo committed Sep 5, 2024
1 parent 557a298 commit 061087c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
31 changes: 16 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,22 @@ Check out [`torchattack.eval.run_attack`](src/torchattack/eval.py) for a simple

Gradient-based attacks:

| Name | $\ell_p$ | Paper | `torchattack` class |
| :----------: | :-----------: | :------------------------------------------------------------------------------------------------------------------------- | :------------------------ |
| FGSM | $\ell_\infty$ | [Explaining and Harnessing Adversarial Examples](https://arxiv.org/abs/1412.6572) | `torchattack.FGSM` |
| PGD | $\ell_\infty$ | [Towards Deep Learning Models Resistant to Adversarial Attacks](https://arxiv.org/abs/1706.06083) | `torchattack.PGD` |
| PGD (L2) | $\ell_2$ | [Towards Deep Learning Models Resistant to Adversarial Attacks](https://arxiv.org/abs/1706.06083) | `torchattack.PGDL2` |
| MI-FGSM | $\ell_\infty$ | [Boosting Adversarial Attacks with Momentum](https://arxiv.org/abs/1710.06081) | `torchattack.MIFGSM` |
| DI-FGSM | $\ell_\infty$ | [Improving Transferability of Adversarial Examples with Input Diversity](https://arxiv.org/abs/1803.06978) | `torchattack.DIFGSM` |
| TI-FGSM | $\ell_\infty$ | [Evading Defenses to Transferable Adversarial Examples by Translation-Invariant Attacks](https://arxiv.org/abs/1904.02884) | `torchattack.TIFGSM` |
| NI-FGSM | $\ell_\infty$ | [Nesterov Accelerated Gradient and Scale Invariance for Adversarial Attacks](https://arxiv.org/abs/1908.06281) | `torchattack.NIFGSM` |
| SI-NI-FGSM | $\ell_\infty$ | [Nesterov Accelerated Gradient and Scale Invariance for Adversarial Attacks](https://arxiv.org/abs/1908.06281) | `torchattack.SINIFGSM` |
| VMI-FGSM | $\ell_\infty$ | [Enhancing the Transferability of Adversarial Attacks through Variance Tuning](https://arxiv.org/abs/2103.15571) | `torchattack.VMIFGSM` |
| VNI-FGSM | $\ell_\infty$ | [Enhancing the Transferability of Adversarial Attacks through Variance Tuning](https://arxiv.org/abs/2103.15571) | `torchattack.VNIFGSM` |
| Admix | $\ell_\infty$ | [Admix: Enhancing the Transferability of Adversarial Attacks](https://arxiv.org/abs/2102.00436) | `torchattack.Admix` |
| FIA | $\ell_\infty$ | [Feature Importance-aware Transferable Adversarial Attacks](https://arxiv.org/abs/2107.14185) | `torchattack.FIA` |
| PNA-PatchOut | $\ell_\infty$ | [Towards Transferable Adversarial Attacks on Vision Transformers](https://arxiv.org/abs/2109.04176) | `torchattack.PNAPatchOut` |
| Name | $\ell_p$ | Paper | `torchattack` class |
| :----------: | :-----------: | :----------------------------------------------------------------------------------------------------------------------------- | :------------------------ |
| FGSM | $\ell_\infty$ | [Explaining and Harnessing Adversarial Examples](https://arxiv.org/abs/1412.6572) | `torchattack.FGSM` |
| PGD | $\ell_\infty$ | [Towards Deep Learning Models Resistant to Adversarial Attacks](https://arxiv.org/abs/1706.06083) | `torchattack.PGD` |
| PGD (L2) | $\ell_2$ | [Towards Deep Learning Models Resistant to Adversarial Attacks](https://arxiv.org/abs/1706.06083) | `torchattack.PGDL2` |
| MI-FGSM | $\ell_\infty$ | [Boosting Adversarial Attacks with Momentum](https://arxiv.org/abs/1710.06081) | `torchattack.MIFGSM` |
| DI-FGSM | $\ell_\infty$ | [Improving Transferability of Adversarial Examples with Input Diversity](https://arxiv.org/abs/1803.06978) | `torchattack.DIFGSM` |
| TI-FGSM | $\ell_\infty$ | [Evading Defenses to Transferable Adversarial Examples by Translation-Invariant Attacks](https://arxiv.org/abs/1904.02884) | `torchattack.TIFGSM` |
| NI-FGSM | $\ell_\infty$ | [Nesterov Accelerated Gradient and Scale Invariance for Adversarial Attacks](https://arxiv.org/abs/1908.06281) | `torchattack.NIFGSM` |
| SI-NI-FGSM | $\ell_\infty$ | [Nesterov Accelerated Gradient and Scale Invariance for Adversarial Attacks](https://arxiv.org/abs/1908.06281) | `torchattack.SINIFGSM` |
| VMI-FGSM | $\ell_\infty$ | [Enhancing the Transferability of Adversarial Attacks through Variance Tuning](https://arxiv.org/abs/2103.15571) | `torchattack.VMIFGSM` |
| VNI-FGSM | $\ell_\infty$ | [Enhancing the Transferability of Adversarial Attacks through Variance Tuning](https://arxiv.org/abs/2103.15571) | `torchattack.VNIFGSM` |
| Admix | $\ell_\infty$ | [Admix: Enhancing the Transferability of Adversarial Attacks](https://arxiv.org/abs/2102.00436) | `torchattack.Admix` |
| FIA | $\ell_\infty$ | [Feature Importance-aware Transferable Adversarial Attacks](https://arxiv.org/abs/2107.14185) | `torchattack.FIA` |
| PNA-PatchOut | $\ell_\infty$ | [Towards Transferable Adversarial Attacks on Vision Transformers](https://arxiv.org/abs/2109.04176) | `torchattack.PNAPatchOut` |
| TGR | $\ell_\infty$ | [Transferable Adversarial Attacks on Vision Transformers with Token Gradient Regularization](https://arxiv.org/abs/2303.15754) | `torchattack.TGR` |

Others:

Expand Down
20 changes: 20 additions & 0 deletions src/torchattack/tgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,26 @@


class TGR(Attack):
"""TGR attack for ViTs (Token Gradient Regularization).
From the paper: 'Transferable Adversarial Attacks on Vision Transformers with Token
Gradient Regularization'
https://arxiv.org/abs/2303.15754
Args:
model: The model to attack.
model_name: The name of the model.
normalize: A transform to normalize images.
device: Device to use for tensors. Defaults to cuda if available.
eps: The maximum perturbation. Defaults to 8/255.
steps: Number of steps. Defaults to 10.
alpha: Step size, `eps / steps` if None. Defaults to None.
decay: Momentum decay factor. Defaults to 1.0.
clip_min: Minimum value for clipping. Defaults to 0.0.
clip_max: Maximum value for clipping. Defaults to 1.0.
targeted: Targeted attack if True. Defaults to False.
"""

def __init__(
self,
model: nn.Module,
Expand Down

0 comments on commit 061087c

Please sign in to comment.