Projected gradient descent attack

Also known as: PGD attack

On this page 7

A projected gradient descent attack (PGD attack) is an iterative white-box method for crafting adversarial examples: it repeatedly moves an input in the direction that increases the model loss and, after every step, projects the result back into a small set of allowed perturbations around the original input. In AI security, PGD is the standard first-order attack used to measure how robust a neural network is against evasion.

The attack was popularized in 2017 as the inner loop of adversarial training, where it serves as a strong approximation of the worst-case perturbation. Because it is simple, reliable and cheap compared with optimization-based attacks, PGD has become the reference benchmark that robustness claims are expected to survive.

How the PGD attack searches for adversarial examples

PGD solves a constrained maximization problem: find a perturbation delta that maximizes the loss of the model on input x plus delta, subject to the norm of delta staying within a budget epsilon. It approaches the solution with gradient steps and enforces the constraint by projection.

  1. Start from the clean input, or from a random point inside the epsilon ball.
  2. Compute the gradient of the loss with respect to the input.
  3. Take a step of size alpha in the gradient direction; for the L-infinity norm, use the sign of the gradient.
  4. Project the perturbed input back into the epsilon ball and the valid data range, for example pixel values between 0 and 1.
  5. Repeat for a fixed number of iterations and keep the most damaging result.

The update for the L-infinity case can be written as x_next = clip(x + alpha * sign(grad), x0 - eps, x0 + eps). The random start matters: running several restarts from different random points helps escape weak local maxima and gives a more reliable estimate of the worst case.

Key parameters of a PGD attack

The strength of a PGD attack is defined by a small set of parameters, and robustness results are only comparable when these values are reported. The table summarizes the parameters with values commonly used for image benchmarks.

ParameterMeaningTypical valueEffect when increased
EpsilonMaximum perturbation size8/255 under L-infinity on CIFAR-10Stronger attack, more visible change
Step size alphaDistance moved per iteration2/255 or about epsilon/4Faster progress, risk of overshooting
IterationsNumber of gradient steps10 for training, 20 to 100 for evaluationStronger attack, higher cost
Random restartsIndependent attack runs1 to 10Better worst-case estimate
NormGeometry of the threat modelL-infinity or L2Changes the shape of allowed changes
Loss functionObjective being maximizedCross-entropy or margin lossMargin loss resists some masking
PGD parameters and typical values

A targeted variant minimizes the loss for a chosen wrong class instead of maximizing the loss for the true class. This is useful when an attacker needs a specific outcome, such as a stop sign classified as a speed limit sign.

PGD compared with other evasion attacks

PGD sits between the very fast fast gradient sign method and expensive optimization attacks. It is often described as a multi-step version of FGSM with projection.

AttackAccess neededIterationsTypical role
FGSMWhite-box gradientsOne stepQuick baseline, cheap training
PGDWhite-box gradients10 to 100 stepsStandard robustness benchmark
Carlini–Wagner attackWhite-box gradientsHundreds to thousandsMinimal-norm perturbations
DeepFoolWhite-box gradientsFew, adaptiveEstimating distance to the decision boundary
AutoAttackWhite-box and score queriesEnsemble of attacksParameter-free robustness evaluation
Transfer attackSurrogate model onlyPGD on surrogateBlack-box attack via adversarial transferability
PGD and related adversarial attacks

Because PGD uses only first-order information, it is considered close to the strongest first-order adversary. Models that resist well-tuned PGD usually also resist other gradient-based attacks, although AutoAttack is now preferred for final evaluations.

PGD in adversarial training and evaluation

PGD is used both to attack models during testing and to harden models during training. In PGD adversarial training, each training batch is replaced or augmented with PGD examples, so the model learns to classify correctly inside the epsilon ball.

GoalRecommended setupReason
Adversarial training7 to 10 steps, one random startBalances robustness and training cost
Robustness evaluation50 to 100 steps, several restartsApproximates the true worst case
Red teaming a deployed modelPGD on a surrogate, then transferReal attackers rarely see gradients
Checking a new defenseAdaptive PGD against the full pipelineExposes gradient masking
Using PGD for different security goals

Adversarial training with PGD typically costs several times more compute than standard training and lowers clean accuracy by a noticeable margin. This robustness-accuracy trade-off is one of the central open problems in adversarial machine learning.

Limitations and pitfalls in PGD evaluations

A PGD result shows that a model is not robust when the attack succeeds, but a failed attack does not prove robustness. Several well-known mistakes inflate reported security.

  • Gradient masking: defenses that obscure or shatter gradients make PGD fail while the model remains vulnerable to other attacks.
  • Too few iterations or restarts underestimate the worst case and overstate robustness.
  • Non-adaptive evaluation ignores preprocessing or randomness that an attacker would account for.
  • Narrow threat models: robustness against L-infinity at 8/255 says little about patches, rotations or physical attacks.
  • No guarantee: only certified methods such as randomized smoothing provide provable bounds.

In simple terms

Think of a picture that a model labels correctly. A PGD attack changes the picture in tiny steps. Each step is chosen to confuse the model a little more. After every step, the attack checks one rule: the picture must stay almost identical to the original.

After a few dozen steps, a person still sees the same image. The model, however, may now give a completely wrong answer. Security teams run this attack on purpose. It reveals how easily a model can be fooled before real attackers try it.

A practical example

A company that builds traffic sign recognition for driver assistance evaluates a new classifier before release. The model reaches over 98 percent accuracy on clean test images, and the safety team must check how it behaves under small, deliberate perturbations.

The team runs an L-infinity PGD attack with epsilon of 8/255, step size 2/255, 50 iterations and five random restarts. Robust accuracy collapses to under 5 percent, and many stop signs become speed limit signs after changes invisible to a human reviewer.

The engineers retrain the classifier with PGD adversarial training using 10 steps per batch. Clean accuracy falls by a few points, but robust accuracy under the same evaluation and under AutoAttack rises to roughly half of the test set. The report documents all parameters, so later model versions can be compared on equal terms.