Lightweight underwater semantic segmentation method based on fine-grained attention and adaptive feature fusion
A lightweight underwater semantic segmentation method based on fine-grained multi-level feature attention and adaptive feature fusion solves the problems of computational complexity of high-precision models and insufficient features of lightweight models in underwater image segmentation, and achieves high-precision underwater target segmentation with low computing resources.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- DALIAN OCEAN UNIV
- Filing Date
- 2026-01-19
- Publication Date
- 2026-05-05
AI Technical Summary
In underwater image semantic segmentation, existing technologies suffer from high computational complexity in high-precision models, making them difficult to run in real time. Lightweight models lack feature extraction capabilities in low-contrast environments, and traditional loss functions are unstable for segmenting small targets.
A fine-grained multi-level feature attention module (FGMLFA) is used to enhance feature extraction, an adaptive feature fusion module (AFFM) is used to achieve multi-scale information fusion, and a hybrid loss function combining Gaussian Dice loss and focus loss is combined to improve the segmentation accuracy of small targets.
High-precision underwater target segmentation was achieved with low computing resources, solving the problems of real-time operation of the model in complex underwater environments and segmentation of small targets, thus improving segmentation accuracy and stability.
Smart Images

Figure CN121982506A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of computer vision and deep learning technology, and in particular to a lightweight underwater image semantic segmentation method for use in aquaculture environments. Background Technology
[0002] As the aquaculture industry transforms towards digitalization and intelligence, utilizing computer vision technology for automatic identification, status monitoring, and behavior analysis of individual organisms such as fish and shellfish in the aquaculture environment has become a key approach to improving aquaculture efficiency. Image semantic segmentation, as a core technology of underwater perception, can classify each pixel in an image, thereby achieving fine segmentation of the target.
[0003] However, in practical underwater applications, image semantic segmentation faces extremely severe challenges. On the one hand, the absorption and scattering of light by water causes images to generally suffer from problems such as light attenuation, color distortion, and blurriness, making feature extraction extremely difficult. On the other hand, underwater biological targets are often small and easily confused with complex aquatic plants and rocky backgrounds, resulting in unclear segmentation boundaries. To address these challenges, existing technologies mainly employ high-precision deep learning models or lightweight models, but both have significant limitations. High-precision models, such as the DeepLab series, while accurate in recognition, have a huge number of parameters and high computational complexity, making them difficult to run in real time on underwater robots with limited computing resources. While existing lightweight models are fast, they are prone to losing shallow spatial details in low-contrast underwater environments, leading to missed detections of small targets. Furthermore, the commonly used DiceLoss loss function is overly sensitive to small shifts in the prediction boundary when dealing with small-scale targets, easily causing the loss value to oscillate wildly during training and making it difficult to converge to the optimal solution. Therefore, developing a method that can maintain lightweight design while effectively enhancing feature extraction capabilities and stabilizing small-target training is a pressing technical challenge that needs to be addressed. Summary of the Invention
[0004] To address the challenges of balancing lightweight and high-precision models, as well as poor small target segmentation performance in existing technologies, this invention proposes a lightweight underwater semantic segmentation method based on fine-grained attention and adaptive feature fusion. This method constructs a lightweight semantic segmentation network for underwater scenarios—LUSSNet. First, to enhance the feature extraction capability of the shallow backbone network under high-noise conditions, a fine-grained multi-level feature attention feature extraction module (FGMLFA) is designed, effectively improving the model's perception of target bodies and blurred edges. Second, to achieve effective fusion of multi-scale semantic information and suppression of channel feature redundancy, an adaptive feature fusion module (AFFM) is constructed, introducing a wavelet downsampling mechanism to acquire edge information at different scales and achieving dynamic weighted integration of semantic features. Finally, to increase the training weights of positive samples and alleviate the scale shift problem in small target segmentation, a Gaussian Dice loss function combining class balancing and small target modeling optimization is proposed, significantly improving the model's accuracy in positive / negative sample discrimination and small target segmentation tasks.
[0005] The technical solution of the present invention is as follows:
[0006] A lightweight underwater semantic segmentation method based on fine-grained attention and adaptive feature fusion includes the following steps:
[0007] S1. Collect raw underwater images of the aquaculture environment, preprocess the images, and construct an underwater semantic segmentation dataset containing training and validation sets;
[0008] S2. Construct a lightweight underwater semantic segmentation network LUSSNet, which includes a fine-grained multi-level feature attention module (FGMLFA), an adaptive feature fusion module (AFFM), and a pixel-level classifier;
[0009] The fine-grained multi-level feature attention module enhances shallow feature extraction from the input underwater image through multi-branch convolution and spatial and channel attention mechanisms;
[0010] The adaptive feature fusion module preserves spatial structure information through wavelet transform downsampling and introduces channel weighting and cosine similarity mechanisms to achieve adaptive complementary fusion of deep and shallow features.
[0011] The pixel-level classifier generates a semantic segmentation mask based on the fused deep semantic features output by the adaptive feature fusion module.
[0012] S3. Construct a hybrid loss function that includes FocalLoss and Gaussian DiceLoss. Use the training set constructed in step S1 to iteratively train the LUSSNet network constructed in step S2. Update the network parameters through the backpropagation algorithm until the loss function converges and the trained optimal model is obtained.
[0013] S4. Input the underwater image to be detected into the trained LUSSNet optimal model. The network outputs a pixel-level semantic segmentation mask to complete the identification and segmentation of underwater targets.
[0014] Furthermore, in step S1, the specific process of constructing the underwater semantic segmentation dataset includes:
[0015] Underwater images of aquaculture environments (such as net cages and ponds) are acquired using equipment such as underwater cameras or diving robots, ensuring that the images include targets with different lighting conditions, different turbidity, and different scales.
[0016] Pixel-level annotations are performed on target areas (such as fish, shellfish, sea cucumbers, etc.) in the acquired underwater images to generate binary or multi-category masks corresponding to the original underwater images;
[0017] The labeled underwater images are preprocessed, including image normalization, size unification (e.g., 640×640), flipping, rotation, and brightness adjustment, to enhance data diversity and the generalization ability of the model, forming an underwater semantic segmentation dataset.
[0018] The underwater semantic segmentation dataset is divided into training, validation, and test sets to ensure the reasonable distribution of scenes.
[0019] Furthermore, the Fine-Grained Multi-Level Feature Attention Module (FGMLFA) aims to enhance the feature extraction capability of shallow networks in blurry underwater environments through fine-grained segmentation and multi-dimensional attention mechanisms. There are four FGMLFA modules, each consisting of two-dimensional channel normalization, channel segmentation, multi-scale dilated convolution, and parallel spatial and channel attention guidance mechanisms. This module effectively extracts discriminative key features from images with limited computational resources, significantly improving the model's ability to perceive blurry underwater targets and small targets. The specific processing flow is as follows:
[0020] First, the input feature F is normalized using two-dimensional channels and then divided into four branch features according to the channels. The process is represented as follows:
[0021] (1)
[0022] Among them, Split is the channel splitting operation, and LayerNorm2D is the two-dimensional channel normalization process;
[0023] right Basic features were extracted using standard 3×3 convolution. ; then and In each stage, the output features of the previous stage are fused together, and multi-scale receptive fields are constructed using convolutional kernels with different dilation rates (3, 5), as shown in the following formula:
[0024] (2)
[0025] in, Indicates the first branch Basic features extracted by standard 3×3 convolution; Concat represents the channel concatenation operation; This represents a dilated convolution operation with a kernel size of 3×3 and a dilation rate of k. d=3 and d=5 are used to construct receptive fields of different scales, respectively. , This represents the output features after multi-scale perception.
[0026] Based on the obtained output features, and combined with spatial and channel attention modules, respectively... Perform spatial attention operations on the branch, for Perform channel attention operations on the branch;
[0027] The spatial attention operation on features Adaptive average pooling is performed along the spatial dimension, followed by convolution and activation to generate a spatial attention weight map. Then multiply it by the original feature, as shown in the following formula:
[0028] (3)
[0029] in, This represents the Sigmoid activation function, used to map weights to the (0,1) interval; Represents standard convolution; Indicates normalization; This represents the generated spatial attention weight map; This indicates features after spatial attention weighting, highlighting important areas;
[0030] The channel attention operation on features Perform global average pooling along the channel dimension, and generate channel weight vectors after convolution and activation. Then multiply it by the original feature, as shown in the following formula:
[0031] (4)
[0032] in, This represents the generated channel attention weight vector; This represents depthwise separable convolution; This indicates an average pooling operation; This represents the features after channel attention weighting, highlighting important dimension information;
[0033] Finally, all sub-branch features are concatenated along the channel dimension and then fused using a 3×3 convolution. Further processing with normalization and activation functions yields attention features that have undergone fine-grained multi-level perception. :
[0034] (5)
[0035] GELU is the activation function.
[0036] Furthermore, there are a total of four adaptive feature fusion modules (AFFM), each of which includes a wavelet transform enhancement module (WFD) and a channel-aware fusion module;
[0037] The wavelet transform enhancement module applies a two-dimensional discrete wavelet transform (DWT) operation to the input feature map, resulting in four sub-bands: one low-frequency approximate component. and three high-frequency directional components (horizontal) ,vertical diagonal The three high-frequency components are integrated and combined with low-frequency features to generate downsampled features containing global structure and local edges through convolution. The process is represented as:
[0038] (6)
[0039] in, This represents the input feature map, including the shallow features enhanced by the output of the fine-grained multi-level feature attention module. The deep semantic features output by the previous AFFM module And features obtained from the original underwater image through two-dimensional discrete wavelet transform; This represents a two-dimensional discrete wavelet transform operation; It represents the low-frequency approximate component while preserving the structural contour information of the image; , , These represent the high-frequency components in the horizontal, vertical, and diagonal directions, respectively, capturing edge and texture details; This indicates that the downsampled features generated after integrating low-frequency and high-frequency information have rich spatial structure expressive capabilities; this process ensures that the features still have rich spatial structure expressive capabilities during the downsampling process.
[0040] The channel-aware fusion module is used to achieve efficient fusion of multi-source features and suppress redundant interference; firstly, learnable parameters are introduced. shallow features Deep semantic features and downsampling features Weighted splicing was performed to obtain preliminary fusion features. :
[0041] (7)
[0042] in, (Right now , , () represents a learnable parameter used to adaptively control the importance of each feature channel; This indicates the initial fusion characteristics after weighting;
[0043] To enhance the discriminative power of the fused features, a feature adjustment mechanism based on cosine similarity is introduced. This mechanism dynamically updates the fusion result by measuring the similarity between features, effectively suppressing redundant features and enhancing key semantic responses. The formula is as follows:
[0044] (8)
[0045] in, Cosine similarity, representing the channel dimension, is used to measure the correlation between features; This indicates the final fused features, or deep semantic features, after dynamic weighting adjustment, which suppresses redundant features and enhances key semantics.
[0046] Furthermore, the pixel classifier first passes the deep semantic feature map output by the adaptive feature fusion module through a 1×1 convolutional layer, mapping the number of feature channels to the number of categories set in the dataset (e.g., for a task containing C class objects, the number of output channels is C), outputting unnormalized predicted values (Logits). Subsequently, a Softmax activation function is applied to this output along the channel dimension to calculate the probability distribution of each pixel belonging to each category, generating a probability map. Finally, an Argmax operation (i.e., taking the channel index corresponding to the maximum probability) is performed on each spatial location of the probability map to convert the probability distribution into a discrete category index map. This category index map is the final semantic segmentation mask output by the network, where the value of each pixel represents the object category predicted for that point (e.g., 0 represents the background, 1 represents fish, 2 represents shellfish, etc.).
[0047] Furthermore, during training, the underwater semantic segmentation network employs a hybrid loss function combining Gaussian Dice loss and focal loss to simultaneously address the scale sensitivity issue in underwater small target segmentation and the extreme imbalance between positive and negative samples. The calculation formula is as follows:
[0048] (9)
[0049] in, These are hyperparameters used to balance the weights of Gaussian Dice loss and FocalLoss; For Gaussian Dice loss; The loss is the focus.
[0050] Furthermore, the Gaussian Dice loss This design aims to address the issue of traditional Dice loss being overly sensitive to boundary offsets of small targets. The new loss function introduces a spatial weighting mechanism based on a two-dimensional Gaussian distribution to weight the target region, making the loss calculation focus more on the central area of the target, thereby reducing the drastic impact of edge pixel prediction errors on the overall loss. The specific construction process is as follows:
[0051] First, a two-dimensional Gaussian distribution map is generated based on the centroid of each connected target region in the real labels, resulting in the spatial weight matrix. Pixels closer to the center of the target are assigned larger weight values. The greater the distance, the smaller the weight; based on the spatial weight matrix Define the Gaussian Dice coefficient and Gaussian Dice loss The formula is as follows:
[0052] (10)
[0053] in, This represents the pixel index after the feature map is flattened; The output of the underwater semantic segmentation network is the first The predicted probability that each pixel belongs to the target category; For the first The actual label value of each pixel; For the first Spatial Gaussian weights corresponding to each pixel; The smoothing factor is used to prevent the denominator from being zero and to smooth the training process.
[0054] Furthermore, the focus loss To address the imbalance between positive and negative samples caused by the excessive proportion of background pixels in underwater images, this method reduces the weight of easily classified samples (i.e., background samples with high confidence), forcing the model to focus on sparse and difficult-to-segment underwater biological targets (hard-to-classify samples) during training. The calculation formula is as follows:
[0055] (11)
[0056] in, is the network's predicted probability of the pixel's true class; 'a' is the weighting factor that balances positive and negative samples. This is a focusing parameter used to adjust the degree of attention given to easy and difficult samples.
[0057] An electronic device includes a memory, a processor, and a computer program stored in the memory and executable on the processor; when the processor executes the computer program, the electronic device performs the lightweight underwater semantic segmentation method based on fine-grained attention and adaptive feature fusion.
[0058] A storage medium comprising a computer program that, when run on an electronic device, causes the electronic device to execute the lightweight underwater semantic segmentation method based on fine-grained attention and adaptive feature fusion.
[0059] The beneficial effects of this invention are as follows: The LUSSNet network proposed in this invention adopts an encoding and decoding architecture of a fine-grained multi-level feature attention module (FGMLFA) and an adaptive feature fusion module (AFFM). Through the synergistic effect of the FGMLFA and AFFM modules, a deep integration of local details and global semantics is achieved, resulting in a significant technological breakthrough in the fine segmentation task of aquaculture environments (such as fish and shellfish): In the encoding stage, the FGMLFA module effectively enhances the feature extraction capability of shallow networks under high noise conditions through multi-scale cascaded convolution and dual attention mechanism. This mechanism improves the model's perception of blurred targets with extremely low computational overhead. In the decoding stage, the AFFM module preserves spatial structure through wavelet transform and combines it with adaptive channel weighting, effectively bridging the semantic gap and avoiding the loss of texture details caused by traditional downsampling. At the same time, the Gaussian Dice loss function solves the scale sensitivity problem in small target segmentation. The performance of this invention has been verified on public datasets. It achieves high-precision segmentation with only 3.82M parameters and 26.36 GFLOPs of computational overhead, achieving the best balance between accuracy and efficiency. It provides a highly reliable and deployable intelligent tool for real-time visual perception of underwater robots. Attached Figure Description
[0060] Figure 1 This is a schematic diagram of the overall architecture of the lightweight underwater semantic segmentation network provided in this embodiment of the invention, showing the encoder-decoder structure adopted by the network, as well as the positions of the fine-grained multi-level feature attention module and the adaptive feature fusion module in the network.
[0061] Figure 2 This is a schematic diagram of the fine-grained multi-level feature attention module provided in the embodiment of the present invention, which shows the specific process of input features being processed by normalization, multi-branch segmentation, multi-scale dilated convolution, and spatial and channel attention mechanisms.
[0062] Figure 3 This is a schematic diagram of the adaptive feature fusion module provided in an embodiment of the present invention, illustrating the wavelet transform downsampling process, channel-aware fusion, and feature adjustment mechanism based on cosine similarity.
[0063] Figure 4 This is a schematic diagram illustrating the impact of target offset on DiceLoss and the principle of Gaussian weighting provided in the embodiments of the present invention. It shows how the Dice loss value changes due to position offset as the number of pixels in the target area decreases, and how Gaussian weighting alleviates this sensitivity. Detailed Implementation
[0064] To enable those skilled in the art to better understand the present invention, 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 merely some embodiments of the present invention, and not all embodiments. The following description of exemplary embodiments 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 should fall within the scope of protection of the present invention.
[0065] Underwater image semantic segmentation is a core task in the field of smart aquaculture. Its goal is to automatically and accurately extract and classify fish, shellfish, and aquaculture facilities from underwater images using computer vision techniques, thereby providing crucial data for biomass statistics, health monitoring, and aquaculture robot operations. Addressing the inherent limitations of traditional lightweight networks, such as weak feature extraction capabilities, loss of spatial details, and difficulty in segmenting small targets in low-contrast underwater environments, this invention provides a lightweight underwater semantic segmentation method that integrates fine-grained perception, adaptive fusion, and Gaussian Dice loss. This method employs a novel encoding / decoding architecture that combines a fine-grained multi-level feature attention module (FGMLFA) with an adaptive feature fusion module (AFFM). The framework consists of two main stages: an encoder and a decoder. The encoding stage uses FGMLFA as its core, employing cascaded dilated convolutions and multi-dimensional attention mechanisms to enhance the perception of blurred edges by shallow features while simultaneously suppressing background interference such as suspended matter in water bodies. The decoding stage utilizes the AFFM module, preserving spatial structure information through wavelet transform downsampling and introducing channel weighting and cosine similarity mechanisms to achieve adaptive complementary fusion of shallow and deep features. Finally, a hybrid loss function combining Focal Loss and Gaussian Dice Loss is used for training to address the issues of positive and negative sample imbalance and sensitivity to small target scales. Figure 1 As shown, the method specifically includes the following steps:
[0066] S1. Obtain raw underwater images of the aquaculture environment and preprocess them to construct an underwater semantic segmentation dataset.
[0067] This embodiment first constructs a widely representative underwater semantic segmentation dataset to ensure the model's robustness in diverse scenarios. Two publicly available benchmarks were selected for experimental data: the SUIM (Segmenting Underwater Imagery) dataset and the DUT-USEG dataset. The SUIM dataset covers typical underwater scenes under different water depths, turbidity, and lighting conditions, including various target categories such as fish, corals, aquatic plants, divers, and robots, totaling over 1500 high-resolution RGB images. Each image is equipped with a professionally cross-validated, pixel-by-pixel semantically annotated mask. The DUT-USEG dataset focuses more on realistic aquaculture environments, including four typical aquatic animals: sea cucumbers, sea urchins, scallops, and starfish, totaling 1487 finely annotated images. This dataset exhibits significant class imbalance and drastic lighting variations. Before network training, the above datasets were scientifically divided into training, validation, and test sets, and the images were uniformly adjusted to 640×640 pixels. Meanwhile, this embodiment employs data augmentation strategies such as normalization, random horizontal flipping, rotation, and brightness adjustment to expand sample diversity, improve the model's generalization ability to complex underwater lighting environments, and prevent overfitting.
[0068] S2. Construct and train a lightweight underwater semantic segmentation network.
[0069] The lightweight underwater semantic segmentation network (LUSSNet) employs an encoder-decoder architecture. In the encoding stage, this embodiment designs a fine-grained multi-level feature attention module (FGMLFA) as the core extraction unit. This module first processes the input features through two-dimensional channel normalization (LayerNorm2D), then divides them into four branches: the first branch uses 3×3 convolutions to extract basic features; the second and third branches combine dilated convolutions with dilation rates of 3 and 5, respectively, to expand the receptive field and embed a spatial attention mechanism to locate salient target regions; the fourth branch introduces a channel attention mechanism to recalibrate the importance of feature channels. Finally, the features from the four branches are concatenated and fused, thereby enhancing the shallow network's ability to perceive blurred edges and small biological targets with extremely low computational cost. In the decoding stage, this embodiment introduces an adaptive feature fusion module (AFFM). This module utilizes two-dimensional discrete wavelet transform (DWT) to replace traditional pooling operations for downsampling, decomposing the feature map into low-frequency components and high-frequency components in three directions, thus preserving spatial texture details to the greatest extent. Simultaneously, it introduces a channel-weighted and cosine similarity feature adjustment mechanism based on learnable parameters, achieving adaptive complementary fusion of deep and shallow features and effectively suppressing interference from redundant features. Training and testing in this embodiment were both performed on a high-performance computing platform. The hardware environment included an Intel Xeon Gold 6248R CPU, 64GB of memory, and an NVIDIA RTX 4090 (24GB) GPU; the software environment was based on the Ubuntu 22.04 LTS operating system and the PyTorch 2.0 deep learning framework. During training, the SGD optimizer was used with a momentum of 0.9 and a weight decay of 0.0001; the initial learning rate was set to 0.01, and a cosine annealing strategy was employed to smoothly decay the learning rate during iteration. To address the challenges of segmenting small underwater targets and the extreme imbalance of samples, this invention employs a hybrid loss function (WDF Loss), a weighted combination of Focal Loss and Gaussian Dice Loss. Gaussian Dice Loss, by introducing two-dimensional Gaussian distributed weights, assigns greater attention to the target's central region, effectively mitigating the loss oscillation problem caused by the boundary shift of small targets. Focal Loss, on the other hand, dynamically adjusts the weights of easy and difficult samples, forcing the model to focus on sparse biological targets.
[0070] To verify the effectiveness of the proposed method, comparative experiments were conducted on the SUIM dataset against nine mainstream algorithms, including HRNet, PSPNet, and BiSeNetV2. Experimental results show that LUSSNet achieves a mIoU of 58.97% and an mPA of 70.27% on the SUIM dataset, both outperforming the comparative models. Compared to the lightweight representative BiSeNetV2, the mIoU is improved by 20.16 percentage points; compared to the high-precision ErfNet, not only is the accuracy improved by 1.73 percentage points, but the inference speed also reaches 59.88 FPS, far exceeding ErfNet's 32.65 FPS. This indicates that the proposed method significantly solves the problem of low segmentation accuracy in complex underwater scenes while maintaining real-time inference capabilities.
[0071] Table 1. Comparative experimental results on the SUIM dataset.
[0072]
[0073] To further verify the model's generalization ability, comparative experiments were conducted on the DUT-USEG dataset, which has a more complex environment and a more imbalanced class distribution. The results show that many lightweight models (such as Lednet and Cgnet) suffer from insufficient feature extraction capabilities, resulting in a significant drop in mIoU to around 20%, while the LUSSNet of this invention maintains an mIoU of 53.09% and an mPA of 63.65%. This result demonstrates that the FGMLFA module exhibits excellent robustness in handling small targets such as sea cucumbers and sea urchins, as well as blurred boundaries, and can adapt to real-world aquaculture environments.
[0074] Table 2. Comparative experimental results on the DUT-USEG dataset.
[0075]
[0076] Furthermore, this embodiment further analyzes the loss function and the role of each module through ablation experiments. In the loss function ablation experiment, comparing the traditional Dice-Loss (mIoU 56.96%) with the WDD-Loss proposed in this invention (mIoU 57.19%), it was found that introducing two-dimensional Gaussian distribution weights improved the mIoU by 0.23 percentage points, proving that the Gaussian weighting mechanism effectively alleviates the oscillations caused by the prediction bias of small target boundaries. The combined strategy of WDD-Loss and Focal-Loss adopted in this invention achieved the best performance (mIoU 58.97%), indicating that the two have a significant synergistic and complementary effect in solving sample imbalance and small target localization.
[0077] Table 3 Results of loss function ablation experiments
[0078]
[0079] Ablation experiments on the network structure confirmed that the FGMLFA module provides a solid feature foundation for the model (mIoU 53.09%), while the addition of the AFFM module further improves the mIoU to 55.60%, ultimately achieving optimal performance when combined with the hybrid loss function. In summary, this invention successfully solves the challenge of balancing accuracy and efficiency in underwater image semantic segmentation through fine-grained feature extraction, adaptive multi-scale fusion, and Gaussian Dice loss optimization.
[0080] Table 4 Ablation Experiment Results
[0081]
[0082] In summary, the experimental results quantitatively and qualitatively validate the advanced nature of the LUSSNet model proposed in this invention. Its performance improvement is mainly attributed to the accurate extraction of underwater blur features by the FGMLFA module, the effective preservation of multi-scale spatial details by the AFFM module, and the optimization of training stability for small targets by Gaussian Dice Loss. This method achieves the best segmentation accuracy among similar lightweight models while maintaining real-time efficiency (~60 FPS), providing a highly reliable and deployable solution for intelligent visual perception of underwater robots.
[0083] Finally, it should be noted that the above embodiments are intended to illustrate the technical solutions of the present invention and do not constitute any limitation on the present invention. Those skilled in the art should fully understand that modifications to the technical solutions described in the foregoing embodiments or equivalent substitutions for any part or all of the technical features are entirely feasible. Such modifications or substitutions, as long as they do not depart from the scope of protection defined by the claims of the present invention, should be considered reasonable extensions of the present invention.
Claims
1. A lightweight underwater semantic segmentation method based on fine-grained attention and adaptive feature fusion, characterized in that, include: S1. Collect raw underwater images of the aquaculture environment, preprocess the images, and construct an underwater semantic segmentation dataset containing training and validation sets; S2. Construct a lightweight underwater semantic segmentation network, which includes a fine-grained multi-level feature attention module, an adaptive feature fusion module, and a pixel-level classifier; The fine-grained multi-level feature attention module enhances shallow feature extraction from the input underwater image through multi-branch convolution and spatial and channel attention mechanisms; The adaptive feature fusion module preserves spatial structure information through wavelet transform downsampling and introduces channel weighting and cosine similarity mechanisms to achieve adaptive complementary fusion of deep and shallow features. The pixel-level classifier generates a semantic segmentation mask based on the fused deep semantic features output by the adaptive feature fusion module. S3. Construct a hybrid loss function that includes Focal Loss and Gaussian Dice Loss. Use the training set constructed in step S1 to iteratively train the lightweight underwater semantic segmentation network constructed in step S2. Update the network parameters through the backpropagation algorithm until the loss function converges and the trained optimal model is obtained. S4. Input the underwater image to be detected into the trained optimal model, and output a pixel-level semantic segmentation mask to complete the identification and segmentation of underwater targets.
2. The lightweight underwater semantic segmentation method based on fine-grained attention and adaptive feature fusion according to claim 1, characterized in that, In step S1, the specific process of constructing the underwater semantic segmentation dataset includes: Acquire underwater images of aquaculture environments, ensuring that the images include targets under different lighting conditions, with different turbidities, and at different scales; Pixel-level annotation is performed on the target area in the acquired underwater image to generate a binary mask or multi-class mask corresponding to the original underwater image; The labeled underwater images are preprocessed, including image normalization, size unification, flipping, rotation and brightness adjustment, to enhance data diversity and the generalization ability of the model, forming an underwater semantic segmentation dataset. The underwater semantic segmentation dataset is divided into training, validation, and test sets to ensure the reasonable distribution of scenes.
3. The lightweight underwater semantic segmentation method based on fine-grained attention and adaptive feature fusion according to claim 1, characterized in that, The processing flow of the fine-grained multi-level feature attention module is as follows: The input feature F is processed through a two-dimensional channel normalization layer, and is divided into four branch features in the channel dimension. ; For the first branch Basic features were extracted using standard 3×3 convolution. ; For the second branch Integrate the output features of the previous stage Feature extraction was performed using a convolutional kernel with a dilation rate of 3. ; For the third branch Integrate the output features of the previous stage Features were extracted using a convolutional kernel with a dilation rate of 5. and to Spatial attention processing is performed to obtain ; For the fourth branch Perform channel attention processing to obtain Finally, the output features of the four branches are... After concatenation along the channel dimension, the data is fused using a 3×3 convolution, and further processed by normalization and activation functions to output the final features. .
4. The lightweight underwater semantic segmentation method based on fine-grained attention and adaptive feature fusion according to claim 1, characterized in that, The adaptive feature fusion module includes a wavelet transform enhancement module and a channel sensing fusion module; The wavelet transform enhancement module applies a two-dimensional discrete wavelet transform operation to the input feature map, resulting in four sub-bands: one low-frequency approximate component. And three high-frequency directional components, the three high-frequency directional components being horizontal ,vertical diagonal The three high-frequency components are integrated and combined with low-frequency features to generate downsampled features containing global structure and local edges through convolution. The process is represented as: (6) in, This represents the input feature map, including the shallow features enhanced by the output of the fine-grained multi-level feature attention module. The deep semantic features output by the previous AFFM module And features obtained from the original underwater image through two-dimensional discrete wavelet transform; This represents a two-dimensional discrete wavelet transform operation; Represents the low-frequency approximate component; , , These represent the high-frequency components in the horizontal, vertical, and diagonal directions, respectively. The channel-sensing fusion module first processes shallow features. Deep semantic features and downsampling features Weighted splicing was performed to obtain preliminary fusion features. : (7) in, , , This represents learnable parameters used to adaptively control the importance of each feature channel; A feature adjustment mechanism based on cosine similarity is introduced. By dynamically weighting and updating the fusion result by measuring the similarity between features, redundant features are effectively suppressed and key semantic responses are enhanced. The formula is as follows: (8) in, Cosine similarity is represented by the channel dimension. This refers to the final fused features, i.e., deep semantic features, after dynamic weighting adjustments.
5. The lightweight underwater semantic segmentation method based on fine-grained attention and adaptive feature fusion according to claim 1, characterized in that, The pixel classifier first passes the deep semantic feature map output by the adaptive feature fusion module through a 1×1 convolutional layer, mapping the number of feature channels to the number of categories set in the dataset, and outputting unnormalized predicted values. Then, it applies the Softmax activation function to the output along the channel dimension to calculate the probability distribution of each pixel belonging to each category, generating a probability map. Finally, it performs an Argmax operation on each spatial location of the probability map, converting the probability distribution into a discrete category index map. This category index map is the final semantic segmentation mask output by the network, where the value of each pixel represents the object category predicted for that point.
6. The lightweight underwater semantic segmentation method based on fine-grained attention and adaptive feature fusion according to claim 1, characterized in that, The underwater semantic segmentation network employs a hybrid loss function combining Gaussian Dice loss and focus loss during training; the hybrid loss function The calculation formula is as follows: (9) in, For hyperparameters; Gaussian Dice loss; The loss is the focus.
7. The lightweight underwater semantic segmentation method based on fine-grained attention and adaptive feature fusion according to claim 6, characterized in that, The specific construction process of the Gaussian Dice loss is as follows: First, a two-dimensional Gaussian distribution map is generated based on the centroid of each connected target region in the real labels, resulting in the spatial weight matrix. Pixels closer to the center of the target are assigned larger weight values. The greater the distance, the smaller the weight; based on the spatial weight matrix Define the Gaussian Dice coefficient and Gaussian Dice loss The formula is as follows: (10) in, This represents the pixel index after the feature map has been flattened; The output of the underwater semantic segmentation network is the first The predicted probability that each pixel belongs to the target category; For the first The actual label value of each pixel; For the first Spatial Gaussian weights corresponding to each pixel; This is a smoothing term.
8. The lightweight underwater semantic segmentation method based on fine-grained attention and adaptive feature fusion according to claim 6, characterized in that, The formula for calculating the focus loss is: (11) in, is the network's predicted probability of the pixel's true class; 'a' is the weighting factor that balances positive and negative samples. For focusing parameters.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and capable of running on the processor; characterized in that, When the processor executes the computer program, it causes the electronic device to perform the lightweight underwater semantic segmentation method based on fine-grained attention and adaptive feature fusion as described in any one of claims 1 to 8.
10. A storage medium comprising a computer program, characterized in that, When the computer program is run on an electronic device, the electronic device performs the lightweight underwater semantic segmentation method based on fine-grained attention and adaptive feature fusion as described in any one of claims 1 to 8.