Rate Coding Or Direct Coding: Which One Is Better For Accurate, Robust, And Energy-Efficient Spiking Neural Networks?

Youngeun Kim, Hyoungseob Park, Abhishek Moitra, Abhiroop Bhattacharjee, Yeshwanth Venkatesha, Priyadarshini Panda

TL;DR

This paper provides the first head-to-head "fair" comparison between the two most popular input encoding methods for Spiking Neural Networks (SNNs): Rate Coding and Direct Coding. The researchers found a clear trade-off: while Direct Coding offers superior accuracy at low latencies, Rate Coding is significantly more energy-efficient and naturally more robust against adversarial attacks.

What Problem Does This Paper Address?

Spiking Neural Networks (SNNs) are the "brain-inspired" cousins of standard Artificial Neural Networks (ANNs), designed to process information using discrete binary spikes rather than continuous values. This makes them incredibly energy-efficient on specialized hardware. However, most data (like photos) is continuous. To process an image, an SNN must first convert pixels into spikes.

Two methods dominate the field:

  1. Rate Coding: Converting pixel intensity into a frequency of spikes (like a Geiger counter).
  2. Direct Coding: Using a learnable neural layer to convert pixels into floating-point values that are then treated as "spikes" (or used to generate them).

Until now, researchers often chose one or the other based on intuition or specific project needs. This paper addresses the lack of a systematic comparison across accuracy, security (robustness), and hardware energy consumption.

Methods

The authors evaluated both coding schemes using a standardized experimental setup:

  • Neuron Model: The standard Leaky Integrate-and-Fire (LIF) model.
  • Training: They used Spatio-Temporal Backpropagation (STBP) with surrogate gradients, which allows SNNs to be trained similarly to standard deep learning models despite the non-differentiable nature of spikes.
  • Architectures: They tested three different scales: a simple Multi-Layer Perceptron (MLP), VGG5, and VGG9.
  • Hardware Simulation: Energy efficiency was estimated using the Eyeriss platform, a well-known 16-bit accelerator architecture for deep learning.

Datasets

The study utilized three benchmark datasets of increasing complexity:

  • MNIST: Handwritten digits (grayscale).
  • CIFAR-10: 10 classes of color images.
  • CIFAR-100: 100 classes of color images.

Key Insights and Ideas

  • The Latency Advantage: Direct coding is the clear winner for "fast" AI. It achieves high accuracy with very few timesteps (low latency), whereas rate coding needs more time to "accumulate" enough spikes to represent the data accurately.
  • Robustness through Non-Differentiability: Rate coding is naturally more resistant to adversarial attacks (like FGSM and PGD). Because the Poisson process used to generate spikes in rate coding is non-differentiable, it's harder for an attacker to calculate the precise "malicious gradient" needed to fool the network.
  • The "Hidden" Cost of Direct Coding: While direct coding is popular, it requires the first layer of the network to perform multi-bit (16-bit) floating-point operations. Rate coding uses binary spikes (0 or 1) from the very beginning. This makes rate coding roughly 50% more energy-efficient on hardware that can exploit spike sparsity.

Key Results

  • Accuracy: Direct coding consistently outperformed rate coding, especially on CIFAR-100. For example, on VGG9/CIFAR-10, direct coding reached peak accuracy much faster than rate coding.
  • Adversarial Robustness: Rate-coded SNNs showed approximately 20% higher accuracy under adversarial pressure compared to direct-coded SNNs.
  • Energy Efficiency: On the Eyeriss platform, rate coding consumed significantly less energy. For VGG5/CIFAR-10, rate coding used ~2.73E+07 normalized energy units, while direct coding used ~4.22E+07.

Limitations and Future Work

  • Static vs. Dynamic Data: This study focused exclusively on static image classification. The authors note that the comparison might look different for neuromorphic datasets (like DVS camera data) where the input is already spike-based.
  • Hardware Specificity: The energy results are tied to the Eyeriss architecture. Future work could explore how these coding schemes perform on truly asynchronous neuromorphic hardware like Intel’s Loihi or IBM’s TrueNorth.
  • Attack Sophistication: While rate coding is robust against standard gradient attacks, the authors acknowledge that more specialized "SNN-aware" attacks might eventually bridge this security gap.

Summary updated

Abstract

Recent Spiking Neural Networks (SNNs) works focus on an image classification task, therefore various coding techniques have been proposed to convert an image into temporal binary spikes. Among them, rate coding and direct coding are regarded as prospective candidates for building a practical SNN system as they show state-of-the-art performance on large-scale datasets. Despite their usage, there is little attention to comparing these two coding schemes in a fair manner. In this paper, we conduct a comprehensive analysis of the two codings from three perspectives: accuracy, adversarial robustness, and energy-efficiency. First, we compare the performance of two coding techniques with various architectures and datasets. Then, we measure the robustness of the coding techniques on two adversarial attack methods. Finally, we compare the energy-efficiency of two coding schemes on a digital hardware platform. Our results show that direct coding can achieve better accuracy especially for a small number of timesteps. In contrast, rate coding shows better robustness to adversarial attacks owing to the non-differentiable spike generation process. Rate coding also yields higher energy-efficiency than direct coding which requires multi-bit precision for the first layer. Our study explores the characteristics of two codings, which is an important design consideration for building SNNs <sup xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">1</sup> .
BibTeX
@inproceedings{kim2022rate,
  author = {Youngeun Kim and Hyoungseob Park and Abhishek Moitra and Abhiroop Bhattacharjee and Yeshwanth Venkatesha and Priyadarshini Panda},
  title = {{Rate Coding Or Direct Coding: Which One Is Better For Accurate, Robust, And Energy-Efficient Spiking Neural Networks?}},
  booktitle = {IEEE International Conference on Acoustics, Speech and Signal Processing},
  year = {2022},
  url = {https://openreview.net/forum?id=qwakKWqcVV},
}

Loading related content...

Figure