# Lightweight Tennis Ball Detection Algorithm Based on Robomaster EP
## 3 YOLOv5s-Z
### Convolutional Coordinate Attention  
This study proposes a convolutional coordinate attention G-CA, as shown in Figure 6. By incorporating the convolutional coordinate attention mechanism in the G-Backbone network, the network can obtain location information of a larger area through multiple convolutions, which further enhances the ability of the Backbone network to sense the field and capture location information and enhances the expression ability of the learning features of the mobile network. Research in neural networks has shown that channel attention significantly improves the model's performance but ignores some vital location information that facilitates the generation of spatially selective attention maps. Therefore, to alleviate the loss of location information caused by two-dimensional global pooling proposed by attention mechanisms such as SENet [30] and CBAM [31], a novel attention mechanism designed for lightweight networks called coordinate attention [32] was proposed by the National University of Singapore. Compared to channel attention, coordinate attention transforms the feature tensor into individual feature vectors using two-dimensional global pooling, decomposing channel attention into two one-dimensional feature encoding processes that aggregate features along two directions, one of which captures remote dependencies along the spatial direction, and the other retains precise location information along the spatial direction. \begin{table}
\begin{tabular}{c c c c} \hline \hline
**Model** & **Parameters** & **GFLOPs** & **Weight/MB** \\ \hline YOLOv5s & 7,022,326 & 15.8 & 14.5 \\ YOLOv5s-Ghost & 3,684,542 & 8.1 & 7.9 \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Comparison results between YOLOv5s and YOLOv5s-Ghost. The resulting feature maps are eventually encoded separately to produce a pair of direction-aware and position-sensitive feature maps that are complementarily applied to the input feature maps and used to enhance the precise localization of targets. Coordinate attention consists of two main steps: coordinate information embedding and coordinate attention generation. First, given an input feature map X with dimension c \(\times\) h \(\times\) w, and using two pooling kernels with spatial ranges (H,1) or (1,W) to encode each channel along the horizontal and vertical coordinates, respectively, the output of the c channel with height h and the c channel with width w is calculated as shown in Equations (4) and (5):  
\[Z_{c}^{h}(h)=\frac{1}{W}\sum_{0\leq i\leq W}X_{c}(h,i) \tag{4}\]  
\[Z_{c}^{w}(h)=\frac{1}{H}\sum_{0\leq j\leq H}X_{c}(j,w) \tag{5}\]  
The above two transformations perform feature aggregation along two directions, respectively, and cascade to generate two feature maps, which generate feature maps of spatial information in horizontal and vertical directions f by a convolution operation, which is beneficial to the network for accurate target localization, and the calculation formula is shown in Equation (6):  
\[f=\delta(F_{1}([Z^{h},Z^{w}])) \tag{6}\]  
After the coordinate information is embedded, the above changes are subjected to the cascade operation, which is a nonlinear activation function that is an intermediate feature map of spatial information encoded along the horizontal and vertical directions, which is decomposed into two tensor sums along the spatial dimension. The transformation operation is then performed using the convolutional transform function, which in turn yields the attention weights of the two spatial directions as \(g^{h}\) and \(g^{w}\), respectively, calculated as shown in Equations (7) and (8):  
\[g^{h}=\sigma((F_{h}(f^{h}))) \tag{7}\]  
\[g^{w}=\sigma((F_{w}(f^{w}))) \tag{8}\]  
The \(\sigma\) in the above equation is the sigmoid [33] activation function, and to reduce the complexity and computational overhead of the model, the number of channels is usually  
Figure 6: Convolutional coordinate attention. reduced using a suitable scaling ratio, and the output is expanded as attention weights, respectively.