# Elderly Fall Detection in Complex Environment Based on Improved YOLOv5s and LSTM
## 3 Fall Detection Based on the Improved YOLOv5s
### Improved YOLOv5s Model
#### 3.2.2 Attention Mechanism
In the coordinate embedding part, for the input features of the \(H\times W\times C\) channel, CA encodes the tensors \(z_{c}^{w}\) and \(z_{c}^{h}\) obtained from the feature maps of each channel in the vertical and horizontal directions, respectively, by using an average pooling kernel  
\[\left\{ \begin{array}{l}z_{c}^{h}(h)=\frac{1}{W}\sum\limits_{0\leq i\sim W}x_{ c}(h,i)\\ z_{c}^{w}(w)=\frac{1}{H}\sum\limits_{0\leq j\sim H}x_{c}(j,w)\end{array} \right. \tag{5}\]  
where \(z_{c}^{h}\) and \(z_{c}^{w}\) represent the horizontal feature at height \(h\) and the vertical feature at width \(w\) of the feature map \(\mathbf{x}_{c}\) of channel \(c\), respectively. In the coordinate memory generation part, CA first imparts the coordinate information into the output aggregate feature map for concat operation, and then processes the convolution layer, BN layer and nonlinear layer to obtain the intermediate feature \(\mathbf{f}\in\mathbb{R}^{C/r\times(H+W)}\) in the vertical direction and the horizontal directions  
\[\mathbf{f}=\delta\Big{(}Conv^{1\times 1}\Big{(}\left[\mathbf{z}^{h},\mathbf{z}^{ w}\right]\Big{)}\Big{)} \tag{6}\]  
The intermediate feature \(\mathbf{f}\) is divided into two independent feature tensors \(\mathbf{f}^{h}\in\mathbb{R}^{C/r\times H}\) and \(\mathbf{f}^{w}\in\mathbb{R}^{C/r\times W}\), and then the dimension is adjusted through the convolution layer. Finally, the attention weights \(g^{h}\) and \(g^{w}\) in the horizontal and vertical directions are obtained through the Rectified Linear Unit (ReLU) activation function  
\[\left\{ \begin{array}{l}g^{h}=\max\Big{(}0,Conv^{1\times 1}\Big{(}\mathbf{f}^{h} \Big{)}\Big{)}\\ g^{w}=\max\Big{(}0,Conv^{1\times 1}\Big{(}\mathbf{f}^{w}\Big{)}\Big{)}\end{array} \right. \tag{7}\]  
Since the ReLU activation function is sparse, there is no complex exponential operation, the calculation is simple, the efficiency is high, and the actual convergence speed is fast. Therefore, this work replaces CA's original Sigmoid function with the ReLU function. The output feature \(y_{c}\) of CA is obtained by multiplying the feature tensor of the attention weight' \(c\) channel with \(\mathbf{x}_{c}\) at the corresponding coordinate position. \[y_{c}(i,j)=x_{c}(i,j)\times g_{c}^{h}(i)\times g_{c}^{w}(j) \tag{8}\]  
3. BiFPN module and SiLU activation function are introduced  
Beginning with the Neck feature fusion, this work introduces the BiFPN to strengthen the underlying feature map information, so that feature maps of different scales can be fused. The specific BiFPN implementation process occurs as follows: Firstly, the input feature map is processed through a series of convolution and pooling operations to obtain a series of feature maps in different scales. Then, the following operations are performed at each scale: a set of \(1\times 1\) convolutional layers is used to unify the number of channels in the feature map to the same value; the weight that fuses the features of that scale with those of other scales is learned at each scale; a set of \(3\times 3\) convolutional layers fuse the feature of each scale with the feature of other scales; a set of \(1\times 1\) convolutional layers obtain the final feature map. In addition, BiFPN also introduces techniques [31], such as dynamic weight updating and cross-level linking, to further improve the feature expression ability and detection performance. The Sigmoid Linear Unit (SiLU) activation function, also known as the Swish activation function, is an adaptive activation function. It is an improvement on the Sigmoid function, which can better adapt to different data distributions. The role of the SiLU activation function is to convert the input signal in the neural network into the output signal, thus activating the neuron. Compared with other activation functions, the SiLU activation function has a faster convergence speed and better performance. SiLU has an attractive self-stabilizing feature.