# A Method for Underwater Biological Detection Based on Improved YOLOXs
## 3 Methods
### Feature Fusion Network Improvement Strategy  
The neck network of YOLOX adopts the PAFPN structure for fusion, as shown in Figure 7. The original image undergoes feature extraction by the backbone network, producing three feature layers of different sizes: P1, P2, and P3. In the FPN structure, P1, P2, and P3 are fused through lateral connections and top-down sampling paths to generate the fused feature maps f1, f2, and f3. This structure merges high-level and low-level feature maps, facilitating the transmission of strong semantic features. Then, f1, f2, and f3 are further fused through lateral connections and bottom-up sampling to generate the feature maps F1, F2, and F3, enabling the transmission of positional information from the bottom layers to the top layers. Finally, the fused feature maps are input into the prediction layer to achieve accurate image prediction. In this paper, the CoT block is introduced into CSPBottleneck_2 to utilize context information between input keys to guide self-attention learning, as depicted in Figure 8.  
The Transformer structure based on self-attention possesses powerful global modeling capabilities and has achieved remarkable success in natural language processing. In recent years, it has also demonstrated good performance in computer vision tasks. However, most Transformer structures directly apply self-attention on two-dimensional feature maps to obtain attention matrices based on a query and key for each spatial position. However, the contextual information between adjacent keys is not fully utilized. To address the problem of feature loss in Transformer, [PERSON] et al. proposed a new attention structure [31], namely, the Contextual Transformer (CoT) block. This module promotes self-attention learning  
Figure 6: Two GhostBottleneck structures. Figure 7: The schematic diagram of the PAFPN network. by leveraging contextual information between keys, ultimately enhancing the network's representational capacity. The CoT block employs a Transformer structure to simplify the extraction process of effectively related features over long distances in the image, expanding the receptive field and better utilizing the context features of key points. Firstly, query vectors Q (Query), key vectors K (Keys), and value vectors V (Values) are created using a weight matrix. Then, by applying a 3 \(\times\) 3 convolution operation to adjacent keys, the contextualization of key feature information is performed, transforming it into a representation of static feature information. The contextualized key features are then concatenated with the query vector and undergo two consecutive 1 \(\times\) 1 convolutions to generate an attention matrix. This concatenation process connects the query vector with the contextualized key features of all key vectors, enabling the attention matrix to learn and generate under the guidance of static contextual information, effectively enhancing self-attention. Subsequently, by multiplying the attention matrix with the value vector, dynamic feature information of the input value vector is obtained. Finally, the static feature information and dynamic feature information are added together as the output. The structure diagram of the CoT block is shown in Figure 9.  
From a computational perspective, for the input feature \(X\), first, define three variables \(K\), \(Q\), and \(V\), representing the query vector \(Q\), key vector \(K\), and value vector \(V\), respectively. Context encoding of the input keys is performed through a 3 \(\times\) 3 convolution to obtain the static contextual features \(K^{1}\) between locally adjacent keys. \(K^{1}\) is then concatenated with \(Q\)  
Figure 8: (**a**) Schematic diagram of CSPBottleneck_2 structure. (**b**) Schematic diagram of CoTBottleneck structure. Figure 9: Contextual Transformer (CoT) block. and through two consecutive \(1\times 1\) convolutions, a matrix, \(A\), is obtained.