Keeping the Bad Guys Out: Protecting and Vaccinating Deep Learning with JPEG Compression

Nilaksh Das, Madhuri Shanbhogue, Shang-Tse Chen, Fred Hohman, Li Chen, Michael E. Kounavis, Duen Horng ChauarXiv 2017

Abstract

Deep neural networks (DNNs) have achieved great success in solving a variety of machine learning (ML) problems, especially in the domain of image recognition. However, recent research showed that DNNs can be highly vulnerable to adversarially generated instances, which look seemingly normal to human observers, but completely confuse DNNs. These adversarial samples are crafted by adding small perturbations to normal, benign images. Such perturbations, while imperceptible to the human eye, are picked up by DNNs and cause them to misclassify the manipulated instances with high confidence. In this work, we explore and demonstrate how systematic JPEG compression can work as an effective pre-processing step in the classification pipeline to counter adversarial attacks and dramatically reduce their effects (e.g., Fast Gradient Sign Method, DeepFool). An important component of JPEG compression is its ability to remove high frequency signal components, inside square blocks of an image. Such an operation is equivalent to selective blurring of the image, helping remove additive perturbations. Further, we propose an ensemble-based technique that can be constructed quickly from a given well-performing DNN, and empirically show how such an ensemble that leverages JPEG compression can protect a model from multiple types of adversarial attacks, without requiring knowledge about the model.

What Problem Does This Paper Address?

Deep neural networks are notoriously "brittle." While they excel at image recognition, they can be easily fooled by adversarial examples: images that have been modified with tiny, human-imperceptible perturbations. These perturbations are mathematically crafted to push an image across a model's decision boundary, causing a "Stop" sign to be classified as a "100 km/h" sign with high confidence.

Visualizing how JPEG compression can recover the correct classification of an adversarially perturbed image.

The challenge is that many existing defenses are either computationally expensive, require modifying the network architecture, or only work against specific types of attacks. Furthermore, "black-box" attacks mean an adversary doesn't even need access to your specific model to break it. The authors sought a model-agnostic, easy-to-implement defense that leverages the way humans—rather than machines—perceive images.

Methods

The authors introduce a three-tiered defense strategy:

  1. JPEG Pre-processing: JPEG compression works by converting images into the frequency domain (using Discrete Cosine Transform) and discarding high-frequency information that the human eye doesn't notice. Since adversarial noise often manifests as high-frequency signals, JPEG acts as a natural "blurring" filter that can strip away these malicious perturbations.
  2. Vaccination (Re-training): Simply applying JPEG to a test image can sometimes confuse a model trained on "clean" images due to compression artifacts. To fix this, the authors "vaccinate" the models by re-training them on images compressed at various quality levels (from 100 down to 20).
  3. Fortified Ensemble: The most robust defense proposed is an ensemble of these vaccinated models. In this setup, nine different models (each trained at a different JPEG quality) vote on nine different compressed versions of the input image. This creates a "moving target" for attackers, making it much harder to find a single perturbation that fools the entire group.

Key Insights and Ideas

  • The "Human" Manifold: The core intuition is that JPEG was designed to preserve what humans see and discard what we don't. Adversarial attacks exploit the "gaps" where machine vision differs from human vision. By forcing the image back into the "JPEG manifold," we remove the artifacts that machines over-index on but humans ignore.
  • The Inflection Point: There is a "Goldilocks zone" for compression. Too little compression leaves the adversarial noise intact; too much compression introduces "blocking" artifacts that degrade the model's accuracy.
  • Transferability Mitigation: Adversarial attacks often "transfer" between models. However, the authors found that by training models on different compression levels, the learned decision boundaries become sufficiently dissimilar, reducing the success rate of transferred attacks.

Key Results

The results show a dramatic recovery of accuracy when the ensemble defense is used against the Fast Gradient Sign Method (FGSM) and DeepFool (DF) attacks. Notably, the defense did not hurt performance on benign (non-attacked) images. In fact, for GTSRB, the ensemble slightly improved benign accuracy from 97.83% to 98.59%.

Misclassification success rates on the GTSRB dataset across varying JPEG quality levels, comparing standard attacks to the proposed ensemble approach.
Dataset Attack Original Accuracy (Under Attack) Ensemble Accuracy (Defended)
CIFAR-10 FGSM 28.97% 79.57%
CIFAR-10 DeepFool 27.44% 82.71%
GTSRB FGSM 41.00% 73.37%
GTSRB DeepFool 68.19% 91.70%

Limitations and Future Work

While promising, the authors acknowledge that adaptive attackers who know exactly how the JPEG ensemble is constructed might find ways to bypass it. However, the ensemble can be easily randomized to stay ahead of such threats. Future work is needed to test these methods on higher-resolution datasets like ImageNet, as this study focused on smaller benchmarks like CIFAR-10 and GTSRB.

Summary updated

BibTeX
@misc{das2017keeping,
  author = {Nilaksh Das and Madhuri Shanbhogue and Shang-Tse Chen and Fred Hohman and Li Chen and Michael E. Kounavis and Duen Horng Chau},
  title = {{Keeping the Bad Guys Out: Protecting and Vaccinating Deep Learning with JPEG Compression}},
  year = {2017},
  eprint = {1705.02900},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1705.02900},
}
Figure