Low Latency of object detection for spikng neural network
Spiking Neural Networks, as a third-generation neural network, are
well-suited for edge AI applications due to their binary spike nature. However,
when it comes to complex tasks like object detection, SNNs often require a
substantial number of time steps to achieve high performance. This limitation
significantly hampers the widespread adoption of SNNs in latency-sensitive edge
devices. In this paper, our focus is on generating highly accurate and
low-latency SNNs specifically for object detection. Firstly, we systematically
derive the conversion between SNNs and ANNs and analyze how to improve the
consistency between them: improving the spike firing rate and reducing the
quantization error. Then we propose a structural replacement, quantization of
ANN activation and residual fix to allevicate the disparity. We evaluate our
method on challenging dataset MS COCO, PASCAL VOC and our spike dataset. The
experimental results show that the proposed method achieves higher accuracy and
lower latency compared to previous work Spiking-YOLO. The advantages of SNNs
processing of spike signals are also demonstrated.
Nemin Qiu, Chuang Zhu
# Low Latency Spiking Neural Network for Object Detection

###### Abstract

Spiking Neural Networks (SNNs), as a third-generation neural network, are well-suited for edge AI applications due to their binary spike nature. However, when it comes to complex tasks like object detection, SNNs often require a substantial number of time steps to achieve high performance. This limitation significantly hampers the widespread adoption of SNNs in latency-sensitive edge devices. In this paper, our focus is on generating highly accurate and low-latency SNNs specifically for object detection. Firstly, we systematically derive the conversion between SNNs and ANNs and analyze how to improve the consistency between them: improving the spike firing rate and reducing the quantization error. Then we propose a structural replacement, quantization of ANN activation and residual fix to alleviate the disparity. We evaluate our method on challenging dataset MS COCO, PASCAL VOC and our spike dataset. The experimental results show that the proposed method achieves higher accuracy and lower latency compared to previous work Spiking-YOLO. The advantages of SNNs processing of spike signals are also demonstrated.

Nemin Qiu, Chuang Zhu\({}^{\star}\)School of Artificial Intelligence, Beijing University of Posts and Telecommunications.

czhu@bupt.edu.cn SNN; ANN-SNN conversion; Time steps; Low latency.

## 1 Introduction

Artificial neural networks have achieved great success in computer vision [1], natural language processing, and other domains. Despite these achievements, there still exists a fundamental difference between the operational mechanisms of artificial neural networks and human neural activity. Consequently, some researchers have begun studying neural networks that emulate the neural activity of the human brain. Spiking neural networks (SNNs) are considered as the third generation of neural network models, utilizing simplified yet biologically realistic neuron models for computation. SNNs differ from traditional artificial neural networks, such as convolutional neural networks (CNNs), in that they transmit activation data between layers as sequences of binary spikes, following specific firing rules. SNNs significantly reduce computational resource requirements and effectively avoids excessive resource consumption [2]. As SNNs have demonstrated successful applications in edge AI [2], research in this field is gaining increased attention from researchers.

In general, there are two mainstream methodologies for developing deep supervised SNNs up to date: direct training for SNNs and converting ANNs into SNNs. However, directly trained SNNs generally do not achieve better performance on relatively complex vision scenes and tasks [2]. For directly trained SNNs, on the one hand,the back-propagation algorithm could not be applied to SNNs as spiking activation functions are inherently non-differentiable. It is hard to find a way to update the SNN neural network weights well. This leads to difficulties in achieving satisfactory performance of SNN on tasks with complex scenarios. On the other hand, directly trained SNNs usually use complex neuron models without specified optimization for storage and operation with binary events. This leads to less practicality[2].

For converted SNNs, as they are transferred from a certain pre-trained ANN model, it is possible to make the SNN achieve a performance close to that of the ANN. in order to attain sufficient representation precision, a considerable number of time steps are usually required for a nearly lossless conversion, which is known as the accuracy-delay tradeoff. This tradeoff significantly restricts the practical application of SNNs. The consumption of a large number of time steps can result in a significant delay in SNN inference, which is detrimental for certain real-time tasks, such as the object detection task emphasized in this paper. Recent works [3][4] propose methods to alleviate this problem by exploiting the quantization and clipping properties of aggregation representations. However, these works primarily focus on the image classification task and overlook the impact of residual voltage and neuron firing rate on error propagation. There still exists a noticeable performance gap between ANNs and SNNs when it comes to low inference latency, and the underlying cause for this degradation remains unclear.

In this work, we identify that the conversion error under low time steps mainly arises from low spike firing rate, quantization error, and the misrepresentation of residual membrane potential. These factors accurately characterize the information loss between the input and output of spiking neurons with asynchronous spike firing. Inspired by these findings, we propose methods to address these issues, namely the low spike firing rate layer replacement, quantization ac
tivation, and residual fix methods. By implementing these techniques, we generate an SNN for object detection that achieves remarkable performance with an extremely low inference delay. The main contributions of this work can be summarized as follows:

* We describe the specific conversion process of ANNs to SNNs and model the errors introduced during the ANN-SNN conversion. Then we propose methods to reduce these errors.
* We propose a scheme for layer replacement in the low spike firing rate layer and quantized ANNs activation for the adaptation conversion. In the first phase, some SNNs-unfriendly layers were replaced in the ANNs before conversion. Quant-ReLU functions are applied to finetune ANNs. In the second phase, using residual fix mechanisms in IF neurons.
* We verify the effectiveness and efficiency of the proposed methods on the MS COCO, PASCAL VOC and spike dataset. Experimental results show significant improvements in accuracy-latency tradeoffs compared to previous works.

## 2 Related Work

Existing SNNs are generally divided into two fields to study, directly trained SNNs and converted SNNs [5]. For directly trained SNNs, unsupervised and supervised learning are both attractive research topics. On the one hand unsupervised learning, the mainstream learning method is the spike timing dependent plasticity rule (STDP). STDP uses synaptic plasticity and spike activity to learn features of input data, which is biologically plausible. On the other hand, the supervised SNNs can achieve much better performance given a large number of labeled training data. There are some successful attempts that introduce BP into SNN models, such as STBP, SLAYER, BPSTDP, which achieve good performance on some simple cognitive tasks.

The conversion of ANN-SNN is in burgeoning research. Cao et al. [6] proposed a ANN-SNN conversion method that neglected bias and max-pooling. In the next work, Diehl et al [7] proposed data-based normalization to improve the performance in deep SNNs. Rueckauer et al [8] presented an implementation method of batch normalization and spike max-pooling. Sengupta et al [5] expanded conversion methods to VGG and residual architectures. Nonetheless, most previous works have been limited to the image classification task [8]. Kim et al [2] have presented Spiking-YOLO, the first SNN model that successfully performs objectdetection by achieving comparable results to those of the original DNNs on non-trivial datasets, PASCAL VOC and MS COCO. Ding et al [4] presented Rate Norm Layer to replace the ReLU function, and obtain the scale through a gradient-based algorithm. Conversion approaches have revealed their potential of achieving ANN level performance in various tasks [2]. However, taking advantage of the artificial neural network's success, network conversion outperforms other methods without auxiliary computation power involved. converted SNN model suffers from efficiency problems. SNNs converted require massive timesteps to reach competitive performance [2]. All of them are complicated procedures vulnerable to high inference latency [2]. Converted SNNs still suffer from increased energy consumption, long inference time and high time delays [2]. Building on these previous efforts, We put toward to minimize the ANN-to-SNN conversion error in complex visual scene tasks, using ultra-low latency when achieving high precision SNNs.

## 3 Preliminaries

In this section, we introduce the activation propagation rule of ANNs and the working principle of the spiking neurons.

**ANN:** Let \(x\) denote the activation. The relationship between the activation of the two adjacent layers is as follows:

\[x_{k}^{l}=f(\sum_{j}(w_{k,j}^{l}\cdot x_{j}^{l-1})+b_{k}^{l}), \tag{1}\]

where \(w_{k,j}^{l}\) represents weights, \(b_{k}^{l}\) represents biases, and the activation \(x_{k}^{l}\) represents the activation of neuron \(k\) in layer \(l\). \(f(.)\) is a type of activation function.

**SNN:** Let us focus on the IF neuron model. Let \(U_{k}^{l}(t)\) denote a transient membrane potential increment of spiking neuron \(k\) in layer \(l\):

\[U_{k}^{l}(t)=\sum_{j}(w_{k,j}^{l}\cdot\Theta_{t,j}^{l-1})+b_{k}^{l}, \tag{2}\]

where \(\Theta_{t,k}^{l}\) denotes a step function indicating the occurrence of a spike at time \(t\):

\[\Theta_{t,k}^{l}=\Theta(V_{k}^{l}(t-1)+U_{k}^{l}(t)-V_{k,th}), \tag{3}\]

\[\mathrm{with}\ \Theta(x)=\left\{\begin{array}{ll}1,&x\geq 0\\ 0,&\mathrm{otherwise}\end{array}\right., \tag{4}\]

The spiking neuron integrates inputs \(U_{k}^{l}(t)\) until the membrane potential \(V_{k}^{l}(t-1)\) exceeds a threshold \(V_{k,th}\) and a spike is generated. After a spike is fired at time \(t\), the membrane potential is reset. The formula for resetting \(V_{k}^{l}(t)\) is as follows:

\[V_{k}^{l}(t)=V_{k}^{l}(t-1)+U_{k}^{l}(t)-V_{k,th}\Theta_{t,k}^{l}. \tag{5}\]

## 4 Method

In order to solve the problem of high latency of SNN for object detection task, this paper proposes a method to generate low latency object detection SNN network. Figure 1 illustrates the overall flow of the generation. The 'unfriendly'
modules in the ANN network are first replaced,then the BN layer is fused into the convolution or linear layer. After completing the restructuring of the network, we use Quant-ReLU instead of ReLU, and use quantization training to update the parameters. After completing training, the weights are subsequently converted using the conversion formula [8], the original activation function is replaced using IF neurons, and finally residual fix is added to further reduce the conversion error. This section describes these improvements that we have proposed through our ANN-SNN conversion error modeling.

### ANN-SNN conversion error modeling

In this section, we will introduce the proof of ANN-SNN conversion[8].And from it, we analyze some improvements that will help reduce latency and improve performance after conversion.

To simplify the description, we assume that the interval of time step \(dt=1\), and inferring an image takes \(T\) time steps. The firing rate of each SNN neuron as \(r_{k}^{l}(T)=N_{k}^{l}(T)/T\), where \(N_{k}^{l}(T)=\sum_{t=1}^{T}\Theta_{t,k}^{l}\) is the number of spikes generated. From the above definition, it is clear that the firing rate of IF neurons \(r_{k}^{l}(T)\,\in\,[0,1]\). Moreover, it is clear that the firing rate is discrete, and has a resolution of 1/T.

Assume that the initial membrane potential is zero \(V_{k}^{l}(0)=0\). After accumulating T time steps, the membrane potential at any time point \(T\) is given as \(V_{k}^{l}(T)=\sum_{t=1}^{T}\,U_{k}^{l}(t)-V_{k,th}\cdot N_{k}^{l}(T)\). From this we can deduce \(N_{k}^{l}(T)=\lfloor\frac{\sum_{t=1}^{T}U_{k}^{l}(t)-V_{k}^{l}(T)}{V_{k,th}}\rfloor\), and then the firing rate \(r_{k}^{l}(T)\) is:

\[r_{k}^{l}(T)=\frac{N_{k}^{l}(T)}{T}=\frac{\lfloor(\frac{\sum_{t=1}^{T}U_{k}^{l }(t)}{V_{k,th}\cdot T}-\frac{V_{k}^{l}(T)}{V_{k,th}\cdot T})\cdot T\rfloor}{T}. \tag{6}\]

\[r_{k}^{l}(T)=\frac{N_{k}^{l}(T)}{T}=\frac{\sum_{t=1}^{T}U_{k}^{l}(t)}{V_{k,th} \cdot T}-\frac{V_{k}^{l}(T)}{V_{k,th}\cdot T}. \tag{7}\]

Assume that the threshold \(V_{k,th}=1\). With this subtraction mechanism, let the Eq. (6) change to:

\[r_{k}^{l}(T)=\frac{\lfloor(\sum_{j}(w_{k,j}^{l}\cdot\frac{\sum_{t=1}^{T}\Theta _{t,j}^{l-1}}{T})+b_{k}^{l}-\frac{V_{k}^{l}(T)}{T})\cdot T\rfloor}{T}, \tag{8}\]

\[r_{k}^{l}(T)=\frac{\lfloor(\sum_{j}(w_{k,j}^{l}\cdot r_{j}^{l-1}(T))+b_{k}^{l }-\frac{V_{k}^{l}(T)}{T})\cdot T\rfloor}{T}. \tag{9}\]

Here we define an approximation of the firing rate \(\widehat{r}_{k}^{l}(T)\):

\[\widehat{r}_{k}^{l}(T)=\sum_{j}(w_{k,j}^{l}\cdot r_{j}^{l-1}(T))+b_{k}^{l}- \frac{V_{k}^{l}(T)}{T}. \tag{10}\]

The relationship between the approximation and the true value of firing rate is:

\[r_{k}^{l}(T)=\frac{\lfloor(\widehat{r}_{k}^{l}(T))\cdot T\rfloor}{T}. \tag{11}\]

**ANN to SNN**: The similarity of IF neurons and ReLU activation functions is an important basis on which ANNs can be converted to SNNs. The principle of ANN-SNN conversion is that the firing rates of spiking neuron \(r_{k}^{l}(T)\) should correlate with the original ANN activations \(x_{k}^{l}\) such that \(r_{k}^{l}(T)\)\(\rightarrow\)\(x_{k}^{l}\). Setting \(V_{k}^{l}(0)=0\), \(V_{k,th}=1\). Figure 2 shows the corresponding relationship between the output of ReLU activation function in ANN and the output of firing rate in SNN with the input \(\hat{x}_{k}^{l}=\sum_{j}(w_{k,j}^{l}\cdot x_{j}^{l-1})+b_{k}^{l}\) and \(r_{k}^{l}(T)=\sum_{j}(w_{k,j}^{l}\cdot r_{j}^{l-1}(T))+b_{k}^{l}\).

### Low spike firing rate layer replacement method

After the derivation in Section 4.1, we can know that the purpose of the conversion is to make \(r_{k}^{l}(T)=\sum_{j}(w_{k,j}^{l}\cdot r_{j}^{l-1}(T))+b_{k}^{l}\). Let us define that the following \(\frac{V_{k}^{l}(T)}{T}=Re\)

Figure 1: Overall flow of training phase and converting phase.

Figure 2: Firing rate of IF neuron and ReLU.
is a remainder. When the time steps T is very large, the remainder \(Re=\frac{V_{k}^{l}(T)}{T}\approx 0\) and \(r_{k}^{l}(T)\approx\tilde{r}_{k}^{l}(T)\). The other case is that the value of the membrane potential \(V_{k}^{l}(T)\) is exactly 0 after each T time step. In this case, \(Re=\frac{V_{k}^{l}(T)}{T}=0\). In addition, the remainder relative error is reduced if the first half of Eq. (10) has a larger value. It can be understood as \(r_{k}^{l}(T)\) has a larger spike firing rate. After satisfying the above conditions we can conclude that:

\[r_{k}^{l}(T)\approx\tilde{r}_{k}^{l}(T)\approx\sum_{j}(w_{k,j}^{l}\cdot r_{j}^ {l-1}(T))+b_{k}^{l}. \tag{12}\]

After the above analysis, it is known that the low spiking firing rate introduces a large error in the ANN-SNN conversion method. The previous works did not bother about the impact that the modules in the network structure bring to the ANN-SNN conversion, we counted the spike firing rate of each layer, and we found that the spike firing rate decreased very seriously in the maximum pooling layer. However, the down-sampling operation inevitably causes the loss of spike information in the convolutional feature map, which affects the detection accuracy. Down-sampling of spike information requires a more accurate information integration process. Considering this, we modified the original network model structure by replacing the network structure of the original model using downsampling convolution and transposed convolution. After the replacement and conversion, we found some improvement in the spike firing rate of neurons in this layer, the time step required for the original model to achieve the same accuracy is shorter.

### Quantizition activation and residual fix methods

In addition to the analysis of spiking firing rate on the network structure. According to equations Eq. (10) and Eq. (11), we also analyzed that there is a quantization error due to the gap between the two activation patterns during the conversion, Figure 3 shows the activation resolution of the spiking neural network is 1/T (T is the time step). Obviously if reducing the gap between the expression of the two neurons helps to reduce the conversion error. For the SNN, we added a residual recovery setting. To address the residual error, we set a specific initial value for the membrane potential when configuring it. This helps to reduce the difference between the activation forms of IF neurons and ReLU neurons in the ANN network. For the ANN, We set the activation value of the activation function ReLU of ANN to be discrete and the resolution is also 1/T. so we proposed a strategy of activation substitution in the training phase and setting the initial membrane potential to reduce the error between the two.

Specifically, our scheme is using Quant-ReLU activation (quantization clipping function) instead of ReLU activation in the pre-transformation ANN training. learning and continuously reducing the quantization error through powerful ANN training methods, making the activation form of the SNN simulated in the training phase. Quant-ReLU activation is more similar to the activation form of IF neurons of the SNN. For residual fix, we set the initial membrane potential \(V_{k}^{l}(0)=0.5\). This setting makes the output firing rate of IF neurons and the input firing rate as shown in the green line in Figure 3, which can greatly reduce the quantization error. In terms of theoretical calculations, the average error ratio of the two methods (red and green lines) is 2 to 1. Similarly, the activation form of Quant-ReLU is also set to this form, which facilitates the ANN training to get the best performance.

Finally, we need to convert the weights of the ANN according to the weight conversion formula (due to the characteristics of spiking neurons, the spiking frequency cannot be higher than one) [8]. After the weight conversion as mentioned in main paper, Eq. (1) changes to the following form:

\[x_{k}^{l}=f(\sum_{j}(\hat{w}_{k,j}^{l}\cdot x_{j}^{l-1})+\hat{b}_{k}^{l}), \tag{13}\]

After weight conversion, the range of \(x_{k}^{l}\) is [0,1]. According to the definition of ReLU activation function, Eq. (13) can then be changed to the following form:

\[x_{k}^{l}=\sum_{j}(\hat{w}_{k,j}^{l}\cdot x_{j}^{l-1})+\hat{b}_{k}^{l}, \tag{14}\]

After applying the weights to the SNN (\(\hat{w}_{k,j}^{l}{\rightarrow}w_{k,j}^{l}\) and \(\hat{b}_{k}^{l}{\rightarrow}b_{k}^{l}\)), Eq. (12) can then be changed to the following form:

\[r_{k}^{l}(T)\approx\sum_{j}(\hat{w}_{k,j}^{l}\cdot r_{j}^{l-1}(T))+\hat{b}_{k} ^{l}. \tag{15}\]

It can be seen that between two adjacent layers, SNN and ANN pass features with the almost same formula.

## 5 Experiment and Evaluation

In this section, all experiments are performed on NVIDIA Tesla V100 32G GPUs and based on the Pytorch framework.

Figure 3: The firing rate of the IF neuron and ANN ReLU.
For the object detection task, we compare our low-latency SNN detection network with the previous work Spiking-YOLO [2]. Our experiment is tested on MS COCO and PASCAL VOC dataset. In addition we tested on our spike dataset. Our spike dataset is mainly for object detection of people and vehicles in some traffic scenarios. Our spike dataset involved in this work are captured using spiking cameras [9] or by encoding the video with spike encoder [2]. The detection results of our experiments are evaluated using mAP50(\(\%\)).

Table 1 illustrates the significant time step savings of our method over Spiking-YOLO [2] on the dataset MS COCO, we only need 150 time steps to achieve comparable performance, and our method achieves a huge improvement (+10.54) in accuracy at 300 time steps. When comparing our method to STDP-Spiking [10], which utilizes direct training with a similar network structure, we have consistently demonstrated superior performance. Even when considering a time frame of 300 steps, our approach outperforms this method as well. Table 2 illustrates the significant time step savings of our method over Spiking-YOLO [2] on the dataset PASCAL VOC, we only need 150 time steps to achieve comparable performance, and our method achieves a considerable improvement (+2.37) in accuracy at 300 time steps. By using our method, SNN with better performance can be obtained. To summarize Table 1 and Table 2, the inclusion of residual fix in our approach yields a slight yet notable performance gain.

Experiments show that on MS COCO and PASCAL VOC datasets, SNNs generated using our method can significantly reduce the time step required for inference, with our method requiring only 1/23 of the time step of spiking-yolo to achieve the same accuracy, and our method achieves good performance at 300 time steps. This highlights the effectiveness of our method in pushing the boundaries of SNN capabilities and achieving superior results in neural network applications.

Table 3 shows the improvement of SNN compared to ANN for the same network structure on the spike dataset we produced. This dataset is composed of gray images, along with the corresponding spike data and annotation information. This demonstrates that SNNs may have an inherent advantage when processing spike signals.

Figure 4 shows some visualization results of object detection using our spiking neural network, with images from both the MS COCO and our spike dataset. In this experiment, we set all time steps to 300. Specifically, for the MS COCO, when performing detection, we will convert the images to spikes first, then use SNN to perform detection and output the detection results to the original images. For our spike dataset, we directly perform detection on the spike data and visualize the results to their corresponding images.

## 6 Conclusion

In this paper, we present a low latency SNN generation method by object detection task for accurate conversion with low latency. We theoretically analyze the error of the ANN-SNN conversion process and illustrate the influence of the quantization error and spike firing rate on the accurate conversion. Then we propose low spike firing rate layer replacement method. It significantly reduces the problem of firing rate due to spike feature scale variation in SNN networks, thus reducing the inference time step required for the

\begin{table}
\begin{tabular}{c c c c} \hline Method & Neural Model & Time Steps & mAP \\ \hline Spiking-YOLO [2] & IBT & 3500 & 25.66 \\ \hline STDP-Spiking [10] & IF & 300 & 26.8 \\ \hline Ours & IF w IMP & 100 & 14.8 \\ \hline Ours & IF w IMP & **150** & 26.3 \\ \hline Ours & IF w IMP & 200 & 31.5 \\ \hline Ours & IF w IMP & 250 & 34.2 \\ \hline Ours & IF w/o IMP & 300 & 35.7 \\ \hline Ours & IF w IMP & 300 & **36.2** \\ \hline \end{tabular}
\end{table}
Table 1: Comparison of the object detection performance between our method (Ours) and Spiking-YOLO [2] (using IBT neuron [2]) on PASCAL VOC. (w IMP or w/o IMP means the IF neuron of SNN with or without residual fix.)

\begin{table}
\begin{tabular}{c c c c} \hline Method & Network & Time Steps & mAP \\ \hline ANN & Tiny-yolov3 & - & 51.6 \\ \hline Ours & SNN-Tiny-yolov3 & 64 & 45.0 \\ \hline Ours & SNN-Tiny-yolov3 & 128 & 50.9 \\ \hline Ours & SNN-Tiny-yolov3 & 256 & **52.4** \\ \hline \end{tabular}
\end{table}
Table 3: Comparison of the object detection performance between our method (Ours) and ANN [1] on our dataset. (The input of ANN is the spike signal reconstructed into gray image, and the input of SNN is the spike signal.)
network. To address the problem of quantization error, we propose the mechanism of quantization activation function Quant-ReLU and residual fix to alleviate the above problem. The experimental results show that the time step required for SNN network inference is greatly reduced after using the above method, thus greatly reducing the real-time delay of the detection network. Beyond the object detection task, the proposed methods are theoretically generalizable to other SNN tasks.
