# Coal Ganguue Target Detection Based on Improved YOLOv5s
## 2 Network Model Improvements
### SimAM Attention Mechanism  
In the task of coal gauge sorting, the colors of the conveyor belt, coal and coal gauge are very similar, which brings a challenge to the target detection algorithm. The SimAM attention mechanism can help the model learn the similarity and difference between the target and the background, and so background interference is suppressed better [23]. The SimAM attention mechanism is based on similarity calculation and applied in neural network models.  
Defining the energy function of each neuron is as follows:  
\[e_{t}(w_{t},b_{t},y,x_{i})=\left(y_{t}-\hat{t}\right)^{2}+\frac{1}{M-1}\sum_{ i=1}^{M-1}(y_{o}-\hat{x}_{i})^{2} \tag{1}\]  
Using binary labeling (i.e., 1 and \(-1\)) for \(y_{t}\) and \(y_{o}\) in the formula and adding regularization, the final energy function is as follows:  
\[e_{t}(w_{t},b_{t},y,x_{i})=\frac{1}{M-1}\sum_{i=1}^{M-1}\left(-1-(w_{t}x_{i}+b _{t})\right)^{2}+\left(1-(w_{t}t+b_{t})\right)^{2}+\lambda w_{t}^{2} \tag{2}\]  
The minimum energy can be expressed as follows:  
\[e_{t}^{*}=\frac{4\left(\phi^{2}+\lambda\right)}{\left(t-\hat{\mu}\right)^{2}+2 \phi^{2}+2\lambda} \tag{3}\]  
In the formula,  
\[\hat{t} =w_{t}t+b_{t}\] \[\hat{x}_{i} =w_{t}x_{i}+b_{t}\]  
Figure 2: Decoupled head structure diagram.  
\[w_{t}=-\frac{2(t-\mu_{t})}{\left(t-\mu_{t}\right)^{2}+2\sigma_{t}^{2}+2\lambda}\]  
\[b_{t}=-\frac{1}{2}(t+\mu_{t})w_{t}\]  
\[\mu_{t}=\frac{1}{M-1}{\sum_{i=1}^{M-1}}x_{i}\]  
\[\sigma_{t}^{2}=\frac{1}{M-1}{\sum_{i=1}^{M-1}}{(x_{i}-\mu_{t})}^{2}\]  
\[\hat{\mu}=\frac{1}{M}{\sum_{i=1}^{M}}x_{i}\]  
\[\hat{\sigma}^{2}=\frac{1}{M}{\sum_{i=1}^{M}}(x_{i}-\hat{\mu})^{2}\]  
In the above formula, \(t\), \(x_{i}\) and \(y\), respectively, represent the target neurons participating in the calculation, other neurons in the channel and calibration values. \(i\) represents the spatial index, \(w_{t}\) and \(b_{t}\) represent the weight and bias of the \(t\)-th layer neurons, \(M\) represents the number of energy functions in the channel and \(\mu_{t}\) and \(\sigma_{t}^{2}\), respectively, represent the mean and variance of other neurons in the channel except for \(t\).  
Formula (3) indicates that the lower the energy, the greater the difference between neuron \(t\) and the surrounding neurons, and the higher the importance. Therefore, the importance of neurons can be obtained through \(\frac{1}{\sigma_{t}^{2}}\).  
According to the similarity calculation results, feature representations of higher similarity receive higher weights and more targeted attention to task-related information. In this paper, the SimAM attention mechanism is added to the Neck part; by fusing the feature representation with the corresponding weights, the final enhanced feature map is generated for subsequent model processing. SimAM enables the neural network to adaptively focus on the important features of the input data and improves the performance of the model. For the dataset with a single-colored conveyor belt as the background, SimAM can effectively capture the difference between the background features and the target features, which improves the target's ability to identify the similar background and achieves more accurate feature representation.