Pipeline defect detection method and system based on improved YOLOv8s
By improving the YOLOv8s network model, combining random grouping convolution, multi-scale attention mechanism and ASPP module, the insufficient detection accuracy and speed in pipeline defect detection are solved, and higher detection accuracy and recall are achieved, and the Model size.
Patent Information
- Application Number
- CN202410943228.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-15
- Publication Date
- 2024-11-29
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The existing pipeline defect detection methods have shortcomings in detection accuracy and speed, especially in complex underground pipeline scenarios, machine learning methods are difficult to effectively identify diverse defect characteristics, and traditional YOLO algorithms have a balance in accuracy and speed. question.
By improving the YOLOv8s network model, random grouping convolution, efficient multi-scale attention mechanism and ASPP module were introduced, and NWD loss function was constructed to optimize the model to improve detection accuracy and recall.
It significantly improves the accuracy, recall and average accuracy of pipeline defect detection, while reducing the model size and enhancing the detection ability of micro defects.
Smart Images

Figure CN119048421A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of visual defect detection, and more specifically, to a pipeline defect detection method and system based on improved YOLOv8s. Background Art
[0002] Urban underground drainage pipes are important infrastructure for urban construction and an important guarantee for normal production and life of human beings. With the increasingly accelerated urbanization process in my country, the burden of urban drainage has gradually increased. Many drainage pipes were built in the last century and have a high risk of damage and aging. If they are blocked or damaged, they will cause varying degrees of loss of life and property. Therefore, regular detection of pipeline defects is very important.
[0003] Commonly used physical detection methods for pipeline interiors include manual detection, sonar detection, periscope detection, and CCTV image inspection. Traditional manual visual inspection methods have low detection efficiency and slow speed. Sonar detection can only identify obvious defects such as sediments and obstacles. Pipeline periscope detection cannot perform continuous detection, has a short single detection distance, and cannot detect conditions under the water surface. Compared with other methods, CCTV image detection has low cost, high safety factor, mature technology, convenient operation, and clear records, making it more suitable for pipeline interior detection.
[0004] CCTV pipeline defect detection can use machine learning or deep learning methods. Machine learning methods have great limitations in the actual pipeline detection process. Underground pipeline scenes change complexly, and the use of image processing algorithms for defect segmentation is easily disturbed by the background environment, resulting in a low success rate of defect segmentation. In addition, there are various types of pipeline defects. Even if they are the same type of defects, they will have great differences in color, texture, shape and other features, making it difficult to select appropriate feature description factors to quantitatively describe the defect features. Deep learning can be divided into two-stage target detection algorithms and single-stage target detection algorithms according to the algorithm flow. The two-stage method refers to the two main processes of realizing detection. First, the object area is extracted, and then the area is classified and recognized by CNN. The accuracy is high but the speed is slow, such as R-CNN and Faster R-CNN; the single-stage target detection method is based on the regression algorithm and does not need to go through the candidate box selection stage. The result can be directly predicted from the input image. Its recognition speed is fast but the accuracy will decrease, such as YOLO, SSD, etc. Summary of the invention
[0005] The object of the present invention is to provide a pipeline defect detection method and system based on improved YOLOv8s, which can improve the detection accuracy of the model for pipeline defects.
[0006] The invention provides a pipeline defect detection method based on improved YOLOv8s, comprising the following steps: S1: acquiring a pipeline defect image, the pipeline defect image comprising a misalignment defect image, a crack defect image, an obstacle defect image and a branch pipe defect image; enhancing the pipeline defect image by using an image enhancement algorithm to obtain a pipeline defect detection data set image; S2: annotating and dividing the pipeline defect detection data set image to obtain a training set, a verification set and a test set; S3: acquiring a YOLOv8s network model, improving the YOLOv8s network model, constructing a loss function, and obtaining an improved YOLOv8s network model; S4: training, verifying and testing the improved YOLOv8s network model by using the training set, the verification set and the test set to obtain a trained improved YOLOv8s network model; S5: acquiring an image of a pipeline to be detected, performing target detection on the image of the pipeline to be detected by using the trained improved YOLOv8s network model to obtain a detection result; and obtaining a detection accuracy according to the detection result.
[0007] Furthermore, the image enhancement algorithm of the above-mentioned pipeline defect detection method based on improved YOLOv8s is the MSRCR algorithm.
[0008] Furthermore, step S2 of the above-mentioned pipeline defect detection method based on improved YOLOv8s specifically includes: S21: annotating the pipeline defect detection dataset image using an image annotation tool to obtain an annotated pipeline defect detection dataset image; S22: dividing the annotated pipeline defect detection dataset image according to a preset ratio to obtain a training set, a validation set, and a test set.
[0009] Furthermore, step S3 of the above-mentioned pipeline defect detection method based on improved YOLOv8s specifically includes: S31: obtaining a YOLOv8s network model, replacing the SPPF module in the backbone of the YOLOv8s network model with an ASPP module, the ASPP module including a preset number of parallel hole convolutions with different preset sampling rates; S32: replacing the convolution Conv in the neck of the YOLOv8s network model with a random group convolution GSConv, the random group convolution GSConv including a GSBottleneck network and a VoV-GSCSP cross-level partial network; S33: adding an efficient multi-scale attention mechanism module EMAttention to the backbone network of the YOLOv8s network model, the efficient multi-scale attention mechanism module EMAttention is used to enhance the generalization ability and robustness of the model; S34: constructing a loss function, such as the formula:
[0010] L NWD =1-NWD(N p ,N g )
[0011] Among them, L NWD is the loss function, NWD(.) is the normalized weighted distance loss function (Normalized WeightedDistance, NWD), N p is the Gaussian distribution of the prediction box, N g It is the Gaussian distribution of the GT box (Ground Truth Box, real box).
[0012] Furthermore, step S5 of the above-mentioned pipeline defect detection method based on improved YOLOv8s specifically includes: obtaining an image of the pipeline to be detected, performing target detection on the image of the pipeline to be detected using the trained improved YOLOv8s network model, and obtaining a detection result; and obtaining a detection accuracy according to the detection result, and the detection accuracy includes a precision rate and a recall rate, as shown in the formula:
[0013]
[0014] Among them, Precision is the precision, Recall is the recall, TP is the number of positive classes predicted as positive classes, FP is the number of negative classes predicted as positive classes, and FN is the number of positive classes predicted as negative classes.
[0015] The present invention also provides a system including the following modules: an image acquisition module, configured to: acquire pipeline defect images, the pipeline defect images include misalignment defect images, crack defect images, obstacle defect images and branch pipe defect images; enhance the pipeline defect images by using an image enhancement algorithm to obtain pipeline defect detection data set images; an annotation and data set division module, configured to: annotate and divide the pipeline defect detection data set images to obtain a training set, a verification set and a test set; a network model construction module, configured to: acquire a YOLOv8s network model, improve the YOLOv8s network model, construct a loss function, and obtain an improved YOLOv8s network model; a model training module, configured to: train, verify and test the improved YOLOv8s network model by using the training set, the verification set and the test set to obtain a trained improved YOLOv8s network model; a target detection and evaluation module, configured to: acquire an image of a pipeline to be detected, perform target detection on the image of the pipeline to be detected by using the trained improved YOLOv8s network model, and obtain a detection result; and obtain a detection accuracy according to the detection result.
[0016] Furthermore, the image enhancement algorithm of the above system is MSRCR algorithm.
[0017] Furthermore, the annotation and data set division module of the above system is specifically configured as follows: using an image annotation tool to annotate the pipeline defect detection data set images to obtain annotated pipeline defect detection data set images; dividing the annotated pipeline defect detection data set images according to a preset ratio to obtain a training set, a validation set and a test set.
[0018] Furthermore, the network model construction module of the above system is specifically configured as follows: obtain the YOLOv8s network model, replace the SPPF module in the backbone of the YOLOv8s network model with the ASPP module, the ASPP module includes a preset number of parallel hole convolutions with different preset sampling rates; replace the convolution Conv in the neck of the YOLOv8s network model with a random group convolution GSConv, the random group convolution GSConv includes a GSBottleneck network and a VoV-GSCSP cross-level partial network; add an efficient multi-scale attention mechanism module EMAttention to the backbone network of the YOLOv8s network model, the efficient multi-scale attention mechanism module EMAttention is used to enhance the generalization ability and robustness of the model; construct a loss function, such as the formula:
[0019] L NWD =1-NWD(N p ,N g )
[0020] Among them, L NWD is the loss function, NWD(.) is the normalized weighted distance loss function (Normalized WeightedDistance, NWD), N p is the Gaussian distribution of the prediction box, N g It is the Gaussian distribution of the GT box (Ground Truth Box, real box).
[0021] Furthermore, the target detection and evaluation module of the above system is specifically configured as follows: obtaining an image of the pipeline to be detected, using the trained improved YOLOv8s network model to perform target detection on the image of the pipeline to be detected, and obtaining a detection result; according to the detection result, obtaining the detection accuracy, which includes the precision rate and the recall rate, as shown in the formula:
[0022]
[0023] Among them, Precision is the precision, Recall is the recall, TP is the number of positive classes predicted as positive classes, FP is the number of negative classes predicted as positive classes, and FN is the number of positive classes predicted as negative classes.
[0024] Implementing the pipeline defect detection method and system based on improved YOLOv8s provided by the present invention has the following beneficial effects:
[0025] The present invention improves the original YOLOv8s network model, introduces random group convolution GSConv convolution at the neck of the network for thin neck design, and reduces the model size; introduces an efficient multi-scale attention mechanism EMAttention attention mechanism module into the backbone network of the original network, and improves the detection accuracy of the model; replaces the SPPF module with the ASPP module, and expands the receptive field of the model; introduces the NWD loss function to improve the CIOU loss function in the original YOLOv8s algorithm, and improves the model's ability to detect tiny defects in pipelines; under the same conditions, compared with the original YOLOv8s, the size of the improved model is significantly reduced, and the precision, recall and average precision of the model are significantly improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] The present invention will be further described below with reference to the accompanying drawings and embodiments, in which:
[0027] Figure 1 It is a flow chart of a pipeline defect detection method based on improved YOLOv8s provided by the present invention;
[0028] Figure 2 This is an example of a data set image after data enhancement of the pipeline defect detection method based on the improved YOLOv8s provided by the present invention;
[0029] Figure 3 It is a schematic diagram of the network model structure of the pipeline defect detection method based on the improved YOLOv8s provided by the present invention;
[0030] Figure 4 This is an example of the detection result of the pipeline defect detection method based on the improved YOLOv8s provided by the present invention;
[0031] Figure 5 It is a mAP comparison chart of different defects of pipeline defect detection based on the pipeline defect detection method based on the improved YOLOv8s provided by the present invention;
[0032] Figure 6 It is a schematic diagram of a CCTV image sampling and detection device of a pipeline defect detection method based on an improved YOLOv8s provided by the present invention. DETAILED DESCRIPTION
[0033] In order to have a clearer understanding of the technical features, purposes and effects of the present invention, specific embodiments of the present invention are now described in detail with reference to the accompanying drawings.
[0034] Figure 1A schematic diagram of a pipeline defect detection method based on improved YOLOv8s in this embodiment is shown. In this embodiment, the pipeline defect detection method based on improved YOLOv8s includes the following steps:
[0035] S1: Obtain pipeline defect images, including misalignment defect images, crack defect images, obstacle defect images and branch pipe defect images; enhance the pipeline defect images using an image enhancement algorithm to obtain pipeline defect detection data set images;
[0036] Specifically, the image enhancement algorithm of the pipeline defect detection method based on the improved YOLOv8s is the MSRCR algorithm;
[0037] S2: Label and divide the pipeline defect detection dataset images to obtain training set, validation set and test set;
[0038] Specifically, step S2 of the above-mentioned pipeline defect detection method based on improved YOLOv8s specifically includes: S21: annotating the pipeline defect detection dataset image using an image annotation tool to obtain an annotated pipeline defect detection dataset image; S22: dividing the annotated pipeline defect detection dataset image according to a preset ratio to obtain a training set, a validation set and a test set;
[0039] S3: obtain the YOLOv8s network model, improve the YOLOv8s network model, construct a loss function, and obtain an improved YOLOv8s network model;
[0040] Specifically, step S3 of the above-mentioned pipeline defect detection method based on improved YOLOv8s specifically includes: S31: obtaining a YOLOv8s network model, replacing the SPPF module in the backbone of the YOLOv8s network model with an ASPP module, the ASPP module including a preset number of parallel hole convolutions with different preset sampling rates; S32: replacing the convolution Conv in the neck of the YOLOv8s network model with a random group convolution GSConv, the random group convolution GSConv including a GSBottleneck network and a VoV-GSCSP cross-level partial network; S33: adding an efficient multi-scale attention mechanism module EMAttention to the backbone network of the YOLOv8s network model, the efficient multi-scale attention mechanism module EMAttention is used to enhance the generalization ability and robustness of the model; S34: constructing a loss function, such as the formula:
[0041] L NWD =1-NWD(N p ,N g )
[0042] Among them, LNWD is the loss function, NWD(.) is the normalized weighted distance loss function (Normalized WeightedDistance, NWD), N p is the Gaussian distribution of the prediction box, N g It is the Gaussian distribution of the GT box (Ground Truth Box, real box);
[0043] S4: Use the training set, validation set and test set to train, validate and test the improved YOLOv8s network model to obtain a trained improved YOLOv8s network model;
[0044] S5: Obtain an image of the pipeline to be detected, use the trained improved YOLOv8s network model to perform target detection on the image of the pipeline to be detected, and obtain the detection result; according to the detection result, obtain the detection accuracy;
[0045] Specifically, step S5 of the above-mentioned pipeline defect detection method based on improved YOLOv8s specifically includes: obtaining an image of the pipeline to be detected, using the trained improved YOLOv8s network model to perform target detection on the image of the pipeline to be detected, and obtaining a detection result; according to the detection result, obtaining the detection accuracy, the detection accuracy includes precision and recall, as shown in the formula:
[0046]
[0047] Among them, Precision is the precision, Recall is the recall, TP is the number of positive classes predicted as positive classes, FP is the number of negative classes predicted as positive classes, and FN is the number of positive classes predicted as negative classes.
[0048] This embodiment provides a system including the following modules:
[0049] The image acquisition module is configured to: acquire pipeline defect images, including misalignment defect images, crack defect images, obstacle defect images, and branch pipe defect images; enhance the pipeline defect images using an image enhancement algorithm to obtain pipeline defect detection data set images;
[0050] Specifically, the image enhancement algorithm of the above system is the MSRCR algorithm;
[0051] The labeling and data set division module is configured to: label and divide the pipeline defect detection data set images to obtain a training set, a validation set, and a test set;
[0052] Specifically, the annotation and data set division module of the above system is specifically configured as follows: annotating the pipeline defect detection data set images using an image annotation tool to obtain annotated pipeline defect detection data set images; dividing the annotated pipeline defect detection data set images according to a preset ratio to obtain a training set, a validation set, and a test set;
[0053] The network model building module is configured to: obtain the YOLOv8s network model, improve the YOLOv8s network model, build a loss function, and obtain an improved YOLOv8s network model;
[0054] Specifically, the network model construction module of the above system is specifically configured as follows: obtain the YOLOv8s network model, replace the SPPF module in the backbone of the YOLOv8s network model with the ASPP module, the ASPP module includes a preset number of parallel hole convolutions with different preset sampling rates; replace the convolution Conv in the neck of the YOLOv8s network model with a random group convolution GSConv, the random group convolution GSConv includes a GSBottleneck network and a VoV-GSCSP cross-level partial network; add an efficient multi-scale attention mechanism module EMAttention to the backbone network of the YOLOv8s network model, the efficient multi-scale attention mechanism module EMAttention is used to enhance the generalization ability and robustness of the model; construct a loss function, such as the formula:
[0055] L NWD =1-NWD(N p ,N g )
[0056] Among them, L NWD is the loss function, NWD(.) is the normalized weighted distance loss function (Normalized WeightedDistance, NWD), N p is the Gaussian distribution of the prediction box, N g It is the Gaussian distribution of the GT box (Ground Truth Box, real box);
[0057] The model training module is configured to: train, verify and test the improved YOLOv8s network model using the training set, verification set and test set to obtain a trained improved YOLOv8s network model;
[0058] The target detection and evaluation module is configured as follows: obtaining the image of the pipeline to be detected, using the trained improved YOLOv8s network model to perform target detection on the image of the pipeline to be detected, and obtaining the detection result; according to the detection result, obtaining the detection accuracy;
[0059] Specifically, the target detection and evaluation module of the above system is specifically configured as follows: obtaining an image of the pipeline to be detected, using the trained improved YOLOv8s network model to perform target detection on the image of the pipeline to be detected, and obtaining a detection result; according to the detection result, obtaining the detection accuracy, which includes the precision rate and the recall rate, as shown in the formula:
[0060]
[0061] Among them, Precision is the precision, Recall is the recall, TP is the number of positive classes predicted as positive classes, FP is the number of negative classes predicted as positive classes, and FN is the number of positive classes predicted as negative classes.
[0062] In some embodiments, the above-mentioned pipeline defect detection method based on improved YOLOv8s can also be implemented in the following manner.
[0063] In this embodiment, the pipeline defect detection method based on the improved YOLOv8s includes the following steps:
[0064] S1: Obtain pipeline defect images, including misalignment defect images, crack defect images, obstacle defect images and branch pipe defect images; use the MSRCR algorithm to enhance the pipeline defect images to obtain pipeline defect detection dataset images;
[0065] Specifically, the MSRCR algorithm is used to enhance the data set images. First, the original image is low-pass filtered using a Gaussian function, and then the original image and the filtered image are converted to the logarithmic domain and the difference is obtained to obtain the reflected image. Then, the above steps are repeated at multiple scales and summed, and finally color restoration and image restoration are performed.
[0066] Specifically, the pipeline defect images used in this embodiment come from the Sewer ML dataset, a large-scale drainage pipeline defect detection dataset created by Haurum et al., which is divided into four types of defects: misalignment, cracks, obstacles, and branch pipes. There are 1,200 images of each defect, and a total of 4,800 images in the dataset. Some images in the dataset are as follows: Figure 2 As shown;
[0067] Specifically, the MSRCR algorithm is used for data enhancement, the original image is low-pass filtered using a Gaussian function, and then the original image and the filtered image are converted to the logarithmic domain and the difference is obtained to obtain the reflected image. Then the above steps are repeated at multiple scales and summed, and finally color restoration and image restoration are performed;
[0068] Multi-Scale Retinex with ColorRestore (MSRCR) is a technology for image enhancement based on the Retinex algorithm. "Retinex" is a compound word that combines the concepts of "retina" and "cortex". It is a computational theory of color constancy perception proposed by Edwin H. Land in 1963, which aims to simulate the brightness and color perception mechanism of the human visual system.
[0069] S2: Label and divide the pipeline defect detection dataset images to obtain training set, validation set and test set;
[0070] Specifically, step S2 specifically includes: S21: annotating the pipeline defect detection dataset image using an image annotation tool to obtain an annotated pipeline defect detection dataset image; S22: dividing the annotated pipeline defect detection dataset image according to a preset ratio to obtain a training set, a validation set, and a test set;
[0071] Specifically, the image annotation tool is labelme; the annotated defect information is in txt format; the ratio of training set, data set, and validation set images is 7:2:1;
[0072] Specifically, the annotated images are divided into training set, validation set and test set. Four folders named after the four defects are established in the training set, validation set and test set, and two folders, images and labels, are established in them respectively. The images of pipeline defects are placed in the images folder, and the corresponding txt files are placed in the labels folder.
[0073] S3: obtain the YOLOv8s network model, improve the YOLOv8s network model, construct a loss function, and obtain an improved YOLOv8s network model;
[0074] Specifically, step S3 specifically includes: S31: obtaining a YOLOv8s network model, replacing the SPPF module in the backbone of the YOLOv8s network model with an ASPP module, wherein the ASPP module includes a preset number of parallel hole convolutions with different preset sampling rates; S32: replacing the convolution Conv in the neck of the YOLOv8s network model with a random group convolution GSConv, wherein the random group convolution GSConv includes a GSBottleneck network and a VoV-GSCSP cross-level partial network; S33: adding an efficient multi-scale attention mechanism module EMAttention to the backbone network of the YOLOv8s network model, wherein the efficient multi-scale attention mechanism module EMAttention is used to enhance the generalization ability and robustness of the model; S34: constructing a loss function, introducing an NWD loss function to improve the CIOU loss function in the original YOLOv8s algorithm, and improving the network model's ability to detect relatively minor defects, and the calculation formula is as follows:
[0075]
[0076] Among them, NWD(.) is the normalized weighted distance loss function (NWD), Np is the Gaussian distribution of the prediction box, and Ng is the Gaussian distribution of the GT box (Ground Truth Box, real box);
[0077] Specifically, the YOLOv8s network model is improved; in order to lighten the original YOLOv8s network model and reduce the model size, the random group convolution GSConv convolution is introduced at the neck of the network for a thin neck design; in order to increase the detection accuracy after improvement, the efficient multi-scale attention mechanism EMAttention attention mechanism module is introduced into the backbone network of the original network, and the SPPF module is replaced with the ASPP module with enhanced receptive field; in order to improve the detection ability of pipeline defect detection for relatively small defects, the NWD loss function is introduced to improve the CIOU loss function in the original YOLOv8s algorithm. And adjust the corresponding parameters;
[0078] Specifically, the SPPF module in the original backbone is replaced by the ASPP module by introducing multiple parallel dilated convolutions with different sampling rates. The features extracted for each sampling rate are further processed in a separate branch and fused to generate the final result. Its main function is to expand the receptive field of the convolution kernel and improve the detection accuracy without losing resolution (without downsampling). At the same time, in order to meet the demand of lightweight network model, random group convolution GSConv convolution is introduced at the neck of the network for thin neck design, and GSBottleneck and VoV-GSCSP are designed and introduced on the basis of GSConv. Cross-level partial network; Specifically, the Conv in the original neck is replaced with GSConv. GSConv first inputs a downsampling of a common convolution, then uses DWConv deep convolution, and concatenates the results of the two Convs (a channel-dense convolution and a channel-sparse convolution); finally, a shuffle operation is performed to bring the corresponding channels of the two convolutions together, so that the output of the channel-sparse convolution is close to the channel-dense convolution and mixes them to reduce the computational cost; by introducing GSConv, the GSBottleneck and VoV-GSCSP modules are formed to form a thin neck network;
[0079] Specifically, an efficient multi-scale attention mechanism (EMAttention) is added to the backbone network. It reshapes some channels into batch dimensions and groups the channel dimensions into multiple sub-features to retain the information of each channel and reduce computational overhead. It also recalibrates the channel weights in each parallel branch by encoding global information and captures pixel-level relationships through cross-dimensional interactions to enhance the generalization and robustness of the model. It has good data expansion capabilities and robustness, and significantly improves the accuracy of the algorithm.
[0080] Specifically, the NWD loss function is introduced to improve the CIOU loss function in the YOLOv5 algorithm. The traditional CIoU only considers the overlapping part of the predicted box and the real box, and does not consider the area between the two, which may lead to deviations in the evaluation results; NWD (Normalized Weighted Distance) replaces loU by modeling the box as a Gaussian distribution and then using the Wasserstein distance to measure the similarity between the two distributions; in this way, even if the two boxes do not overlap at all, or overlap very little, the similarity can still be measured; in addition, NWD is insensitive to the scale of the target and is more stable for small targets; compared with the traditional loss function IOU (Intersection over Union), NWD is scale-invariant and changes smoothly with position differences. The improved YOLOv8s network is as follows: Figure 3 As shown;
[0081] S4: Use the training set, validation set and test set to train, validate and test the improved YOLOv8s network model to obtain a trained improved YOLOv8s network model;
[0082] Specifically, the hardware configuration of the training model is: CPU Intel Core i9-13900k, GPU NVIDIA GeForceRTX3080, memory 16G; software configuration is: operating system is Windows 1164-bit, CUDA version configured for the graphics card is 11.7; deep learning framework is Pytorch, development language is Python3.10, and development tool is Pycharm;
[0083] Specifically, in the training phase, training, verification and testing are performed in a ratio of 7:2:1. The input size of the network is uniformly adjusted to 640×640×3, the training epoch is set to 300, and the batch size is set to 4. After reaching the maximum training epoch, the training is stopped, the network model is saved, and the corresponding weight file is obtained. After verification, test optimization, the best weight file best.pt is obtained.
[0084] S5: Obtain an image of the pipeline to be detected, use the trained improved YOLOv8s network model to perform target detection on the image of the pipeline to be detected, and obtain the detection result; according to the detection result, obtain the detection accuracy;
[0085] Specifically, the best weight file after training is saved in the YOLOv8s network model, and this weight file is used to verify the validation set data; the trained YOLOv8s model is used to detect pipeline defects on the test set images to check the corresponding defects and detection accuracy. The precision and recall are expressed as:
[0086]
[0087] Among them, Precision is the precision, Recall is the recall, TP is the number of positive classes predicted as positive classes, FP is the number of negative classes predicted as positive classes, and FN is the number of positive classes predicted as negative classes.
[0088] The detection results of the pipeline defect target detection method of YOLOv8s, which combines random group convolution with efficient multi-scale attention mechanism, are shown in the following example after testing the test set. Figure 4 As shown; the mAP graph of different defects of the pipeline defect detection method of YOLOv8s combining random group convolution and efficient multi-scale attention mechanism is as follows Figure 5As shown in the figure, after experimental testing, the pipeline defect target detection method of YOLOv8s, which combines random group convolution with efficient multi-scale attention mechanism, has improved the average accuracy of various defects and the overall accuracy compared with the original YOLOv8s, and the model size, floating-point operations and parameters have been reduced to a certain extent.
[0089] like Figure 6 As shown, this embodiment provides a CCTV image acquisition and detection device A01, which is used to: acquire CCTV pipeline defect images in real time, and use the CCTV pipeline image defect target detection method of YOLOv8s that combines random group convolution with efficient multi-scale attention mechanism for detection; CCTV image acquisition and detection device A01 includes:
[0090] CCTV image acquisition device A02 is used for: CCTV camera A02 to collect CCTV pipeline defect image data;
[0091] The pipeline defect detection processor A03 is used to: transplant the CCTV pipeline image defect target detection method algorithm of YOLOv8s that combines random group convolution and efficient multi-scale attention mechanism to A03, read the image data in C02 and perform pipeline defect detection;
[0092] The storage and display device A04 is used to store and display data information after the pipeline defect detection processor A03 performs pipeline defect detection.
[0093] The embodiments of the present invention are described above in conjunction with the accompanying drawings, but the present invention is not limited to the above-mentioned specific implementation modes, which are merely illustrative rather than restrictive. Under the guidance of the present invention, ordinary technicians in this field can also make many forms without departing from the scope of protection of the present invention and the claims, all of which are within the protection of the present invention.
Claims
1. A pipeline defect detection method based on improved YOLOv8s, characterized in that , including the following steps: S1: Acquire pipeline defect images, which include misalignment defect images, crack defect images, obstacle defect images, and branch pipe defect images; enhance the pipeline defect images using an image enhancement algorithm to obtain pipeline defect detection data set images; S2: annotating and dividing the pipeline defect detection dataset images to obtain a training set, a validation set, and a test set; S3: Obtain a YOLOv8s network model, improve the YOLOv8s network model, construct a loss function, and obtain an improved YOLOv8s network model; S4: Using the training set, validation set and test set to train, validate and test the improved YOLOv8s network model to obtain a trained improved YOLOv8s network model; S5: Obtain an image of the pipeline to be detected, and use the trained improved YOLOv8s network model to perform target detection on the image of the pipeline to be detected to obtain a detection result; and obtain a detection accuracy based on the detection result.
2. The pipeline defect detection method based on improved YOLOv8s according to claim 1, characterized in that: The image enhancement algorithm is the MSRCR algorithm.
3. The pipeline defect detection method based on improved YOLOv8s according to claim 1, characterized in that: Step S2 specifically includes: S21: annotating the pipeline defect detection dataset image using an image annotation tool to obtain an annotated pipeline defect detection dataset image; S22: Divide the annotated pipeline defect detection dataset images according to a preset ratio to obtain a training set, a validation set, and a test set.
4. The pipeline defect detection method based on improved YOLOv8s according to claim 1, characterized in that: Step S3 specifically includes: S31: Obtain a YOLOv8s network model, and replace the SPPF module in the backbone of the YOLOv8s network model with an ASPP module, wherein the ASPP module includes a preset number of parallel dilated convolutions with different preset sampling rates; S32: Replace the convolution Conv in the neck of the YOLOv8s network model with a random group convolution GSConv, wherein the random group convolution GSConv includes a GSbottleneck network and a VoV-GSCSP cross-level partial network; S33: Add an efficient multi-scale attention mechanism module EMAttention to the backbone network of the YOLOv8s network model, where the efficient multi-scale attention mechanism module EMAttention is used to enhance the generalization ability and robustness of the model; S34: Construct the loss function, such as formula: L NWD =1-NWD(N p ,OF g ) Among them, L NWD is the loss function, NWD(.) is the normalized weighted distance loss function (Normalized WeightedDistance, NWD), N p is the Gaussian distribution of the prediction box, N g It is the Gaussian distribution of the GT box (Ground Truth Box, real box).
5. The pipeline defect detection method based on improved YOLOv8s according to claim 1, characterized in that: Step S5 specifically includes: obtaining an image of the pipeline to be detected, performing target detection on the image of the pipeline to be detected using the trained improved YOLOv8s network model, and obtaining a detection result; and obtaining a detection accuracy based on the detection result, wherein the detection accuracy includes a precision rate and a recall rate, as shown in the formula: Among them, Precision is the precision, Recall is the recall, TP is the number of positive classes predicted as positive classes, FP is the number of negative classes predicted as positive classes, and FN is the number of positive classes predicted as negative classes.
6. A system, characterized in that: The system includes the following modules: The image acquisition module is configured to: acquire pipeline defect images, including misalignment defect images, crack defect images, obstacle defect images, and branch pipe defect images; enhance the pipeline defect images using an image enhancement algorithm to obtain pipeline defect detection data set images; The labeling and data set division module is configured to: label and divide the pipeline defect detection data set images to obtain a training set, a validation set and a test set; The network model construction module is configured to: obtain a YOLOv8s network model, improve the YOLOv8s network model, construct a loss function, and obtain an improved YOLOv8s network model; The model training module is configured to: train, verify and test the improved YOLOv8s network model using the training set, verification set and test set to obtain a trained improved YOLOv8s network model; The target detection and evaluation module is configured to: obtain an image of the pipeline to be detected, use the trained improved YOLOv8s network model to perform target detection on the image of the pipeline to be detected, and obtain a detection result; and obtain a detection accuracy based on the detection result.
7. The system according to claim 6, characterized in that The image enhancement algorithm is the MSRCR algorithm.
8. The system according to claim 6, characterized in that The specific configuration of the labeling and data set partitioning module is as follows: Annotating the pipeline defect detection dataset image using an image annotation tool to obtain an annotated pipeline defect detection dataset image; The labeled pipeline defect detection dataset images are divided according to a preset ratio to obtain a training set, a validation set, and a test set.
9. The system according to claim 6, characterized in that The network model building module is specifically configured as follows: Obtain a YOLOv8s network model, and replace the SPPF module in the backbone of the YOLOv8s network model with an ASPP module, wherein the ASPP module includes a preset number of parallel atrous convolutions with different preset sampling rates; The convolution Conv in the neck of the YOLOv8s network model is replaced with a random group convolution GSConv, wherein the random group convolution GSConv includes a GSbottleneck network and a VoV-GSCSP cross-level partial network; An efficient multi-scale attention mechanism module EMAttention is added to the backbone network of the YOLOv8s network model. The efficient multi-scale attention mechanism module EMAttention is used to enhance the generalization ability and robustness of the model. Construct the loss function as follows: L NWD =1-NWD(N p ,OF g ) Among them, L NWD is the loss function, NWD(.) is the normalized weighted distance loss function (Normalized WeightedDistance, NWD), N p is the Gaussian distribution of the prediction box, N g It is the Gaussian distribution of the GT box (Ground Truth Box, real box).
10. The system according to claim 6, characterized in that The target detection and evaluation module is specifically configured as follows: obtaining an image of the pipeline to be detected, performing target detection on the image of the pipeline to be detected using the trained improved YOLOv8s network model, and obtaining a detection result; and obtaining a detection accuracy based on the detection result, wherein the detection accuracy includes a precision rate and a recall rate, as shown in the formula: Among them, Precision is the precision, Recall is the recall, TP is the number of positive classes predicted as positive classes, FP is the number of negative classes predicted as positive classes, and FN is the number of positive classes predicted as negative classes.
Citation Information
Patent Citations
PCB surface defect detection method based on improved YOLOv8 algorithm
CN117422681A
Improved YOLOv8-based SAR image ship target detection method, medium and device
CN117689870A
Industrial pipeline defect detection method and system based on improved YOLOv8
CN117934430A
CCTV pipeline image defect target detection method and device based on YOLOv5 and medium
CN118096701A
Coal mine filling mining effect evaluation method and system
CN118279081A
Cited By
Construction method and application of small sample chip surface defect detection model based on improved YOLOv8
CN120070343A
Pipeline damage and water leakage detection method and system based on machine vision
CN120543529A
