Skip to content

Commit

Permalink
add docstring for mi_fgsm
Browse files Browse the repository at this point in the history
  • Loading branch information
lcy committed Nov 9, 2023
1 parent f4facdb commit 72f3381
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions foolbox/attacks/mi_fgsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@


class GDMOptimizer(Optimizer):
# create GD optimizer with momentum
"""Momentum-based Gradient Descent Optimizer
Args:
x : Optimization variable for initialization of accumulation grad
stepsize : Stepsize for gradient descent
momentum : Momentum factor for accumulation grad
normalize_fn : Function to normalize the gradient
"""

def __init__(
self,
x: ep.Tensor,
Expand All @@ -32,6 +40,16 @@ def __call__(self, gradient: ep.Tensor) -> ep.Tensor:


class L1MomentumIterativeFastGradientMethod(L1BasicIterativeAttack):
"""L1 Momentum Iterative Fast Gradient Sign Method (MI-FGSM) [#Dong18]
Args:
momentum : Momentum factor for accumulation grad
rel_stepsize : Stepsize relative to epsilon
abs_stepsize : If given, it takes precedence over rel_stepsize.
steps : Number of update steps to perform.
random_start : Whether the perturbation is initialized randomly or starts at zero.
"""

def __init__(
self,
*,
Expand All @@ -56,6 +74,16 @@ def get_optimizer(self, x: ep.Tensor, stepsize: float) -> Optimizer:


class L2MomentumIterativeFastGradientMethod(L2BasicIterativeAttack):
"""L2 Momentum Iterative Fast Gradient Sign Method (MI-FGSM) [#Dong18]
Args:
momentum : Momentum factor for accumulation grad
rel_stepsize : Stepsize relative to epsilon
abs_stepsize : If given, it takes precedence over rel_stepsize.
steps : Number of update steps to perform.
random_start : Whether the perturbation is initialized randomly or starts at zero.
"""

def __init__(
self,
*,
Expand All @@ -80,7 +108,14 @@ def get_optimizer(self, x: ep.Tensor, stepsize: float) -> Optimizer:


class LinfMomentumIterativeFastGradientMethod(LinfBasicIterativeAttack):
"""Momentum Iterative Fast Gradient Sign Method (MI-FGSM) [#Dong18]
"""Linf Momentum Iterative Fast Gradient Sign Method (MI-FGSM) [#Dong18]
Args:
momentum : Momentum factor for accumulation grad
rel_stepsize : Stepsize relative to epsilon
abs_stepsize : If given, it takes precedence over rel_stepsize.
steps : Number of update steps to perform.
random_start : Whether the perturbation is initialized randomly or starts at zero.
References: .. [#Dong18] Dong Y, Liao F, Pang T, et al. Boosting adversarial attacks with momentum[
C]//Proceedings of the IEEE conference on computer vision and pattern recognition. 2018: 9185-9193.
Expand Down

0 comments on commit 72f3381

Please sign in to comment.