# Energy-Efficient Respiratory Anomaly Detection in Premature Newborn Infants
## 5 SNN-Based Respiratory Classification
### Model Conversion  
In this work, the 1 DCNN architecture is converted to SNN in order to execute it on a neuromorphic hardware such as Loihi [15]. The conversion steps are briefly discussed below. 1. ReLU Activation Functions: This is implemented as the approximate firing rate of a leaky integrate and fire (LIF) neuron. 2. Bias: A bias is represented as a constant input current to a neuron, the value of which is proportional to the bias of the neuron in the corresponding analog model. 3. Weight Normalization: This is achieved by setting a factor \(\lambda\) to control the firing rate of spiking neurons. 4. Softmax: To implement softmax, an external Poisson spike generator is used to generate spikes proportional to the weighted sum accumulated at each neuron. 5. Max and Average Pooling: To implement max pooling, the neuron which fires first is considered to be the winning neuron, and therefore, its responses are forwarded to the next layer, suppressing the responses from other neurons in the pooling function. To implement average pooling, the average firing rate (obtained from total spike count) of the pooling neurons are forwarded to the next layer of the SNN. 6. 1-D Convolution: The 1-D convolution is implemented to extract patterns from inputs in a single spacial dimension. A 1 xn filter, called a kernel, slides over the input while computing the element-wise dot-product between the input and the kernel at each step. Figure 8: Seven-stage pipeline, including the two new stages to process and optimize the SNN model. Figure 7: Integration of spike trains at the post-synaptic neuron from four pre-synaptic neurons in a spiking neural network (SNN). Each spike is a voltage waveform of ms time duration. Residual Connections: Residual connections are implemented to convert the residual block used in CNN models such as ResNet. Typically, the residual connection connects the input of the residual block directly to the output neurons of the block, with a synaptic weight of '1'. This allows for the input to be directly propagated to the output of the residual block while skipping the operations performed within the block. * Flattening: The flatten operation converts the 2-D output of the final pooling operation into a 1-D array. This allows for the output of the pooling operation to be fed as individual features into the decision-making fully connected layers of the CNN model. * Concatenation: The concatenation operation, also known as a merging operation, is used as a channel-wise integration of the features extracted from two or more layers into a single output. We now briefly elaborate how an analog operation such as Rectified Linear Unit (ReLU) is implemented using SNN. The output \(Y\) of a ReLU activation function is given by  
\[Y=\max 0,\sum_{i}w_{i}*x_{i}, \tag{12}\]  
where \(w_{i}\) is the weight and \(x_{i}\) is the activation on the \(i^{\text{th}}\) synapse of the neuron. To map the ReLU activation function, we consider a particular type of spiking neuron model known as an integrate and fire (IF) neuron model. The IF spiking neuron's transfer function can be represented as  
\[v_{m}(t+1)=v_{m}(t)+\sum_{i}w_{i}*x_{i}(t), \tag{13}\]  
where \(v_{m}(t)\) is the membrane potential of the IF neuron at time \(t\), \(w_{i}\) is the weight, and \(x_{i}(t)\) is the activation on the \(i^{\text{th}}\) synapse of the neuron at time \(t\). The IF spiking neuron integrates incoming spikes (\(X_{i}\)) and generates an output spike (\(Y_{\text{spike}}\)) when the membrane potential (\(v_{m}\)) exceeds the threshold voltage (\(v_{\text{th}}\)) of the IF neuron. Therefore, by ensuring that the output spiking rate \(Y_{\text{spike}}\) is proportional to the ReLU activation \(Y\), i.e., \(Y_{\text{spike}}\propto Y\), we accurately convert the ReLU activation to the spike-based model. To further illustrate this, we consider the multi-layer perceptron (MLP) of Figure 9a and its SNN conversion using rate-based encoding (Figure 9b) and inter-spike interval (ISI) encoding (Figure 9c).