Training-free Conversion of Pretrained ANNs to SNNs for Low-Power and High-Performance Applications
Tong Bu Maohua Li Zhaofei Yu














Training-free Conversion of Pretrained ANNs to SNNs for Low-Power and High-Performance Applications
    
    Tong Bu Equal contributors 

    School of Computer Science

    Peking University

     

    Maohua Li [1] 

    School of Artificial Intelligence and Automation 

    Hohai University

     

    Zhaofei Yu Corresponding author

    Institution for Artificial Intelligence

    Peking University 

     


    
=============================================================================================================================================================================================================================================================================================================================



§ ABSTRACT 
Spiking Neural Networks (SNNs) have emerged as a promising substitute for Artificial Neural Networks (ANNs) due to their advantages of fast inference and low power consumption. However, the lack of efficient training algorithms has hindered their widespread adoption. Existing supervised learning algorithms for SNNs require significantly more memory and time than their ANN counterparts. Even commonly used ANN-SNN conversion methods necessitate re-training of ANNs to enhance conversion efficiency, incurring additional computational costs. To address these challenges, we propose a novel training-free ANN-SNN conversion pipeline. Our approach directly converts pre-trained ANN models into high-performance SNNs without additional training. The conversion pipeline includes a local-learning-based threshold balancing algorithm, which enables efficient calculation of the optimal thresholds and fine-grained adjustment of threshold value by channel-wise scaling. We demonstrate the scalability of our framework across three typical computer vision tasks: image classification, semantic segmentation, and object detection. This showcases its applicability to both classification and regression tasks. Moreover, we have evaluated the energy consumption of the converted SNNs, demonstrating their superior low-power advantage compared to conventional ANNs. Our training-free algorithm outperforms existing methods, highlighting its practical applicability and efficiency. This approach simplifies the deployment of SNNs by leveraging open-source pre-trained ANN models and neuromorphic hardware, enabling fast, low-power inference with negligible performance reduction.
  













§ INTRODUCTION

Recent advancements in large models have significantly reshaped the landscape of deep learning technology, industry, and the research community. These advanced models, characterized by their massive scale and unprecedented zero-shot generalizability in downstream tasks, greatly impact our daily lives. Nevertheless, the pursuit of larger models raises concerns about high energy consumption for model inference and training. The deployment of large models on resource-constrained devices has also become a challenge. Spiking Neural Networks (SNNs), known for their fast inference and low power consumption, offer a potential solution to these issues as an alternative to Artificial Neural Networks (ANNs).


Spiking neural networks are a well-established type of neural network that mimics the function of biological neurons and are considered the third generation of ANNs <cit.>. Unlike conventional ANNs, SNNs utilize more complex spiking neurons as their basic components and employ diverse encoding methods. Spiking neurons have two main characteristics: they encode information as discrete events (binary spikes or action potentials) and generate output based on their inputs and current internal state. These characteristics enable spiking neurons to process spatio-temporal information and use sparse representation, attracting increasing attention from researchers.






With the development of the neuromorphic computing hardware <cit.>, SNNs can be deployed on neuromorphic chips and further applied in power-limited scenarios <cit.>. However, the lack of efficient training algorithms has hindered the widespread application of SNNs. Recent learning methods have made progress in training deep CNN-based SNNs <cit.> or large spiking transformers using supervised learning algorithms <cit.>. 
Although SNNs obtained through supervised training require little inference time and have comparable performance to ANNs with the same network architecture, the memory and time cost of training an SNN, which is linearly proportional to the inference time-step, can be multiple times higher than that of an ANN. This makes it impractical to train large energy-efficient models.

 ANN-SNN conversion is another feasible way to train SNNs <cit.>. ANN-SNN conversion algorithms are designed to obtain SNNs from pre-trained ANNs with little computational cost. However, the converted SNNs often need more inference time-steps to achieve comparable performance as ANNs, which can increase inference latency and energy consumption. One possible solution is to retrain a modified ANN and then convert it to an SNN, which significantly improves SNN performance while reducing inference time-steps <cit.>. Although retraining-based ANN-SNN conversion methods perform better in most tasks, the cost of retraining an ANN is not negligible. In Figure <ref>-a/b, we compare the supervised training method <cit.>, hybrid training method <cit.>, training-required ANN-SNN conversion method <cit.> and our training-free ANN-SNN conversion method. We find that the training-free conversion method can efficiently train SNNs with very little computational overhead while balancing performance and inference speed. In Figure <ref>-c, we further clarify the difference between training-free and training-required conversion. Training-free methods allow for the conversion of SNNs from open-source pre-trained ANN models, reducing or even eliminating dependence on GPU resources.
Therefore, in this paper, we are looking for an algorithm that can directly get high-performance SNNs from pre-trained ANNs without additional training or finetuning. This simplifies the deployment of spiking neural networks by directly obtaining SNNs from the open-source pre-trained ANN models and directly applying SNNs to the neuromorphic chip.

In this paper, we provide a solution for the training-free conversion of high-performance and low-power SNNs. We mainly focus on developing a general conversion method, applicable to different models and tasks. By improving the data-based threshold balancing algorithm, we utilize a more effective local learning approach for fast ANN-SNN conversion without relying on costly backpropagation-based training or fine-tuning.

Our contribution can be summarized as follows:




    
  * We introduce the concept of training-free ANN-SNN conversion. Such conversion methods are able to obtain high-performance SNNs from pre-trained ANN models without any additional training or fine-tuning. Due to the advantage of low training cost, the training-free algorithms are more feasible solutions for developing large-scale SNNs.
    
  * We propose an efficient training-free algorithm, theoretically deriving the upper bound of the conversion error between the original ANN and the converted SNN. To minimize the conversion error bound, we introduce a local threshold balancing method for threshold value optimization, which can efficiently convert pre-trained ANN model into their SNN counterparts using very little computational resources.
    
  * We successfully scale our conversion framework to three typical computer vision tasks. In conventional image classification tasks, our training-free algorithm outperforms other training-free conversion-based methods. Additionally, we implement ANN-SNN conversion on multiple regression-based vision tasks, including semantic segmentation
    and object detection tasks, demonstrating the practical applicability of the training-free ANN-SNN conversion algorithm.
    




§ RELATED WORKS

Researchers have endeavoured to explore effective SNN training approaches for decades. Due to the brain-like characteristics of SNNs, early research mainly focused on the unsupervised Spike-Timing-Dependent Plasticity (STDP) algorithm, inspired by the Hebbian learning principles <cit.>. These studies mainly aimed to utilize the STDP algorithm to train shallow networks and design unsupervised feature extractor <cit.>. At the same time, supervised training approaches have been developed to achieve high-performance SNNs. <cit.> were pioneers in applying the backpropagation algorithm to train SNNs, introducing a temporal-based backpropagation method that uses timestamps as intermediate variables during gradient backpropagation. In another approach, Wu et al. <cit.> treated SNNs as recurrently connected networks and utilized Back Propagation Through Time (BPTT) for training, termed spatial-temporal backpropagation (STBP). Unlike these methods, Cao et al. <cit.> proposed an ANN-SNN conversion method that achieves high-performance SNNs from pre-trained ANNs. Currently, research efforts are primarily focused on enhancing the efficiency of training algorithms for high-performance SNNs, leveraging the three methods mentioned above.

Based on the training cost, those learning methods of SNNs can be ascribed into two types, training-free learning methods and training-required learning methods. The training-required methods, including direct training of SNNs <cit.>, conversion from re-trained ANNs<cit.> and finetuning for converted SNNs <cit.>, usually requires the participation of the back-propagation algorithms on the GPUs.

The training-free learning methods are conversion-based algorithms that directly convert the pre-trained ANN into SNN without additional training or finetuning. <cit.> mapped the weights of a light CNN network to an SNN and reported a great improvement of the energy efficiency based on the hardware analysis. Since the conversion-based method have nature advantage for fast training of neuromorphic-hardware-compatible spike-based networks, researchers began to explore advanced conversion techniques targeting for high-performance SNNs. <cit.> propose a weight and threshold balancing method to avoid performance degradation. <cit.> further extend the conversion-based learning to LIF neurons. The theoretical framework of the conversion-based algorithm has been proposed by <cit.>. A more effective threshold balancing method, robust normalization, is proposed to balance the inference latency and accuracy <cit.>. <cit.> convert ANN to temporal coding SNNs and promote accuracy and further use the reset-by-subtraction mechanism instead of the reset-to-zero mechanism to prevent information loss in <cit.>. The conversion-based method can also be applied to regression tasks such as object detection, as <cit.> successfully converted a spike-based object detection model. <cit.> suggest adding initial membrane potential for better performance and low latency. <cit.> use a light conversion pipeline to search optimal threshold and add a bias term at each inference step. Although performance is limited, those lightweight training methods are able to acquire SNNs from pre-trained ANNs with negligible cost of multiple iterations of inference. 



§ PRELIMINARIES



 §.§ Neuron Models


The core components of conventional ANNs are point neurons, where their forward propagation can be represented as a combination of linear transformations and non-linear activations, that is 

    a^l=f(w^l a^l-1).

Here, w^l is the weights between layer l-1 and layer l, a^l is the activation vector in layer l, and f(·) denotes the non-linear activation function, commonly set as the ReLU function or its variants.


The neurons in SNNs are spiking neurons with temporal structures. Like most ANN-SNN conversion methods  <cit.>, we employ the commonly used Integrate-and-Fire (IF) neuron  <cit.> in this paper. 






For computational convenience, we use the following discrete neuron function:







    v^l(t^-)   =v^l(t-1)+w^ls^l-1(t)θ^l, 
    s^l(t)   = H(v^l(t^-)-θ^l),
    v^l(t)   = v^l(t^-)-θ^l s^l(t).

Here s^l(t) describes whether neurons in layer l fire at time-step t and the trigger is that the membrane potential before firing v^l(t^-) reaches the firing threshold θ^l, as represented by the Heaviside step function H(·). For membrane potential after spike firing v^l(t), we consider the “reset-by-subtraction” mechanism <cit.> to alleviate information loss. Specifically, after emitting a spike, the membrane potential is subtracted by the threshold θ^l instead of decaying to the resting potential. 










 §.§ ANN-SNN Conversion

The pivotal idea of ANN-SNN conversion is to map the activation of analog neurons to the postsynaptic potential (or firing rate) of spiking neurons. Specifically, by accumulating the neuron function (Equations (<ref>) and (<ref>)) from 1 to T and dividing both sides by time-step T, we obtain:

    1/T(v^l(T)-v^l(0))=1/T∑_t=1^Tw^ls^l-1(t) θ^l-1 -1/T∑_t=1^Tθ^ls^l(t).

This equation reveals a linear relationship between the average firing rate of neurons in adjacent layers by defining average postsynaptic potential as r^l(t) = ∑_i=1^t s^l(i) θ^l /t:

    r^l(T)=w^l r^l-1(T)-1/T(v^l(T)-v^l(0)).

As T → +∞, we can generally assume that the conversion error approaches zero. Therefore, using the equations presented, a trained ANN model can be converted to an SNN by replacing ReLU neurons with IF neurons, which is the primary principle of ANN-SNN conversion. Note that Equations (<ref>) and (<ref>) are not identical, indicating that some conversion error typically remains.










    














  §.§.§ Threshold Balancing

The most common methods to reduce the conversion errors discussed above include threshold balancing <cit.> and weight scaling algorithms <cit.>. 
Both approaches aim to adjust the synaptic weights or neuron thresholds according to the neuron input distribution range, thus minimizing the clipping error. Previous studies have shown that weight scaling and threshold balancing are equivalent in effect and can achieve high-performance SNNs <cit.>. For the sake of simplicity, we adopt the threshold balancing method here, which involves determining the optimal threshold value for each layer, allowing the weights to remain consistent between the ANN and SNN models.

There are mainly two types of threshold balancing algorithms: model-driven and data-driven algorithms. The former calculates the maximum activation value from the given model weights, and uses it as the threshold. The latter involves sampling a subset of data from the training set for inference, obtaining a statistical distribution of activation values, and then determining the threshold with specific algorithms. Data-driven algorithms are typically more effective and have been widely used in recent works <cit.>. For example, one commonly used training-free conversion method is robust normalization, which sets the threshold at the 99-th percentile of the total activity distribution. The algorithm presented in this paper also utilizes a data-driven approach.



§ METHODS

In this section, we present our training-free ANN-SNN conversion pipeline. First of all, we define the conversion error and derive its upper bound. After that, we propose a local threshold balancing method based on a local learning rule. Additionally, we also introduce the channel-wise threshold balancing technique, which refines the scaling parameter to enhance overall performance without altering the behavior of IF neurons.



 §.§ Conversion Error Bound

We follow the representation of the conversion error from <cit.> and define the layer-wise conversion error e^l in layer l as the 2-norm between the postsynaptic potential of neurons in SNNs and the activation output of neurons in ANNs, that is 

    e^l    = ‖PSP(ẑ^l; θ^l) - ReLU(z^l)‖_2.

Here, ẑ^l = w^l r^l-1 denotes the average input current from layer l-1 in SNNs, and z^l = w^l a^l-1 represents the activation input from layer l-1 in ANNs. Both the ANN model and SNN model share the same weights, denoted as w^l. The ReLU(z) represents the output of nonlinear ReLU activation function while PSP(ẑ^l; θ^l)=r^l(T) represents the average output synaptic potential at the last time-step T with given average input ẑ^l. 

Since our goal is to minimize the error of the final outputs in most tasks, we can define the conversion error between the ANN and SNN models as the layer-wise conversion error in the last layer L, denoted as e_model = e^L. A straightforward approach is to use the conversion error between models as the loss function and optimize it, which can be viewed as a variant of knowledge distillation. However, this training method is similar to the supervised training of SNNs, which is costly in terms of time and memory. To address this, we scale the conversion error and estimate the error upper bound, thereby simplifying the task. We present the following theorem.



Theorem 1 The layer-wise conversion error can be divided into intra-layer and inter-layer errors:

    e^l    ⩽‖PSP(ẑ^l; θ^l) - ReLU(ẑ^l)‖_2^intra-layer error + ‖w^l ‖_2 e^l-1^inter-layer error.

Given that both ANN and SNN models receive the same input in the first layer, resulting in e^0 = 0, the upper bound for the conversion error between models in a L-layer fully-connected network is 

    e_model=e^L    ⩽∑_l=1^L (∏_k=l+1^L‖w^k ‖_2 ) ‖PSP(ẑ^l; θ^l) - ReLU(ẑ^l) ‖_2












The detailed proof is provided in the Appendix. Theorem 1 indicates that the conversion error is bounded by the weighted sum of the error in each layer. Based on Theorem 1, we will derive the local threshold balancing algorithm in the next section.



 §.§ Local Threshold Balancing Algorithm


The target of ANN-SNN conversion is to minimize the conversion error and achieve high-performance SNNs.  An alternative approach involves optimizing the error bound, defined as:

    min_θ𝔼_x^0 ∈𝒟[ ∑_l=1^L (∏_k=l+1^L‖w^k ‖_2 ) ‖PSP(ẑ^l; θ^l) - ReLU(ẑ^l) ‖_2  ].

Here θ represents the set of threshold values to be optimized across all layers, that is, θ={θ^1,θ^2,...,θ^L}. x^0 represents the input data sample drawn from the dataset 𝒟. This approach leverages data-driven conversion, minimizing the expectation of the conversion error bound over the data distribution.  To reduce computational costs during optimization, we made some simplifications. Firstly, we use a greedy strategy to optimize the threshold θ, allowing the optimization process to be performed layer by layer,

which is 

    For each layer l, min_θ^l𝔼_x^0 ∈𝒟[  (∏_k=l+1^L‖w^k ‖_2 ) ‖PSP(ẑ^l; θ^l) - ReLU(ẑ^l) ‖_2  ].

Secondly, we simplify the function PSP(·; θ) by neglecting its temporal dynamics and approximating it with the clipping function ReLUX(·; θ). Previous works have demonstrated that the PSP and clipping functions can be identical given sufficient number of time-steps <cit.>. We utilize the squared norm in the objective function for smoother optimization. The optimization problem then becomes:


    For each layer l,    min_θ^l𝔼_x^0 ∈𝒟 (∏_k=l+1^L‖w^k ‖_2 ) ‖ReLUX(ẑ^l;θ^l) - ReLU(ẑ^l)‖_2^2, 
    where    ReLUX(·; θ) = min (max(0, x), θ).

Intuitively, we can employ the stochastic gradient descent algorithm to optimize the threshold. Since ∏_k=l+1^L‖w^k ‖_2 can be considered as a constant when the weights are fixed for each layer, this term can be absorbed into the parameter learning rate. The final update rule for the local threshold balancing algorithm at each step is:

    Δθ^l    =  - 1/N∑_i=0^N 2(ẑ^l_i-θ^l)H(ẑ^l_i-θ^l), 
    θ^l    ←θ^l - ηΔθ^l.

Detailed derivation is provided in the Appendix. Here Δθ^l is the value of the step size during optimization and η is the learning rate or update step size. N is the number of elements for the input vector while ẑ_i denotes each element in the vector ẑ^l. H(·) is the Heaviside step function. 

In practice, as shown in Figure <ref>, we jointly optimize the threshold for each layer by sampling a small set of image samples from the training dataset. Before starting the conversion process, we first replace all ReLU functions by ReLUX functions and set the initial value of the threshold to zero. We then randomly sample data batches from the training dataset and run model inference with these data samples. The thresholds are locally updated during the inference process until they converge. Note that the parameter θ^l is updated locally, ensuring that the computational cost of the conversion process is similar to the inference of the ANN model over the given data samples.





 §.§ Channel-wise Threshold Balancing

During conversion, similar to <cit.>, we employ a channel-wise threshold balancing method, applicable to both fully connected and convolutional layers. 

Different from previous conversion algorithms where all neurons in each layer share a single threshold value, our method utilizes the channel-wise threshold approach, where all neurons in each channel share one threshold value for convolutional layers while each neuron has its independent threshold value for fully connected layers. Specifically, for convolutional layers, we channel-wisely determine the threshold value, while for fully connected layers, we optimize the threshold value element-wise. 

After optimization, the thresholds for each channel can be individually absorbed into the corresponding channel of the convolutional kernel or the weight vectors of the fully connected layers. This channel-wise (or element-wise) operation ensures that the behavior of the IF neuron remains unaffected. This algorithm aims to more precisely determine the optimal threshold value while preserving the fundamental properties of the spiking neuron.





 §.§ Pre-Neuron Maxpooling Layer

The conversion of the max pooling layer is also a challenging problem that needs to be addressed. As a pivotal feature in the process of down-sampling input representations, the max pooling layer is a fundamental component in convolutional neural networks and is widely used in most convolutional architectures. However, due to the binary nature of spiking neurons, max pooling layers cannot effectively perform downsampling in feature maps. Typically, during a single max-pooling operation, multiple elements may have the same value, preventing the extraction of the most salient features. This often leads to the avoidance of using max pooling as a downsampling layer in SNNs. In most previous ANN-SNN methods, the max pooling layer in ANN is often replaced by an average pooling layer, and the model is re-trained or fine-tuned before conversion.

To convert architectures that contain max pooling layers, we propose a simple yet effective method. We replace all max-pooling layers with neuron layers, allowing the pre-neuron floating-point input to go through the downsampling layer before being input into the neurons.






The order of the max pooling layer and ReLU layer does not affect the output results.

    max_i ReLU(z) =  ReLU(max_iz),  when max(z)>0.



The detailed proof is provided in the Appendix. Theorem 2 guarantees that such an operation does not affect the final performance. When deployed on neuromorphic chips or FPGAs, the max pooling operation can be performed through a comparator, preventing an increase in power consumption due to additional floating-point multiplication.



§ EXPERIMENTS

We conduct extensive experiments to demonstrate the effectiveness of our method and highlight its potential practical value. We showcase the advantages of our approach by comparing it with other training-free algorithms and conduct ablation experiments to validate the effectiveness of our local threshold balancing algorithm. Subsequently, we apply our algorithm to three classical visual tasks: image classification, semantic segmentation, and object detection. To underscore the feature that our conversion method does not require additional training, we utilize open-source pre-trained ANN models as the original ANN models for conversion, with most pre-trained models provided by TorchVision <cit.>.
We highlighted the feasibility of our algorithm across both classification and regression tasks, demonstrating its superiority over other conversion algorithms on various datasets.

In addition to the described algorithms, our conversion process incorporated other methods to further enhance the performance of the converted SNN. Firstly, during inference, we applied the membrane potential initialization algorithm <cit.>, setting the threshold membrane potential to half before each inference. We also utilized the delayed evaluation approach when collecting the spike counts of the output layer, ensuring performance with fewer inference steps <cit.>. The pseudocode for our conversion pipeline and the detailed training settings are provided in the Appendix.






 §.§ Effectiveness of the Conversion Pipeline

We first demonstrated the effectiveness of the local threshold balancing algorithm using the ResNet-34 architecture on the ImageNet dataset. We compare three different SNNs obtained from the Robust-Norm <cit.> algorithm, our proposed layer-wise local threshold balancing algorithm, and our proposed channel-wise threshold balancing algorithm. As a commonly used training-free ANN-SNN conversion method, we considered the Robust-Norm as the baseline, which sets the 99-th percentile activation value as the threshold. 

Figure <ref> illustrates the accuracy change of the three converted SNNs with respect to the inference time-steps. 

The performance of our proposed channel-wise local threshold balancing method (brown curve) consistently outperforms the Robust-Norm method (blue curve) and the local threshold balancing method without channel-wise operation (yellow curve). This indicates an excellent balance between fast inference and high performance. Moreover, compared to the robust norm method (blue curve), the peak performance of the SNNs obtained from our local threshold balancing method (both brown and yellow curves) is much closer to the original ANN accuracy, which demonstrates the effectiveness of the proposed training-free conversion method.




We further investigate the convergence speed of the local threshold balancing method by estimating the conversion error through the accumulation of clipping errors in each layer at each iteration. Figure <ref> illustrates how the conversion error changes with respect to the iteration steps of the local learning process. The blue curve gradually converges to a value near zero, indicating that the conversion error generally decreases as the number of iterations increases. This demonstrates the good convergence of the proposed local threshold balancing method.



Moreover, we evaluate the influence of the number of iteration steps on the threshold balancing method.
We converted five different SNNs from the pre-trained ResNet-34 model, varying the number of iterations of the local threshold balancing method from 1000 to 5000. 

The batch size during local threshold balancing is consistently set to 100. Figure <ref> shows the final accuracy of the different converted SNNs. As the number of iterations increases, the peak performance of the converted SNNs at different inference steps approaches the accuracy of the original ANN. Furthermore, these SNNs demonstrate better performance at low time-steps when fewer iteration steps are used. On the ImageNet dataset, with only 1000 iterations of local threshold balancing, the performance gap between the SNN at 512 inference time-steps and the ANN is approximately 1%. With 5000 iterations, this difference is further reduced to around 0.2%. Notably, the accuracy surpasses 65% within just 55 time-steps, achieving a balance between inference time and performance.




 §.§ Test on Image Classification task

We evaluate the performance of our conversion method on the classification task using the ImageNet dataset, employing different architectures including ResNet and MobileNet. To highlight the advantages of our algorithm, we conduct comparisons with previous training-free algorithms, showcasing its superior performance. When using the ResNet34 architecture, the SNNs converted by our algorithm exceeds 70% accuracy within 128 time steps. In contrast, the SNNs converted by the previous training-free algorithm <cit.> and the calibration-required conversion algorithm <cit.> require longer time-steps to achieve comparable accuracy. Our algorithm can achieve nearly loss-less conversion, as the performance gaps between the converted SNNs and the original ANNs are always less than 2% when the inference time-steps exceed 256 for all architectures. The experiments on the ImageNet dataset demonstrate the superior performance of our training-free conversion algorithm and highlight its potential for further applications in other vision tasks.

In addition to the evaluation on classification performance, we also demonstrate the energy-saving advantage of our method by theoretically estimating the energy efficiency of our converted SNN. We use the same energy consumption estimation approach as <cit.>. With ResNet-34 architecture on ImageNet, SNN converted from our algorithm can achieve an energy efficiency at 622FPS/W while maintaining 90% performance. In comparison, the energy efficiency of original ANN is only 22FPS/W, which is 28 times lower than that of the converted SNN. For detailed energy consumption analysis, please refer to the appendix.



 §.§ Test on Semantic Segmentation and Object Detection Tasks

Previous works on ANN-SNN conversion have primarily focused on the image classification task. Here, we extend the proposed training-free ANN-SNN conversion method to semantic segmentation and object detection tasks. For the semantic segmentation task, we evaluate our method on two commonly used datasets: Pascal VOC 2012 <cit.> augmented by SBD <cit.> and MS COCO 2017 <cit.>. We employ various semantic segmentation models, including FCN <cit.> and DeepLabV3 <cit.>, provided by TorchVision <cit.> and other open-source repositories. As shown in Table <ref>, our method is compatible with tackling semantic segmentation tasks without any preparatory training.  Specifically, we achieved a 52.42% mIoU with the FCN model using a ResNet-34 backbone in 64 time-steps on the Pascal VOC dataset and a 60.54% mIoU with the DeepLabV3 model using a ResNet-50 architecture on the more complex MS COCO 2017 dataset. Given that pixel-level classification tasks require precise model output, this excellent performance highlights the effectiveness and generalizability of the proposed conversion method.

For object detection tasks, we use the benchmark dataset MS COCO 2017 <cit.> with open-source models from TorchVision <cit.>.  We employ the fully convolutional object detection method RetinaNet <cit.> and FCOS <cit.>, and convert the pre-trained ANN models to SNNs using the proposed method. Table <ref> shows detailed performance under different inference time-steps. Within 64 time-steps, the converted SNN can achieve 25.1% mAP, which represents a significant improvement compared to previous exploration <cit.> of training-free ANN-SNN conversion for object detection. The previous method required over 1000 time-steps, which is detrimental to real-time detection and energy efficiency.











 §.§ Combination with Other Conversion Algorithm



The conversion method we propose offers a lightweight, plug-and-play solution that capable of integrating with other conversion algorithms to achieve enhanced performance. To validate its versatility and efficiency, we conducted experiments comparing our method with two established post-conversion calibration algorithm, LCP and ACP <cit.>. The results, presented in Table <ref>, showcase the performance of various configurations. Rows 1 to 5 illustrate the performance of our standalone method, the LCP method, our method combined with LCP, the ACP method, and our method combined with ACP, respectively. Notably, the composite approaches, which involve combining our method with LCP or ACP, consistently outperform single conversion methods across all timesteps, highlighting the advantages of using our approach in conjunction with existing techniques.



§ CONCLUSION AND LIMITATION

This paper introduces the concept of a training-free ANN-SNN conversion algorithm, which can directly convert pre-trained ANN models into SNNs without requiring GPU-based training, thus achieving extremely low-cost SNN learning. The significant reduction in training overhead highlights the potential for the rapid deployment of large-scale SNNs in various scenarios. We also present a specific training-free conversion algorithm and evaluate its performance across multiple visual tasks, demonstrating its effectiveness and generalizability.
However, there is a trade-off between performance and training cost, with the overall performance of our algorithm being slightly weaker compared to other training-based SNN learning methods. Additionally, while this work focuses on the conversion of convolutional and fully connected layers, future efforts will aim to extend the training-free conversion approach to attention blocks and other complex layers.










plainnat




§ PROOF FOR ERROR BOUND



The layer-wise conversion error can be divided into intra-layer and inter-layer errors, expressed as follows: 

    e^l    ⩽‖PSP(ẑ^l; θ^l) - ReLU(ẑ^l)‖_2^intra-layer error + ‖w^l ‖_2 e^l-1^inter-layer error.

Given that both ANN and SNN models receive the same input in the first layer, resulting in e^0 = 0, the upper bound for the conversion error between models in a L-layer fully-connected network is 

    e_model=e^L    ⩽∑_l=1^L (∏_k=l+1^L‖w^k ‖_2 ) ‖PSP(ẑ^l; θ^l) - ReLU(ẑ^l) ‖_2




According to the definition of the conversion error, we have

    e^l    = 
        ‖PSP(ẑ^l) - ReLU(z^l)‖_2  
       =
        ‖PSP(ẑ^l) - ReLU(ẑ^l) +
        ReLU(ẑ^l) - ReLU(z^l)‖_2 
       ⩽‖PSP(ẑ^l) - ReLU(ẑ^l)‖_2 +
        ‖ReLU(ẑ^l) - ReLU(z^l)‖_2

Here we will first prove that ‖ReLU(ẑ^l) - ReLU(z^l)‖_2 ⩽‖ (ẑ^l - z^l)‖_2. we consider four different situations of z^l_i and ẑ^l_i, which are single elements in z^l and ẑ^l, respectively.

    {   if ẑ^l_i ⩾ 0, z^l_i ⩾ 0, then (ReLU(ẑ^l_i) - ReLU(z^l_i))^2=(ẑ^l_i - z^l_i)^2
       if ẑ^l_i ⩾ 0, z^l_i ⩽ 0, then (ReLU(ẑ^l_i) - ReLU(z^l_i))^2=(ẑ^l_i - 0)^2 ⩽ (ẑ^l_i - z^l_i)^2
       if ẑ^l_i ⩽ 0, z^l_i ⩾ 0, then (ReLU(ẑ^l_i) - ReLU(z^l_i))^2=(0 - z^l_i)^2 ⩽ (ẑ^l_i - z^l_i)^2
       if ẑ^l_i ⩽ 0, z^l_i ⩽ 0, then (ReLU(ẑ^l_i) - ReLU(z^l_i))^2=(0 - 0)^2 ⩽ (ẑ^l_i - z^l_i)^2
        .

Therefore, for each element in vector z^l and ẑ^l, we can summarize that ∀ i, (ReLU(ẑ^l_i) - ReLU(z^l_i))^2 ⩽ (ẑ^l_i - z^l_i)^2, which can further derive

    ‖ReLU(ẑ^l) - ReLU(z^l)‖_2 ⩽‖ (ẑ^l - z^l)‖_2.

Back to the main theorem, we continue to rewrite the conversion error bound as

    e^l    ⩽‖PSP(ẑ^l) - ReLU(ẑ^l)‖_2 +
        ‖ (ẑ^l - z^l)‖_2 
       ⩽‖PSP(ẑ^l) - ReLU(ẑ^l)‖_2 +
        ‖w^l (PSP(ẑ^l-1) - ReLU(z^l-1))‖_2 
       ⩽‖PSP(ẑ^l) - ReLU(ẑ^l)‖_2 +
        ‖w^l ‖_2 ‖PSP(ẑ^l-1) - ReLU(z^l-1) ‖_2 
       ⩽‖PSP(ẑ^l) - ReLU(ẑ^l)‖_2^intra-layer error + ‖w^l ‖_2 e^l-1^inter-layer error.

Note that ‖w^l ‖_2 in Equation <ref> is the matrix norm (p=2) or spectral norm of the weight matrix w^l, and the derivation from <ref> to <ref> holds true because of the property of the spectral norms. From the inequality above, we can find that the layer-wise conversion error is bounded by the intra-layer error, which is layer-wise error when both the analog neuron and spiking neuron receive the same input, and the inter-layer error, which is proportional to the layer-wise error in the previous layer.

We will then further derive the conversion error between models, which is the conversion error in the last output layer. For simplicity, we define the intra-layer error in each layer as ε^l.

    e^L    ⩽‖PSP(ẑ^L) - ReLU(ẑ^L)‖_2 + ‖w^L ‖_2 e^L-1
       = ε^L + ‖w^L ‖_2 e^L-1.


Also, since we use direct input coding for SNNs, there will be no conversion error in the 0-th layer and the conversion error in the first layer will be e^1 = ‖PSP(ẑ^1) - ReLU(ẑ^1)‖_2. Therefore, we can iteratively derive the error bound for an arbitrary layer and the error bound for the final output should be

    e^L    ⩽ε^L + ‖w^L ‖_2 e^L-1
       ⩽ε^L + ‖w^L ‖_2 ε^L-1 + ‖w^L ‖_2 ‖w^L-1‖_2 e^L-2
        ...
       ⩽∑_l=1^L(∏_k=l+1^L‖w^k ‖_2 ) ε^l 
       ⩽∑_l=1^L (∏_k=l+1^L‖w^k ‖_2 ) ‖PSP(ẑ^l; θ^l) - ReLU(ẑ^l) ‖_2





§ PROOF FOR UPDATE RULE

The final update rule for the local threshold balancing algorithm at each step is:

    Δθ^l    =  - 1/N∑_i=0^N 2(ẑ^l_i-θ^l)H(ẑ^l_i-θ^l), 
    θ^l    ←θ^l - ηΔθ^l.









    



    As we have mentioned in the main text, our goal is to:
    
    ∀ l, min_θ^l (∏_k=l+1^L‖w^k ‖_2 ) ‖ReLUX(ẑ^l; θ^l) - ReLU(ẑ^l) ‖_2^2.

    We can utilize the gradient descent method, which is to iteratively update the threshold value by subtracting the first-order derivative of threshold, which is
    
    Δθ^l 
               = ∂ (∏_k=l+1^L‖w^k ‖_2 ) ‖ReLUX(ẑ^l; θ^l) - ReLU(ẑ^l) ‖_2^2/∂θ^l.

     We consider each element ẑ^l_i in vector ẑ^l, for each i we have
    
    ∂ (∏_k=l+1^L‖w^k ‖_2 )  ( ReLUX(ẑ_i^l; θ^l) - ReLU(ẑ_i^l)  )^2/∂θ^l
       = {
            -  (∏_k=l+1^L‖w^k ‖_2) · 2(ẑ^l_i-θ^l)   if ẑ^l_i>θ^l
    
            0   if ẑ^l_i ⩽θ^l 
            . 
       = -  (∏_k=l+1^L‖w^k ‖_2) · 2(ẑ^l_i-θ^l)H(ẑ^l_i-θ^l)

    Therefore, the derivative for θ^l should be
    
    Δθ^l
               = ∂ (∏_k=l+1^L‖w^k ‖_2 ) 1/N∑_i=0^N ( ReLUX(ẑ_i^l; θ^l) - ReLU(ẑ_i^l)  )^2/∂θ^l
       = -  (∏_k=l+1^L‖w^k ‖_2 ) 1/N∑_i=0^N 2(ẑ^l_i-θ^l)H(ẑ^l_i-θ^l).

    Since (∏_k=l+1^L‖w^k ‖_2 ) is an constant with fixed weight matrix, we absorb this term into learning rate parameter η. Therefore, we can finally derive the update rule as
    
    Δθ^l    =  - 1/N∑_i=0^N 2(ẑ^l_i-θ^l)H(ẑ^l_i-θ^l), 
    θ^l    ←θ^l - ηΔθ^l.





§ PROOF FOR PRE-NEURON MAX POOLING LAYER


The order of max pooling layer and ReLU activation layer does not affect the output results.

    maxReLU(z) =  ReLU(maxz),  when max(z)>0.



Since ReLU(x)=max(x, 0), we can rewrite the left hand side as max (ReLU(z)) = max (max(z, 0)) = max(z). Similarly, the right-hand side can be written as max(max(z), 0) = max(z), which is equal to the left-hand side. 




























































§ DETAILS FOR EXPERIMENTS







 §.§ Full Conversion Pipeline

In this section, we present the pseudo-code of the full conversion pipeline in Algorithm <ref>. At the beginning of the overall conversion process, we first initialize the model by replacing all activation layers with the ReLUX function and set the initial value of thresholds at each layer as 0. The model uses the same weight as the pre-trained ANN model and all modules are set to inference mode. During the threshold balancing algorithm, we will sample minibatches from the training dataset and input it into the model. The threshold value will be automatically optimized during the forward propagation.  

When evaluating SNNs, our conversion process incorporates other methods to further enhance the performance of the converted SNN. Firstly, we apply the membrane potential initialization algorithm <cit.>, setting the membrane potential as half of the threshold value before each inference iteration. We also utilize the delayed evaluation approach to obtain the average spike count of the output layer, ensuring performance with fewer inference steps <cit.>.








 §.§ Image Classification

When conducting experiments on the ImageNet dataset, we use the pre-trained models from TorchVision. During the threshold balancing process, we employ several commonly used data augmentation methods, including RandomResizeCrop, RandomHorizontalFlip, ColorJitter, and tensor Normalization. The iteration step number of the threshold balancing process is 1000 unless mentioned. During the evaluation of converted models, we only Crop and Resize the model into 224x224 normalized images. The delayed evaluation step length is set to a fixed 16 time-steps. 



 §.§ Semantic Segmentation

For the experiments of Pascal VOC 2012 dataset, the weights of the original ANN models are from open-source Github repositories. The data preprocessing operations during both threshold balancing process and inference process include resizing the data into 256x256 image and normalizing the data value. The delayed evaluation step length is set to half of the inference step length. The iteration step number of the threshold balancing process is set to 5 traversals of the training set for FCN and 6 traversals of the training set for DeepLab. Moreover, Pascal VOC 2012 is augmented by the extra annotations provided by SBD, resulting in 10582 training images.

For the experiments of the MS COCO 2017 dataset, the weights are directly downloaded from TorchVision. When performing data preprocessing, We first resize the input data into 400x400 images and normalize the images. The delayed evaluation length is set to half of the inference step length. The iteration step number of the threshold balancing process is set to 3 traversals of the training set. Note that these weights were trained on a subset of MS COCO 2017, using only the 20 categories that are present in the Pascal VOC dataset. This subset contains 92518 images for training.



 §.§ Object Detection

For our object detection experiments, we utilized pre-trained weights from TorchVision. During the threshold balancing process, we use similar dataset augmentation as SSD <cit.>. The input images are augmented by RandomPhotometricDistort, RandomZoomOut, RandomIoUCrop, and RandomHorizontalFlip. The optimization iteration step numbers is set to 1000 unless mentioned. During the evaluation of converted models, we only Crop and Resize the model into 224x224 normalized images. The delayed evaluation length is set to half of the inference step length.



§ VISUALIZATIONS ON OBJECT DETECTION AND SEMANTIC SEGMENTATION

In Figure <ref> and Figure <ref> we present the visualization of the semantic segmentation and object detection results. In each row of the figure, we illustrate the visualization of ground truth, original image (only for semantic segmentation), results from original ANN and results from converted SNN at different time-steps.







§ ENERGY CONSUMPTION ANALYSIS

Since the low-power consumption is one of the advantages of SNNs, we calculate the average energy consumption of the converted SNNs and compare it with the energy consumption of the ANN counterparts. We employed a method similar to previous work, estimating the energy consumption of the SNN by calculating the number of Synaptic Operations (SOP). Since the total spike activity of the SNN increases proportionally with the inference time, we define SOP90 and SOP95 as the metrics for converted SNNs on ImageNet. The SOP90/95 denotes the average synaptic operation per image when the accuracy of the converted SNN exceeds 90%/95% of the original ANN while SNN90-FPS/W denotes the total number of frames per joule when the performance of the converted SNN exceeds 90%. In order to further estimate the energy consumption, we utilize the average energy efficiency of 77fJ/SOP for SNN and 12.5pJ/FLOP for ANN <cit.> to calculate the required energy for one frame. The detailed comparison is demonstrated in the table below.

For ImageNet classification tasks, using the same ResNet-34 architecture, the SNN is over 28 times more energy efficient than the original ANN while maintaining 90% performance of the original ANN, achieving an estimation of 622 FPS/W energy efficiency while deployed on neuromorphic hardware. It is worth noticing the SNN can be easily obtained by converting open-source pre-trained ANN models with negligible training cost and then deploy on specific hardware for energy-saving purpose.


























































































































    

























    































































