# 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  
This work introduces the SE channel attention mechanism into the original YOLOv5s model's Backbone network so that the network pays more attention to the detected target, improving the detection effect. At the same time, to enhance the YOLOv5s model's understanding of the input data's spatial structure, a CA module is introduced. The detection accuracy of the model can be improved by adding an attention mechanism. 1. SE and Tanh activation function are introduced  
The SE's main aim is to improve the model's performance by compressing and stimulating the input features. Specifically, the SE attention mechanism consists of two steps: squeeze and excitation [29]. In the squeeze step, the input feature map is compressed into a vector by a global averaging pooling operation, which is then mapped to a smaller vector through a fully connected layer. By contracting the output \(\mathbf{U}=[\mathbf{u}_{1},\mathbf{u}_{2},...,\mathbf{u}_{C}]\) of the convolution operator \(\mathbf{F}_{tr}:\mathbf{X}\in\mathbb{R}^{H^{\prime}\times W^{\prime}\times C ^{\prime}}\rightarrow\mathbf{U}\in\mathbb{R}^{H\times W\times C}\) through the spatial dimension \(H\times W\), the statistic \(\mathbf{z}\in\mathbb{R}^{C}\) is generated, where the calculation formula for the \(c\) element of \(\mathbf{z}\) is as follows:  
\[z_{c}=\mathbf{F}_{sq}(\mathbf{u}_{c})=\frac{1}{H\times W}\sum_{i=1}^{H}\sum_{ j=1}^{W}u_{c}(i_{j}), \tag{1}\]  
where  
\[\mathbf{u}_{c}=\mathbf{v}_{c}*\mathbf{X}=\sum_{s=1}^{C^{\prime}}\mathbf{v}_{ c}^{s}*\mathbf{x}^{s} \tag{2}\]  
Here, \(\mathbf{v}_{c}=\left[\mathbf{v}_{c}^{1},\mathbf{v}_{c}^{2},...,\mathbf{v}_{ c}^{C^{\prime}}\right]\) is the learned set of filter kernels, referring to the parameters of the c-th filter, \(\mathbf{v}_{c}^{s}\) is a 2D spatial kernel, denoting a single channel of \(\mathbf{v}_{c}\) that acts on the corresponding channel of \(\mathbf{X}=\left[\mathbf{x}^{1},\mathbf{x}^{2},...,\mathbf{x}^{C^{\prime}}\right]\). In the excitation step, the Sigmoid activation function is changed to the Tanh activation function. Tanh was born a little later than Sigmoid, but one disadvantage of the Sigmoid function is that the output is not centered on 0, making the convergence slower. Tanh solves this problem. Hence, the Tanh function is used to compress each element of the vector from the squeeze step into a range between \(-1\) and 1. \[\mathbf{s}=\mathbf{F}_{ex}(\mathbf{z},\mathbf{W})=\tanh(g(\mathbf{z},\mathbf{ W}))=\tanh(\mathbf{W}_{2}\tanh(\mathbf{W}_{1}\mathbf{z})) \tag{3}\]  
It then multiplies it with the original input feature map to obtain the weighted feature map. \[\mathbf{\tilde{x}}_{c}=\mathbf{F}_{scale}(\mathbf{u}_{c},s_{c})=s_{c}\cdot \mathbf{u}_{c} \tag{4}\]  
where \(r\) is the reduction ratio, \(\mathbf{W}_{1}\in\mathbb{R}^{\tilde{\gamma}\times C}\) and \(\mathbf{W}_{2}\in\mathbb{R}^{C\times\tilde{\gamma}}\), \(\mathbf{\tilde{X}}=\left[\mathbf{\tilde{x}}_{1},\mathbf{\tilde{x}}_{2},..., \mathbf{\tilde{x}}_{C}\right]\), and \(\mathbf{F}_{scale}(\mathbf{u}_{c},s_{c})\) refers to channel-wise multiplication between the feature map \(\mathbf{u}_{c}\in\mathbb{R}^{H\times W}\) and the scalar \(s_{c}\). Through the SE attention mechanism, the model can adaptively learn the importance of each channel, thus improving the model's performance. In practical applications, the SE attention mechanism is widely used in various deep learning models, achieving good results. 2. CA attention module and ReLu activation function are introduced  
To suppress irrelevant information, a CA attention module is used to embed position information in the channel. This mechanism effectively combines location information and channel information to improve the model's ability to understand the input data,thus improving the model's accuracy. In addition, CA can encode horizontal and vertical position information into channel attention, so that the mobile network pays attention to a large range of position information without too much computation [30].