## 2 Algorithm Improvement
### Introduction of Attention Mechanism  
The size of the target pixel value can be calculated by the surrounding pixels in the convolutional neural network. However, the results calculated by local information usually lead to the loss of global information and deviation. To alleviate the information bias, not only larger convolutional filters can be used, but also deeper convolutional neural networks can be constructed. However, the relative amount of calculation climbs faster and the effect is not significant [25]. Therefore, the attention mechanism is analyzed in this article to improve the training effect of the network.  
The information of interest can be located by adding the attention mechanism to the neural network. The useless information can be suppressed. The attention mechanism is mainly divided into three types: spatial attention mechanism, channel attention mechanism, and mixed attention mechanism of the two. The spatial attention mechanism is responsible for the establishment of the target positions. The channel attention mechanism is mainly responsible for the classification of the targets.  
Convolutional Block Attention Module (CBAM) is an effective light-weight feedforward convolutional neural network attention module. The structure of the CBAM attention mechanism is shown in Figure 4. The feature information of the two dimensions of space and channel are combined in the CBAM model. The CBAM model has the advantages of simple structure, small computation, and fast computation speed. It can be plugged into the network architecture as needed to improve performance. If the intermediate feature map is given, the attention map can be judged independently by the two dimensions of channel and spatial in the CBAM module. Firstly, the input features are mapped to the channel attention module. The corresponding attention mappings are output. Then, the output map is multiplied by the input characteristics and attention map, which is output through the spatial attention module. Finally, the output characteristics of the map are obtained. The mathematical expressions are written as follows.  
\[\mathbf{F}=M_{c}(\mathbf{F})\otimes\mathbf{F} \tag{3}\]  
\[\mathbf{F}^{\prime\prime}=M_{s}(\mathbf{F})\otimes\mathbf{F} \tag{4}\]  
where \(\otimes\) represents element multiplication, \(\mathbf{F}\) is the input feature map, \(M_{c}(\mathbf{F})\) is the channel attention map output by the channel attention module, \(M_{s}(\mathbf{F})\) is the space attention map output by the space attention module, and \(\mathbf{F}^{\prime\prime}\) is the feature map output by the CBAM.  
The maximum pooling and average pooling are first performed on the input image by the channel attention module. Then, the transformation results are obtained through several MLP layers. The results are respectively applied to two channels. The attention  
Figure 4: Structure diagram of CBAM attention mechanism. Where the Max represents the maximum pool processing, the Avg represents the global average pooling processing, the Conv represents the convolution layer, \(\int\) represents the sigmoid activation function.  
Figure 3: Scatter plots of prior frame sizes obtained under two different clustering algorithms.  
of the channel enhancement effect is obtained by using the sigmoid function. Firstly, the maximum pooling and mean pooling are performed on the input images, respectively, under the spatial attention module. Then a convolution layer is used to learn the new feature map [26].  
To obtain a more efficient attention network structure, the CBAM module is inserted among the three channels output of the CSPNet structure and the first two positions of the last five layers of each channel in the YOLOv4 network structure. The more focused learning effect of the network structure can be obtained by the above modification. The schematic diagram of adding the CBAM attention module to YOLOv4 network structure is shown in Figure 5.