Lightweight ship detection method based on improved YOLOv8

By improving the YOLOv8 model, using the FasterNet network and BiFPN module, combining the WIoUv3 loss function with packet convolution and dynamic non-monotonic focus mechanism, the existing ship object detection algorithm has solved the problem of large parameters, slow speed and insufficient accuracy, and realized a lightweight and efficient ship detection method.

CN119888640APending Publication Date: 2025-04-25JIANGSU UNIV OF SCI & TECH
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202411935952.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-26
Publication Date
2025-04-25

AI Technical Summary

Technical Problem

The existing ship object detection algorithm has shortcomings in the large number of model parameters, slow detection speed and insufficient accuracy, which is difficult to meet the real-time detection needs of intelligent water transportation.

Method used

A lightweight ship detection method based on improved YOLOv8 is proposed. By replacing the CSP DarkNet feature extraction network in the YOLOv8 model with the FasterNet network, the weighted bidirectional feature pyramid network BiFPN module is introduced, and the detection head part is improved by using packet convolution, and WIoUv3 with a dynamic non-monotonic focusing mechanism is introduced as the bounding box loss calculation function.

Benefits of technology

It effectively reduces the amount of model parameters and calculations, improves the detection speed and accuracy, and achieves the goal of balancing the detection accuracy and model parameter size while ensuring real-time performance. It is suitable for water ship target detection in complex weather.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119888640A_ABST
    Figure CN119888640A_ABST
Patent Text Reader

Abstract

The invention discloses a lightweight ship detection method based on improved YOLOv8. Belongs to the technical field of intelligent ships. Carrying out fog and rain data enhancement processing on the target data set; a Faster Net network is adopted to replace a CSP DarkNet feature extraction network in the YOLOv8 model; a weighted bidirectional feature pyramid network BiFPN module is introduced into a YOLOv8 neck network to replace an original PANet structure of the YOLOv8, and a C2f-Faster module is used for replacing a C2f module in the YOLOv8 neck network; a YOLOv8 detection head part is improved by adopting grouping convolution; wIoUv3 with a dynamic non-monotonic focusing mechanism is introduced to replace CIoU to serve as a bounding box loss calculation function of the YOLOv8 model; through an improved YOLOv8 model, a water ship target data set is utilized to train the improved YOLOv8 model, a best weight file best.pt is obtained, and images in a test set are classified and positioned. The problems that in water traffic intelligence, the ship target detection precision is not enough, the model parameter quantity is large, and the model is complex and difficult to apply to practice are solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the technical field of intelligent ships and relates to a lightweight ship detection method based on improved YOLOv8. Background Art

[0002] With the vigorous development of the marine transportation industry, maritime traffic safety has become increasingly important. In order to ensure the safe and efficient navigation of smart ships, promoting the intelligentization of water transportation has become an inevitable trend. Ship target detection, as the key content of intelligent water transportation, is one of the key links in realizing the effective management of intelligent water transportation. Using computer vision technology to accurately and quickly identify and locate ships in the collected images can improve work efficiency and reduce manpower consumption, which has important research significance for the intelligentization of water transportation.

[0003] In the field of computer vision, the target detection algorithms based on deep learning are mainly divided into one-stage target detection algorithms based on regression and two-stage target detection algorithms based on selected regions. Among them, two-stage is represented by SSP-Net, Fast R-CNN and R-FCN, which mainly classifies targets by generating regional candidate boxes. Although it has high detection accuracy, it is slow and difficult to achieve real-time ship detection tasks. One-stage is an end-to-end method for detecting the entire image. A single detection can obtain the final detection result, but the accuracy is poor, such as YOLO, SSD, etc. At present, the ship target detection algorithm has been optimized in terms of model parameter size, detection accuracy and speed, but most of the improved model parameters are still large and the detection speed is slow. Therefore, lightweight network models with fast detection capabilities have always been the focus of research in the industry. Summary of the invention

[0004] In view of the above problems, the purpose of the present invention is to propose a lightweight ship detection method based on improved YOLOv8, which can effectively solve the problems of insufficient accuracy of ship target detection in intelligent water transportation, large number of model parameters, and complex model that is difficult to apply in practice.

[0005] The technical solution of the present invention is: a lightweight ship detection method based on improved YOLOv8 described in the present invention, and its operation steps are as follows:

[0006] Step (1): Establish a water vessel target dataset;

[0007] Step (2): Perform fog and rain data enhancement processing on the water ship target data set;

[0008] Step (3): Use FasterNet network to replace the CSP DarkNet feature extraction network in the YOLOv8 model;

[0009] Step (4): Introduce the weighted bidirectional feature pyramid network BiFPN module into the YOLOv8 neck network, replace the original PANet structure of YOLOv8, and replace the C2f module in the YOLOv8 neck network with the C2f-Faster module;

[0010] Step (5): Use group convolution to improve the YOLOv8 detection head;

[0011] Step (6): Introduce WIoUv3 with dynamic non-monotonic focusing mechanism to replace CIoU as the bounding box loss calculation function of the YOLOv8 model;

[0012] Step (7): After steps (3)-(6), an improved YOLOv8 model is obtained. The improved YOLOv8 model is trained using the water ship target dataset to obtain the best weight file best.pt, and the images in the test set are classified and located.

[0013] Furthermore, the process of establishing the data set in step (1) is:

[0014] Step (1.1): Establish a water ship target dataset through camera acquisition and network collection; the collected dataset images are all from real scenes;

[0015] Step (1.2): Manually clean the water vessel target dataset, delete duplicate, blurred, and erroneous dataset images, and finally obtain a water vessel target dataset containing bulk cargo ships, container ships, cruise ships, sail ships, tugboats, warships, and other ships.

[0016] Furthermore, in step (2), the water surface obstacle dataset is subjected to fog and rain data enhancement processing, including:

[0017] Step (2.1): Use OpenCV to perform pixel-level rain, fog and noise fusion processing on the dataset images to simulate the weather background of water surface obstacles under complex weather conditions and expand the water surface obstacle dataset;

[0018] Step (2.2): Use the LabelImg image annotation tool to annotate the ships, reefs, and buoy obstacles in the surface obstacle dataset in the PASCAL VOC format, and convert them into txt text labels in the YOLO format through a script;

[0019] Step (2.3): Divide the enhanced water surface obstacle dataset into training set, validation set and test set in a ratio of 7:1:2.

[0020] Furthermore, in step (3), the FasterNet-t0 network is used to replace the CSPDarkNet feature extraction network in the YOLOv8s model, including:

[0021] Step (3.1): The FasterNet network consists of three modules, including the embedding layer, the merging layer, and the FasterNet Block module;

[0022] Step (3.2): The embedding layer and merging layer are composed of 4×4 convolution and 2×2 convolution respectively, which play the role of downsampling and expanding the number of channels. The FasterNet Block module is the main feature extraction module. Each FasterNet block is composed of a partial convolution (PConv) and two subsequent point-wise convolutions (PWConv), and a normalization layer is set between the two point-wise convolutions.

[0023] Step (3.3): The calculation formula of PConv is as follows:

[0024]

[0025] When the number of channels for convolution operation is 1 / 4, the computational complexity of PConv is only 1 / 16 of that of conventional convolution. In addition, the memory access of Pconv is small, and the calculation formula is as follows:

[0026]

[0027] In the formula, h is the height of the channel, w is the width of the channel, k is the convolution kernel scale, c p The first or last segment is usually selected as the continuous c p channels.

[0028] Furthermore, in step (4), the weighted bidirectional feature pyramid network BiFPN module is introduced into the YOLOv8 neck network to replace the original PANet structure of YOLOv8, and the C2f-Faster module replaces the C2f module in the YOLOv8 neck network, including:

[0029] Step (4.1): Weighted bidirectional feature pyramid network BiFPN, the weighted feature fusion calculation formula is as follows:

[0030]

[0031] In the formula, w i and w j represents different weight learning parameters, ε=0.0001, I i Represents input features;

[0032] Step (4.2): Replace all Bottleneck in the C2f module in the YOLOv8 neck network with FasterNetBlock to obtain the C2f-Faster module.

[0033] Furthermore, in step (5), the YOLOv8 detection head is improved by using group convolution, including:

[0034] Step (5.1): The detection head of YOLOv8 adopts a decoupled head structure to separate the regression branch and the prediction branch. Each branch will perform two Conv modules with 3×3 convolution kernels and one Conv2d module with 1×1 convolution kernel, which will generate a lot of calculation and parameter amount;

[0035] Step (5.2): Group convolution can divide the input data and convolution kernel into multiple groups, and each group performs convolution operations independently. By dividing the input feature map into multiple groups for independent convolution operations, the amount of parameters and calculations can be effectively reduced;

[0036] Assume that the size of the input feature map is H×W and the number of input channels is C in , the number of channels of the output feature map is C out , the size of the convolution kernel is K×K, then the calculation formula of ordinary convolution is as follows;

[0037] C out ×C in ×K×K

[0038] If the grouped convolution divides the input feature map into G groups, the number of channels in each group is C in / G, the number of channels of the output feature map is Cout / G, the calculation formula for each group is as follows:

[0039]

[0040] The total parameter calculation formula is as follows:

[0041]

[0042] From the above formula, the total number of parameters of grouped convolution is 1 / G of the number of parameters of ordinary convolution;

[0043] Step (5.3): Replace the original 3×3 convolution with the Two Group Convolution composed of two group convolutions in parallel to construct a lightweight detection head TGC_Head.

[0044] Furthermore, in step (6), the introduction of WIoUv3 with a dynamic non-monotonic focusing mechanism instead of CIoU as the bounding box loss calculation function of the YOLOv8 model includes:

[0045] Step (6.1): The bounding box loss function predicts the position of the target in the entire image through a rectangular bounding box, where IoU represents the degree of overlap between the predicted box and the actual box of the detected target. The greater the overlap between the two, the better the detection effect.

[0046] YOLOv8 uses the CIoU loss function, which mainly considers three factors: overlapping area, center point and aspect ratio. The CIoU loss function calculation formula is as follows:

[0047]

[0048] In the formula, ρ 2 (x,x gt ) represents the true box X and the predicted box X gt The Euclidean distance of the center point, c is the diagonal length of its circumscribed rectangle, αv represents the aspect ratio penalty term, where α is the weight coefficient, v is the coefficient for predicting the relative proportion of the two rectangular boxes, w and h represent the width and height of the predicted box, w gt and h gt It represents the width and height of the actual frame, and IoU is the intersection-over-union ratio of two frames;

[0049] Step (6.2): ​​Introduce WIoUv3 with a dynamic non-monotonic focusing mechanism to replace CIoU as the bounding box loss calculation function of the YOLOv8 model. WIoUv3 adds a dynamic non-monotonic focusing mechanism based on WIoUv1. The specific calculation formula of WIoUv1 is as follows:

[0050] L IoU =1-IoU

[0051]

[0052] L WIoUv1 =R WIoU L IoU

[0053] In the formula, (x, y) and (x gt ,y gt ) are the center point coordinates of the predicted box and the real box, W g and H g is the width and height of the minimum bounding box of the predicted box and the real box, R WIoU ∈[1,e) is used to enlarge the L of the normal quality anchor box IoU , L IoU ∈[0,1] is used to reduce the R of high-quality anchor boxes WIoU ;

[0054] In order to avoid the negative impact of low-quality samples, WIoUv3 defines the outlier degree β, combined with the sliding average IoU value with momentum m The formula is as follows:

[0055]

[0056] Combining the training model hyperparameters α and δ, the non-monotonic focusing coefficient γ is constructed as follows:

[0057]

[0058] Applying γ to WIoUv1, we get the WIoUv3 loss function, the formula is as follows:

[0059] L WIoUv3 =γR WIoU L IoU .

[0060] Further, in step (7), the improved YOLOv8 model obtained through steps (3)-(6) is trained using the water ship target data set to obtain the best weight file best.pt, and the images in the test set are classified and located, including:

[0061] Step (7.1): Set the training strategy and set the momentum to 0.93; to prevent overfitting during training, set the weight decay rate to 0.0005, the initial learning rate to 0.01, the minimum learning rate to 0.0001, the number of training iterations to 200, the input image size to 640*640, and the batch size to 4; after training, the model will save the best weight file best.pt;

[0062] Step (7.2): Use best.pt as the weight file of the improved YOLOv8 model, and then randomly select several images to be tested from the test set as data sources for detection.

[0063] The beneficial effects of the present invention are as follows: 1. The present invention obtains data set images through camera acquisition and network collection, does not require a large amount of manpower and material resources, and the image acquisition method is simple to operate; 2. The present invention simulates the complex weather conditions based on the OpenCV image processing method to perform data enhancement processing on the water ship target data set, thereby improving the adaptability and generalization ability of the model in the actual application process; 3. The present invention adopts the FasterNet network to replace the CSP DarkNet feature extraction network in the YOLOv8 model, which can effectively reduce the amount of calculation and the amount of parameters in the target detection task process, improve the speed of model reasoning on low-performance computers and edge devices, and have a certain lightweight level; 4. The present invention introduces a weighted bidirectional feature pyramid network BiFPN module in the YOLOv8 neck network, simplifies the network structure, realizes the fusion of more feature information without increasing the calculation cost, and improves the network's detection effect on targets of different scales; replaces the original PANet structure of YOLOv8, replaces the C2f module in the YOLOv8 neck network with the C2f-faster module, and further optimizes the detection speed and computational complexity without losing the detection accuracy; 5. The present invention adopts group convolution (GroupConvolution) to YO The LOv8 detection head part is improved to effectively reduce the model complexity and the network calculation amount, while keeping the network detection accuracy unaffected, so that the model can also perform well in the limited computing resource environment of intelligent water transportation; 6. The present invention introduces WIoUv3 with a dynamic non-monotonic focusing mechanism to replace CIoU as the bounding box loss calculation function of the YOLOv8 model, so that the model prediction box is closer to the target real bounding box, thereby improving the model detection accuracy and generalization ability; 7. The method of the present invention has a detection accuracy loss of only 0.36% compared with the original model, the model parameters are reduced by 68.6%, and the calculation amount is reduced by 64.2%. While ensuring real-time performance, it can effectively balance the detection accuracy and the size of the model parameters, and even for water ship targets in complex weather, it can achieve better detection effects. BRIEF DESCRIPTION OF THE DRAWINGS

[0064] Figure 1 It is an operation flow chart of the present invention;

[0065] Figure 2 This is a diagram of the FasterNet network structure in an embodiment of the present invention;

[0066] Figure 3It is a structural diagram of FasterNet Block in an embodiment of the present invention;

[0067] Figure 4 It is a structural diagram of a PConv module in an embodiment of the present invention;

[0068] Figure 5 : is a comparison diagram of the BiFPN and PANet network structures in an embodiment of the present invention;

[0069] Figure 6 is a C2f-faster structure diagram in an embodiment of the present invention;

[0070] Figure 7 It is a structural diagram of a YOLOv8 detection head in an embodiment of the present invention;

[0071] Figure 8 is a diagram of a grouped convolution structure in an embodiment of the present invention;

[0072] Fig. 9 It is a diagram of the structure of Two Group Convolution in an embodiment of the present invention;

[0073] Fig.10 is a structural diagram of a lightweight detection head TGC_Detect in an embodiment of the present invention;

[0074] Fig.11 This is a schematic diagram of WIoUv3 in an embodiment of the present invention;

[0075] Fig.12 It is a diagram showing the improved YOLOv8 detection effect in an embodiment of the present invention. DETAILED DESCRIPTION

[0076] The specific technical scheme of the present invention is further described in detail below with reference to specific examples.

[0077] As shown in the figure, a lightweight ship detection method based on improved YOLOv8 disclosed in the present invention includes the following steps:

[0078] Step 1: Establish a water vessel target dataset. The specific steps include:

[0079] 1.1. The water vessel target dataset of the present invention is established by camera acquisition and network collection, and the collected dataset images are all from real scenes;

[0080] 1.2. After manually cleaning the water ship target dataset and deleting duplicate, blurred, and erroneous dataset images, we finally get Figure 2As shown in the figure, the target dataset of water vessels includes bulk cargo ships, container ships, cruise ships, sail ships, tugboats, warships, and other ships.

[0081] Step 2: Perform fog and rain data enhancement processing on the water ship target dataset. The specific steps include:

[0082] 2.1. To improve the robustness of the water ship target dataset, OpenCV is used to perform pixel-level rain, fog and noise fusion processing on the dataset images, simulate the weather background of water ships under complex weather conditions, and expand the water ship target dataset;

[0083] 2.2. Use the LabelImg image annotation tool to annotate various types of ships in the water ship target dataset in the PASCAL VOC format, and convert them into txt text labels in the YOLO format through the script;

[0084] 2.3. Divide the enhanced water ship target dataset into training set, validation set and test set in the ratio of 7:1:2.

[0085] Step 3: Use the FasterNet network to replace the CSP DarkNet feature extraction network in the YOLOv8 model. The specific steps include:

[0086] 3.1. The FasterNet network consists of three modules, including the Embedding layer, the Merging layer and the FasterNet Block module;

[0087] 3.2. The embedding layer and merging layer are composed of 4×4 convolution and 2×2 convolution respectively, which play the role of downsampling and expanding the number of channels. The FasterNet Block module is the main feature extraction module. Each FasterNet block is composed of a partial convolution (PConv) and two subsequent point-wise convolutions (PWConv), and a normalization layer is set between the two point-wise convolutions.

[0088] 3.3、 Figure 4The PConv module structure diagram is shown. From the PConv module structure diagram, we can know its working principle. It only needs to apply conventional Conv to a part of the input and output channels to extract spatial features, and keep the size of the remaining channels unchanged.

[0089] For the access of the latter rule, the first or last continuous channel is regarded as the representative of the entire feature map for calculation; without loss of generality, the input and output feature maps have the same number of channels; the calculation formula of PConv is as follows:

[0090]

[0091] When the number of channels for convolution operation is 1 / 4, the computational complexity of PConv is only 1 / 16 of that of conventional convolution. In addition, the memory access of Pconv is small, and the calculation formula is as follows:

[0092]

[0093] In the formula, h is the height of the channel, w is the width of the channel, k is the convolution kernel scale, c p The first or last segment is usually selected as the continuous c p channels.

[0094] Step 4: In order to simplify the network structure and improve the network's detection effect on targets of different sizes, the weighted bidirectional feature pyramid network BiFPN module is introduced into the YOLOv8 neck network to replace the original PANet structure of YOLOv8, and more feature information is integrated without increasing the computational cost; the C2f-faster module replaces the C2f module in the YOLOv8 neck network, and the detection speed and computational complexity are further optimized without losing the detection accuracy; the specific steps include:

[0095] 4.1. Weighted Bidirectional Feature Pyramid Network BiFPN. Different from the fixed symmetric bidirectional feature fusion structure of PANet, BiFPN flexibly deletes the fusion nodes with only one edge at both ends, simplifying the network structure. In addition, BiFPN also adds an additional connection between the original input and output nodes of the same layer, realizing the fusion of more feature information without increasing the computational cost. The weighted feature fusion calculation formula is as follows:

[0096]

[0097] In the formula, w i and w j represents different weight learning parameters, ε=0.0001, I i Represents input features;

[0098] 4.2. The C2f module in the neck network of YOLOv8 consists of a standard convolution Conv and multiple Bottelneck blocks; multiple Bottelneck blocks perform a large number of 3×3 convolution operations, making the neck network structure more complex and computationally intensive;

[0099] To solve this problem, all Bottleneck in the original network C2f module is replaced by FasterNet Block to obtain C2f-faster module.

[0100] Step 5: Use group convolution to improve the YOLOv8 detection head, effectively reduce the model complexity and network calculation amount, while keeping the network detection accuracy unaffected, so that the model can also perform well in the limited computing resource environment of water transportation intelligence; the specific steps include:

[0101] 5.1. The detection head of YOLOv8 adopts a decoupled head structure to separate the regression branch and the prediction branch. Each branch will perform two Conv modules with 3×3 convolution kernels and one Conv2d module with 1×1 convolution kernel, which will generate a lot of calculation and parameter amount;

[0102] 5.2. Group Convolution can divide the input data and convolution kernel into multiple groups, and each group performs convolution operations independently. By dividing the input feature map into multiple groups for independent convolution operations, the amount of parameters and calculations can be effectively reduced;

[0103] Assume that the size of the input feature map is H×W and the number of input channels is C in , the number of channels of the output feature map is C out , the size of the convolution kernel is K×K, then the calculation formula of ordinary convolution is as follows:

[0104] C out ×C in ×K×K

[0105] If the grouped convolution divides the input feature map into G groups, the number of channels in each group is C in / G, the number of channels of the output feature map is C out / G, the calculation formula for each group is as follows:

[0106]

[0107] The total parameter calculation formula is as follows:

[0108]

[0109] From the above formula, we can see that the total number of parameters of grouped convolution is 1 / G of the number of parameters of ordinary convolution;

[0110] 5.3. Replace the original 3×3 convolution with the Two Group Convolution composed of two group convolutions in parallel to build a lightweight detection head TGC_Detect;

[0111] Step 6: Introduce WIoUv3 with dynamic non-monotonic focusing mechanism to replace CIoU as the bounding box loss calculation function of the YOLOv8 model; the specific steps include:

[0112] 6.1. Bounding box loss function predicts the position of the target in the entire image through a rectangular bounding box, where IoU represents the degree of overlap between the predicted box and the actual box of the detected target. The greater the overlap between the two, the better the detection effect. YOLOv8 uses the CIoU loss function, which mainly considers three factors: overlapping area, center point and aspect ratio. The calculation formula of the CIoU loss function is as follows:

[0113]

[0114] In the formula, ρ 2 (x,x gt ) represents the true box X and the predicted box X gt The Euclidean distance of the center point, c is the diagonal length of its circumscribed rectangle, αv represents the aspect ratio penalty term, where α is the weight coefficient, v is the coefficient for predicting the relative proportion of the two rectangular boxes, w and h represent the width and height of the predicted box, w gt and h gt It represents the width and height of the actual frame, and IoU is the intersection-over-union ratio of two frames;

[0115] 6.2. The water environment is complex and changeable, and there are many types of ships. The images of ships captured on the water surface often have mutual occlusion between ships, which brings considerable difficulty to model detection. At the same time, the CIoU loss function is very sensitive to the position deviation of small target ships that are close to large target ships, and the frame selection and positioning of small target ships are prone to large deviations. At the same time, the imbalance of positive and negative samples is also inevitable in the training data set. This problem will inevitably lead to the appearance of low-quality samples. The previous loss function will increase the penalty for low-quality samples and reduce the generalization ability of the model. Therefore, WIoUv3 with a dynamic non-monotonic focusing mechanism is introduced to replace CIoU as the bounding box loss calculation function of the YOLOv8 model. The dynamic non-monotonic focusing mechanism in WIoUv3 can effectively avoid the negative impact of low-quality samples during training by weighing the proportion of high- and low-quality samples, and focus the bounding box regression results on the target object, solving the problem that ships are difficult to detect due to occlusion. WIoUv3 adds a dynamic non-monotonic focusing mechanism based on WIoUv1. The specific calculation formula of WIoUv1 is as follows:

[0116] L IoU =1-IoU

[0117]

[0118] L WIoUv1 =R WIoU L IoU

[0119] In the formula, (x, y) and (x gt ,y gt ) are the center point coordinates of the predicted box and the real box, W g and H g is the width and height of the minimum bounding box of the predicted box and the real box, R WIoU ∈[1,e) is used to enlarge the L of the normal quality anchor box IoU , L IoU ∈[0,1] is used to reduce the R of high-quality anchor boxes WIoU ;

[0120] In order to avoid the negative impact of low-quality samples, WIoUv3 defines the outlier degree β, combined with the sliding average IoU value with momentum m The formula is as follows:

[0121]

[0122] Combining the training model hyperparameters α and δ, the non-monotonic focusing coefficient γ is constructed as follows:

[0123]

[0124] Applying γ to WIoUv1, we get the WIoUv3 loss function, the formula is as follows:

[0125] L WIoUv3 =γR WIoU L IoU .

[0126] Step 7: After steps 4, 5, and 6, an improved YOLOv8 model is obtained. The improved YOLOv8 model is trained using the water ship target data set to obtain the best weight file best.pt, and the images in the test set are classified and located. The specific steps include:

[0127] 7.1. Set the training strategy and set the momentum to 0.93. To prevent overfitting during training, set the weight decay rate to 0.0005, the initial learning rate to 0.01, the minimum learning rate to 0.0001, the number of training iterations to 200, the input image size to 640*640, and the batch size to 4. After training, the model will save the best weight file best.pt.

[0128] 7.2. Use best.pt as the weight file of the improved YOLOv8 model, and then randomly select several images to be tested from the test set as data sources for detection.

[0129] In order to objectively evaluate the comprehensive performance of the present invention, the present invention is compared with several representative algorithms and the detection results are analyzed. The specific steps include: selecting the comparison algorithms as Faster-RCNN, YOLOv5 and YOLOv8, and in order to comprehensively judge the quality of the model, the model parameter amount Para (MB), the number of floating point operations per second FLOPS (Floating Point Operations Per Second) and the mean average precision mAP (Mean Average Precision) are counted in the experiment. The mAP value represents the average value of the average detection precision AP (Average Precision) of all categories, and the AP value is calculated by the PR curve formed by the precision rate and the recall rate and the area composed of the horizontal and vertical coordinates. AP is defined as:

[0130]

[0131] In the formula, P (Pecision) represents the precision rate (the proportion of true positive examples in the detected positive examples), R (Recall) represents the recall rate (the proportion of positive examples detected in all samples to all positive examples), and the average precision mAP of various water obstacles is defined as:

[0132]

[0133] In the formula, k represents a single sample, n is the number of target types, AP i Indicates the accuracy of detection of each image; the above algorithms are trained on the water ship target dataset, and the comparison results are shown in Table 1. From the comprehensive perspective of various performance indicators, the improved YOLOv8 model balances the detection speed, accuracy and size of model parameters. Compared with several other algorithms, it has more advantages in the detection task of water ship targets.

[0134] Table 1 Comparison of experimental results of different algorithms

[0135]

[0136]

Claims

1. A lightweight ship detection method based on improved YOLOv8, characterized in that: The operation steps are as follows: Step (1): Establish a water vessel target dataset; Step (2): Perform fog and rain data enhancement processing on the water ship target data set; Step (3): Use FasterNet network to replace the CSP DarkNet feature extraction network in the YOLOv8 model; Step (4): Introduce the weighted bidirectional feature pyramid network BiFPN module into the YOLOv8 neck network, replace the original PANet structure of YOLOv8, and replace the C2f module in the YOLOv8 neck network with the C2f-Faster module; Step (5): Use group convolution to improve the YOLOv8 detection head; Step (6): Introduce WIoUv3 with dynamic non-monotonic focusing mechanism to replace CIoU as the bounding box loss calculation function of the YOLOv8 model; Step (7): After steps (3)-(6), an improved YOLOv8 model is obtained. The improved YOLOv8 model is trained using the water ship target dataset to obtain the best weight file best.pt, and the images in the test set are classified and located.

2. According to claim 1, a lightweight ship detection method based on improved YOLOv8 is characterized in that: The process of establishing the data set in step (1) is: Step (1.1): Establish a water vessel target dataset through camera acquisition and network collection; Step (1.2): Manually clean the water ship target dataset, delete duplicate, blurred, and incorrectly formatted dataset images, and finally obtain the water ship target dataset.

3. A lightweight ship detection method based on improved YOLOv8 according to claim 2, characterized in that: In step (1.1), the collected dataset images are all from real scenes; In step (1.2), the finally obtained water vessel target data set includes bulk carriers, container ships, cruise ships, sailboats, tugboats, warships and other ships.

4. A lightweight ship detection method based on improved YOLOv8 according to claim 1, characterized in that: The process of performing the enhancement processing in step (2) is: Step (2.1): Use OpenCV to perform pixel-level rain, fog and noise fusion processing on the dataset images to simulate the weather background of water surface obstacles under complex weather conditions and expand the water surface obstacle dataset; Step (2.2): Use the LabelImg image annotation tool to annotate the ships, reefs, and buoy obstacles in the surface obstacle dataset in the PASCAL VOC format, and convert them into txt text labels in the YOLO format through a script; Step (2.3): Divide the enhanced water surface obstacle dataset into training set, validation set and test set in a ratio of 7:1:

2.

5. A lightweight ship detection method based on improved YOLOv8 according to claim 1, characterized in that: The specific process of step (3) is: Step (3.1): The FasterNet network consists of three modules: embedding layer, fusion layer and FasterNet Block module; Step (3.2): The embedding layer and fusion layer consist of 4×4 convolution and 2×2 convolution respectively; The FasterNet Block module is the main feature extraction module. Each FasterNet block consists of a PConv and two subsequent PWConvs, and a normalization layer is set between the two point-by-point convolutions. Step (3.3): The calculation formula of PConv is as follows: When the number of channels for convolution operation is 1 / 4, the computational complexity of PConv is only 1 / 16 of that of conventional convolution. In addition, the memory access of Pconv is small, and the calculation formula is as follows: In the formula, h is the height of the channel, w is the width of the channel, k is the convolution kernel scale, c p The first or last segment is usually selected as the continuous c p channels.

6. A lightweight ship detection method based on improved YOLOv8 according to claim 1, characterized in that: The specific process of step (4) is: Step (4.1): Weighted bidirectional feature pyramid network BiFPN, the weighted feature fusion calculation formula is as follows: In the formula, w i and w j represents different weight learning parameters, ε=0.0001, I i Represents input features; Step (4.2): Replace all Bottleneck in the C2f module in the YOLOv8 neck network with FasterNetBlock to obtain the C2f-Faster module.

7. A lightweight ship detection method based on improved YOLOv8 according to claim 1, characterized in that: The specific process of step (5) is: Step (5.1): The detection head of YOLOv8 adopts a decoupled head structure to separate the regression branch and the prediction branch. Each branch will perform two Conv modules with 3×3 convolution kernels and one Conv2d module with 1×1 convolution kernel, thereby generating a lot of calculations and parameters. Step (5.2): Grouped convolution divides the input data and convolution kernel into multiple groups, and each group performs convolution operations independently of each other. By dividing the input feature map into multiple groups, independent convolution operations are performed; Step (5.3): Replace the original 3×3 convolution with the Two Group Convolution composed of two group convolutions in parallel to construct a lightweight detection head TGC_Head.

8. A lightweight ship detection method based on improved YOLOv8 according to claim 1, characterized in that: In step (5.2), assume that the size of the input feature map is H×W and the number of input channels is C in , the number of channels of the output feature map is C out , the size of the convolution kernel is K×K, then the calculation formula of ordinary convolution is as follows: C out ×C in ×K×K If the grouped convolution divides the input feature map into G groups, the number of channels in each group is C in / G, the number of channels of the output feature map is C out / G, the calculation formula for each group is as follows: The total parameter calculation formula is as follows: From the above formula, it can be concluded that the total number of parameters of grouped convolution is 1 / G of the number of parameters of ordinary convolution.

9. A lightweight ship detection method based on improved YOLOv8 according to claim 1, characterized in that: The specific process of step (6) is: Step (6.1): The bounding box loss function predicts the position of the target in the entire image through a rectangular bounding box, where IoU represents the degree of overlap between the predicted box and the actual box of the detected target; YOLOv8 uses the CIoU loss function, which considers three factors: overlapping area, center point, and aspect ratio. The CIoU loss function calculation formula is as follows: In the formula, ρ 2 (x,x gt ) represents the true box X and the predicted box X gt The Euclidean distance of the center point, c is the diagonal length of its circumscribed rectangle, αv represents the aspect ratio penalty term, where α is the weight coefficient, v is the coefficient for predicting the relative proportion of the two rectangular boxes, w and h represent the width and height of the predicted box, w gt and h gt It represents the width and height of the actual frame, and IoU is the intersection-over-union ratio of two frames; Step (6.2): ​​Introduce WIoUv3 with a dynamic non-monotonic focusing mechanism to replace CIoU as the bounding box loss calculation function of the YOLOv8 model. WIoUv3 adds a dynamic non-monotonic focusing mechanism based on WIoUv1. The specific calculation formula of WIoUv1 is as follows: L IoU =1-IoU L WIoUv1 =R WIoU L IoU In the formula, (x,y) and (x gt ,y gt ) are the center point coordinates of the predicted box and the real box, W g and H g is the width and height of the minimum bounding box of the predicted box and the real box, R WIoU ∈[1,e) is used to enlarge the L of the normal quality anchor box IoU , L IoU ∈[0,1] is used to reduce the R of high-quality anchor boxes WIoU ; To avoid the negative impact of low-quality samples, WIoUv3 defines the outlier degree β, combined with the sliding average IoU value L with momentum m IoU The formula is as follows: Combining the training model hyperparameters α and δ, the non-monotonic focusing coefficient γ is constructed as follows: Applying γ to WIoUv1, we get the WIoUv3 loss function, the formula is as follows: IT WIoUv3 =γR WIoU IT IoU 。 10. A lightweight ship detection method based on improved YOLOv8 according to claim 1, characterized in that: The specific process of step (7) is: Step (7.1): Set the training strategy and set the momentum to 0.93; to prevent overfitting during training, set the weight decay rate to 0.0005, the initial learning rate to 0.01, the minimum learning rate to 0.0001, the number of training iterations to 200, the input image size to 640*640, and the batch size to 4; After training is completed, the model will save the best weight file of the training result, best.pt; Step (7.2): Use best.pt as the weight file of the improved YOLOv8 model, and then randomly select several images to be tested from the test set as data sources for detection.

Citation Information

Patent Citations

  • Lightweight underwater target real-time detection method

    CN116977844A

  • C2f-Faster-based YOLOv8n power transmission line fault detection method

    CN117636125A

  • Remote sensing tailing pond image detection method based on YOLOv8-RVSW

    CN118447411A

  • Ship detection method based on YOLOv5

    CN118982796A