Controllable Stochastic Quantization Encoding for Adversarially Robust Spiking Neural Networks

Yujia Liu, Peiyu Liu, Yajing Zheng, Tiejun HuangarXiv 2026

TL;DR

This paper introduces Stochastic Quantization Encoding (SQE), a novel input encoding method for Spiking Neural Networks (SNNs) that provides a "tunable knob" for adversarial robustness. By adjusting a quantization scale $N$, researchers can precisely control the amount of randomness injected into the network, bridging the gap between the high accuracy of direct encoding and the high robustness of Poisson encoding.

What Problem Does This Paper Address?

Spiking Neural Networks (SNNs) are prized for their energy efficiency and brain-like temporal dynamics, but they share a major weakness with traditional Artificial Neural Networks (ANNs): adversarial vulnerability. Tiny, imperceptible perturbations to an input image can completely derail a model's predictions.

While most defenses focus on complex training strategies (like adversarial training), this paper looks at the very first step: input encoding. Currently, SNN researchers typically choose between two extremes:

  1. Direct Encoding: Feeds constant pixel values. It’s accurate on clean data but extremely fragile to attacks.
  2. Poisson Encoding: Converts pixels into stochastic spike trains. It’s more robust because the randomness "washes out" some adversarial noise, but it significantly degrades accuracy on clean images.

The authors identified a need for a middle ground—a way to inject just enough randomness to be robust without destroying the model's performance on normal data.

Methods

The authors propose Stochastic Quantization Encoding (SQE). Instead of choosing between deterministic values or binary spikes, SQE quantizes a normalized pixel value $x$ into $N$ levels.

At each time step $t$, a pixel is stochastically rounded to either its nearest upper quantization level $\lceil xN \rceil / N$ or its lower level $\lfloor xN \rfloor / N$. The probability of picking the upper level is determined by the fractional part of $xN$.

Figure 1: Illustration of the proposed stochastic quantization encoding method. At each time step, the normalized pixel value x is randomly encoded as the upper quantiztaion level ⌈xN⌉/N with probability p0, or as the lower quantiztaon level ⌊xN⌋/N with probability 1−p0, where N is the quantization scale. At different time steps, the encoded values are independently sampled from the same distribution, and together form a quantization encoded sequence. When N = 1, the proposed method reduces to Poisson encoding, where each encoded value is sampled from {0, 1}. As N increases, the encoded values become more stable and gradually approach direct encoding.

Key technical highlights: * Unified Framework: The authors mathematically prove that when $N=1$, SQE becomes Poisson encoding. As $N \to \infty$, it converges to Direct encoding. * Controllable Randomness: The quantization scale $N$ acts as a bound on the variance of the input. A smaller $N$ means more randomness (more robustness), while a larger $N$ means more stability (higher clean accuracy). * Differentiable Training: Because stochastic rounding is non-differentiable, the authors use a Straight-Through Estimator (STE) to allow gradients to flow back to the input during training.

Datasets

The method was evaluated on two standard computer vision benchmarks:

  • CIFAR-10: 60,000 32x32 color images in 10 classes.
  • CIFAR-100: 60,000 32x32 color images in 100 classes.

The researchers tested these datasets across two popular SNN architectures: VGG-11 and WideResNet-16 (WRN-16).

Key Insights and Ideas

  • The "Randomness Knob": The most significant insight is that adversarial robustness in SNNs is not a binary choice. By treating the quantization scale $N$ as a hyperparameter, practitioners can find the "sweet spot" for their specific application.
  • Biological Inspiration: The authors link SQE to population coding in the brain. In biology, larger populations of neurons provide more stable representations by averaging out noise. In SQE, a larger $N$ mimics a larger neuronal population, leading to higher representational fidelity.
  • Perturbation Diffusion: Visualizing the "difference maps" (the difference between clean and adversarial encoded inputs) reveals that SQE makes adversarial perturbations much sparser. While direct encoding allows noise to permeate the entire image, SQE's randomness causes many perturbed pixels to "round" back to their original values, effectively filtering the attack.
Figure 3: Visualization of clean and adversarial images (gen- erated by PGD10) after different encoding methods. For SQE and Poisson encoding, the encoded results are averaged over 8 time steps. For each encoding method, the first row shows the distribution of pixel-wise encoding randomness (Defini- tion 1), with the mean randomness across all pixels indicated by the dashed line. The last row shows the difference between the encoded clean image and the encoded adversarial image.

Key Results

The experimental results demonstrate that SQE consistently outperforms baseline encodings when facing strong attacks like PGD (Projected Gradient Descent) and Auto-PGD (APGD).

  • Better Trade-offs: On CIFAR-10 with VGG-11, SQE achieved a 16.82% accuracy under APGD10 attacks while maintaining 87.36% clean accuracy. In contrast, direct encoding dropped to 0% accuracy under the same attack. While Poisson encoding had higher robustness (29.11%), its clean accuracy was much lower (81.67%).
  • Compatibility: SQE isn't just a standalone defense; it works synergistically with training-based methods. When combined with Regularized Adversarial Training (RAT), SQE improved average robustness on WRN-16 by approximately 17% compared to RAT with direct encoding.
Table 1: Effectiveness of the proposed SQE on the CIFAR-10 dataset under different training strategies, measured by classification accuracy (%). The last column reports the average accuracy across all attacks. Better results are highlighted in gray.

Limitations and Future Work

The primary limitation noted by the authors is that the quantization scale $N$ is currently global and fixed. Every pixel in every image uses the same $N$, which is selected empirically through trial and error.

Future directions include: * Learnable Scales: Developing methods to let the network learn the optimal $N$ during training. * Pixel-Adaptive Quantization: Implementing different quantization scales for different parts of an image (e.g., higher precision for complex textures and lower precision for flat backgrounds) to further optimize the accuracy-robustness frontier.

Summary updated

BibTeX
@misc{liu2026controllable,
  author = {Yujia Liu and Peiyu Liu and Yajing Zheng and Tiejun Huang},
  title = {{Controllable Stochastic Quantization Encoding for Adversarially Robust Spiking Neural Networks}},
  year = {2026},
  eprint = {2610.01558},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2610.01558},
}
Figure