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

Input Preprocessing Defenses

Defending against adversarial examples through JPEG compression, bit-depth reduction, and input transformations.

Input Preprocessing Defenses

What you'll learn: How to defend neural networks against adversarial examples by transforming inputs before they reach the model.

Adversarial examples exploit the model's sensitivity to tiny, imperceptible perturbations. Input preprocessing defenses work by "smoothing out" these perturbations through transformations applied to inputs before inference, effectively removing or reducing the adversarial signal.

Core Idea

Think of adversarial perturbations like high-frequency noise carefully crafted to fool your model. Preprocessing defenses act like filters that remove or distort this noise, making the attack less effective—similar to how noise-canceling headphones filter out unwanted sounds.

Common Preprocessing Techniques

JPEG Compression: Adversarial perturbations often exist in high-frequency components of images. JPEG compression removes these high frequencies through its lossy encoding. By compressing and decompressing an input image, you can discard some adversarial information while preserving the semantic content.

Bit-Depth Reduction: Reducing color precision (e.g., from 8-bit to 4-bit color depth) quantizes pixel values, removing fine-grained perturbations. This is like rounding numbers—small adversarial changes get "rounded away."

Input Transformations: Various transformations can disrupt adversarial patterns:

  • Random resizing and padding
  • Total variation minimization
  • Gaussian blurring
  • Image quilting (reconstructing from patches)

Limitations

These defenses provide some protection but aren't foolproof. Adaptive attackers can craft adversarial examples that survive preprocessing (called "obfuscated gradients" problem). Additionally, preprocessing may degrade performance on clean inputs if too aggressive.

Key Takeaway: Input preprocessing defenses use transformations like JPEG compression, bit-depth reduction, and filtering to remove adversarial perturbations before inference, offering a computationally efficient first line of defense against adversarial attacks.