Manuscript Offprint

arXiv:2610.01558

Controllable Stochastic Quantization Encoding for Adversarially Robust Spiking Neural Networks

Yujia Liu, Peiyu Liu, Yajing Zheng, Tiejun Huang

Abstract

Spiking Neural Networks (SNNs) have attracted increasing attention due to their impressive temporal dynamics, energy efficiency, and brain-inspired mechanisms. Although SNNs have demonstrated promising performance in image classification tasks, recent studies have shown that they remain vulnerable to adversarial attacks, where imperceptible perturbations are added to input images to mislead model predictions. Existing defense methods mainly focus on training strategies, while the role of input encoding remains less explored. An observation is that the robustness advantage of Poisson encoding over direct encoding may benefit from its inherent randomness. Motivated by this, we propose a stochastic quantization encoding method that encodes the input image with controllable randomness adjusted by the quantization scale, thereby improving the adversarial robustness of SNNs. We further show that this method constitutes a general framework that reduces to both Poisson encoding and direct encoding under different choices of the quantization scale. Since it enhances robustness at the input encoding stage, it can be combined with existing training-based defenses for further gains. Experimental results on CIFAR-10 and CIFAR-100 demonstrate the effectiveness of the proposed stochastic quantization encoding method. To sum up, this work highlights the importance of input encoding for the adversarial robustness of SNNs, providing a new perspective for understanding and improving it.

1 Introduction

Spiking Neural Networks (SNNs) are characterized by high energy efficiency and brain-inspired computing mechanisms, making them an attractive topic for neuromorphic computing (Maass 1997; Bohte, Kok, and La Poutré 2000; Zheng et al. 2021). Different from Artificial Neural Networks (ANNs), which process information through continuous real-valued activations (He et al. 2016), SNNs employ discrete binary spike trains for information transmission (Roy, Jaiswal, and Panda 2019). In addition, SNNs explicitly incorporate temporal dynamics, allowing them to effectively capture and process temporal information (Kim et al. 2023; Han, Liu, and Karimi 2025). Because of these advantages, SNNs have demonstrated remarkable performance in image classification tasks, with some models achieving results comparable to those of ANNs (Huang et al. 2024; Bu, Li, and Yu 2025; Zhou et al. 2026).

However, similar to ANNs, SNNs are also vulnerable to adversarial attacks (Sharmin et al. 2019; Bu et al. 2023), where carefully crafted imperceptible perturbations can lead the network to give incorrect predictions (Goodfellow, Shlens, and Szegedy 2015; Chen et al. 2017). To address this issue, a variety of defense methods have been proposed for SNNs. Among them, adversarial training and its variants are the most widely adopted approaches, which enhance robustness by augmenting the training set with adversarial examples and solving a min-max optimization problem (Madry et al. 2018). Other methods aim to improve robustness through specifically designed regularization terms in the training loss, such as enforcing a bounded Lipschitz constant (Ding et al. 2022) or introducing temporal constraints (Leontev, Antonov, and Sukhov 2021). More recently, it has been reported that promoting gradient sparsity can also contribute to improved adversarial robustness (Liu et al. 2024; Wang et al. 2026b).

In addition to training strategies, input encoding methods also play a crucial role in the adversarial robustness of SNNs. Direct encoding and Poisson encoding are the most widely used methods in SNN training (Wu et al. 2019; Kim et al. 2022; Fang et al. 2023). For input images normalized to [0,1][0, 1], direct encoding feeds constant pixel intensities across all time steps, whereas Poisson encoding converts each pixel into stochastic spike trains where the pixel value serves as the firing probability. Recent studies have shown that Poisson encoding generally improves adversarial robustness compared with direct encoding, but at the cost of a noticeable drop in clean-image classification accuracy (Sharmin et al. 2020). This phenomenon is closely related to the randomness introduced by Poisson encoding (Wu et al. 2024). Stochastic spike generation may weaken the effect of adversarial perturbations, but it can also inject uncertainty into clean-image representations, leading to less stable predictions.

Inspired by this observation, we propose a stochastic quantization encoding method that can control the degree of randomness in input representations, thereby improving adversarial robustness while keeping the degradation in clean accuracy under control. As shown in Fig. 1, each input pixel value x is scaled by a quantization scale N and then stochastically rounded to either ⌊xN⌋/N\lfloor xN \rfloor/N or ⌈xN⌉/N\lceil xN \rceil/N according to its fractional part. The quantization scale N controls the upper bound of the encoding randomness, so different choices of N achieve different trade-offs between adversarial robustness.

Figure

Quantization stochastic values

Quantization encoded sequence

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 quantization level ⌈xN⌉/N\lceil xN \rceil/N with probability p0p_0, or as the lower quantization level ⌊xN⌋/N\lfloor xN \rfloor/N with probability 1−p01 - p_0, 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}\{0, 1\}. As N increases, the encoded values become more stable and gradually approach direct encoding.

ness and clean accuracy. We further show that the proposed encoding provides a unified formulation of direct encoding and Poisson encoding under different choices of N. Since the proposed method operates at the input encoding stage, it can be combined with existing training-based defense strategies to further enhance adversarial robustness. The main contributions of this work are summarized as follows:

• We propose stochastic quantization encoding, an input encoding method for SNNs that introduces controllable randomness into input representations and thereby improves adversarial robustness.

• We provide a theoretical analysis showing that the proposed quantization encoding is a general formulation that recovers both direct encoding and Poisson encoding as special cases under different choices of N.

• Experimental results on CIFAR-10 and CIFAR-100 validate the effectiveness of the proposed method and demonstrate its compatibility with existing training strategies for further robustness enhancement.

References (44)

  • Estimating or propagating gradients through stochastic neurons for conditional computation (opens arXiv in a new tab)
  • Spike-Prop: Backpropagation for networks of spiking neurons
  • Rate gradient approximation attack threats deep spiking neural networks
  • Inference-Scale complexity in ANN-SNN conversion for high-performance and low-power applications
  • ZOO: Zeroth order optimization based black-box attacks to deep neural networks without training substitute models
  • Reliable evaluation of adversarial robustness with an ensemble of diverse parameter-free attacks
  • Theoretical neuroscience: Computational and mathematical modeling of neural systems
  • SNN-RAT: Robustness-enhanced spiking neural network through regularized adversarial training
  • Spikingjelly: An open-source machine learning infrastructure platform for spike-based intelligence
  • Neuronal population coding of movement direction
  • Explaining and harnessing adversarial examples
  • Exploring temporal information dynamics in spiking neural networks: Fast temporal efficient training
  • Deep residual learning for image recognition
  • Towards high-performance spiking transformers from ANN to SNN conversion
  • Timestep-Compressed attack on spiking neural
  • Exploring temporal information dynamics in spiking neural networks
  • Rate coding or direct coding: Which one is better for accurate, robust, and energy-efficient spiking neural networks? In Proceedings of the IEEE International Conference on Acoustics, Speech and Signal Processing, 71–75
  • Hire-SNN: Harnessing the inherent robustness of energy-efficient deep spiking neural networks by training with crafted input noise
  • Robustness of spiking neural networks against adversarial attacks
  • Enhancing adversarial robustness in SNNs with sparse gradients
  • Networks of spiking neurons: The third generation of neural network models
  • Towards Deep Learning Models Resistant to Adversarial Attacks
  • Information processing with population codes
  • Towards spike-based machine intelligence with neuromorphic computing
  • A comprehensive analysis on adversarial robustness of spiking neural networks
  • Inherent adversarial robustness of deep spiking neural networks: Effects of discrete input encoding and non-linear activations
  • Very Deep Convolutional Networks for Large-Scale Image Recognition
  • Ensemble adversarial training: Attacks and defenses
  • Boosting the robustness-accuracy trade-off of SNNs by robust temporal self-ensemble
  • Robust spiking neural networks against adversarial attacks
  • Fast is better than free: Revisiting adversarial training (opens arXiv in a new tab)
  • RSC-SNN: Exploring the trade-off between adversarial robustness and accuracy in spiking neural networks via randomized smoothing coding
  • Direct training for spiking neural networks: Faster, larger, better
  • Wide Residual Networks
  • Going deeper with directly-trained larger spiking neural networks
  • Spikingformer: A key foundation model for spiking neural networks
  • To enable end-to-end training, we employ the Straight-Through Estimator (STE) (Bengio, Léonard, and Courville 2013), which retains the stochastic quantization operation in the forward pass while approximating it as an identity mapping in the backward pass
  • Therefore, setting $N = 255$ is sufficient to make $x_{i}N$ an integer
  • >AT</td><td>attack</td><td>PGD</td><td rowspan=
  • This observation is consistent with Theorem 2, which shows that the quantization scale $N$ controls the degree of encoding randomness
  • This is more clear in the first group of examples
  • Since stochastic quantization is unbiased, the expected difference between the encoded clean and adversarial images equals the input perturbation itself, making it largely independent of $N$
  • When $N$ is large, the differences between the encoded clean and adversarial images have relatively small magnitudes but are densely distributed across the image
  • For SQE and Poisson encoding, the encoded images are obtained by averaging the encoding results over eight time steps