Training the Camera's JPEG Table as a Free Adversarial Defense for Edge Classifiers

Many edge cameras already compress every frame with a hardware JPEG encoder before a small neural network sees it. JPEG works by splitting the image into 8x8 blocks, converting each block into frequency components (the discrete cosine transform, or DCT), and rounding each component to a coarse step set by a quantization table. That rounding costs nothing extra at inference, because the silicon runs it anyway. Prior work has shown that a hand-designed table can strip much of an adversarial perturbation, the small, carefully optimized pixel noise that flips a classifier's decision. Such hand-designed tables were also broken, or badly weakened, once attackers modeled the filter. We propose to treat the quantization table as a learnable parameter and train it jointly with the tiny classifier under adversarial training, while assuming the attacker knows the table exactly. The goal is not to hide the defense. The goal is to spend the encoder's fixed, already-paid rounding budget on throwing away the input directions that attackers use most, and to measure whether this buys more robustness per millisecond than any other way of spending the same edge budget.

The two-sentence version is this. On microcontroller-class hardware, every defense competes for the same few milliseconds and kilobytes, and the camera's JPEG stage is the only robustness-relevant compute that is free. We ask whether a quantization table learned with adversarial training, and evaluated against attackers who know the table, moves the robustness-versus-latency frontier beyond what adversarial training alone, a fixed Feature Distillation table, or test-time defenses achieve.

Core Claim

The claim is narrow and falsifiable. For small edge classifiers at a fixed measured latency and memory budget, a deterministic, attacker-known, adversarially co-trained DCT quantization front end improves robust accuracy under full adaptive white-box attack beyond what adversarial training of the same classifier achieves without it. The improvement should come from projection: the defense shrinks the set of perturbations that survive rounding. It should not come from gradient masking. If the gain disappears under proper adaptive evaluation, or if a slightly larger adversarially trained model at the same latency matches it, we will report that the free encoder is not a useful defense. That outcome is also worth knowing, because the field currently has no measured robustness-per-millisecond comparison on edge hardware.

The objective jointly learns the classifier weights $\theta$ and the per-coefficient quantization steps $Q$ (64 values, optionally separate for color channels):

$$\min_{\theta, Q} \; \mathbb{E}_{(x,y)} \Big[ \max_{\|\delta\|_\infty \le \epsilon} \mathcal{L}\big(f_\theta(J_Q(x+\delta)), y\big) \Big] + \lambda \, R(Q)$$

Here $J_Q$ is JPEG compress-and-decompress with table $Q$, $f_\theta$ is the edge classifier, $\mathcal{L}$ is cross-entropy, $\epsilon$ is the perturbation budget, and $R(Q)$ is the encoded bit rate. The rate term $R(Q)$ ties the table to the device's transmission budget, so the learned table remains a real JPEG table that the hardware encoder can load. During training, rounding uses a straight-through gradient. At deployment, it is the encoder's hard rounding.

How This Relates to Prior Work

Feature Distillation supplies the method we build on. It hand-designs a table with fine steps in "accuracy-sensitive" frequencies and coarse steps in "malicious defense" frequencies. On ImageNet it raised adversarial accuracy from 20% to about 90%, at under 1% clean cost and a 259x speedup over Total Variation minimization, and it kept about 60% accuracy against an attack that approximates the filter's gradient. We differ in three ways. Our table is learned under adversarial training rather than set by heuristic. The classifier is co-trained to live with it. We evaluate on microcontroller-class models with measured latency rather than desktop ImageNet networks.

Two papers motivate the work by showing that static frequency filters invite targeted bypass. BAFLE-DCT embeds signals in five mid-frequency coefficients, scaled to the JPEG table, and 83.8% of the signal survives compression. The Simulated OSN attack adds a differentiable JPEG layer to the attacker's loss and keeps over 60% success after Facebook transmission, where vanilla C&W falls to 12%. Both imply that any fixed table leaves fine-step coefficients open. Our answer is to let adversarial training decide which coefficients to coarsen, and to make the classifier robust in the ones that remain.

Obfuscated Gradients constrains the design. It broke 7 of 9 ICLR 2018 defenses with differentiable approximations of non-differentiable steps (BPDA) and averaging over randomness (EOT). For that reason we rule out randomized tables and treat the rounding step as an evaluation hazard. RobustBench supplies the evaluation discipline: AutoAttack, and the finding that published robustness was often overestimated by more than 10%.

Test-time defenses form the competing branch. IG-Defense masks unimportant penultimate neurons after a pseudo-labeling pass and gains +2.6% AutoAttack accuracy on CIFAR-10 at twice the cost of a forward pass. Its mask depends on a first prediction that an attacker can flip. Contrastive Spectral Rectification runs test-time optimization on CLIP, and its low-pass anchor fails under global color shifts (Contrastive Spectral Rectification: Test-Time Defense towards Zero-shot Adversarial Robustness of CLIP Contrastive Spectral Rectification: Test-Time Defense towards Zero-shot Adversarial Robustness of CLIP). DeepCloak uses a static mask and was tested only against single-step FGSM. These methods either add inference passes that edge devices cannot afford or rest on a decision point the attacker controls. Our front end adds no passes and has no attacker-steerable branch.

On the edge side, lightweight IoT malware classification shows that tiny CNNs of 104 nodes run in milliseconds but were never adversarially evaluated. That gap motivates our focus on very small models, though byte-images are not JPEG-encoded, so we do not use that domain.

Research Program

We will build the differentiable training loop described by the objective above. We will then export each learned table to a real JPEG encoder, so that exactly the deployed bitstream is evaluated. The classifiers will be microcontroller-scale CNNs and MobileNetV2-width variants, with latency and peak RAM measured on a Cortex-M-class board and a hardware-JPEG camera pipeline.

The analysis has three parts. The first is a robustness-per-latency frontier: each defense is a point at its measured milliseconds and kilobytes. The second is an inspection of the learned tables, which tests whether they coarsen the mid-frequency bands that BAFLE-DCT targets, or instead push attackers into low-frequency color directions. Low-frequency color attacks are the known failure mode for spectral defenses, so we will build a dedicated low-frequency adaptive attack. The third is a gradient-masking audit.

Baselines

The naive reference point is the undefended small classifier, run with the standard camera JPEG table at the device's default quality. It establishes how fragile tiny models are, which no paper in our file has measured for this class of model.

The strongest competitor is plain adversarial training of the same architecture with the standard JPEG table. It adds zero inference cost, so it occupies the same latency point as our method. A second version scales the model width up until its measured latency matches the small model's latency plus any overhead our method adds, which in principle is none. We found no reported result on Lacuna for adversarially trained microcontroller-scale models on CIFAR-10. We will therefore train these baselines ourselves with the same data, the same PGD steps, the same epochs, and the same hyperparameter search budget as our method. Beating this baseline means a statistically reliable improvement in AutoAttack-with-BPDA robust accuracy at matched latency and clean accuracy within one point, across three seeds.

The strongest existing preprocessing method is Feature Distillation's fixed table, combined with the same adversarially trained classifier fine-tuned behind it. Its reported figure is about 60% accuracy on ImageNet against BPDA (Feature Distillation), measured on desktop networks and against a different attack strength, so we rerun it under our attack suite.

The key ablation freezes the table at the Feature Distillation values while training the classifier adversarially, and compares that to learning the table jointly. This isolates whether learning $Q$ matters beyond simply having some coarse table.

IG-Defense is included at its 2x overhead, placed on the frontier at its true latency. Its reported figure is a +2.6% CIFAR-10 AutoAttack gain over the base model (IG-Defense).

Why not just…?

Why not just adversarially train the small model and skip the table? This is the real threat, and we take it seriously. Adversarial training is free at inference, and a co-trained classifier may absorb whatever benefit the table offers. The frozen-table and no-table ablations settle the question directly. If learned tables do not beat latency-matched adversarial training, the paper's conclusion becomes "spend your budget on model width, not filtering," and we will report it that way.

Why not just use Feature Distillation's hand-designed table? Its partition is fixed and public. BAFLE-DCT's 83.8% survival rate through JPEG and the Simulated OSN attack's over-60% post-compression success suggest that attackers move into the fine-step coefficients. Our experiments test that move explicitly with a band-restricted adaptive attack against both tables.

Why not randomize the table per frame as a moving target? Randomized preprocessing is exactly what EOT defeats. Obfuscated Gradients reduced several such defenses to near-zero accuracy. We will include a randomized-table variant evaluated with EOT to show this, rather than assume it.

Why not purify with a diffusion model or offload to a server? IMPRESS needs about 141 seconds per image, several orders of magnitude over a frame budget. Offloading still requires shipping the frame over a link the device is already compressing. Network-side detectors such as N-BaIoT address traffic anomalies, not perceptual evasion.

Proposed Experiments

We will use CIFAR-10 and CIFAR-100 under RobustBench's AutoAttack at $\ell_\infty$ budget 8/255, plus an ImageNet subset at MobileNetV2 width. Every defended model is attacked by AutoAttack with BPDA through the hard rounding. We add a soft-rounding white-box attack, a Simulated-OSN-style attack that knows the exact table, a band-restricted mid-frequency attack, and a low-frequency color attack. As a transfer check, we run the released Simulated OSN dataset of over 10,000 transmitted adversarial pairs ( Generating Robust Adversarial Examples against Online Social Networks (OSNs)) through each defense. Metrics are clean accuracy, worst-case robust accuracy across attacks, measured latency, peak RAM, and bits per frame.

The decisive checks guard against fake robustness. Robust accuracy must fall to zero as $\epsilon$ grows large. The black-box Square attack must never outperform white-box attacks. Robust accuracy must not rise when attack iterations increase. Any learned-table model that fails these checks is reported as obfuscated, not robust.

The headline result is a single plot: robust accuracy against measured on-device milliseconds. The proposal succeeds only if the learned-table points sit above the latency-matched adversarial-training curve.