# A Resource Constrained Neural Network for the Design of Embedded Human Posture Recognition Systems
## 3 System Design  
The HW architecture of the FCN follows the scheme in Figure 1. It is composed of 5 sequential layers and a simple control logic, which initiates and terminates the processing and initializes the memories embedded into the layers. The layer operations are the same of the model in Figure 2: the first three are CONV layers, followed by the GAP and a dense FC layer. The last layer differs from the model because the SoftMax classifier has been substituted by a simple prediction stage, which only selects the maximum output values from the FC layer. This has been possible since the combination of GAP and FC layers calculates the scores of the output classes as:  
\[ \begin{split} Score(C)=\sum_{i=1}^{32}W_{i,C}\times X_{i}=\sum_{ i=1}^{32}W_{i,C}\times\frac{\sum_{k=1}^{N-30}b_{k}}{N-30}=\\ =\frac{1}{N-30}\left(\sum_{i=1}^{32}W_{i,C}\times\left(\sum_{k=1} ^{N-30}b_{k}\right)\right)\end{split}  \tag{3}\]  
where \(C\) is the class, \(W_{i,C}\) are the weights for each class and \(b_{k}\) are the binarized inputs to the GAP and the other quantities can be taken from Table 1. Given the linearity of Equation (3), and the only interest toward the class with the highest score, which can be obtained by a trivial comparison between the scores of all the classes, not only the SoftMax but also the division in Equation (3) can be avoided for a more compact HW implementation of the FCN, without loss of accuracy. FCN is fully synchronous, namely the layers exchange data after a fixed number of cycles. All the layers share the architecture in Figure 6, composed by the control unit (CU), the memories to store the kernel coefficients and the outputs of the BN and Operational (OP) Block whose dimensions can be obtained by Table 1 once \(N\) and the number of classes have been selected. The OPBlocks of CONV and FC layers are schematized in Figure 7. Thanks to the base-2 quantization, the OP block is free of multipliers and it has been essentially reduced to SAC operators, which are in turn composed by multiplexers and shifters. \begin{table}
\begin{tabular}{c c c c c} \hline \hline
**Class** & **Precision** & **Recall** & **F1-Score** & **Support** \\ \hline Initial position & 0.99 & 0.99 & 0.99 & 839 \\ Bent forward & 0.99 & 0.98 & 0.98 & 128 \\ Rested back & 1 & 0.98 & 0.99 & 123 \\ Bent left & 0.98 & 1 & 0.99 & 125 \\ Left-bent thinker & 1 & 1 & 1 & 116 \\ Right-bent thinker & 1 & 0.98 & 0.99 & 114 \\ Legs up & 0.98 & 0.99 & 0.99 & 120 \\ Straight legs & 1 & 1 & 1 & 115 \\ \hline \hline \end{tabular}
\end{table} 
Table 4: Accuracy results of the FCN for all the sitting postures. Muxes are used to select 0, the input value or the left-shifted input value to emulate the product between inputs and quantized weights, according to Equation (1). The CONV1 layer differs from the other two CONV layers for the number of the operators, considering the different number of filters between the first three layers, as well as for the dimensions of the input data which depend on the acquisition system, and that in our case is of 12 bits. The remaining parts are the same of Figure 7. BNs and activations are simply implemented by a XNOR gate considering that:  
\[sign(Y_{BN})=sign\bigg{(}\frac{\text{ConvResult}-\mu}{\sigma}\bigg{)}=sign( \text{ConvResult}-\mu)\ XNORsign(\sigma) \tag{4}\]  
where \(\mu\) and \(\sigma\) are calculated during training and stored in a proper memory. Considering that activations are binarized, the GAP scheme is a simplified version of the one in Figure 7a. It is composed by a popcount and a memory buffer for results as reported in Figure 7b, where signed additions are calculated as in Figure 8.  
Figure 6: Block scheme of the layers. Figure 7: **(a)**: Architecture of the OPBlock of Figure 3 in the case of CONV and FC Layers. Mux selects “0”, the input or the left-shifted input to emulate the products with weights. Mux with Adder tree compose the SAC operator. **(b)**: PopCount tree for the OPBlock of Figure 3 in the case of GAP layer.