# Light-YOLO: A Study of a Lightweight YOLOv8n-Based Method for Underwater Fishing Net Detection
## 3 Model Improvement
### Citing an Attention Mechanism  
In the field of underwater environmental monitoring, monitoring objects such as fishing nets often present multiple elongated slit features. Traditional convolutional neural networks (CNNs) may not be effective in recognizing and modelling such elongated slit features due to their inherent ability to model local information. This is mainly due to the fact that CNNs lack the ability to model long-range dependencies, which is crucial for the accurate recognition and processing of elongated features. To address this problem, we introduce the transformer module, which has powerful global information modelling capabilities. However, the self-attention mechanism in the standard transformer architecture calculates the attention weights mainly through the interaction between query and key, which does not fully consider the interconnections between keys. For this reason, we adopt the CoT (contextual transformer) block [22]. The CoT (contextual transformer) block is designed to dig deep into the contextual information of the keys and utilize this information to guide the process of computing dynamic attention weights. In this way, the CoT block can effectively enhance the model's ability to process visual representations, aggregating the advantages of contextual information mining and the self-attention mechanism into one. As shown in Figure 3, the implementation of this structure significantly improves the model's recognition and modelling effect on slender gap features.  
In the initial stage of processing the input features, we set three key variables and let the variables Q and K initially share the same input value, X. In order to capture and represent the features with local context, we perform a k \(\times\) k sized grouped convolution on K, which in turn yields an augmented K (denoted as K*). This step essentially models the local information statically. Further, we merged K* with Q with the aim of integrating the local contextual information with the original query information. Immediately after that, we performed two successive rounds of convolutional processing on the merged result; these steps aim to refine further and optimize the fused feature representation to enhance the model's ability to represent the input data.  
\[\text{A}=\left[\text{K}^{-1},\text{Q}\right]\text{W}_{\theta}\text{W}_{\delta} \tag{5}\]  
Unlike traditional self-attention mechanisms, the A-matrix construction in our approach relies not only on the direct relationship between query and key but is realized through the interaction between Q and K* augmented with local context. This design allows the attention mechanism to not only focus on the direct connection between query  
Figure 3: CoTAttention module diagram.  
and key but also incorporates the interaction of local context information, thus significantly improving the performance of the self-attention mechanism. Next, by multiplying this dynamically generated attention map with the value vector V, we implement dynamic context-based modelling. This process allows the model to dynamically adjust its emphasis on information, which in turn significantly improves the quality of the feature representation.  
\[\text{K}^{2}=\text{V}*\text{A} \tag{6}\]  
Ultimately, the contextual transformer (CoT) module effectively fuses local and global contexts by integrating features obtained from local static context modelling with those obtained based on dynamic context modelling. The CoT module is able to better distinguish fishing nets from the background through its ability to efficiently integrate contextual information and maintain a high recognition accuracy even in the case of poor visibility. In addition, dynamic context modelling allows the model to adapt to the changes of the fishing nets in different scenarios, such as the changes in the state of the net under the action of water currents.