# PBA-YOLOv7: An Object Detection Method Based on an Improved YOLOv7 Network
## 2 Methodology
### Pba-Yolov7: Improved Algorithm for YOLOv7
#### 2.2.3 Coordinate Attention Mechanism  
As the network structure becomes deeper and deeper and the layers are superimposed, although richer semantic information can be obtained, the resolution of the feature map decreases, resulting in the loss of some target location information. The attention mechanism is a standard data processing method widely used in machine learning tasks in various fields [37]. To ensure the network can extract rich semantic information while obtaining accurate location-aware information, the coordinate attention mechanism module is embedded before the representative convolution module in the Neck network. The coordinate attention mechanism [33] can capture the associations and dependencies between different locations in an image by computing attention on the spatial coordinates of the features. This allows the model to understand better the spatial structure information in the image, which improves the understanding and perception of the target. The coordinate attention mechanism focuses on specific locations in the image and spatial relationships at different scales. This allows the model to adapt to targets and scenes at different scales, with better robustness to size, scale, and rotation changes in the image. The coordinate attention mechanism also allows the network model to better model the spatial relationships between different locations and more accurately model and understand the details and local structures in the image. The structure of the coordinate attention mechanism is shown in Figure 6, which enhances the sensitivity to attentional information by decomposing the channel attention into a process of one-dimensional feature encoding performed in parallel to form a set of feature maps sensitive to both direction and position dimensions simultaneously. The coordinate attention mechanism module decomposes the coordinate information into a set of one-dimensional feature codes by global pooling according to Equation (4). \[\mathbf{Z_{c}}=\frac{1}{\mathbf{H}\times\mathbf{W}}\sum_{i=1}^{H}\sum_{j=1}^{W}\mathbf{x_{c}}( \mathbf{i},\mathbf{j}) \tag{4}\]  
In the equation, \(\mathbf{Z_{c}}\) is the output associated with the \(C\) channel, \(\mathbf{H}\) and \(\mathbf{W}\) are the height and width of the input feature map, respectively, and \(\mathbf{x_{c}}\) (\(\mathbf{i},\mathbf{j}\)) is the input feature map of the \(\mathbf{C}\) channel. Figure 6: Structure diagram of coordinate attention mechanism. For an input tensor X, each channel is encoded in the horizontal coordinate direction using a pooling kernel of dimension (\(\mathbf{H}\), 1), and the output of the CChannel with height \(\mathbf{H}\) can be represented as  
\[Z_{C}^{H}(h)=\frac{1}{W}\sum_{0\leq i\leq W}x_{c}(H,i) \tag{5}\]  
In Equation \(Z_{C}^{H}(h)\) is the output of the Cth channel with height \(\mathbf{H}\). \(\mathbf{W}\) is the width of the input feature map. Encoding each channel in the vertical coordinate direction using a pooling kernel of dimension (1, W), the output of the \(C\) channel of width \(\mathbf{W}\) can be expressed as  
\[Z_{C}^{W}(w)=\frac{1}{H}\sum_{0\leq i\leq H}x_{c}(j,W) \tag{6}\]  
After Equations (5) and (6) are used to aggregate features in horizontal and vertical directions on the input, a pair of direction-sensitive attention features \(Z_{H}\) and \(Z_{W}\) are outputted. This step enables the coordinate attention module to acquire remote dependence in one spatial direction while preserving precise position information along another spatial direction, which helps the network to better acquire the global sensory field and encode more precise position information. In the coordinate attention generation phase, the \(Z_{H}\) and \(Z_{W}\) attentional representations generated in the previous layer are first utilized in a cascade operation. \[\mathsf{f}= \delta(\mathrm{F}[Z_{H},Z_{W}]) \tag{7}\]  
\(\mathbf{F}\) is the transform function and \(\delta\) is the h_swish() activation function.