🤖 AI/ML

Adversarial Example

Adversarial Example

An input designed to make an AI misclassify it. Looks normal to humans.

📖 Detailed Explanation

An Adversarial Example is input data intentionally designed to cause an AI model to make incorrect predictions. Although the perturbation is subtle and nearly indistinguishable from the original to the human eye, a Deep Learning model outputs a completely different result. Since Szegedy et al. first discovered it in 2013, it has become a core research area of AI security.

The principle behind generating adversarial examples is to exploit the model's gradient information. Representative attack techniques include FGSM (Fast Gradient Sign Method), PGD (Projected Gradient Descent), and C&W (Carlini & Wagner). Even when noise imperceptible to the naked eye is added to an image, it can cause a self-driving car to recognize a stop sign as a speed limit sign, posing a serious safety threat.

Defense techniques include Adversarial Training, input preprocessing, Defensive Distillation, and Certified Defense. However, a perfect defense is close to impossible, and new attack techniques continue to be developed, so continuous security updates are necessary.

In practice, adversarial examples are treated as important in AI system vulnerability assessments, red team testing, and security audits. The EU AI Act also specifies the ability to respond to Adversarial Attacks in the cybersecurity requirements for high-risk AI systems, so from 2025 onward, robustness testing against adversarial examples is mandatory for all high-risk AI systems.

💻 Code Example

Generating adversarial examples using FGSM (Fast Gradient Sign Method):

import torch
import torch.nn.functional as F

def fgsm_attack(model, image, label, epsilon=0.03):
    """
    FGSM 적대적 예제 생성
    - epsilon: 섭동(perturbation)의 강도 (0.03 = 3%)
    """
    image.requires_grad = True

    # 순전파
    output = model(image)
    loss = F.cross_entropy(output, label)

    # 역전파로 그래디언트 계산
    model.zero_grad()
    loss.backward()

    # 그래디언트 부호 방향으로 섭동 추가
    perturbation = epsilon * image.grad.sign()
    adversarial_image = image + perturbation

    # 이미지 값 범위 클리핑 [0, 1]
    adversarial_image = torch.clamp(adversarial_image, 0, 1)

    return adversarial_image

# 적대적 훈련 (방어 기법)
def adversarial_training(model, train_loader, epsilon=0.03):
    """적대적 예제를 포함한 강건한 모델 훈련"""
    for images, labels in train_loader:
        # 50%는 원본, 50%는 적대적 예제로 훈련
        adv_images = fgsm_attack(model, images, labels, epsilon)
        mixed_images = torch.cat([images, adv_images])
        mixed_labels = torch.cat([labels, labels])

        # 모델 업데이트
        outputs = model(mixed_images)
        loss = F.cross_entropy(outputs, mixed_labels)
        loss.backward()
        optimizer.step()

📊 Performance & Cost

Attack/Defense Technique Attack Success Rate Computational Cost Features
FGSM (Attack) 70-85% 1x (fastest) Single step, real-time attack possible
PGD (Attack) 90-99% 10-100x Iterative optimization, strongest attack
C&W (Attack) 95-100% 100-1000x Minimal perturbation, effective at evading detection
Adversarial Training (Defense) Defense rate 60-80% Training time increases 2-10x Most effective practical defense
Certified Defense (Defense) Guaranteed defense rate 40-60% Inference time increases 5-50x Mathematical guarantee, accuracy loss

🗣️ Say It Like This in Practice

💬 In a security review
"We tested this image classification model for adversarial examples using a PGD attack. At epsilon 0.03, the attack success rate was 87%, so adversarial training is needed."
💬 In a Planning Meeting
"Since this is an autonomous driving system, robustness against adversarial examples is essential. We also need to test physical Adversarial Attack scenarios (e.g., attaching stickers) on the sign recognition model."
💬 In an Interview
"Adversarial examples occur because the model's decision boundary differs from the human perceptual boundary. FGSM is fast because it uses only the sign of the gradient, but PGD generates a stronger attack through iterative optimization."

Take a mock interview on this topic → WIA SOOM AI Interview · Start for free

⚠️ Common Mistakes & Cautions

❌
Testing robustness with FGSM only

FGSM is a weak attack. If you do not test with strong attacks such as PGD or AutoAttack, you will fall into a false sense of security.

❌
Considering only white-box attacks

Real attackers may not know the model architecture. You must also test black-box attacks that exploit transferability.

❌
Ignoring the accuracy vs. robustness trade-off

Adversarial training can reduce accuracy on regular data by 2-5%. It must be balanced against business requirements.

✅
The right approach

Evaluate with standardized benchmarks such as RobustBench, combine various attack techniques, and also consider physical attack scenarios.

🔗 Related Terms

📚 Learn More