MIFGSM¶
MIFGSM
¶
Bases: Attack
The MI-FGSM (Momentum Iterative FGSM) attack.
From the paper: Boosting Adversarial Attacks with Momentum.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
Module | AttackModel
|
The model to attack. |
required |
normalize
|
Callable[[Tensor], Tensor] | None
|
A transform to normalize images. |
None
|
device
|
device | None
|
Device to use for tensors. Defaults to cuda if available. |
None
|
eps
|
float
|
The maximum perturbation. Defaults to 8/255. |
8 / 255
|
steps
|
int
|
Number of steps. Defaults to 10. |
10
|
alpha
|
float | None
|
Step size, |
None
|
decay
|
float
|
Decay factor for the momentum term. Defaults to 1.0. |
1.0
|
clip_min
|
float
|
Minimum value for clipping. Defaults to 0.0. |
0.0
|
clip_max
|
float
|
Maximum value for clipping. Defaults to 1.0. |
1.0
|
targeted
|
bool
|
Targeted attack if True. Defaults to False. |
False
|
Source code in torchattack/mifgsm.py
forward(x, y)
¶
Perform MI-FGSM on a batch of images.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
A batch of images. Shape: (N, C, H, W). |
required |
y
|
Tensor
|
A batch of labels. Shape: (N). |
required |
Returns:
Type | Description |
---|---|
Tensor
|
The perturbed images if successful. Shape: (N, C, H, W). |