## 3 Materials and Methods
### Attention Module
#### 3.2.2 Neck: SPP-MHSA, FPN, and PANet
Therefore, to detect images with large targets, this study proposes replacing the convolutional block in the feature fusion stage and at various positions in images with the MHSA module. After replacing the convolution block with the SPP module, this study renames the transformer's MHSA as the SPP-MHSA module. Figure 8 depicts the particular operation. The model's first spatial (3 \(\times\) 3) convolutions are replaced by an MHSA layer that employs global self-attention of a 2D feature map. This was included at the beginning, as shown in Figure 8. The beginning of FPN coincides with the end of CSPDarknet53 because every residual block typically exhibits its strongest characteristics at its deepest layer, and the strongest feature retrieved is in the output of the deepest block at the end of the network. CSPDarknet-53, the YOLOv4 backbone, is responsible for extracting numerous characteristics from images via 5 Resblocks (C1-C5). The network has 53 convolution layers ranging in size from 1 \(\times\) 1 to 3 \(\times\) 3. The feature map generated from the MHSA operation can be considered by each succeeding layer and multiscale feature fusion and extraction based on FPN and PANet network design. This is also analogous to transferring the global features perceived by the MHSA layer to the succeeding deep CNN, thus modeling semantic information from global to local using the MHSA layer first, then the convolutional layer. After replacing the block with the MHSA layer, no further operations are necessary because the stride of the convolution block is 1. This enhancement (SPP-MHSA) permits global information to be acquired from feature  
maps with varying receptive field sizes, and a multiscale fusion of global information can be conducted in subsequent operations. This enhances the model's detection accuracy for large-size targets. As shown in Figure 7, the present study used four heads. * represents the multiplication sign. The 3D nature of the feature map passed to the module is determined by the \(H\times W\times d\), putting these feature maps as \(W_{Q},W_{K},W_{V}\). Pointwise convolution is represented by \(1\times 1\), \(\oplus\) is the element-wise sum, and \(\otimes\) represent matrix multiplication. When \(h\) represents height and \(w\) represents width, \(R_{h}\) and \(R_{w}\) are \(t\) relative position encodings. Add the \(R_{h}\) and \(R_{w}\) together and output as \(r\), representing the position distance coding. Matrix multiplication of \(qr\) obtains content-position (content-position) output \(qr^{T}\), and matrix multiplication of \(qk\) obtains content-content (content-content) output \(qk^{T}\). After \(qk^{T}+qr^{T}\), softmax normalization is applied to the obtained matrix, where \(q,\ k,\ r\) represent query, key, and position encodings, respectively (this study uses relative distance encodings [38; 41; 42; 43]). After processing, the matrix is \(HW\times HW\), and then this matrix is multiplied by the weight \(V\). The final output \(z\). In addition to using multiple heads, we introduce a two-dimensional position encoding in the content-position section to accommodate the matrix form in image processing. It differs most from the Transformer mechanism [38; 48; 49]. MHSA focuses more on global information. In Figure 9, the important semantic features of small target images are in the surroundings of the targets and are transferred between contexts. Global information can sometimes cause redundancy in the transfer of essential features of small-size targets. Therefore, this study used convolution operations and attention mechanisms to separate the most significant context features instead of using the self-attention mechanism in the attention stage for detecting small-size target images. Figure 8: Structure of SPP, FPN, and PANet. In Figure 9, the bold red part is to replace the 3\(\times\)3 convolution block position with the MHSA layer.