Underwater target detection method based on improved YOLOv8
By improving the YOLOv8 model, using DCNv2 and ECA attention mechanisms, combining the bidirectional feature pyramid network and SIoU loss function, the problems of complex background and lighting effects of underwater images are solved, the accuracy and robustness of small object detection are improved, and the more High detection accuracy and efficiency.
Patent Information
- Application Number
- CN202411395787.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-08
- Publication Date
- 2024-12-31
AI Technical Summary
The underwater image background is complex and is easily affected by the water quality of light, resulting in color deviation and blurred degradation, making it difficult to determine the target location, especially the small target detection accuracy is low, which makes it easy to miss detection problems.
Improve the YOLOv8 model, by converting the Conv in the C2f bottleneck into DCNv2 variable row convolution, and adding an ECA attention mechanism, combining the bidirectional feature pyramid network and weighted fusion features, SIoU loss function is used to perform image preprocessing such as white balance and Gamma correction, dynamically adjusting the learning rate to improve model performance.
It improves the accuracy and robustness of underwater target detection, enhances feature extraction capabilities, improves the brightness and contrast of images, reduces the possibility of misjudgment and misjudgment, and improves observation efficiency.
Smart Images

Figure CN119229272A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of underwater biological detection, and in particular to an underwater target detection method based on improved YOLOv8. Background Art
[0002] The ocean covers 97% of the water on the earth and breeds many creatures. With the gradual exploration of the ocean, underwater target detection technology has emerged. However, the background of underwater images is complex and easily affected by light and water quality, resulting in serious color deviation and blur degradation in the image, making it difficult to determine the target position in the underwater image. In addition, there are many small targets in underwater creatures, and the small targets occupy a small proportion of pixels in the image, making it difficult to see clearly and prone to missed detection, thereby reducing the accuracy of underwater target detection. Summary of the invention
[0003] The purpose of this application is to provide an underwater target detection method based on improved YOLOv8 to solve the problems raised in the above-mentioned background technology, such as the complex background of underwater images, which are easily affected by light and water quality, resulting in serious color deviation and blur degradation in the images, making it difficult to determine the target position in the underwater image, and there are many small targets in underwater organisms. The proportion of pixels in the image occupied by small targets is small, making it difficult to be clearly visible and prone to missed detection.
[0004] To achieve the above objectives, the present application provides the following technical solution: an underwater target detection method based on improved YOLOv8, comprising the following steps:
[0005] Convert the Conv in the C2f bottleneck to a DCNv2 variable row convolution, and then add the ECA attention mechanism to get the C2f_DCNv2_ECA module;
[0006] The improved neck feature fusion module is obtained by using the bidirectional feature pyramid network (BiFPN) combined with bidirectional path enhancement and weighted fusion features.
[0007] The SIou loss function, C2f_DCNv2_ECA module and improved neck feature fusion module are embedded into the YOLOv8n model to obtain the improved YOLOv8n model;
[0008] The improved YOLOv8n model is trained and verified using the preprocessed underwater biological images to obtain the target detection model;
[0009] The target detection model is used to detect real-time images to obtain underwater organism detection results.
[0010] Furthermore, the working steps of underwater biological image preprocessing include:
[0011] White balance processing is performed first, followed by image gamma correction.
[0012] Furthermore, the method for training the improved YOLOv8n model includes: dynamically adjusting the learning rate using a cosine annealing strategy and training by a stochastic gradient descent method.
[0013] Furthermore, the method for verifying the trained model includes: judging the model output results, dividing the model output results into true positive examples, true negative examples, false positive examples and false negative examples according to the judgment, calculating the precision, recall rate and average precision mean according to the number of true positive examples, true negative examples, false positive examples and false negative examples, evaluating the trained model by the precision, recall rate and average precision mean, and obtaining the verification result.
[0014] In summary, the technical effects and advantages of the present invention are as follows:
[0015] In the present invention, through image preprocessing, improved network architecture, feature fusion optimization and improvement of loss function, the performance and robustness of underwater target detection can be effectively improved, feature extraction can be strengthened, the accuracy of target detection can be improved, the brightness and contrast of the image can be improved, the clarity and visibility of the image can be improved, the observation efficiency can be improved, and the possibility of subsequent misjudgment and missed judgment can be reduced. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the prior art description are briefly introduced below.
[0017] Figure 1 It is a framework diagram of the improved YOLOv8n model in the embodiment of the present application;
[0018] Figure 2 This is a diagram of the data set preprocessing process in the embodiment of this application;
[0019] Figure 3 PR curves of each organism in the original model and the improved model in the embodiment of the present application;
[0020] Figure 4 This is a comparison chart of mAP curves of various models in the embodiments of this application;
[0021] Figure 5 This is a comparison chart of various model parameter quantities in the embodiments of this application. DETAILED DESCRIPTION
[0022] The technical solutions in the embodiments of the present invention will be described clearly and completely below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments.
[0023] Example: Reference Figure 1-5 The underwater target detection method based on improved YOLOv8 shown in the figure includes the following steps:
[0024] Convert the Conv in the C2f bottleneck to a DCNv2 variable row convolution, and then add the ECA attention mechanism to get the C2f_DCNv2_ECA module;
[0025] YOLOv8n uses traditional convolution and C2f modules for feature extraction, however, the fixed receptive field size of these modules limits the quality of feature extraction for small targets. A receptive field that is too large may result in loss of details, while a receptive field that is too small may not cover the entire target. In addition, traditional convolution is insensitive to changes in target position and cannot capture subtle boundary features of the target. The C2f_DCNv2_ECA module has an adaptive and sophisticated information extraction method that allows better focus on the target area and reduces interference from the underwater image background to improve detection accuracy.
[0026] The difference between deformable convolution and traditional convolution is that the convolution position is not fixed and can be adjusted adaptively. It introduces learnable offsets on top of traditional convolution. For the traditional two-dimensional standard convolution calculation process, a set of pixels are sampled from the input feature map and then the up-sampled result is calculated using the convolution operation to obtain the result. DCNv2 introduces the weight coefficient Δm n , suppress irrelevant background information, reduce the interference of irrelevant content, and thus optimize the feature learning process. DCNv2 introduces a significant value (mask) based on the offset of the original DCN output sampling point. The value range is between 0 and 1, which is used to describe the importance of the sampling point and the weight distribution in the convolution process. By giving different attention to different sampling points, the feature extraction ability of DCN is further optimized and the accuracy of the model is improved. Because DCNv2 has more variability and is more difficult to train than DCN, DCNv2 uses a teacher-student training method, which can optimize the training process of the model to accelerate the convergence of the network model;
[0027] Since DCNv2 has better performance, the present invention applies DCNv2 deformable convolution to the backbone feature extraction network and integrates the idea of DCNv2 into the C2F module of YOLOv8n, thus forming the C2F_DCNv2 layer. The backbone network is mainly responsible for extracting low-level features and global information from the original image. These feature details are crucial for understanding the overall context of the entire image. The introduction of DCNv2 deformable convolution allows for increased sampling of effective receptive fields and effective positions, replacing the Conv operation in the bottleneck of the C2F module with DCNv2, so that YOLOv8n can more accurately capture the detailed information of the target object boundary and complex shape, thereby improving the accuracy of underwater target detection;
[0028] In order to further improve the model's detection capability for underwater small targets, the present invention also introduces an ECA attention mechanism. Although the existing attention mechanism improves the model accuracy, it also greatly increases the computational complexity, which also increases the cost in the underwater target detection application scenario. The ECA channel attention module can further balance accuracy and complexity, and only requires a few parameters to achieve good results. The feature map is converted from a matrix of [h, w, c] to a vector of [1, 1, c] by global averaging, and the adaptive one-dimensional convolution kernel size kernel_size is calculated according to the number of channels of the feature map. Then, the normalized weights and the original input feature map are multiplied channel by channel for one-dimensional convolution to complete the information interaction across channels. By using the adaptively changing convolution kernel size, the layers with more features can interact more across channels to generate weighted feature maps. ECANet uses a 1x1 convolution layer directly after the global average pooling layer, removing the fully connected layer to efficiently capture cross-channel interactions. By using the adaptively changing convolution kernel size, the layers with more features can interact more across channels to generate weighted feature maps. ECANet uses a 1x1 convolutional layer directly after the global average pooling layer and removes the fully connected layer to efficiently capture cross-channel interactions. The improved C2f_DCNv2_ECA module better understands the relationship between channels in the input data, greatly reducing the computational complexity of the model while improving the detection accuracy and generalization ability of the model;
[0029] The improved neck feature fusion module is obtained by using the bidirectional feature pyramid network (BiFPN) combined with bidirectional path enhancement and weighted fusion features.
[0030] In the original network of YOLOv8n, the Neck part integrates Feature Pyramid Networks (FPN) and Path Aggregation Networks (PANet). FPN connects high-level, low-resolution but high-semantic information features with low-level, high-resolution but low-semantic information features in a top-down manner to generate feature maps of different scales, which contain rich semantic information. Based on the FPN architecture, PANet introduces a bottom-up information enhancement channel. This design uses the precise positioning information in the underlying feature map to enhance the feature representation of each layer. However, PANet feature fusion is performed from the low layer to the upper layer. The path of feature fusion is very long. When reaching the high layer of the network structure, most of the information retained by the feature fusion may be shallow information, and less information may be retained for deeper layers.
[0031] Considering that input features of different resolutions may have different degrees of influence on output features, in order to effectively fuse these features, BiFPN introduces a weighted feature fusion strategy. The weighted fusion method in the BiFPN structure uses fast normalized fusion, which is proposed for slow training speed. The weights are scaled to the range of 0-1, and the Softmax method is not used, so the training speed is fast. The cross-scale connection is achieved by adding a skip connection and a bidirectional path, realizing weighted fusion and bidirectional cross-scale connection;
[0032] The present invention replaces the feature fusion network with BiFPN to assign different weights to features of different scales, and performs cross-scale weight suppression and feature expression to strengthen feature fusion. This feature fusion method can not only expand the perception field of view, but also effectively improve the perception ability of small target information and make the network more adaptable to multi-scale changes of targets, providing richer feature information for subsequent convolutional layers, while also maintaining a controllable computational load and effectively reducing the number of parameters;
[0033] The SIou loss function, C2f_DCNv2_ECA module, and improved neck feature fusion module are embedded into the YOLOv8n model to obtain an improved YOLOv8n model. The improved YOLOv8n model is named YOLOv8n-DBS model in the picture (as shown in Figure 5 shown);
[0034] The YOLOv8n model uses CIoU as the loss function for detection box regression. The CIoU loss function takes into account the distance, overlap, and size between the centers of each bounding box. The SIoU loss function subtly combines factors such as angle error, distance deviation, and shape inconsistency. Compared with the CIoU loss, SIoU introduces a soft threshold when calculating IoU, and reduces the sensitivity to the binarization of IoU by smoothing on exponential functions and other methods. This method can calculate IoU more stably, and is particularly suitable for situations such as blurred boundaries and large changes in target size. At the same time, SIoU takes into account the aspect ratio of the target box when calculating IoU, which can more accurately reflect the shape information of the target box;
[0035] In the RUOD dataset, there are often small or blurred creatures, and these data samples are usually of substandard quality. In this case, CIoU's reliance on distance and aspect ratio metrics may disproportionately penalize these low-quality samples. When low-quality samples are combined with an effective loss function, it may affect feature learning, causing the model to overfit these abnormal samples, destroying model convergence and compromising robustness, and ultimately leading to a decrease in the generalization ability of the model. In order to address this shortcoming of CIoU loss and further accelerate the convergence of the model, the SIoU loss function was introduced. SIoU introduces the vector angle between the true box and the predicted box to redefine the correlation. The SIoU loss function consists of four parts: angle loss, distance loss, shape loss, and IoU loss;
[0036] 1) The angle loss function is as follows:
[0037]
[0038]
[0039] 2) The distance loss function is as follows:
[0040]
[0041] Among them, c w , c h The width and height of the minimum bounding rectangle of the real box and the predicted box;
[0042] 3) The shape loss function is as follows:
[0043]
[0044] where w, h, w gt ,h gt are the width and height of the predicted box and the real box respectively, and θ controls the degree of attention to shape loss;
[0045] 4) IoU loss function;
[0046]
[0047] Among them, A represents the predicted box and B represents the real box;
[0048] 5) SIoU loss function;
[0049] By integrating the above four types of loss functions, the final SIoU loss function is defined using the following formula:
[0050]
[0051] SIoU uses a smoothing function to calculate the area of intersection and union, which more accurately measures the similarity between the predicted box and the true box. This allows SIoU to evaluate the detection results more carefully, especially when dealing with blur or partial overlap. In addition, SIoU takes into account pixel-level information, so it is more accurate when dealing with irregular shapes or complex scenes. In general, SIoU has a more detailed and comprehensive evaluation capability in underwater biological detection, which can better reflect the similarity between the predicted box and the true box, thereby improving detection accuracy and robustness;
[0052] The improved YOLOv8n model is trained and verified using the preprocessed underwater biological images to obtain the target detection model;
[0053] The working steps of underwater biological image preprocessing include: firstly, white balance processing is applied, and secondly, image gamma correction is performed;
[0054] For low-quality images in the dataset, white balance processing is used, followed by image gamma correction. White balance is used to correct the color temperature and restore the color of the subject. The gray world algorithm is one of the most widely used white balance algorithms. The present invention processes the image based on the traditional gray world algorithm, and obtains the gray value K of the image by calculating the average value of the three channels R, G, and B of the image:
[0055]
[0056] Then calculate the channel gain coefficient according to K:
[0057]
[0058] Adjust the three color components of pixel C on the image. The adjustment strategy is as follows:
[0059] C(R′)=C(R)*k r ,C(G′)=C(G)*k g ,C(B′)=C(B)*k b
[0060] For the underwater image with color cast, the original image (a) is processed by white balance algorithm, but there is still foggy blur in Figure (b). Consider using image fusion method to enhance the edge and details of the image scene and reduce the image blur caused by backscattering. Generally speaking, underwater images processed by grayscale world method are often too bright, so the present invention continues to perform gamma correction on the previously processed underwater image, as shown in Figure (c), to correct the global contrast of the image and increase the difference between bright and dark areas;
[0061] It can be seen that after gamma correction (c), the difference between light and dark areas is more obvious and the details are more prominent compared to the case of only white balance processing. After color correction and image fusion, the color deviation of the image is effectively compensated, and the image contrast, clarity and details are significantly improved, which improves the quality of underwater images and is conducive to the subsequent detection and positioning of underwater organisms.
[0062] The method for training the improved YOLOv8n model includes: dynamically adjusting the learning rate using a cosine annealing strategy and training by stochastic gradient descent;
[0063] Use the target detection model to detect the real-time captured images and obtain underwater biological detection results;
[0064] The method for verifying the trained model includes: judging the model output results, dividing the model output results into true positive examples, true negative examples, false positive examples and false negative examples according to the judgment, calculating the precision, recall rate and average precision mean according to the number of true positive examples, true negative examples, false positive examples and false negative examples, evaluating the trained model through the precision, recall rate and average precision mean, and obtaining the verification result.
[0065] 1: Ablation experiment
[0066] In order to evaluate and verify the effectiveness of the proposed improvements, four groups of ablation experiments were conducted. Under the same environment and training parameters, the experimental group was used for training and the corresponding results were recorded. The results of the ablation experiment are shown in the following table:
[0067] Table 1 Ablation experiment
[0068]
[0069] The first group demonstrated the original, unmodified YOLOv8n algorithm in underwater biological target detection, with a Map@0.5 of 0.752. In the second group, the C2F_DCNv2_EMA module was introduced to replace the original C2F structure. This change makes the model more flexible in handling complex shapes and irregular target features, thereby improving detection accuracy. Experimental results show that the mAP@0.5 value rises to 0.760. On this basis, the third group further replaces the PAFPN structure with the more effective BIFPN feature fusion. This change helps the model better integrate multi-scale feature information, especially showing advantages in identifying small or complex surface defects. At the same time, this operation greatly reduces the number of parameters of the model to 2.1M. Experimental results show that the mAP value further increases to 0.766. Finally, the fourth group applies the SIoU loss function to the optimized network structure to more accurately guide the bounding box regression process. The final experimental results show that the cumulative effect of these improvements is significant, and the mAP value is increased to 0.783. Through a series of ablation experiments, we can clearly see the positive contribution of each improvement point to the overall detection effect, thus proving the effectiveness of these improvements.
[0070] 2: Comparative experiment
[0071] In order to comprehensively test the detection effect of the present invention, the improved model is compared with the basic YOLOv8n model and also compared with the mainstream model.
[0072] Table 2 Comparison of experimental results
[0073]
[0074]
[0075] Compared with other models, the improved YOLOv8n model has the highest detection accuracy. The basic algorithm YOLOv8n selected by the present invention has increased mAP by 6.7% compared to the Faster RCNN algorithm, and the number of parameters has also been greatly reduced, mainly because YOLOv8n adopts a one-stage design compared to Faster RCNN, that is, directly regressing the position and category probability of the bounding box. This one-stage design simplifies the detection process, making YOLOv8n faster in detection speed, while maintaining high accuracy while also improving mAP. The mAP of the improved YOLOv8n model algorithm is 2.8% higher than the TOOD algorithm, 8.4% higher than the CenterNet algorithm, 5.2% higher than YOLOF, 0.2% higher than the larger-scale YOLOv8s model, 3.1% higher than the basic algorithm YOLOv8n, and the number of parameters is reduced by 32.2% compared to YOLOv8n, achieving an improvement in detection accuracy and speed. Compared with the newer YOLOv9-tiny at this stage, its accuracy has been improved, the number of parameters has been reduced, and the detection speed has also been improved. This is mainly due to the design of the C2f_DCNv2_ECA module in the improved YOLOv8n model, which better understands the relationship between the channels in the input data, improves the detection accuracy and generalization ability of the model, and greatly reduces the calculation amount of the model. At the same time, the weighted bidirectional feature pyramid network (BiFPN) structure is adopted to further enhance the feature fusion ability through the cross-level connection trainable weight mechanism, which improves the detection accuracy of the model while reducing the number of parameters. Finally, the SIoU loss function is used to evaluate the underwater biological detection more carefully and comprehensively, and better reflect the similarity between the predicted box and the real box.
[0076] Finally, it should be noted that the above is only a preferred embodiment of the present invention and is not intended to limit the present invention. Although the present invention has been described in detail with reference to the aforementioned embodiments, it is still possible for those skilled in the art to modify the technical solutions described in the aforementioned embodiments or to make equivalent substitutions for some of the technical features therein. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
Claims
1. An underwater target detection method based on improved YOLOv8, characterized by: The following steps are involved: Convert the Conv in the C2f bottleneck to a DCNv2 variable row convolution, and then add the ECA attention mechanism to get the C2f_DCNv2_ECA module; An improved neck feature fusion module is obtained by using a bidirectional feature pyramid network combined with bidirectional path enhancement and weighted fusion features. The SIou loss function, C2f_DCNv2_ECA module and improved neck feature fusion module are embedded into the YOLOv8n model to obtain the improved YOLOv8n model; The improved YOLOv8n model is trained and verified using the preprocessed underwater biological images to obtain the target detection model; The target detection model is used to detect real-time images to obtain underwater organism detection results.
2. The underwater target detection method based on improved YOLOv8 according to claim 1, characterized in that: The working steps of underwater biological image preprocessing include: White balance processing is performed first, followed by image gamma correction.
3. The underwater target detection method based on improved YOLOv8 according to claim 1, characterized in that: The method for training the improved YOLOv8n model includes: dynamically adjusting the learning rate using a cosine annealing strategy and training by stochastic gradient descent.
4. The underwater target detection method based on improved YOLOv8 according to claim 1, characterized in that: The method for verifying the trained model includes: judging the model output results, dividing the model output results into true positive examples, true negative examples, false positive examples and false negative examples according to the judgment, calculating the precision, recall rate and average precision mean according to the number of true positive examples, true negative examples, false positive examples and false negative examples, evaluating the trained model through the precision, recall rate and average precision mean, and obtaining the verification result.
Citation Information
Cited By
Vision-based underwater moving target speed measurement method and system
CN119559491A
A vision-based method and system for measuring the speed of underwater moving targets
CN119559491B
Wrist image fracture recognition and detection method and system based on improved YOLOv8 network
CN119992603A