Abstract
Preprocessing defenses such as pixel discretization are appealing to remove adversarial attacks due to their simplicity. However, they have been shown to be ineffective except on simple datasets like MNIST. We hypothesize that existing discretization approaches failed because using a fixed codebook for the entire dataset limits their ability to balance image representation and codeword separability. We first formally prove that adaptive codebooks can provide stronger robustness guarantees than fixed codebooks as a preprocessing defense on some datasets. Based on that insight, we propose a content-adaptive pixel discretization defense called Essential Features, which discretizes the image to a per-image adaptive codebook to reduce the color space. We then find that Essential Features can be further optimized by applying adaptive blurring before the discretization to push perturbed pixel values back to their original value before determining the codebook. Against adaptive attacks, we show that content-adaptive pixel discretization extends the range of datasets that benefit in terms of both $L_2$ and $L_\infty$ robustness where previously fixed codebooks were found to have failed. Our findings suggest that content-adaptive pixel discretization should be part of the repertoire for making models robust.
Introduction
Adversarial attacks—subtle, engineered perturbations that trick machine learning models—remain a major hurdle for deploying AI in safety-critical fields. One intuitive defense is pixel discretization: reducing the number of colors in an image to "squeeze out" the attacker's noise.
However, previous research suggested this only works on simple datasets like MNIST. On complex, colorful datasets, these defenses usually rely on a fixed codebook (a universal set of allowed colors for the whole dataset). This creates a catch-22: use too few colors, and you destroy the image's "representation" (the model can't tell what it's looking at); use too many, and you lose "separability" (the attacker can easily nudge a pixel from one color to another).
The "Essential Features" Framework
The authors propose a pipeline called Essential Features (EF) that breaks the fixed-codebook constraint through two main stages:
- Adaptive Gaussian Blurring: Before discretizing, the system applies an edge-aware blur. Using Sobel filters to detect edges, it blurs "flat" areas heavily while preserving sharp edges. This "pushes" pixels perturbed by an attacker back toward their original color clusters before the final palette is chosen.
- Content-Adaptive Pixel Discretization: Instead of a global palette, the defense calculates a unique codebook for each individual image using a variant of $k$-means clustering. It heuristically selects the number of colors ($k$) and ensures a minimum distance ($d$) between colors to maintain high separability.
By combining these, the defense preserves the "essential features" needed for classification while drastically shrinking the "attack surface" available to an adversary.
Key Insights and Results
- The "Stop Sign vs. Flamingo" Logic: A single global codebook must accommodate every color in a dataset. However, a specific image (like a red and white STOP sign) only needs a few colors. An adaptive codebook can provide massive "gaps" between colors for that specific image, making it much harder for an attacker to flip a pixel's color value.
- Blurring as a Pre-filter: Adaptive blurring is crucial because it reduces the adversary's influence over the selection of the codebook itself. By smoothing out noise in non-essential areas, the subsequent $k$-means clustering is more likely to find the "true" color centers of the original image.
The EF approach showed dramatic improvements in $L_2$ robustness when combined with adversarial training (ATTA):
- RESISC45: Robustness jumped from 12.09% (baseline) to 52.44% with EF.
- CIFAR-10: Robustness increased from 20.15% to 38.46%.
- Imagenette: $L_\infty$ robustness improved from 75.97% to 80.71%.
Importantly, the defense held up against adaptive attacks (where the attacker knows the defense is there), suggesting the gains aren't just due to "gradient masking."
Limitations and Future Work
The defense is most effective on higher-resolution images (like RESISC45). On very low-resolution images (like the $32\times32$ traffic signs in GTSRB), the adaptive blur can sometimes destroy the very features needed for classification. Additionally, calculating a per-image codebook adds latency to the inference pipeline. Future work could explore how to align model robustness more closely with human visual intuition, as resulting adversarial images sometimes contain "blob-like" perturbations visible to the human eye.
Summary updated