# Feature Squeezing: Detecting Adversarial Examples in Deep Neural Networks

Feature squeezing detects adversarial examples by comparing predictions on squeezed inputs

Xu, Weilin, Evans, David, Qi, Yanjun · arXiv · 2017-4-4

- **Problem** Adversarial examples fool deep networks with small, purposeful distortions. Earlier defenses mostly changed the model itself, and they gave limited success or cost too much computation.
- **Method** Feature squeezing keeps the model fixed and changes only its inputs. It reduces pixel bit depth and smooths neighboring pixels, then flags an input when predictions on the squeezed copies differ too much from the original.
- **Results** The joint detector catches 98.15% of successful adversarial examples on MNIST, at a 3.98% false positive rate.

## Why detect adversarial inputs at all

Image classifiers can be pushed into wrong outputs by perturbations that are barely visible, and these inputs are produced by an optimization search rather than by chance. Such inputs are normally built from a correctly classified seed by changing it only within a limited amount, so the attacker controls how far the input can move.

For a deployed classifier, a flag is useful even when an attack fails, because it reveals that someone is probing the system and lets the operator respond to that client. A single successful input can be enough for an attacker in an asymmetric setting such as malware detection, which makes detecting unsuccessful search attempts valuable.

Most earlier hardening work modifies the model, through adversarial training or gradient masking, while feature squeezing keeps the model fixed and changes only the inputs it receives.

## Where detection sits among earlier defenses

Earlier detectors fall into three groups: those based on sample statistics, those that train a detector, and those based on prediction inconsistency, and feature squeezing belongs to the last group. Sample-statistic tests need large sets of legitimate and adversarial inputs and do not judge single inputs well, while training a detector needs many adversarial examples and can overfit to the attacks that generated them.

Feinman et al. measured disagreement among dropout sub-models, and Meng and Chen compared predictions on original and filtered images, but their filter is a trained autoencoder. Feature squeezing uses hard-coded transformations instead, which the authors argue makes it cheaper in the training phase.

## Squeezing and comparing predictions

A squeezer maps many distinct inputs onto one squeezed input, which reduces the freedom an adversary has to hide a perturbation. The intuition is that a legitimate input should keep its label after squeezing, while an input tuned against the original model is more likely to change its prediction once its fine detail is removed.

The model is run on the original input and on each squeezed copy, producing one prediction vector per copy. The distances between the original prediction and each squeezed prediction are combined by taking the largest one, and the input is flagged as adversarial when that maximum exceeds the threshold.

Because the classifier is not altered, feature squeezing can be placed in front of any model and combined with other defenses such as adversarial training.

## Bit depth and smoothing as squeezers

An 8-bit grayscale pixel has 256 levels, while a 24-bit color pixel can take about 16 million values, so the input space of an image is much larger than what a person needs to recognize it. Bit depth reduction maps each pixel onto fewer levels, with the inputs kept on the \[0, 1\] scale so the model does not need to change.

For an i-bit depth, the implementation scales the input by 2^i − 1, rounds to integers, and divides by 2^i − 1 to return to \[0, 1\]. On MNIST the 1-bit version uses a cutoff of 0.5, which reduces the feature space to 1/128 of the 8-bit grayscale space while the digits stay recognizable.

Spatial smoothing reduces the variation among neighboring pixels, and the study uses it in two forms, local smoothing and non-local smoothing. The local median filters use 2 × 2 and 3 × 3 windows, and the non-local version averages over similar patches found elsewhere in the image when it smooths a center patch.

## Attack suite and evaluation conditions

Eleven attacks are used: three untargeted attacks (FGSM, BIM and DeepFool) and two targeted variants each of JSMA, CW∞, CW2 and CW0. Each targeted attack is run toward the next class and toward the least-likely class, and the seeds are the first 100 correctly predicted examples in each test or validation set.

The attack parameters are tuned to produce high-confidence adversarial examples, since the three models already classify legitimate inputs with high confidence, at over 99% mean confidence on MNIST, 92% on CIFAR-10 and 75% on ImageNet. DeepFool is excluded on MNIST because its outputs look unrecognizable, and JSMA is not run on ImageNet because it exhausts the available memory.

MNIST has 60,000 training images and 10,000 test images of 28 × 28 pixels, CIFAR-10 has 60,000 images of 32 × 32 pixels in 10 classes, and ImageNet inputs are resized to 224×224 for MobileNet.

## Single squeezers against static attacks

On MNIST the 1-bit filter barely changes accuracy on legitimate test examples, moving from 99.43% to 99.33%. The same filter lifts accuracy on CW∞ adversarial examples from 0% to 100%, and it is effective across the L2 and L∞ attacks. It does little against the L0 attacks, which change a few pixels by large amounts, and the smoothing squeezers cover that gap.

On CIFAR-10 the 5-bit filter keeps legitimate accuracy at 94.55% compared with 94.84% and raises CW2 Next accuracy from 0% to 40%. The 4-bit filter is stronger, lifting CW2 accuracy to 84%, but it lowers legitimate accuracy to 93.11%, so the authors do not consider it a stand-alone defense.

On CIFAR-10 the 2 × 2 median filter raises accuracy under the four L0 attacks above 75%, from 0% without squeezing, and the same pattern appears on ImageNet for CW0. The 2 × 2 median filter also lowers legitimate CIFAR-10 accuracy from 94.84% to 89.29%, while non-local smoothing keeps it at 91.18%.

Composed with adversarial training on MNIST, the binary filter gives 93.03% against FGSM at ε = 0.3, compared with 92.38% for the adversarially trained model. At ε = 0.4 against PGD, the binary filter alone reaches 87.60% and the composed model reaches 94.21%, which shows the two defenses can be stacked.

## Choosing a threshold and measuring detection

The threshold is set on training data so that at most 5% of legitimate samples exceed it, which means the adversarial examples are not needed for training. The authors choose a low false positive target instead of maximizing training accuracy, because the expected traffic is mostly benign.

Detection is measured on successful adversarial examples, while failed adversarial examples are tracked separately because flagging them still signals an attack early. Legitimate inputs that get flagged count as false positives.

Single-squeezer detectors use one squeezer per attack in the oracle row, which assumes the operator knows the attack type, while the joint detector uses one configuration for all attacks.

## Joint detector results

On MNIST the joint detector combines 1-bit depth reduction with 2 × 2 median smoothing and detects 98.15% of successful adversarial examples at a 3.98% false positive rate. Its ROC-AUC excluding failed adversarial examples is 99.44%.

On CIFAR-10 the joint detector detects 84.53% of successful adversarial examples at a 4.93% false positive rate, with ROC-AUC 95.74%. On ImageNet it detects 85.94% at an 8.33% false positive rate, with ROC-AUC 94.24%, so the ImageNet false positive rate is above the 5% training target shown in the table.

Detection of FGSM and BIM examples is weak on color data: the best single squeezer detects 18.75% of successful FGSM examples and 55% of BIM examples on CIFAR-10, and 35.85% and 55.56% on ImageNet. The authors attribute this to those attacks making larger perturbations than the CW attacks, which the squeezers are better suited to counter.

Using a single threshold across squeezers means some attacks lose detection compared with the best single squeezer, such as CW0 (LL) on MNIST falling from 100% to 93%.

## Comparison with MagNet

The authors reran MagNet on the same target models and matched the false positive rates, at 0.40% on MNIST and 1.28% on CIFAR-10. On MNIST, MagNet detects 91.77% of adversarial examples against 69.08% for feature squeezing. On CIFAR-10, feature squeezing detects 60.87% against 50.36% for MagNet.

The authors argue that MagNet costs more because it trains an autoencoder on the whole dataset, and that its end-to-end differentiable pipeline is exposed to a white-box adversary.

## Adaptive adversaries on MNIST

He et al. built an adaptive attack that adds a penalty for the prediction distance between original and squeezed inputs, which needs differentiable squeezers and random restarts for bit depth reduction. The attack takes roughly 20 seconds per MNIST sample, about 60 times slower than the original CW2 attack.

Against the joint detector with threshold 0.0029 on MNIST, the untargeted adaptive success rate is 68%, while targeted-next reaches 44% and targeted-LL reaches 24%. The authors attribute the gap from He et al.'s reported 100% to the different MNIST model and the smaller threshold, which is 0.0029 against over 0.3076 in their setup.

Because these success rates allow arbitrary pixel changes, the authors clip the perturbation to ε from 0 to 1, and at ε = 0.3 the targeted success rate is 0% and the untargeted rate is 1%. The authors also note that the larger perturbations needed by an ensemble adaptive adversary produce many unrecognizable images.

Randomizing the binary filter cutoff as a normal distribution with mean 0.5 and standard deviation 0.0625 lowers the success rates to 17.0 ± 2.4%, 16.2 ± 2.6% and 7.6 ± 2.2%, measured over 10 executions. An ensemble-adaptive adversary that considers cutoffs of 0.4, 0.5 and 0.6 together reaches 46.5 ± 2.1%, 34.5 ± 3.5% and 28.5 ± 2.1%.

## Limitations

The main experiments cover image classification only, although the authors note that the approach could apply in other domains. Robustness against an adaptive adversary is left for future work, and the authors state that it needs further investigation.

The adaptive attack was evaluated only on MNIST, because no TensorFlow implementation of the non-local means filter was available for CIFAR-10 and ImageNet. The adaptive results cover one configuration of the joint detector and the random-cutoff variant, so other squeezer settings were not tested against this attack.

The authors note that feature squeezers are not effective against FGSM and BIM on the color datasets, and that developing squeezers for these attacks remains future work.

## Paper info

- **Authors**: Xu, Weilin, Evans, David, Qi, Yanjun
- **Venue**: arXiv · Preprint
- **First published**: 2017-4-4
- **Added**: 2026-11-12
- **Updated**: 2017-12-5
- **Version**: v2
- **arXiv**: 1704.01155
- **DOI**: 10.14722/ndss.2018.23198
- **Category**: cs.CV · cs.CR · cs.LG
- **Original paper terms**: [arXiv non-exclusive 1.0](https://arxiv.org/licenses/nonexclusive-distrib/1.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/1704.01155v2) · [PDF ↗](https://arxiv.org/pdf/1704.01155v2)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Xu, Weilin, Evans, David, Qi, Yanjun (2017). Feature Squeezing: Detecting Adversarial Examples in Deep Neural Networks. arXiv:1704.01155v2. https://doi.org/10.14722/ndss.2018.23198

**BibTeX**

```
@article{weilin2017feature,
  title = {{Feature Squeezing: Detecting Adversarial Examples in Deep Neural Networks}},
  author = {Xu, Weilin and Evans, David and Qi, Yanjun},
  year = {2017},
  eprint = {1704.01155},
  archivePrefix = {arXiv},
  doi = {10.14722/ndss.2018.23198},
  url = {https://arxiv.org/abs/1704.01155v2}
}
```

## Other paper commentary

- [Towards Principled Methods for Training Generative Adversarial Networks](https://refivu.com/en/papers/b0f4dfa6-159a-4785-ba9c-7a882bcab62f-towards-principled-methods-for-training-generative.md)
- [Diffusion Models: A Comprehensive Survey of Methods and Applications](https://refivu.com/en/papers/88553d75-09f1-48d0-a32d-bbb93fe0b6e8-diffusion-models-a-comprehensive-survey-of-methods-and.md)
- [DreamFusion: Text-to-3D using 2D Diffusion](https://refivu.com/en/papers/8748788c-c1b0-47b9-a624-78c1f27630e6-dreamfusion-text-to-3d-using-2d-diffusion.md)
- [Obfuscated Gradients Give a False Sense of Security: Circumventing Defenses to Adversarial Examples](https://refivu.com/en/papers/6d5ee375-978f-4c78-87e2-0c8e55a1127f-obfuscated-gradients-give-a-false-sense-of-security.md)
- [SeqGAN: Sequence Generative Adversarial Nets with Policy Gradient](https://refivu.com/en/papers/29153239-a1df-4102-9df1-abd1ba2a9c96-seqgan-sequence-generative-adversarial-nets-with-policy.md)
- [Tutorial on Variational Autoencoders](https://refivu.com/en/papers/51a9cfc2-6285-4935-b55a-3d6450af8eff-tutorial-on-variational-autoencoders.md)
- [Unsupervised Image-to-Image Translation Networks](https://refivu.com/en/papers/23eee1aa-7651-4535-93bf-d37262ee5dff-unsupervised-image-to-image-translation-networks.md)
- [Methods of Hierarchical Clustering](https://refivu.com/en/papers/b67289cf-e579-4f78-a7ff-bdea1acaa376-methods-of-hierarchical-clustering.md)
- [Designing Network Design Spaces](https://refivu.com/en/papers/37f6e2ac-519b-4565-a6cb-673b7ed0265a-designing-network-design-spaces.md)
- [The Concrete Distribution: A Continuous Relaxation of Discrete Random Variables](https://refivu.com/en/papers/a2b9da66-2864-4212-85c2-c935a02c48cf-the-concrete-distribution-a-continuous-relaxation-of.md)
- [Personalized Top-N Sequential Recommendation via Convolutional Sequence Embedding](https://refivu.com/en/papers/7c1f4e3a-96df-4fe9-a8b5-6c36b294a565-personalized-top-n-sequential-recommendation-via.md)
- [TSM: Temporal Shift Module for Efficient Video Understanding](https://refivu.com/en/papers/e7e3764b-d00b-4555-9a23-62f113a3fdfe-tsm-temporal-shift-module-for-efficient-video-understanding.md)

## Terms in this paper

- [CIFAR-10](https://refivu.com/en/terms/19035a518d0a-cifar-10)
- [adversarial examples](https://refivu.com/en/terms/277fed423ea7-adversarial-examples)
- [FGSM](https://refivu.com/en/terms/5e096cf3ee8d-fgsm)
- [MobileNet](https://refivu.com/en/terms/373a038a6bbb-mobilenet)
- [ROC-AUC](https://refivu.com/en/terms/4a16e24a9f10-roc-auc)
- [DeepFool](https://refivu.com/en/terms/60b20595f296-deepfool)
- [false positive rate](https://refivu.com/en/terms/902ec4a8638c-false-positive-rate)
- [MagNet](https://refivu.com/en/terms/7f05672b52f5-magnet)
- [detection rate](https://refivu.com/en/terms/dcd10e61ed08-detection-rate)
- [Feature squeezing](https://refivu.com/en/terms/4b3ae49ff599-feature-squeezing)
- [JSMA](https://refivu.com/en/terms/966f0db5a084-jsma)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/12afca27-3173-4d16-a76b-cb72a4fa0438-feature-squeezing-detecting-adversarial-examples-in-deep)
