# UAV Image Small Object Detection Based on RSAD Algorithm
## 3 Proposed Method
### Self-Attention Mechanism Based Feature Fusion  
The self-attention mechanism is a variant of the attention mechanism that is less dependent on external information and more adept at capturing the internal correlations of data or features. The self-attention mechanism gives weights to features and correlations between features and features through convolution and softmax to establish global feature dependencies. In this study, a self-attention mechanism feature fusion module SAFM is designed based on this, as shown in Figure 5. The method aims to organically fuse the high-level semantic information of small objects in the deep layer of the UAV image through the self-attention mechanism with the shallow layer after establishing the correlation, which is no longer a simple stacking. At the same time, large weights are given to important information and small weights are given to background and noise information. \begin{table}
\begin{tabular}{c c c c c c c c c c c c} \hline \hline
**Backbone** & **A** & **B** & **C** & **D** & **E** & **F** & **G** & **H** & **I** & **J** & **K** & **L** \\ \hline Parameters/M & 61.1 & 65 & 6.8 & 4.5 & 6.6 & 11.7 & 138.4 & 143.7 & 21.8 & 25.6 & 44.6 & 60.2 \\ Flops/G & 1.2 & 0.8 & 1.15 & 0.6 & 2.6 & 3.4 & 27.2 & 34.6 & 6.9 & 7.71 & 14.9 & 21.5 \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Number of parameters and Flops for different backbone networks. Figure 5: SAFM structure. SAFM first reshaped and concatenated the features extracted from the ResNet-50 backbone network, and then obtains the global information. The global information is obtained by the following equation:  
\[X=\Big{[}f_{i}^{3\times 3}(s_{i})\Big{]},\ \ \ \ i=1,2,\ldots,n \tag{3}\]  
where: \(s_{i}\) is the feature information extracted by the backbone network, \(X\in\mathbb{R}^{C\times H\times W}\), \(C\) denotes the resultant tensor's channel dimension, \(H\times W\) denotes the resolution of the feature map, \(f_{i}^{3\times 3}\) denotes that the convolutional layer with \(3\times 3\) kernel size to unify the channel dimension. [] denotes the concatenation calculation, and n represents the number of fused feature layers in a pyramid. The acronym AU refers for self-attention mechanism, which enables the computation of the pertinent data in a single feature and the further establishment of the global feature correlation at the pixel level. Note that the AU is shown in the lower right corner of Figure 4. Receiving a single tensor obtained by concatenation, AU uses two lightweight convolutional layers with the kernel size of \(1\times 1\) are adopted to generate features \(Q\) and \(K\). \(Q\), \(K\in\mathbb{R}^{C\times H\times W}\), \(C^{\prime}=\text{C}/8\) is used to reduce computing overhead. Then, based on the features \(Q\) and \(K\), the global weighted feature mapping \(A\) can be obtained by matrix multiplication followed by softmax operation  
\[D=Q^{T}K \tag{4}\]  
\[A=\frac{e^{D_{ij}}}{\sum_{j=1}^{H\times W}e^{D_{ij}}},\ \ \ i,j=1,2,3,\ldots,H\times W \tag{5}\]  
where \(D\in\mathbb{R}^{HW\times HW}\) and \(A_{ij}\) represents the elements of the \(i\)th row and \(j\)th column. After obtaining \(A\), \(V\in\mathbb{R}^{C\times H\times W}\) is obtained by another convolution kernel. Then, the weighted sum of all positions in the same feature is obtained by multiplying the feature with the weighted mapping \(A\). Finally, the original concatenated features and the multiplication result are added to obtain the output of the AU.