A lightweight underwater target detection method based on self-attention mechanism
By combining an underwater inverse residual module, a self-attention global feature extraction module, and an underwater bounding box loss function, a lightweight underwater target detection network was constructed. This solved the problems of low underwater detection accuracy and limited computing resources, improved detection accuracy and robustness, and made it suitable for complex underwater scenarios.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- DALIAN MARITIME UNIVERSITY
- Filing Date
- 2026-02-28
- Publication Date
- 2026-05-29
AI Technical Summary
Existing lightweight underwater target detection methods suffer from low detection accuracy, poor scene adaptability, and limited computational resources in underwater environments. In particular, the accuracy decays significantly in small target detection tasks, and there is a lack of effective local and global feature fusion mechanisms and scale-adaptive design.
We employ an underwater inverse residual module (UIRB) to extract local features in a lightweight manner, introduce a self-attention global feature extraction module (SAEM) to fuse local and global features, design an underwater bounding box loss function (UW-IoU) for scale-adaptive training, and construct a lightweight underwater target detection network (GSAM-LUOD) based on a self-attention mechanism.
It improves the accuracy and robustness of target detection in complex underwater scenes, reduces computational complexity, adapts to resource-constrained underwater equipment, enhances the sensitivity and training stability of small target detection, and achieves a balance between lightweight design and detection performance.
Smart Images

Figure CN122115979A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of target detection technology and relates to a lightweight underwater target detection method based on a self-attention mechanism. Background Technology
[0002] Underwater target detection technology has significant application value in fields such as marine resource exploration, marine aquaculture monitoring, and marine ecological protection. However, due to the unique characteristics of the underwater environment, problems such as prominent background interference, large fluctuations in target size, and uneven illumination distribution frequently occur. In addition, underwater deployment equipment generally suffers from limited computing resources, which directly leads to serious constraints on the detection accuracy, scene adaptability, and engineering deployment feasibility of existing target detection algorithms in practical underwater scenarios.
[0003] Existing lightweight underwater target detection methods mostly directly adopt general lightweight backbone networks (such as the MobileNet series and ShuffleNet series), lacking specific optimizations for fusing complex underwater scene features with self-attention mechanisms. This makes it difficult to achieve an efficient balance between lightweight design and detection accuracy. Some existing underwater detection methods that introduce self-attention mechanisms simply embed the attention module into the network structure without optimizing the module design to take into account the characteristics of varying underwater target scales and complex background interference, thus failing to fully leverage the global feature capture advantages of self-attention.
[0004] Meanwhile, existing underwater detection networks incorporating self-attention mechanisms generally suffer from redundant attention module design and poor adaptability to lightweight structures, resulting in large model parameter counts and low computational efficiency. This makes them difficult to deploy on computationally limited real-time underwater application platforms such as underwater robots and remotely operated vehicles. Therefore, there is an urgent need for a target detection method that can deeply integrate self-attention mechanisms with lightweight structures and adapt to complex underwater scenarios. This method should enhance global feature capture and improve detection accuracy while maintaining lightweight design and real-time performance to meet the pressing needs of practical underwater applications.
[0005] Currently, underwater target detection technology plays a vital role in marine resource exploration, underwater security monitoring, and underwater operation support. However, underwater scenarios present challenges such as complex background interference, variable target scale, uneven lighting conditions, and limited model computational resources. These challenges significantly restrict the detection accuracy, scene adaptability, and deployment feasibility of existing target detection algorithms when applied in underwater environments.
[0006] To address the shortcomings of existing technologies, although existing lightweight detection methods attempt to balance detection performance and computational cost by simplifying model structure and introducing attention mechanisms, these methods typically suffer from the following technical drawbacks:
[0007] (1) Problem 1: Existing lightweight methods mostly achieve lightweighting by simply reducing the model structure, which easily leads to a weakening of local feature extraction capabilities, making it difficult to adapt to complex underwater backgrounds and targets with varying scales, and failing to balance lightweighting and detection accuracy.
[0008] (2) Problem 2: Existing methods are not targeted enough for underwater scenes, lack an effective mechanism for integrating local and global features, and have weak resistance to complex background interference and uneven lighting, especially in small target detection tasks where the accuracy is significantly reduced.
[0009] (3) Problem 3: The loss function of the existing method lacks scale-adaptive design, and the training constraints for targets of different scales are unbalanced, resulting in insufficient sensitivity of the model to small underwater targets and poor training stability.
[0010] To address the aforementioned issues, this study proposes a lightweight underwater target detection method based on an attention mechanism (GSAM-LUOD), which effectively solves the problems through the following methods: (1) Solution to problem one: This method designs an underwater inverse residual module (UIRB) to efficiently extract local features in a lightweight manner. While significantly reducing the number of model parameters and computational complexity, it retains the feature expression capability to the maximum extent, thus achieving a balance between lightweight and detection accuracy.
[0011] (2) Solution to problem 2: This method introduces a self-attention global feature extraction module (SAEM), which combines the local modeling capability of convolution with the global dependency modeling advantage of Transformer to build a local-global feature fusion mechanism, enhance the model's semantic understanding of complex underwater backgrounds and uneven lighting scenes, and improve scene adaptability.
[0012] (3) Solution to problem three: This method designs an underwater bounding box loss function (UW-IoU), introduces a scale-adaptive weighting mechanism, optimizes the training constraint weights of targets of different scales, effectively improves the model's sensitivity to small underwater targets, enhances the stability of the training process, and further ensures detection accuracy. Summary of the Invention
[0013] To address the aforementioned problems, the technical solution adopted in this invention is: a lightweight underwater target detection method based on a self-attention mechanism, comprising the following steps: Acquire underwater images to be detected; Based on underwater image datasets, a lightweight underwater target detection network model based on a self-attention mechanism is constructed. The lightweight underwater target detection network model is trained end-to-end to obtain a trained lightweight underwater target detection network model. The acquired underwater image to be detected is input into a trained lightweight underwater target detection network model to achieve target detection in the underwater image.
[0014] Furthermore: the lightweight underwater target detection network model includes: Backbone network: Extracts local and global features from the input raw image; PANet path aggregation network: performs multi-scale fusion based on local and global features transmitted by the backbone network; Detection Head: Based on the fused features transmitted by the PANet path aggregation network, the underwater bounding box loss function is used to complete the underwater target detection and output the target's location, category, and confidence information.
[0015] Furthermore: the backbone network includes: The module comprises a first convolutional module, a first local feature extraction module, a second local feature extraction module, a first global and local feature fusion module, and a second global and local feature fusion module. The first convolution module, the first local feature extraction module, the second local feature extraction module, the first global and local feature fusion module, and the second global and local feature fusion module are connected sequentially. The first local feature extraction module includes a second convolution module and a first underwater inverse residual module. The second convolution module and the first underwater inverse residual module are connected sequentially; The second local feature extraction module includes a third convolution module and a second underwater inverse residual module, wherein the third convolution module and the second underwater inverse residual module are connected sequentially. The first underwater residual conversion module and the second underwater residual conversion module have the same structure. The first underwater inverse residual module efficiently extracts underwater image texture and local edge features by employing a combination of channel expansion, depth convolution, channel compression and residual connection. The first global and local feature fusion module includes a fourth convolution module and a first self-attention global feature extraction module; the fourth convolution module and the first self-attention global feature extraction module are connected sequentially. The second global and local feature fusion module includes a fifth convolutional module and a second self-attention global feature extraction module; the fifth convolutional module and the second self-attention global feature extraction module are connected sequentially. The first self-attention global feature extraction module and the second self-attention global feature extraction module have the same structure. The first self-attention global feature extraction module combines the efficiency of convolutional local modeling with the advantages of Transformer global modeling. By transforming the feature dimension through convolution, it sequentially performs local convolutional feature extraction, global feature enhancement, and fusion of local convolutional features and global features to strengthen feature discrimination.
[0016] Furthermore, the process of extracting local features of underwater image texture and edges in a lightweight manner using a combination of channel expansion, depthwise convolution, channel compression, and residual connections is as follows: First, a 1×1 convolution is used to process the input feature map. Channel expansion This doubles the feature representation capability, thereby capturing more feature information: (1) in: For expansion factor, BN is a regularization method; Then, a 3×3 depthwise convolution is performed on the expanded features, with a separate convolution kernel applied to each channel of the input: (2) Next, the features obtained from the depthwise convolution are passed through a 1×1 convolution to remap the high-dimensional features back to the target output space: (3) Finally, residual connections are performed to obtain the feature output:
[0017] in: This represents element-level addition.
[0018] Furthermore: the process of extracting local features of underwater image texture and edges based on the underwater inverse residual module, transforming the feature dimension through convolution, performing sequential local convolution feature extraction and global feature enhancement, and then fusing the local and global features through channel stitching is as follows: Step 3-1: Local convolutional feature extraction stage, as follows: The first layer uses 3×3 convolutions on the input features. Processing, used to aggregate domain context information; The second layer uses a 1×1 convolution to project the number of feature channels onto the dimension d required for Transformer processing. The specific formula is as follows: (5) in: This represents the output feature of the local convolution feature extraction stage. loc is an abbreviation for local. This design realizes the transformation from the convolution domain to the Transformer domain. Step 3-2: Based on the extracted local experience and features, perform global feature extraction, as follows: right Grouping, dividing into several groups of size The patch is divided into groups. ,in ; When multi-head attention is fed into the Transformer network model, each token only interacts with tokens at the same position in other patches. The output features of the Transformer network model are remapped to the spatial domain after an inverse rearrangement operation, resulting in a model with the input features. Same size ; Step 3-3: Fuse the extracted local convolutional features and the extracted global features, as detailed below: A residual concatenation strategy is employed to extract the output of global features. Input features The data is concatenated along the channel dimension, and then integrated using a 3×3 convolution layer. : .
[0019] Furthermore: the aforementioned During multi-head attention computation in the Transformer network model, each token only interacts with tokens at the same position in other patches; the output features of the Transformer network model are remapped to the spatial domain after an inverse rearrangement operation, resulting in a representation that is identical to the input features. Same size The process is as follows: Step 4-1: In the Transformer network model, use a multi-head attention mechanism to... Regularization is then applied, followed by mapping to the Q, K, and V spaces, and then splitting it into multiple headers: (7) in: It refers to the number of heads in a multi-head attention mechanism. These are the dimensions of each head; Step 4-2: Calculate the pairwise similarity between all tokens with the same position in all patches using a multi-head attention mechanism to obtain a similarity feature map. The attention distribution map of each token to the same position in all other patches is obtained by normalizing the data using the Softmax function: (8) (9) Step 4-3: Obtain the context weights by weighted summation: After that The results of the size were pieced back together to restore the original state. Dimension, multi-head attention output With the original input Add: (10) Step 4-4: Finally, The data is then regularized and fed into a standard feedforward neural network to obtain the feature output. .
[0020] Furthermore: the formula for the underwater bounding box loss function is: (11) in: , : Represents the difference in width and height between the predicted bounding box and the ground truth bounding box; Indicates the width of the smallest closed region. Indicates the height of the smallest closed region; (12) : Area of the actual bounding box The area of the entire image. Hyperparameters.
[0021] A lightweight underwater target detection device based on a self-attention mechanism includes: Acquisition module: Used to acquire underwater images to be detected; Build module: Used to build a lightweight underwater target detection network model based on a self-attention mechanism based on an underwater image dataset; Training module: used to perform end-to-end training on the lightweight underwater target detection network model to obtain the trained lightweight underwater target detection network model; Detection module: This module takes the acquired underwater image to be detected and inputs it into a trained lightweight underwater target detection network model to achieve target detection in the underwater image.
[0022] This invention provides a lightweight underwater target detection method based on a self-attention mechanism, which has the following significant advantages compared with existing technologies: (1) This invention achieves collaborative extraction of local and global features through modular architecture design, which effectively improves the accuracy and robustness of target detection in complex underwater scenes; (2) The underwater inverse residual module (UIRB) proposed in this invention is highly compatible with the self-attention global feature extraction module (SAEM), which can reduce computational overhead while ensuring feature expression ability, and balance lightweight and detection performance. (3) The underwater bounding box loss function (UW-IoU) designed in this invention is adapted to multi-scale targets, and specifically improves the detection accuracy and training stability of small underwater targets; (4) The overall network architecture of the present invention is simple and efficient, with a small number of parameters and low computational complexity. It can be deployed in real time in resource-constrained underwater equipment and is suitable for actual application scenarios. Attached Figure Description
[0023] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0024] Figure 1 This is a diagram of a lightweight underwater target detection network structure based on a self-attention mechanism; Figure 2 This is a structural diagram of the underwater residual module; Figure 3 It is a self-attention global feature extraction module; Figure 4 It is a Transformer network model; Figure 5 This is a schematic diagram of the PANet path aggregation network; Figure 6 The image shows a comparison of the detection results of GSAM-LUOD and the contrasting methods on the DUO dataset, where (a) is LibraRCNN, (b) is Center Net, and (c) is the method of this application. Figure 7 The image shows a comparison of the detection results of GSAM-LUOD and the contrasting methods on the RUOD dataset, where (a) is LibraRCNN, (b) is Center Net, and (c) is the method of this application. Detailed Implementation
[0025] It should be noted that, unless otherwise specified, the embodiments and features in the embodiments of the present invention can be combined with each other. The present invention will be described in detail below with reference to the accompanying drawings and embodiments.
[0026] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. The following description of at least one exemplary embodiment is merely illustrative and is in no way intended to limit the present invention or its application or use. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0027] A lightweight underwater target detection method based on a self-attention mechanism includes the following steps: S1: Acquire the underwater image to be detected; S2: Based on underwater image datasets, construct a lightweight underwater target detection network model based on self-attention mechanism; S3: Perform end-to-end training on the lightweight underwater target detection network model to obtain the trained lightweight underwater target detection network model. Iteratively optimize the parameters and guide the UIRB, SAEM and UW-IoU detection head modules to work together to generate feature representations that are more suitable for underwater target detection until the model converges. S4: Input the acquired underwater image to be detected into the trained lightweight underwater target detection network model to achieve target detection in the underwater image.
[0028] Steps S1 / S2 / S3 / S4 are executed sequentially; Figure 1 This is a diagram of a lightweight underwater target detection network structure based on a self-attention mechanism; The lightweight underwater target detection network model (GSAM-LUOD) includes: Backbone network: Extracts local and global features from the input raw image; and adjusts the original image size. PANet path aggregation network: performs multi-scale fusion based on local and global features transmitted by the backbone network; Detection Head: Based on the fused features transmitted by the PANet path aggregation network, the underwater bounding box loss function (UW-IoU) is used to complete underwater target detection and output the target's location, category, and confidence information.
[0029] The backbone network includes: The module comprises a first convolutional module, a first local feature extraction module, a second local feature extraction module, a first global and local feature fusion module, and a second global and local feature fusion module. The first convolution module, the first local feature extraction module, the second local feature extraction module, the first global and local feature fusion module, and the second global and local feature fusion module are connected sequentially. The first local feature extraction module includes a second convolution module and a first underwater inverse residual module (UIRB), which are sequentially connected. The second local feature extraction module includes a third convolution module and a second underwater inverse residual module, wherein the third convolution module and the second underwater inverse residual module are connected sequentially. The first underwater inverse residual module and the second underwater inverse residual module have the same structure. The first underwater inverse residual module adopts a combination of channel expansion, depth convolution, channel compression and residual connection to simplify the number of parameters and computation while efficiently extracting underwater image texture and local edge features, improving gradient flow and avoiding gradient vanishing. The first global and local feature fusion module includes a fourth convolution module and a first self-attention global feature extraction module (SAEM). The fourth convolutional module and the first self-attention global feature extraction module (SAEM) are sequentially connected; The second global and local feature fusion module includes a fifth convolutional module and a second self-attention global feature extraction module; the fifth convolutional module and the second self-attention global feature extraction module are sequentially connected. The first self-attention global feature extraction module and the second self-attention global feature extraction module have the same structure. The first self-attention global feature extraction module integrates the efficiency of convolutional local modeling and the advantages of Transformer global modeling. It optimizes the Transformer multi-head attention process, and outputs optimized global features through feature normalization, dimension mapping, attention calculation and residual connection. This enhances the understanding of long-distance dependence and overall structure of underwater scenes. By transforming the feature dimension through convolution, it sequentially performs local convolutional feature extraction, global feature enhancement and fusion of local convolutional features and global features to enhance feature discrimination.
[0030] Figure 2 This is a structural diagram of the underwater residual module; Figure 3 It is a self-attention global feature extraction module; Figure 5 This is a schematic diagram of the PANet path aggregation network; PANet path aggregation network: consists of two main modules: Bottom-up path aggregation module (nodes 10, 11, 12): This module starts with a high-resolution feature map and passes information down layer by layer through downsampling operations. Similarly, at each level, the high-resolution feature map is laterally connected and point-by-point added to the low-resolution feature map.
[0031] Top-down path aggregation module (nodes 13, 14, 15): This module starts with a lower-resolution feature map and propagates information upwards layer by layer through upsampling operations. At each level, low-resolution feature maps are laterally connected and point-by-point added to high-resolution feature maps to integrate information at different scales.
[0032] The PANet path aggregation network's input and output contain feature maps at three different scales, and its network structure diagram is as follows: Figure 5 As shown in the diagram, shallow feature maps 12 and 13 have a size of 80×80, intermediate feature maps 11 and 14 have a size of 40×40, and deep feature maps 10 and 15 have a size of 20×20. The receptive fields of these feature maps increase sequentially, and the features at these three scales are used to detect small, medium, and large targets, respectively.
[0033] The PANet module's workflow is based on a bidirectional path aggregation logic of "upsampling + bottleneck module + feature fusion," combining the functions of convolutional units and bottleneck modules. The specific workflow is as follows: First, multi-scale feature input: receiving features of different scales corresponding to nodes 10, 11, and 12; next, bidirectional feature transfer and fusion: the features of node 10 are upsampled and fused with the features of node 11, and then input into the bottleneck module (a "Conv2d+BN+SiLU" process containing convolutional units) for processing to generate intermediate features; the features of node 11 are upsampled and fused with the features of node 12, and then input into the bottleneck module for processing; finally, hierarchical feature output: the outputs of each bottleneck module correspond to nodes 13, 14, and 15, and the features of these nodes will be passed to the subsequent detection head.
[0034] The process of extracting local features of texture and edges in underwater images in a lightweight manner using a combination of channel expansion, depthwise convolution, channel compression, and residual connections is as follows: First, a 1×1 convolution is used to process the input feature map. Channel expansion This multiplies the feature representation capability by a factor of 1 (t is the expansion factor), thereby capturing more feature information. (1) in: For expansion factor, BN is a regularization method; Then, a 3×3 depthwise convolution is performed on the expanded features. The depthwise convolution applies a separate convolution kernel to each channel of the input, which can significantly reduce the number of model parameters and improve computation speed compared to traditional convolution. (2) Next, the features obtained from the depthwise convolution are passed through a 1×1 convolution to remap the high-dimensional features back to the target output space: (3) Finally, residual connections are performed to obtain the feature output:
[0035] in: Representing element-wise addition, residual connections can effectively preserve key information in the input features and improve gradient flow, preventing the gradient vanishing problem.
[0036] Furthermore: the process of extracting local features of underwater image texture and edges based on the underwater inverse residual module, transforming the feature dimension through convolution, performing sequential local convolution feature extraction and global feature enhancement, and then fusing the local and global features through channel stitching is as follows: Step 3-1: Local convolutional feature extraction stage, as follows: The first layer uses 3×3 convolutions on the input features. Processing, used to aggregate domain context information; The second layer uses a 1×1 convolution to project the number of feature channels onto the dimension d required for Transformer processing. The specific formula is as follows: (5) in: The output features represent the local convolutional feature extraction stage. loc is an abbreviation for local. This design realizes the transformation from the convolutional domain to the Transformer domain. Step 3-2: In shallow, high-resolution underwater feature maps, there is significant redundancy between adjacent pixels, with almost no difference in information between them. Furthermore, the convolutional layers have already extracted local features in the previous step. If each token were to focus on all other tokens, especially within a short distance, the benefit would be very low relative to the enormous computational cost. Therefore, before implementing the Transformer, we... The data is grouped into several patches of size p×p. ,in ; When multi-head attention is fed into the Transformer network model, each token only interacts with tokens at the same position in other patches (e.g., Figure 3 As shown in the diagram, tokens of the same color (to indicate tokens in the same color) effectively reduce computational load and increase computational speed. The computational cost is reduced from the original... Reduce to .
[0037] The output features of the Transformer network model are remapped to the spatial domain after an inverse rearrangement operation, resulting in a model with the input features. Same size ; Step 3-3: Fuse the extracted local convolutional features and the extracted global features, as detailed below: To combine the representation capabilities of convolution and Transformer, a residual concatenation strategy is adopted. This strategy extracts the global features from the output... Input features The data is concatenated along the channel dimension, and then integrated using a 3×3 convolution layer. :
[0038] The Transformer network model is shown in Figure 4; Furthermore: the aforementioned During multi-head attention computation in the Transformer network model, each token only interacts with tokens at the same position in other patches; the output features of the Transformer network model are remapped to the spatial domain after an inverse rearrangement operation, resulting in a representation that is identical to the input features. Same size The process is as follows: Step 4-1: In Transformer, use a multi-head attention mechanism to... Batch normalization is then applied, followed by mapping to three spaces: Q (Query), K (Key), and V (Value), and then splitting it into multiple headers. (7) in: It refers to the number of heads in a multi-head attention mechanism. These are the dimensions of each head; Step 4-2: Utilize Multi-Head Attention to calculate the pairwise similarity between all tokens with the same position (same color) in all patches, thus obtaining a similarity feature map. The attention distribution map of each token to the same position in all other patches is obtained by normalizing the data using the Softmax function: (8) (9) Step 4-3: Obtain the context weights by weighted summation: After that The results of the size were pieced back together to restore the original state. Dimension, multi-head attention output With the original input Add: (10) Step 4-4: Finally, The data is then regularized and fed into a standard feedforward neural network to obtain the feature output. .
[0039] Furthermore: the underwater bounding box loss function is adapted to address the issues of blurred edges and unstable localization of small underwater targets. By introducing a scale-weighted factor to optimize multi-scale target training, it provides accurate loss constraints for the detection head. The specific formula is as follows: (11) in: , : Represents the difference in width and height between the predicted bounding box and the ground truth bounding box; Indicates the width of the smallest closed region. Indicates the height of the smallest closed region; (12) : Area of the actual bounding box The area of the entire image. Hyperparameters.
[0040] When the target is very small As the target value approaches 0, the weight increases; when the target is very large, the weight approaches 1. Scale factor This significantly increases the loss weight for small targets. When a target occupies a small proportion of the entire image, increasing its weight means that the target will contribute more gradients during backpropagation, causing the model to focus more on the localization and shape of small targets. This can improve the recall and localization accuracy of small targets.
[0041] A lightweight underwater target detection device based on a self-attention mechanism includes: Acquisition module: Used to acquire underwater images to be detected; Build module: Used to build a lightweight underwater target detection network model based on a self-attention mechanism based on an underwater image dataset; Training module: used to perform end-to-end training on the lightweight underwater target detection network model to obtain the trained lightweight underwater target detection network model; Detection module: This module takes the acquired underwater image to be detected and inputs it into a trained lightweight underwater target detection network model to perform target detection on the underwater image.
[0042] Example 1 In practical implementation, the publicly available datasets DUO and RUOD were used to experiment with the proposed GSAM-LUOD network. Ablation tests were conducted on the UIRB module, SAEM module, and UW-IoU loss function, and performance was compared with current mainstream object detection methods to demonstrate the effectiveness and superiority of the present invention. The specific implementation steps are as follows: Step 1: Acquire the underwater image to be detected; Step 2: Based on the underwater image dataset, construct a lightweight underwater target detection network model based on the self-attention mechanism; Dataset preparation and performance validation: The DUO dataset (7782 images, 4 target classes) was divided into a training set of 6671 images and a test set of 1111 images; the RUOD dataset (14000 images, 10 target classes) was divided into training, validation, and test sets in a 7:2:1 ratio. Ablation experiments were conducted using mAP50, mAP50-90, Precision, Recall, Parameters, and GFLOPs as metrics to verify the effectiveness of UIRB, SAEM, and UW-IoU individually and in combination. Performance comparison experiments demonstrated that the model outperformed mainstream methods.
[0043] S21: Construct a full-link network consisting of a backbone network, a PANet path aggregation network, and a detection head. The backbone network specifically integrates the underwater inverse residual module (UIRB) and the self-attention global feature extraction module (SAEM). The detection head embeds the underwater bounding box loss function (UW-IoU), forming a collaborative optimization system from feature extraction to target detection. Its network structure is shown in Figure 1. S22: Design and build a lightweight underwater reverse residual module (UIRB): This module receives the raw image. As input, the output is an enhanced feature map, where H and W are generally fixed at 640. The input and output sizes are the same, and the network structure is as follows: Figure 2 As shown, a combined structure of channel expansion, depthwise convolution, channel compression, and residual connection is adopted.
[0044] S23. Design and construct the Self-Attention Global Feature Extraction Module (SAEM): It combines the efficiency of local modeling of convolution with the advantages of global modeling of Transformer. It is divided into three parts: local convolution feature extraction, global feature enhancement and local-global fusion. Its network structure is shown in Figure 3.
[0045] S24, Optimize the Transformer multi-head attention process: Process features through a multi-head attention mechanism to enhance the understanding of long-range dependencies and overall structure of underwater scenes. S25. Design and construct the underwater bounding box loss function (UW-IoU): adapt to the problems of blurred edges and unstable localization of small underwater targets. By introducing a scale weighting factor to optimize multi-scale target training, it provides accurate loss constraints for the detection head.
[0046] S3, Lightweight Underwater Target Detection Network End-to-End Training: The entire network is trained end-to-end using an NVIDIA GeForce RTX 3090 GPU, with a total of 500 epochs, a batch size of 16, and an initial learning rate of 0.01. Random flipping and Mosaic data augmentation methods are used to improve the model's generalization ability. The loss function is a combination of UW-IoU bounding box loss, classification loss, and confidence loss. Parameters are iteratively optimized to guide the UIRB, SAEM, and UW-IoU detection head modules to work together to generate feature representations more suitable for underwater target detection until the model converges.
[0047] S4: Input the acquired underwater image to be detected into the trained lightweight underwater target detection network model to realize target detection in the underwater image.
[0048] This invention proposes a GSAM-LUOD network for underwater target detection, which improves the detection performance of small underwater targets while maintaining the detection effect of normal-sized targets, and significantly reduces the number of model parameters and computational complexity. First, this invention proposes an Underwater Inverse Residual Module (UIRB), employing a combined structure of channel expansion, depthwise convolution, channel compression, and residual connections. This reduces the number of parameters and computational cost while efficiently extracting local features such as texture and edges from underwater images, improving gradient flow and avoiding gradient vanishing. Second, a Self-Attention Global Feature Extraction Module (SAEM) is designed, combining the efficiency of convolutional local modeling with the advantages of Transformer global modeling. It transforms the feature dimension through convolution, optimizes the attention calculation logic to reduce overhead, and then fuses local and global features through channel concatenation to enhance feature discriminative power. Finally, an Underwater Bounding Box Loss Function (UW-IoU) is proposed to adapt to the problems of blurred edges and unstable localization of small underwater targets. By introducing a scale-weighted factor to optimize multi-scale target training, it provides accurate loss constraints for the detection head. Finally, through end-to-end optimization of the backbone network, PANet path aggregation network, and detection head, the network's target recognition accuracy and localization capability are effectively improved, ultimately forming a lightweight underwater target detection model (GSAM-LUOD) based on a self-attention mechanism suitable for resource-constrained edge computing platforms.
[0049] We conducted related experiments on the DUO and RUOD datasets.
[0050] Experiment 1, Qualitative Comparison Experiment: To verify the detection performance of GSAM-LUOD in real underwater scenarios, we qualitatively compared it with mainstream methods such as CenterNet and Libra RCNN. The experiment selected images from the DUO and RUOD datasets that exhibit typical underwater degradation phenomena such as color cast (blue-green tone), blurring (scattering effect), and low contrast (light attenuation) as test samples to visually observe the bounding box fit, missed detections, and false detections.
[0051] Experimental results are as follows Figure 6-7 The results show that when images on the DUO and RUOD datasets exhibit typical underwater degradation phenomena such as color cast (blue-green hues), blurring (scattering effects), and low contrast (light attenuation), the detection bounding boxes of GSAM-LUOD more closely match the true boundaries of the targets. Methods such as CenterNet and Libra RCNN may experience bounding box offsets or complete missed detections, while the detection bounding boxes of GSAM-LUOD closely match the true boundaries of the targets, significantly reducing missed and false detections, and demonstrating more stable performance in complex underwater degradation scenarios.
[0052] Experiment 2, Quantitative Comparison Experiment: To comprehensively verify the detection performance of GSAM-LUOD, we conducted quantitative comparisons with several mainstream object detection methods on the DUO and RUOD datasets. Evaluation metrics included mAP50, mAP50-90, Precision, Recall, number of parameters, and computational cost (Flops). The comparison results of GSAM-LUOD with other methods on the DUO dataset are shown in the table below: Table 1. Comparative experimental results of GSAM-LUOD and other comparative methods on the DUO dataset.
[0053] The results of the comparative experiments between GSAM-LUOD and other methods on the RUOD dataset are shown in the table below: Table 2. Comparison results of GSAM-LUOD with other comparative methods on the RUOD dataset.
[0054] On the DUO dataset, GSAM-LUOD achieves an mAP50 of 84.5% and an mAP50-90 of 64.8%, significantly higher than traditional methods such as Faster R-CNN (83.4% / 63.0%) and RetinaNet (83.3% / 64.1%). While lower than DINO-4scale (86.6% / 66.1%), it has only 2.7M parameters and 5.2 GFLOPs of computation, more than an order of magnitude lower than DINO-4scale (47.5M / 274 GFLOPs). On the more complex RUOD dataset, GSAM-LUOD achieves an mAP50 of 84.0% and an mAP50-90 of 59.4%, with a recall of 75.9% and a precision of 84.6%, demonstrating balanced performance superior to most comparative methods while maintaining its lightweight advantage. Experimental results show that GSAM-LUOD maintains competitive detection accuracy while ensuring lightweight operation, balancing performance and resource adaptability.
[0055] Experiment 3: Loss Function Comparison Experiment: To verify the effectiveness of the Underwater Bounding Box Loss Function (UW-IoU), we conducted comparative experiments on the DUO and RUOD datasets, comparing it with mainstream loss functions such as CIoU, DIoU, GIoU, and SIoU, focusing on the changes in mAP50 and mAP50-90 metrics. The comparison experiment of the Underwater Bounding Box Loss Function UW-IoU and other loss functions on the DUO dataset is shown in the table below: Table 3. Comparison of underwater bounding box loss function UW-IoU and other loss functions on the DUO dataset;
[0056] Table 4 below shows a comparison experiment of the underwater bounding box loss function UW-IoU and other loss functions on the RUOD dataset: Table 4. Comparison of the underwater bounding box loss function UW-IoU and other loss functions on the RUOD dataset.
[0057] The underwater bounding box loss function UW-IoU proposed in this invention achieves best or tied-best performance on the DUO and RUOD datasets compared to mainstream loss functions such as CIoU, DIoU, and GIoU, in terms of mAP50 and mAP50-95 metrics. Particularly on the DUO dataset, UW-IoU improves mAP50 from the baseline (0.840 for CIoU) to 0.845 and mAP50-95 from 0.645 to 0.648. This verifies that the scale-adaptive weighting mechanism introduced in UW-IoU effectively improves the model, especially its ability to locate small targets and perform shape regression, enhancing the fairness and stability of the training process.
[0058] Experiment 4, Module Ablation Experiment: To verify the effectiveness and synergistic effect of the core modules (UIRB, SAEM, UW-IoU) in GSAM-LUOD, we designed multiple module combination experiments on the DUO and RUOD datasets, gradually adding each core module and observing performance changes. The ablation experiment results of different module combinations of GSAM-LUOD on the DUO dataset are shown in the following 5 tables: Table 5 Ablation experimental results of different GSAM-LUOD module combinations on the DUO dataset.
[0059] The ablation experiments of different modules of the DAM-LUOD model on the RUOD dataset are shown in the table below: Table 6 Ablation experiments of different modules of the DAM-LUOD model on the RUOD dataset.
[0060] On the DUO and RUOD datasets, using UIRB, SAEM, or UW-IoU alone all resulted in varying degrees of performance improvement. Adding the UW-IoU loss function resulted in the largest improvement in mAP50-90, demonstrating the crucial role of the scale-adaptive weighting mechanism in small object detection. On the DUO dataset, when UIRB and SAEM were combined, mAP50 increased to 0.839, indicating a significant synergistic effect between lightweight local feature extraction and global context modeling. The combination of all three (UIRB+SAEM+UW-IoU) achieved the best performance of 0.845, fully validating the effectiveness and complementarity of each module.
[0061] This invention proposes a lightweight underwater target detection method (GSAM-LUOD) based on a self-attention mechanism. Through modular collaborative optimization and specialized design, it achieves significant breakthroughs in detection accuracy, lightweight design, and scene adaptability. Experimental results show that on the publicly available DUO dataset, the proposed method achieves an mAP50 of 84.5% and an mAP50-90 of 64.8%, a 0.5% improvement in accuracy compared to the CIoU loss function's 84.0%. On the RUOD dataset, the proposed method achieves an mAP50 of 84.0% and an mAP50-90 of 59.4%, a 2.3% improvement over benchmark methods. Compared to mainstream general-purpose detectors such as Faster R-CNN and RetinaNet, it demonstrates accuracy improvements ranging from 1% to 5%. These results indicate that the proposed method significantly improves the performance of target detection in underwater environments and is significantly superior to existing mainstream detection algorithms.
[0062] This invention employs a lightweight network architecture design. GSAM-LUOD has only 2.7M parameters and a computational cost of only 5.2G. Compared to traditional two-stage detectors (such as Cascade RCNN's 69.2M / 236G) and state-of-the-art single-stage detectors (such as DINO-4scale's 47.5M / 274G), the number of parameters and computational cost are reduced by more than an order of magnitude. This demonstrates that the model has successfully achieved its lightweight objective in its structural design, possessing the potential for deployment on computationally limited embedded or mobile platforms. This significantly improves the efficiency and real-time performance of underwater target detection tasks.
[0063] Furthermore, the underwater bounding box loss function UW-IoU proposed in this invention achieves best or tied-best performance on the DUO and RUOD datasets compared to mainstream loss functions such as CIoU, DIoU, and GIoU, in terms of mAP50 and mAP50-95 metrics. Particularly on the DUO dataset, UW-IoU improves mAP50 from the baseline (0.840 for CIoU) to 0.845 and mAP50-95 from 0.645 to 0.648. This verifies that the scale-adaptive weighting mechanism introduced in UW-IoU effectively improves the model, particularly its ability to locate small targets and perform shape regression, enhancing the fairness and stability of the training process.
[0064] Figure 6 The image shows a comparison of the detection results of GSAM-LUOD and the contrasting methods on the DUO dataset, where (a) is LibraRCNN, (b) is Center Net, and (c) is the method of this application. Figure 7 The image shows a comparison of the detection results of GSAM-LUOD and the contrasting methods on the RUOD dataset, where (a) is LibraRCNN, (b) is Center Net, and (c) is the method of this application.
[0065] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A lightweight underwater target detection method based on a self-attention mechanism, characterized in that: Includes the following steps: Acquire underwater images to be detected; Based on underwater image datasets, a lightweight underwater target detection network model based on a self-attention mechanism is constructed. The lightweight underwater target detection network model is trained end-to-end to obtain a trained lightweight underwater target detection network model. The acquired underwater image to be detected is input into a trained lightweight underwater target detection network model to achieve target detection in the underwater image.
2. The lightweight underwater target detection method based on a self-attention mechanism according to claim 1, characterized in that: The lightweight underwater target detection network model includes: Backbone network: Extracts local and global features from the input raw image; PANet path aggregation network: performs multi-scale fusion based on local and global features transmitted by the backbone network; Detection Head: Based on the fused features transmitted by the PANet path aggregation network, the underwater bounding box loss function is used to complete the underwater target detection and output the target's location, category, and confidence information.
3. The lightweight underwater target detection method based on a self-attention mechanism according to claim 2, characterized in that: The backbone network includes: The module comprises a first convolutional module, a first local feature extraction module, a second local feature extraction module, a first global and local feature fusion module, and a second global and local feature fusion module. The first convolution module, the first local feature extraction module, the second local feature extraction module, the first global and local feature fusion module, and the second global and local feature fusion module are connected sequentially. The first local feature extraction module includes a second convolution module and a first underwater inverse residual module. The second convolution module and the first underwater inverse residual module are connected sequentially; The second local feature extraction module includes a third convolution module and a second underwater inverse residual module, wherein the third convolution module and the second underwater inverse residual module are connected sequentially. The first underwater residual conversion module and the second underwater residual conversion module have the same structure. The first underwater inverse residual module efficiently extracts underwater image texture and local edge features by employing a combination of channel expansion, depth convolution, channel compression and residual connection. The first global and local feature fusion module includes a fourth convolution module and a first self-attention global feature extraction module; the fourth convolution module and the first self-attention global feature extraction module are connected sequentially. The second global and local feature fusion module includes a fifth convolutional module and a second self-attention global feature extraction module; the fifth convolutional module and the second self-attention global feature extraction module are connected sequentially. The first self-attention global feature extraction module and the second self-attention global feature extraction module have the same structure. The first self-attention global feature extraction module combines the efficiency of convolutional local modeling with the advantages of Transformer global modeling. By transforming the feature dimension through convolution, it sequentially performs local convolutional feature extraction, global feature enhancement, and fusion of local convolutional features and global features to strengthen feature discrimination.
4. The lightweight underwater target detection method based on a self-attention mechanism according to claim 3, characterized in that: The process of extracting local features of texture and edges in underwater images in a lightweight manner using a combination of channel expansion, depthwise convolution, channel compression, and residual connections is as follows: First, a 1×1 convolution is used to process the input feature map. Channel expansion This doubles the feature representation capability, thereby capturing more feature information: (1) in: For expansion factor, BN is a regularization method; Then, a 3×3 depthwise convolution is performed on the expanded features, with a separate convolution kernel applied to each channel of the input: (2) Next, the features obtained from the depthwise convolution are passed through a 1×1 convolution to remap the high-dimensional features back to the target output space: (3) Finally, residual connections are performed to obtain the feature output: in: It represents element-level addition.
5. A lightweight underwater target detection method based on a self-attention mechanism according to claim 3, characterized in that: The process of extracting local features of underwater image texture and edges based on the underwater inverse residual module, transforming the feature dimension through convolution, performing sequential local convolution feature extraction and global feature enhancement, and then fusing the local and global features through channel concatenation is as follows: Step 3-1: Local convolutional feature extraction stage, as follows: The first layer uses 3×3 convolutions on the input features. Processing, used to aggregate domain context information; The second layer uses a 1×1 convolution to project the number of feature channels onto the dimension d required for Transformer processing. The specific formula is as follows: (5) in: This represents the output features of the local convolution feature extraction stage. loc is an abbreviation for local. This design realizes the transformation from the convolutional domain to the Transformer domain. Step 3-2: Based on the extracted local experience and features, perform global feature extraction, as follows: right Grouping, dividing into several groups of size The patch is divided into groups. ,in ; When multi-head attention is fed into the Transformer network model, each token only interacts with tokens at the same position in other patches. The output features of the Transformer network model are remapped to the spatial domain after an inverse rearrangement operation, resulting in a model with the input features. Same size ; Step 3-3: Fuse the extracted local convolutional features and the extracted global features, as detailed below: A residual concatenation strategy is employed to extract the output of global features. Input features The data is concatenated along the channel dimension, and then integrated using a 3×3 convolution layer. : (6)。 6. A lightweight underwater target detection method based on a self-attention mechanism according to claim 4, characterized in that: The When multi-head attention is fed into the Transformer network model, each token only interacts with tokens at the same position in other patches. The output features of the Transformer network model are remapped to the spatial domain after an inverse rearrangement operation, resulting in a model with the input features. Same size The process is as follows: Step 4-1: In the Transformer network model, use a multi-head attention mechanism to... Regularization is then applied, followed by mapping to the Q, K, and V spaces, and then splitting it into multiple headers: (7) in: It refers to the number of heads in a multi-head attention mechanism. These are the dimensions of each head; Step 4-2: Calculate the pairwise similarity between all tokens with the same position in all patches using a multi-head attention mechanism to obtain a similarity feature map. The attention distribution map of each token to the same position in all other patches is obtained by normalizing the data using the Softmax function: (8) (9) Step 4-3: Obtain the context weights by weighted summation: After that The results of the size were pieced back together to restore the original state. Dimension, multi-head attention output With the original input Add: (10) Step 4-4: Finally, The data is then regularized and fed into a standard feedforward neural network to obtain the feature output. .
7. A lightweight underwater target detection method based on a self-attention mechanism according to claim 1, characterized in that: The formula for the underwater boundary box loss function is: (11) in: , : Represents the difference in width and height between the predicted bounding box and the ground truth bounding box; Indicates the width of the smallest closed region. Indicates the height of the smallest closed region; (12) : Area of the actual bounding box The area of the entire image. Hyperparameters.
8. A lightweight underwater target detection device based on a self-attention mechanism, characterized in that: include: Acquisition module: Used to acquire underwater images to be detected; Build module: Used to build a lightweight underwater target detection network model based on a self-attention mechanism based on an underwater image dataset; Training module: used to perform end-to-end training on the lightweight underwater target detection network model to obtain the trained lightweight underwater target detection network model; Detection module: This module takes the acquired underwater image to be detected and inputs it into a trained lightweight underwater target detection network model to achieve target detection in the underwater image.