Course contentsShow
← Machine Learning and Deep Learning
Lesson 3389 of 3,53874. Adversarial RobustnessFree lesson

Fast Gradient Sign Method (FGSM)

Learn the foundational single-step attack using the sign of the gradient to create adversarial perturbations.

Fast Gradient Sign Method (FGSM)

You'll learn the simplest and fastest technique for crafting adversarial examples that fool neural networks.

The Core Idea

FGSM is the "hello world" of adversarial attacks. Instead of searching exhaustively for the perfect perturbation to fool a model, FGSM takes a single step in the direction that maximally increases the loss. Think of it like pushing a boulder: rather than calculating the perfect trajectory, you just shove it in the steepest uphill direction and see what happens.

Here's how it works:

  1. Feed your input through the model and compute the loss
  2. Calculate the gradient of the loss with respect to the input image
  3. Take the sign of each gradient value (converting everything to +1, -1, or 0)
  4. Multiply by a small constant ε (epsilon) to control perturbation size
  5. Add this perturbation to the original input

The formula: x_adv = x + ε · sign(∇_x L(θ, x, y))

Where x is your input, L is the loss, and sign() extracts just the direction (+1 or -1), ignoring magnitude.

Why Just the Sign?

Using only the sign creates a perturbation where every pixel moves by exactly ε in the direction that hurts the model most. This is computationally cheap (one gradient calculation!) and surprisingly effective. It's like asking "which way should I nudge each pixel to confuse the classifier?" and moving all of them the same small amount.

FGSM is untargeted—it just tries to make the model wrong, not steer it toward a specific wrong answer.

Key Takeaway: FGSM creates adversarial examples in a single gradient step by adding small perturbations in the direction of the loss gradient's sign—fast, simple, and foundational to adversarial robustness research.