An underwater debris identification method based on improved YOLOv8s
By improving the backbone, neck, and head networks of the YOLOv8s model and combining a specific attention mechanism and a dynamic sampling module, the problem of difficult extraction of target features in underwater debris identification was solved, achieving higher identification accuracy and robustness.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- NORTHEAST DIANLI UNIVERSITY
- Filing Date
- 2026-01-27
- Publication Date
- 2026-07-31
AI Technical Summary
Existing underwater debris identification technologies face challenges such as difficulty in extracting target features, poor identification accuracy, and poor robustness. In particular, they struggle to effectively distinguish debris from the background in complex underwater environments.
The YOLOv8s model is improved by constructing an improved backbone network, neck network, and head network, and combining the C2f-Faster-EMA module, BRSAM module, and MS-DSFLAM module to enhance feature extraction and target detection capabilities. The EMA attention mechanism and the Bilevel-RoutingAttention mechanism are adopted to dynamically adjust the sampling rate to improve recognition accuracy.
It significantly improves the accuracy and robustness of underwater debris identification, enhances the ability to distinguish debris features in complex underwater environments, improves the model's ability to capture targets in similar backgrounds, and enhances detection accuracy and the ability to detect diverse features.
Smart Images

Figure CN122023895B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of artificial intelligence, and more specifically to an underwater debris identification method based on an improved YOLOv8s. Background Technology
[0002] In recent years, autonomous underwater robots, with their intelligent and autonomous capabilities, have become key tools for environmental protection and underwater operations in deep-sea, strong-current, and polluted waters, significantly improving operational safety and coverage. However, existing underwater debris identification technologies still face multiple challenges: underwater debris varies significantly in shape, color, and size, and often closely resembles the surrounding environment in color and texture, making it difficult to effectively extract target features; furthermore, uneven underwater lighting, interference from suspended matter, and image degradation further reduce the accuracy and robustness of the identification model. Therefore, to address the specific needs of underwater debris identification, it is necessary to optimize existing detection models to improve identification accuracy and stability, thereby providing reliable technical support for autonomous underwater robot cleaning operations. Summary of the Invention
[0003] To address the problems existing in the prior art, this invention provides an underwater debris identification method based on an improved YOLOv8s model. By improving the YOLOv8s model, the method reduces the false negatives and false positives of debris with different shapes, colors and sizes, and those that are similar to the background.
[0004] The technical solution provided by this invention includes the following steps:
[0005] Step 1: Acquire underwater debris images to form the first dataset;
[0006] Step 2: Add annotation information to the images in the first dataset to form the second dataset, and divide the second dataset into training set, validation set and test set according to a preset ratio;
[0007] Step 3: Construct an underwater debris recognition model based on an improved YOLOv8s network. This model includes an improved backbone network, an improved neck network, and an improved head network. The construction of this model further includes steps 3.1 to 3.3:
[0008] Step 3.1: The improved backbone network consists of Conv-1, Conv-2, C2f-1, Conv-3, C2f-2, Conv-4, C2f-Faster-EMA-1, Conv-5, C2f-Faster-EMA-2 and SPPF modules connected in sequence;
[0009] The training and validation sets from the second dataset are used as inputs to the improved backbone network;
[0010] The improved backbone network outputs feature information at five different scales through the C2f-1, C2f-2, C2f-Faster-EMA-1, C2f-Faster-EMA-2 and SPPF modules, respectively.
[0011] Step 3.2: The improved neck network consists of BRSAM, TFE-1C2f-3, TFE-2C2f-4, MS-DSFLAM, CPAM-1, Upsample, CPAM-2, Concat-1, and Concat-2 modules;
[0012] The outputs of C2f-1 and C2f-2 serve as the inputs of TFE-2C2f-4, and the output of C2f-1 also serves as the input of CPAM-1.
[0013] The outputs of C2f-2, C2f-Faster-EMA-1, and C2f-Faster-EMA-2 serve as the inputs of MS-DSFLAM, and the outputs of MS-DSFLAM and TFE-2C2f-4 serve as the inputs of CPAM-2.
[0014] The output of MS-DSFLAM also serves as the input of UpSample, and the output of UpSample serves as the input of CPAM-1;
[0015] The output of SPPF is used as the input of BRSAM, the output of C2f-Faster-EMA-1 and BRSAM is used as the input of TFE-1C2f-3, the output of CPAM-2 and TFE-1C2f-3 is used as the input of Concat-1, and the output of TFE-1C2f-3 and Concat-1 is used as the input of Concat-2.
[0016] Step 3.3: The improved head network includes Detect-1, Detect-2, Detect-3, and Detect-4 modules; the output of CPAM-1 is used as the input of Detect-1; the output of CPAM-2 is used as the input of Detect-2; the output of Concat-1 is used as the input of Detect-3; and the output of Concat-2 is used as the input of Detect-4.
[0017] Step 4: Train the underwater debris recognition model based on the improved YOLOv8s using the training set and validation set, and save the trained model parameters as the optimal model;
[0018] Step 5: Test the saved optimal model using the test set, evaluate the test results of the test set using objective evaluation indicators, ensure that the accuracy requirements are met, and obtain the final underwater debris recognition model based on the improved YOLOv8s.
[0019] Furthermore, in step 1, the images in the first dataset can be collected and acquired through a network or captured by an underwater robot;
[0020] Preferably, in step 2, the training set, validation set, and test set can be divided in a ratio of 8:1:1.
[0021] Furthermore, the two C2f-Faster-EMA modules in step 3.1 have the same structure, and their construction method further includes steps 3.1.1 to 3.1.3:
[0022] Step 3.1.1: The C2f-Fater-EMA module is the replacement of the BottleNeck module in the C2f module of the original YOLOv8s network with the Faster-EMA module;
[0023] Step 3.1.2: The Faster-EMA module in step 3.1.1 is obtained by adding the FasterBlock module in the FasterNet network to the EMA attention mechanism.
[0024] Step 3.1.3: The EMA attention mechanism in step 3.1.2 is based on a multi-scale parallel processing architecture and includes two 1×1 convolutional paths and one 3×3 convolutional path;
[0025] In the two 1×1 convolutional paths, dual-path 1D global average pooling is used to encode channel information along the x-axis and y-axis directions respectively; at the same time, the two feature encodings are concatenated in the direction h; in addition, in order to realize different cross-channel interactive features between the two parallel paths of the 1×1 branch, the two channel attention maps in each group are aggregated by simple multiplication.
[0026] In the 3×3 convolution path, a single-layer 3×3 convolution kernel stacking structure is adopted. Local cross-channel interaction is achieved through 3×3 convolution operations. The 3×3 branch also introduces a global average pooling layer and achieves adaptive transformation of feature dimensions through a joint activation function.
[0027] Furthermore, in step 3.2, the BRSAM module replaces the channel attention mechanism in the CBAM attention mechanism with the Bilevel-RoutingAttention attention mechanism, while retaining the spatial attention mechanism;
[0028] The Bilevel-RoutingAttention mechanism is further constructed using steps 3.2.1 to 3.2.5:
[0029] Step 3.2.1: Given a 2D input feature map X, this feature map... H represents height, W represents width, and C represents the number of channels; it is divided into S×S non-overlapping regions, each region containing Feature vectors, this step is accomplished by reconstructing X, that is Based on the resulting query, key, and value tensors, Q, K, Then the linear projection is as shown in formulas (1) to (3):
[0030] (1),
[0031] (2),
[0032] (3),
[0033] In equations (1) to (3), Q, K, and V represent the query, key, and value, respectively; W q W k and These represent the projected weights of the query, key, and value, respectively.
[0034] Step 3.2.2: By applying the average value across various regions, derive the region-level query and key. The inter-region affinity matrix is derived by matrix multiplication between Q and transpose K, and the calculation formula is shown in formula (4):
[0035] (4),
[0036] In equation (4), the adjacency matrix A r The elements in the table measure the semantic relevance between two regions;
[0037] Step 3.2.3: Trim the affinity graph to obtain a routing index matrix I. r The calculation formula is shown in equation (5):
[0038] (5),
[0039] In equation (5), k represents the number of most relevant regions selected for each region; A r This represents the adjacency matrix; TopK represents the index selection function, which calculates the k regions most relevant to the current region.
[0040] Step 3.2.4: Each query token in region i lies in all key-value pairs whose attention remains within the k routing index matrix areas, while... To obtain the tensor of keys and values using the index, the calculation formula is shown in equation (6-7):
[0041] (6),
[0042] (7),
[0043] In equations (6) to (7), It is a tensor of keys and values;
[0044] Step 3.2.5: Apply the Bilevel-RoutingAttention mechanism to the calculated key-value pairs. The calculation formula is shown in Equation (8):
[0045] (8),
[0046] In equation (8), O represents the attention output feature, and LCE(V) represents the local context enhancement method;
[0047] The spatial attention mechanism is further constructed using steps 3.2.6 to 3.2.7:
[0048] Step 3.2.6: Apply global max pooling and global average pooling operations to the features obtained by the Bilevel-RoutingAttention module. The process generates two weight matrices that describe the importance of each spatial location.
[0049] Step 3.2.7: Perform channel concatenation on the two weight matrices. A 7×7 convolution operation reduces the dimensionality of the two channels to one channel, which is then processed using the SigMod activation function to obtain the final result. ; The calculation formula is shown in equation (9):
[0050] (9),
[0051] In equation (9), f 7×7 For convolution operations, AvgPool is the global average pooling operation, MaxPool is the global max pooling operation, and σ is the SigMod activation function. For average pooling characteristics, This is a max-pooling feature.
[0052] Furthermore, the MS-DSFLAM module in the improved neck network in step 3.2 is constructed by adding a DySample dynamic sampling module to the SSFF module in the ASF-Yolo neck network.
[0053] The MS-DSFLAM module includes three inputs, P3, P4-1 and P5, two Conv1d, two DySample, Concat, Conv3d, BN, LeakyReLU and MaxPool3d modules and one output, P4-2.
[0054] The DySample dynamic sampling module transforms the feature upsampling process into a sampling point-based resampling process by learning the sampling position and dynamically adjusting the regular sampling points. Specifically, the module takes a low-resolution feature map as input, uses a lightweight offset prediction network to generate a sampling offset, and combines it with a predefined regular sampling grid to obtain the dynamic sampling point position. Then, it reconstructs high-resolution features in a continuous feature space through bilinear resampling, thereby significantly reducing computational complexity while achieving adaptive modeling of target edges and structural information.
[0055] Furthermore, the underwater debris recognition model training process based on the improved YOLOv8s in step 4 specifically includes steps 4.1 to 4.4:
[0056] Step 4.1: Set the training parameters for the underwater debris recognition model based on the improved YOLOv8s;
[0057] Model training parameters include: number of iterations, batch size, optimizer, learning rate, momentum, weight decay, and number of threads;
[0058] Step 4.2: Input the training set, validation set, and corresponding labels into the underwater debris recognition model based on the improved YOLOv8s, and use the backpropagation algorithm to calculate the gradient of the loss function with respect to the model parameters;
[0059] Step 4.3: Use the optimizer to update the model parameters in the direction of gradient descent until the loss function of the training and validation sets no longer decreases, and the accuracy P, recall R, mAP50, and mAP50-95 metrics no longer improve.
[0060] Step 4.4: Save the trained model parameters as the optimal model.
[0061] Furthermore, step 5 specifically includes steps 5.1 to 5.3:
[0062] Step 5.1: Input the test set into the optimal model saved in Step 4;
[0063] Step 5.2: Calculate model performance metrics: accuracy (P), recall (R), mAP50, and mAP50-95. The specific calculation formulas are as follows:
[0064] (10)
[0065] (11),
[0066] (12)
[0067] (13)
[0068] In equations (10) to (13), P is the precision, R is the recall, mAP is the mean precision of all categories, AP is the average precision, m is the total number of categories of underwater debris tags, TP represents the number of positive samples correctly identified as positive samples, FP represents the number of negative samples incorrectly identified as positive samples, and FN represents the number of positive samples incorrectly identified as negative samples.
[0069] mAP50 represents the average accuracy when the IoU threshold is fixed at 0.5, and mAP50-95 represents the average accuracy calculated every 0.05 when the IoU threshold is between 0.5 and 0.95, and then the average of these average accuracies is taken.
[0070] Step 5.3: Evaluate the test results of the test set using objective evaluation metrics to ensure that the accuracy requirements are met, thus obtaining the final underwater debris recognition model based on the improved YOLOv8s.
[0071] Compared with the prior art, the beneficial effects of the present invention are:
[0072] The C2f-Faster-EMA module disclosed in this invention can maintain accurate representation of high-order semantic features in the deep stage of the model, adapt to complex underwater environments, and enhance semantic feature learning and efficient use of GPU resources by combining the EMA attention mechanism. It can also dynamically adjust channel weights and retain integrated spatial structure information, improve the underwater debris feature discrimination ability, and improve the problem of poor feature extraction effect of Yolov8s model.
[0073] The BRSAM module disclosed in this invention combines the advantages of Bileverl-RoutingAttention and spatial attention mechanisms, which can significantly improve the distinction between underwater debris outlines and background, thereby enhancing the model's ability to capture the edge features of underwater debris in similar background environments.
[0074] The improved neck network disclosed in this invention significantly enhances the model's ability to detect the diverse features of underwater debris. DySample can adaptively select the sampling rate based on the input features, and the sampler is weighted according to the importance of the features, thereby comprehensively considering multiple aspects of underwater debris such as color, shape, and outline, achieving a high degree of information aggregation. Attached Figure Description
[0075] Figure 1 This is a flowchart of the underwater debris identification method based on the improved YOLOv8s of the present invention;
[0076] Figure 2 This is a schematic diagram of the underwater debris recognition model based on the improved YOLOv8s of this invention.
[0077] Figure 3 This is a schematic diagram of the C2f-Faster-EMA module structure;
[0078] Figure 4 This is a schematic diagram of the BRSAM module structure;
[0079] Figure 5 This is a schematic diagram of the MS-DSFLAM module structure; Detailed Implementation
[0080] To make the technical solution, structural features, achieved objectives and advantages of the present invention clearer, the present invention will be further described in detail below with reference to specific embodiments and accompanying drawings. It should be noted that the specific embodiments described herein are only used to explain the present invention more clearly and are not intended to limit the present invention.
[0081] Figure 1 This is a flowchart of an underwater debris identification method based on an improved YOLOv8s disclosed in this invention. The implementation process is as follows:
[0082] Step 1: Acquire underwater debris images to form the first dataset; the underwater debris images in the first dataset can be collected through the network or captured by an underwater robot;
[0083] In this embodiment, in order to better evaluate the detection performance of the underwater debris identification method based on the improved YOLOv8s disclosed in this invention, the publicly available dataset TrashCan1.0 was used; the first dataset was formed using the TrashCan1.0 dataset.
[0084] Step 2: Add annotation information to the images in the first dataset to form the second dataset, and divide the second dataset into training set, validation set and test set according to a preset ratio;
[0085] Since the publicly available dataset TrashCan1.0 used in this embodiment already contains labeled information, this step is omitted. The odgt format label files in the first dataset described in this embodiment are converted into txt format label files required by YOLOv8s to form the second dataset, and the second dataset is divided into training set, validation set and test set in an 8:1:1 ratio. The resulting training set has 4000 images, the test set has 500 images, and the validation set has 500 images, with a total of eight categories. The categories are arranged from most to least number of instances as follows: textile waste (Trash-fabric), rubber waste (Trash-rubber), paper waste (Trash-paper), fishing gear waste (Trash-fishinggear), unknown waste (Trash-etc), plastic waste (Trash-plastic), wood waste (Trash-wood), and metal waste (Trash-metal). In this embodiment, the image resolution in the second dataset is 640×640.
[0086] Step 3: Construct an underwater debris recognition model based on the improved YOLOv8s. The structure of the improved YOLOv8s model is as follows: Figure 2 As shown, the model includes an improved backbone network, an improved neck network, and an improved head network. The construction of the model further includes steps 3.1 to 3.3:
[0087] Step 3.1: The improved backbone network consists of Conv-1, Conv-2, C2f-1, Conv-3, C2f-2, Conv-4, C2f-Faster-EMA-1, Conv-5, C2f-Faster-EMA-2 and SPPF modules connected in sequence;
[0088] The training and validation sets from the second dataset are used as inputs to the improved backbone network;
[0089] The improved backbone network outputs feature information at five different scales through the C2f-1, C2f-2, C2f-Faster-EMA-1, C2f-Faster-EMA-2 and SPPF modules, respectively.
[0090] Step 3.2: The improved neck network consists of BRSAM, TFE-1C2f-3, TFE-2C2f-4, MS-DSFLAM, CPAM-1, Upsample, CPAM-2, Concat-1, and Concat-2 modules;
[0091] The outputs of C2f-1 and C2f-2 serve as the inputs of TFE-2C2f-4, and the output of C2f-1 also serves as the input of CPAM-1.
[0092] The outputs of C2f-2, C2f-Faster-EMA-1, and C2f-Faster-EMA-2 serve as the inputs of MS-DSFLAM, and the outputs of MS-DSFLAM and TFE-2C2f-4 serve as the inputs of CPAM-2.
[0093] The output of MS-DSFLAM also serves as the input of UpSample, and the output of UpSample serves as the input of CPAM-1;
[0094] The output of SPPF is used as the input of BRSAM, the output of C2f-Faster-EMA-1 and BRSAM is used as the input of TFE-1C2f-3, the output of CPAM-2 and TFE-1C2f-3 is used as the input of Concat-1, and the output of TFE-1C2f-3 and Concat-1 is used as the input of Concat-2.
[0095] Step 3.3: The improved head network includes Detect-1, Detect-2, Detect-3, and Detect-4 modules; the output of CPAM-1 is used as the input of Detect-1; the output of CPAM-2 is used as the input of Detect-2; the output of Concat-1 is used as the input of Detect-3; and the output of Concat-2 is used as the input of Detect-4.
[0096] Furthermore, the two C2f-Faster-EMA modules in step 3.1 have the same structure, as shown in the schematic diagram below. Figure 3 As shown, its construction method further includes steps 3.1.1 to 3.1.3:
[0097] Step 3.1.1: The C2f-Fater-EMA module is the replacement of the BottleNeck module in the C2f module of the original YOLOv8s network with the Faster-EMA module;
[0098] Step 3.1.2: The Faster-EMA module in step 3.1.1 is obtained by adding the FasterBlock module in the FasterNet network to the EMA attention mechanism.
[0099] Step 3.1.3: The EMA attention mechanism in step 3.1.2 is based on a multi-scale parallel processing architecture and includes two 1×1 convolutional paths and one 3×3 convolutional path;
[0100] In the two 1×1 convolutional paths, dual-path 1D global average pooling is used to encode channel information along the x-axis and y-axis directions respectively; at the same time, the two feature encodings are concatenated in the direction h; in addition, in order to realize different cross-channel interactive features between the two parallel paths of the 1×1 branch, the two channel attention maps in each group are aggregated by simple multiplication.
[0101] In the 3×3 convolution path, a single-layer 3×3 convolution kernel stacking structure is adopted. Local cross-channel interaction is achieved through 3×3 convolution operations. The 3×3 branch also introduces a global average pooling layer and achieves adaptive transformation of feature dimensions through a joint activation function.
[0102] Furthermore, the BRSAM module in step 3.2 replaces the channel attention mechanism in the CBAM attention mechanism with a Bilevel-RoutingAttention mechanism, while retaining the spatial attention mechanism. A schematic diagram of the structure is shown below. Figure 4 As shown;
[0103] The Bilevel-RoutingAttention mechanism is further constructed using steps 3.2.1 to 3.2.5:
[0104] Step 3.2.1: Given a 2D input feature map X, this feature map... H represents height, W represents width, and C represents the number of channels; it is divided into S×S non-overlapping regions, each region containing Feature vectors, this step is accomplished by reconstructing X, that is Based on the resulting query, key, and value tensors, Q, K, Then the linear projection is as shown in formulas (1) to (3):
[0105] (1),
[0106] (2),
[0107] (3),
[0108] In equations (1) to (3), Q, K, and V represent the query, key, and value, respectively; W q W k and These represent the projected weights of the query, key, and value, respectively.
[0109] Step 3.2.2: By applying the average value across various regions, derive the region-level query and key. The inter-region affinity matrix is derived by matrix multiplication between Q and transpose K, and the calculation formula is shown in formula (4):
[0110] (4),
[0111] In equation (4), the adjacency matrix A r The elements in the table measure the semantic relevance between two regions;
[0112] Step 3.2.3: Trim the affinity graph to obtain a routing index matrix I. r The calculation formula is shown in equation (5):
[0113] (5),
[0114] In equation (5), k represents the number of most relevant regions selected for each region; A r This represents the adjacency matrix; TopK represents the index selection function, which calculates the k regions most relevant to the current region.
[0115] Step 3.2.4: Each query token in region i lies in all key-value pairs whose attention remains within the k routing index matrix areas, while... To obtain the tensor of keys and values using the index, the calculation formula is shown in equation (6-7):
[0116] (6),
[0117] (7),
[0118] In equations (6) to (7), It is a tensor of keys and values;
[0119] Step 3.2.5: Apply the Bilevel-RoutingAttention mechanism to the calculated key-value pairs. The calculation formula is shown in Equation (8):
[0120] (8),
[0121] In equation (8), O represents the attention output feature, and LCE(V) represents the local context enhancement method;
[0122] The spatial attention mechanism is further constructed using steps 3.2.6 to 3.2.7:
[0123] Step 3.2.6: Apply global max pooling and global average pooling operations to the features obtained by the Bilevel-RoutingAttention module. The process generates two weight matrices that describe the importance of each spatial location.
[0124] Step 3.2.7: Perform channel concatenation on the two weight matrices. A 7×7 convolution operation reduces the dimensionality of the two channels to one channel, which is then processed using the SigMod activation function to obtain the final result. ; The calculation formula is shown in equation (9):
[0125] (9),
[0126] In equation (9), f 7×7 For convolution operations, AvgPool is the global average pooling operation, MaxPool is the global max pooling operation, and σ is the SigMod activation function. For average pooling characteristics, This is a max-pooling feature.
[0127] Furthermore, the MS-DSFLAM module in the improved neck network in step 3.2 is constructed by adding a DySample dynamic sampling module to the SSFF module in the ASF-Yolo neck network, as shown in the schematic diagram below. Figure 5 As shown.
[0128] The MS-DSFLAM module includes three inputs, P3, P4-1 and P5, two Conv1d, two DySample, Concat, Conv3d, BN, LeakyReLU and MaxPool3d modules and one output, P4-2.
[0129] The DySample dynamic sampling module transforms the feature upsampling process into a sampling point-based resampling process by learning the sampling position and dynamically adjusting the regular sampling points. Specifically, the module takes a low-resolution feature map as input, uses a lightweight offset prediction network to generate a sampling offset, and combines it with a predefined regular sampling grid to obtain the dynamic sampling point position. Then, it reconstructs high-resolution features in a continuous feature space through bilinear resampling, thereby significantly reducing computational complexity while achieving adaptive modeling of target edges and structural information.
[0130] Step 4: Train the underwater debris recognition model based on the improved YOLOv8s using the training and validation sets, and save the trained model as the optimal model; the training process of the underwater debris recognition model based on the improved YOLOv8s further includes steps 4.1 to 4.4:
[0131] Step 4.1: Set the training parameters for the underwater debris recognition model based on the improved YOLOv8s;
[0132] In this embodiment, the training parameters include: Epoch number of iterations is 300, batch size is 16, optimizer is SGD, initial learning rate 1r0 is 0.001, momentum is 0.937, weight decay is 0.0005, and number of threads (workers) is 4.
[0133] Step 4.2: Input the training and validation set images and their corresponding labels into the underwater debris recognition model based on the improved YOLOv8s, and use the backpropagation algorithm to calculate the gradient of the loss function with respect to the model parameters. The backpropagation algorithm is an effective method for calculating gradients. It uses the chain rule to calculate the gradient of each parameter with respect to the loss function. Specifically, backpropagation calculates the gradient of each parameter layer by layer by propagating the loss function backward from the output layer. In this process, the gradient of each parameter represents the rate of change of the loss function with respect to that parameter, that is, how the loss function changes with the parameter. The model parameters are adjusted to gradually approach the optimal solution by minimizing the loss function.
[0134] Step 4.3: After calculating the gradients of the model parameters, the optimizer is used to update these parameters. The optimizer updates the parameters in the opposite direction of the gradient based on the gradient information. Parameters with larger gradients are updated at larger steps, while parameters with smaller gradients are updated at smaller steps. By iteratively updating the model parameters, the value of the loss function can be gradually reduced. By minimizing the loss function, the values of the model parameters are adjusted to gradually approach the optimal solution, that is, the parameter values at which the loss function reaches its minimum value. The difference between the model's prediction results and the true values is minimized, and evaluation metrics such as mAP50, mAP50-95, recall R, and accuracy P no longer improve.
[0135] Step 4.4: Save the trained model parameters as the optimal model;
[0136] Step 5: Test the optimal model using a test set. If the test results meet the accuracy requirements, the final model is obtained. Specifically, step 5 further includes steps 5.1 to 5.3:
[0137] Step 5.1: Input the test set into the optimal model saved in Step 4;
[0138] Step 5.2: Calculate model performance metrics: accuracy (P), recall (R), mAP50, and mAP50-95. The specific calculation formulas are as follows:
[0139] (10)
[0140] (11),
[0141] (12)
[0142] (13)
[0143] In equations (10) to (13), P is the precision, R is the recall, mAP is the mean precision of all categories, AP is the average precision, m is the total number of categories of underwater debris tags, TP represents the number of positive samples correctly identified as positive samples, FP represents the number of negative samples incorrectly identified as positive samples, and FN represents the number of positive samples incorrectly identified as negative samples.
[0144] mAP50 represents the average accuracy when the IoU threshold is fixed at 0.5, and mAP50-95 represents the average accuracy calculated every 0.05 when the IoU threshold is between 0.5 and 0.95, and then the average of these average accuracies is taken.
[0145] Step 5.3: When the performance indicators meet the accuracy requirements, the final underwater debris recognition model based on the improved YOLOv8s is obtained.
[0146] In this embodiment, in order to verify the effect of the recognition model disclosed in this invention, the Faster R-CNN model, SSD model, Yolov3-Tiny model, Yolov5s model, Yolov6n model, Yolov7n model and Yolov8s model were tested on the TrashCan1.0 dataset along with the recognition model disclosed in this invention. The evaluation results are shown in Table 1.
[0147] Table 1 Comparison of experimental results
[0148] ;
[0149] As shown in Table 1, the underwater debris identification model based on the improved YOLOv8s proposed in this paper outperforms other comparative models in terms of accuracy P, mAP50, and mAP50-95 evaluation metrics.
[0150] To verify the effectiveness of the three improvements in Yolov8s, an ablation experiment was conducted, and the results are shown in Table 2.
[0151] Table 2 Ablation Experiment
[0152] ;
[0153] As shown in Table 2, the improved modules proposed in this study complement each other, effectively enhancing the model's ability to extract, fuse, and identify underwater debris features, thereby improving the accuracy and robustness of underwater debris detection.
[0154] The above description is merely one embodiment of the present invention and does not limit the scope of protection of the present invention. For those skilled in the art, the present invention can have various modifications and variations. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A method for underwater debris identification based on an improved YOLOv8s, characterized in that, Specifically, the following steps are included: Step 1: Acquire underwater debris images to form the first dataset; the images in the first dataset can be collected through the network or captured by an underwater robot; Step 2: Add annotation information to the images in the first dataset to form the second dataset, and divide the second dataset into training set, validation set and test set according to a preset ratio; Step 3: Construct an underwater debris recognition model based on an improved YOLOv8s network. This model includes an improved backbone network, an improved neck network, and an improved head network. The construction of this model further includes steps 3.1 to 3.3: Step 3.1: The improved backbone network consists of Conv-1, Conv-2, C2f-1, Conv-3, C2f-2, Conv-4, C2f-Faster-EMA-1, Conv-5, C2f-Faster-EMA-2 and SPPF modules connected in sequence; The training and validation sets from the second dataset are used as inputs to the improved backbone network; The improved backbone network outputs feature information at five different scales through the C2f-1, C2f-2, C2f-Faster-EMA-1, C2f-Faster-EMA-2 and SPPF modules, respectively. Step 3.2: The improved neck network consists of BRSAM, TFE-1C2f-3, TFE-2C2f-4, MS-DSFLAM, CPAM-1, Upsample, CPAM-2, Concat-1, and Concat-2 modules; The outputs of C2f-1 and C2f-2 serve as the inputs of TFE-2C2f-4, and the output of C2f-1 also serves as the input of CPAM-1. The outputs of C2f-2, C2f-Faster-EMA-1, and C2f-Faster-EMA-2 serve as the inputs of MS-DSFLAM, and the outputs of MS-DSFLAM and TFE-2C2f-4 serve as the inputs of CPAM-2. The output of MS-DSFLAM also serves as the input of UpSample, and the output of UpSample serves as the input of CPAM-1; The output of SPPF is used as the input of BRSAM, the output of C2f-Faster-EMA-1 and BRSAM is used as the input of TFE-1C2f-3, the output of CPAM-2 and TFE-1C2f-3 is used as the input of Concat-1, and the output of TFE-1C2f-3 and Concat-1 is used as the input of Concat-2. Step 3.3: The improved head network includes Detect-1, Detect-2, Detect-3, and Detect-4 modules; the output of CPAM-1 is used as the input of Detect-1; the output of CPAM-2 is used as the input of Detect-2; the output of Concat-1 is used as the input of Detect-3; and the output of Concat-2 is used as the input of Detect-4. Step 4: Train the underwater debris recognition model based on the improved YOLOv8s using the training set and validation set, and save the trained model as the optimal model; the training process of the underwater debris recognition model based on the improved YOLOv8s further includes steps 4.1 to 4.4: Step 4.1: Set the training parameters for the underwater debris recognition model based on the improved YOLOv8s; Model training parameters include: number of iterations, batch size, optimizer, learning rate, momentum, weight decay, and number of threads; Step 4.2: Input the training set and validation set into the underwater debris identification model based on the improved YOLOv8s, and use the backpropagation algorithm to calculate the gradient of the loss function with respect to the model parameters; Step 4.3: Use the optimizer to update the model parameters in the direction of gradient descent until the loss function of the training and validation sets no longer decreases, and the accuracy P, recall R, mAP50, and mAP50-95 metrics no longer improve. Step 4.4: Save the trained model parameters as the optimal model; Step 5: Test the optimal model using the test set, evaluate the test results of the test set using objective evaluation indicators, ensure that the accuracy requirements are met, and obtain the final underwater debris recognition model based on the improved YOLOv8s.
2. The underwater debris identification method based on the improved YOLOv8s according to claim 1, characterized in that, The two C2f-Faster-EMA modules in step 3.1 have the same structure, and their construction method further includes steps 3.1.1 to 3.1.3: Step 3.1.1: The C2f-Faster-EMA module is the replacement of the BottleNeck module in the C2f module of the original YOLOv8s network with the Faster-EMA module; Step 3.1.2: The Faster-EMA module in step 3.1.1 is obtained by adding the FasterBlock module in the FasterNet network to the EMA attention mechanism. Step 3.1.3: The EMA attention mechanism in step 3.1.2 is based on a multi-scale parallel processing architecture and includes two 1×1 convolutional paths and one 3×3 convolutional path; In the two 1×1 convolutional paths, dual-path 1D global average pooling is used to encode channel information along the x-axis and y-axis directions respectively; at the same time, the two feature encodings are concatenated in the direction h; in addition, in order to realize different cross-channel interactive features between the two parallel paths of the 1×1 branch, the two channel attention maps in each group are aggregated by simple multiplication. In the 3×3 convolution path, a single-layer 3×3 convolution kernel stacking structure is adopted. Local cross-channel interaction is achieved through 3×3 convolution operations. The 3×3 branch also introduces a global average pooling layer and achieves adaptive transformation of feature dimensions through a joint activation function.
3. The underwater debris identification method based on the improved YOLOv8s according to claim 1, characterized in that, The BRSAM module in step 3.2 replaces the channel attention mechanism in the CBAM attention mechanism with the Bilevel-RoutingAttention attention mechanism, while retaining the spatial attention mechanism; The Bilevel-RoutingAttention mechanism is further constructed using steps 3.2.1 to 3.2.5: Step 3.2.1: Given a 2D input feature map X, this feature map... H represents height, W represents width, and C represents the number of channels; it is divided into S×S non-overlapping regions, each region containing Feature vectors, this step is accomplished by reconstructing X, that is Based on the resulting query, key, and value tensors, Q, K, Then the linear projection is as shown in formulas (1) to (3): (1), (2), (3), In equations (1) to (3), Q, K, and V represent the query, key, and value, respectively; W q W k and These represent the projected weights of the query, key, and value, respectively. Step 3.2.2: By applying the average value across various regions, derive the region-level query and key. The inter-region affinity matrix is derived by matrix multiplication between Q and transpose K, and the calculation formula is shown in formula (4): (4), In formula (4), the elements in the adjacency matrix A r measure the degree of semantic relevance between two regions. Step 3.2.3: Cropping the affinity graph, resulting in a routing index matrix I r The calculation formula is shown in equation (5): (5), In equation (5), k represents the number of most relevant regions selected for each region; A r This represents the adjacency matrix; TopK represents the index selection function, which calculates the k regions most relevant to the current region. Step 3.2.4: Each query token in region i lies in all key-value pairs whose attention remains within the k routing index matrix areas, while... To obtain the tensor of keys and values using the index, the calculation formula is shown in equation (6-7): (6), (7), In equations (6) to (7), It is a tensor of keys and values; Step 3.2.5: Apply the Bilevel-RoutingAttention mechanism to the calculated key-value pairs. The calculation formula is shown in Equation (8): (8), In Equation (8), O represents the attention output feature, and LCE(V) represents the local context enhancement method; The spatial attention mechanism is further constructed using steps 3.2.6 to 3.2.7: Step 3.2.6: Apply global max pooling and global average pooling operations to the features obtained by the Bilevel-RoutingAttention module. The process generates two weight matrices that describe the importance of each spatial location. Step 3.2.7: Perform channel concatenation on the two weight matrices. A 7×7 convolution operation reduces the dimensionality of the two channels to one channel, which is then processed using the SigMod activation function to obtain the final result. ; The calculation formula is shown in equation (9): (9), In equation (9), f 7×7 For convolution operations, AvgPool is the global average pooling operation, MaxPool is the global max pooling operation, and σ is the SigMod activation function. For average pooling characteristics, This is a max-pooling feature.
4. The underwater debris identification method based on the improved YOLOv8s according to claim 1, characterized in that, In the improved neck network in step 3.2, the MS-DSFLAM module is constructed by adding a DySample dynamic sampling module to the SSFF module in the ASF-Yolo neck network. The MS-DSFLAM module includes three inputs, P3, P4-1 and P5, two Conv1d, two DySample, Concat, Conv3d, BN, LeakyReLU and MaxPool3d modules and one output, P4-2. The DySample dynamic sampling module transforms the feature upsampling process into a sampling point-based resampling process by learning the sampling position and dynamically adjusting the regular sampling points. Specifically, the module takes a low-resolution feature map as input, uses a lightweight offset prediction network to generate a sampling offset, and combines it with a predefined regular sampling grid to obtain the dynamic sampling point position. Then, it reconstructs high-resolution features in a continuous feature space through bilinear resampling, thereby significantly reducing computational complexity while achieving adaptive modeling of target edges and structural information.
5. The underwater debris identification method based on improved YOLOv8s according to claim 1, characterized in that, Step 5 further includes steps 5.1 to 5.3: Step 5.1: Input the test set into the optimal model saved in Step 4; Step 5.2: Calculate model performance metrics: accuracy (P), recall (R), mAP50, and mAP50-95. The specific calculation formulas are shown below: (10), (11), (12), (13), In equations (10) to (13), P is the precision, R is the recall, mAP is the mean precision of all categories, AP is the average precision, m is the total number of categories of underwater debris tags, TP represents the number of positive samples correctly identified as positive samples, FP represents the number of negative samples incorrectly identified as positive samples, and FN represents the number of positive samples incorrectly identified as negative samples. mAP50 represents the average accuracy when the IoU threshold is fixed at 0.5, and mAP50-95 represents the average accuracy calculated every 0.05 when the IoU threshold is between 0.5 and 0.95, and then the average of these average accuracies is taken. Step 5.3: Evaluate the test results of the test set using objective evaluation metrics to ensure that the accuracy requirements are met, thus obtaining the final underwater debris recognition model based on the improved YOLOv8s.