A method for detecting underground drainage pipes based on an improved YOLOv8
By introducing ShuffleNetV2 and the DIoU loss function into YOLOv8, the problems of insufficient performance of YOLOv8 in detecting small targets and high computational resource consumption in underground drainage pipe inspection are solved, and efficient and accurate underground drainage pipe defect detection is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- YANCHENG INST OF TECH
- Filing Date
- 2025-01-17
- Publication Date
- 2026-05-26
Smart Images

Figure CN119888364B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of underground drainage pipe inspection technology, and in particular to an underground drainage pipe inspection method based on an improved YOLOv8. Background Technology
[0002] Currently, drainage pipe defect detection is a research area that has received considerable attention in recent years, especially given the aging and increasing load on urban infrastructure. During use, drainage pipes are susceptible to various factors such as soil settlement, water erosion, chemical corrosion, and external loads, making them prone to problems like cracks, leaks, and blockages. These defects not only affect the normal operation of drainage systems, leading to urban flooding and environmental pollution, but can also pose serious safety hazards. Traditional defect detection methods are effective at handling obvious defects, but when faced with minute cracks or images affected by noise (such as changes in lighting or environmental interference), they often fail to capture the details and morphological features of the cracks, affecting the accuracy of the detection. YOLOv8 is a version in the YOLO (YouOnlyLookOnce) series, primarily used for object detection and image segmentation. However, existing YOLOv8 applications for underground drainage pipe detection have the following drawbacks:
[0003] (1) Limited performance in small object detection; YOLOv8 is not as accurate as some other specially optimized small object detection networks (such as Faster R-CNN) in detecting small objects (such as tiny cracks), especially in complex scenes.
[0004] (2) It has poor adaptability to unstructured scenes and limited ability to handle complex backgrounds and occlusions. In particular, low light and water vapor in underground environments will further reduce image quality, which limits the model's ability to identify targets. Especially when targets are dense and there is a large overlap between targets (such as multiple defects in a pipe), the model may be interfered with and unable to accurately locate the defect location information, resulting in false detection or missed detection. The robustness of the model needs to be improved.
[0005] (3) High computational resource consumption and high computational cost: To improve detection accuracy, YOLOv8 tends to use more complex network architectures or higher resolution input data. However, high-resolution images require a large amount of memory to store intermediate computation results and feature maps during processing, especially when using large batch sizes for inference, where memory usage increases dramatically. This resource requirement may lead to insufficient GPU memory, resulting in a decrease in inference speed and failure to meet the requirements of real-time detection. To solve this problem, a balance needs to be struck between detection speed and accuracy when constructing a feature extraction network for underground drainage pipe defects. Although increasing the number of model parameters can usually improve feature extraction capability and performance, an overly large model will bring high computational complexity, increase computational cost, and affect real-time performance. Existing backbone networks such as VGG16 and MobileNetV1, which utilize multi-layer convolution and residual structures, can indeed effectively extract features and improve detection accuracy, but they are also accompanied by extremely high computational complexity, making it difficult to meet the real-time requirements in practical applications.
[0006] Therefore, this invention proposes a method for detecting underground drainage pipes based on an improved YOLOv8. Summary of the Invention
[0007] This invention provides an improved YOLOv8-based method for detecting underground drainage pipes by introducing a lightweight network architecture—ShuffleNetV2—into YOLOv8. This network significantly reduces computational cost and parameter count through depthwise separable convolution and channel shuffling techniques. Specifically, depthwise separable convolution decomposes standard convolution into depthwise convolution and pointwise convolution, drastically reducing computational complexity; channel shuffling rearranges feature channels, promoting cross-channel information exchange and feature recombination, enhancing information interaction between features. These innovations enable ShuffleNetV2 to significantly improve model efficiency while maintaining high detection accuracy. Secondly, incorporating features into YOLOv8 enhances feature extraction capabilities. By adding a hybrid attention mechanism within and at the end of the base model and improving the sampling layers of the neural network, the model can strengthen important feature information, especially for micro-cracks, while suppressing irrelevant or secondary information. This method not only helps the model better understand contextual relationships but also improves the detection accuracy of drainage pipe defects. Secondly, by employing the DIoU (Distance-IoU) loss function, the model focuses not only on overlapping regions but also on the center position of the bounding boxes. This allows the model to better optimize the bounding box positions, typically resulting in faster convergence during training, especially when there is significant target overlap. Based on these improvements, the YOLOv8 model becomes lighter, reducing the number of parameters and enabling better extraction of target features, leading to faster convergence and better regression accuracy. This, in turn, improves the efficiency and accuracy of underground drainage pipe defect detection.
[0008] This invention provides a method for detecting underground drainage pipes based on an improved YOLOv8, comprising:
[0009] S1: Capture images of underground drainage pipes and preprocess them to obtain preprocessed images of underground drainage pipes.
[0010] S2: A defect detection model for underground drainage pipes was built based on a YOLOv8 convolutional neural network that integrates ShuffleNetV2 and LSKA attention mechanisms and adopts the DIoU loss function.
[0011] S3: Input the preprocessed underground drainage pipe image into the underground drainage pipe defect detection model to obtain the underground drainage pipe defect image.
[0012] Preferably, the underground drainage pipe detection method based on the improved YOLOv8 includes the following steps: S1: capturing images of underground drainage pipes and preprocessing the images to obtain preprocessed images of underground drainage pipes, including:
[0013] Images of the underground drainage pipes under test are obtained by capturing images of the underground drainage pipes using CCTV cameras.
[0014] The image of the underground drainage pipe is preprocessed to obtain the preprocessed image of the underground drainage pipe.
[0015] Preferably, the underground drainage pipe detection method based on the improved YOLOv8 preprocesses the underground drainage pipe image to obtain a preprocessed underground drainage pipe image, including:
[0016] The pipeline outline in the underground drainage pipeline image is identified, and the underground drainage pipeline image is divided into regions based on the pipeline outline to obtain the clean pipeline image and background image of the underground drainage pipeline image.
[0017] The background image of the underground drainage pipe image is converted to grayscale to obtain a grayscale background image. The contrast of the grayscale background image is then compressed until the pixel value of all pixels in the grayscale background image is within the preset grayscale value, thus obtaining the preprocessed background image.
[0018] Pixel enhancement is performed on the clean image of the underground drainage pipe to obtain a preprocessed image of the underground drainage pipe.
[0019] Preferably, the underground drainage pipe detection method based on the improved YOLOv8 performs pixel enhancement on the clean image of the underground drainage pipe to obtain a preprocessed underground drainage pipe image, including:
[0020] Obtain the pixel stretch range ladder table;
[0021] Based on the stretching range of each pixel in the stretching range ladder table, the clean image of the underground drainage pipe is subjected to multiple contrast stretches to obtain a high-contrast pipe image under each pixel stretching range.
[0022] The high-contrast pipeline image under the stretching range of each pixel is grayscaled to obtain the grayscale pipeline image under the stretching range of each pixel, and the frequency of occurrence of each grayscale value in the grayscale pipeline image under the stretching range of each pixel is counted.
[0023] The cumulative distribution probability of each gray value in the grayscale pipeline image under each pixel stretching range is determined based on the occurrence frequency of all gray values in the grayscale pipeline image under each pixel stretching range.
[0024] Based on the cumulative distribution probability of each gray value in the grayscale pipeline image under each pixel stretching range and the maximum gray value of the grayscale pipeline image under each pixel stretching range, the grayscale pipeline image under each pixel stretching range is uniformly stretched to obtain the grayscale equalized pipeline image under each pixel stretching range.
[0025] Based on the grayscale equalization of the pipeline image under all pixel stretching ranges, a preprocessed image of the underground drainage pipeline is obtained.
[0026] Preferably, the underground drainage pipe detection method based on the improved YOLOv8, based on the cumulative distribution probability of each grayscale value in the grayscale pipe image within each pixel stretching range and the maximum grayscale value of the grayscale pipe image within each pixel stretching range, performs uniform stretching on the grayscale pipe image within each pixel stretching range to obtain a grayscale balanced pipe image within each pixel stretching range, including:
[0027] The product of the difference between the maximum gray value and 1 in the grayscale pipeline image under the stretching range of each pixel and the cumulative distribution probability of each gray value in the grayscale pipeline image under the stretching range of the corresponding pixel is used as the new gray value of each gray value in the grayscale equalization pipeline image under the stretching range of the corresponding pixel.
[0028] Based on the new gray values of all gray values in the grayscale equalization pipeline image under each pixel stretching range, obtain the grayscale equalization pipeline image under each pixel stretching range.
[0029] Preferably, the underground drainage pipe detection method based on the improved YOLOv8 obtains a preprocessed underground drainage pipe image based on the grayscale equalized pipe image under all pixel stretching ranges, including:
[0030] Calculate the image display effect evaluation value of the grayscale equalization pipeline image under the stretching range of each pixel:
[0031]
[0032] In the formula, AM IQ I is the evaluation value of the image display effect of the grayscale equalization pipeline image under the currently calculated pixel stretching range. max Let I be the maximum grayscale value of the grayscale equalization pipeline image within the currently calculated pixel stretching range, and let n be the total number of pixels in the grayscale equalization pipeline image within the currently calculated pixel stretching range. iorg Let I be the grayscale value of the i-th pixel in the clean image of the underground drainage pipe. iproc Let μ be the grayscale value of the i-th pixel in the grayscale equalization pipeline image within the currently calculated pixel stretching range, m be the total number of image display attributes, and μ be the grayscale value of the i-th pixel in the pipeline image. jproc Let μ be the mean value of the j-th visible attribute of the clean image of the underground drainage pipe. jproc The mean value of the j-th visible attribute of the grayscale equalization pipeline image under the current pixel stretching range;
[0033] The grayscale equalized pipe image corresponding to the maximum display effect evaluation value among all grayscale equalized pipe images within the pixel stretching range is taken as the preprocessed underground drainage pipe image.
[0034] Preferably, the underground drainage pipe detection method based on improved YOLOv8, S2: Based on a YOLOv8 convolutional neural network that integrates ShuffleNetV2 and LSKA attention mechanisms and adopts the DIoU loss function, a defect detection model for underground drainage pipes is built, including:
[0035] Images of underground drainage pipes were captured using CCTV cameras and preprocessed to obtain a dataset.
[0036] The images in the dataset are preprocessed and corresponding real labels are established to obtain the preprocessed dataset, which is then divided into training set, test set and validation set.
[0037] We selected a YOLOv8 convolutional neural network that combines ShuffleNetV2 and LSKA attention mechanisms and uses the DIoU loss function as the pre-trained model.
[0038] The training set is input into the pre-trained model for training to obtain a trained detection model;
[0039] The trained detection model is used to detect defects on the test set and validation set. The recognition accuracy of the trained detection model is optimized by the algorithm until the defect detection model of underground drainage pipe is obtained.
[0040] Preferably, the underground drainage pipe detection method based on the improved YOLOv8 selects a YOLOv8 convolutional neural network that integrates ShuffleNetV2 and LSKA attention mechanisms and adopts the DIoU loss function as the pre-trained model, including:
[0041] Load the pre-trained weights of the YOLOv8 model, replace the feature extraction network in the YOLOv8 model with ShuffleNetV2, introduce the LSKA attention mechanism in the head of the YOLOv8 model, and replace the loss function of the YOLOv8 model with the DIoU loss function to obtain the pre-trained model.
[0042] In the pre-trained model, the input channels of the basic unit blocks and the downsampling units are all equal, and the corresponding output channels are all equal.
[0043] Preferably, the underground drainage pipe detection method based on the improved YOLOv8 model replaces the feature extraction network in the YOLOv8 model with ShuffleNetV2, including:
[0044] ShuffleNetV2 is integrated into the YOLOv8 framework; the C2f module in the YOLOv8 backbone network is replaced with the basic module of ShuffleNetV2.
[0045] Preferably, the formula for the DIoU loss function in the underground drainage pipe detection method based on the improved YOLOv8 is:
[0046]
[0047] In the formula, IoU is the intersection-union ratio of the predicted box and the ground truth box, Area of Intersection is the area of the intersection between the predicted box and the ground truth box, Area of Union is the area of the union between the predicted box and the ground truth box, DIOU is the output value of the DIoU loss function, d is the Euclidean distance between the center point of the predicted box and the center point of the ground truth box, and c is the diagonal length of the minimum bounding box of the predicted box and the ground truth box.
[0048] The beneficial effects of this invention compared to existing technologies are as follows: Firstly, it introduces a lightweight network architecture—ShuffleNetV2—into YOLOv8. This network significantly reduces computational cost and parameter count through depthwise separable convolution and channel shuffling techniques. Specifically, depthwise separable convolution decomposes standard convolution into depthwise convolution and pointwise convolution, greatly reducing computational complexity; channel shuffling, by rearranging feature channels, promotes cross-channel information exchange and feature recombination, enhancing information interaction between features. These innovations enable ShuffleNetV2 to significantly improve model efficiency while maintaining high detection accuracy. Secondly, it enhances feature extraction capabilities by incorporating features into YOLOv8. By adding a hybrid attention mechanism within and at the end of the base model and improving the sampling layers of the neural network, the model can strengthen important feature information, especially for micro-cracks, while suppressing irrelevant or secondary information. This method not only helps the model better understand contextual relationships but also improves the detection accuracy of drainage pipe defects. Secondly, by employing the DIoU (Distance-IoU) loss function, the model focuses not only on overlapping regions but also on the center position of the bounding box. This allows the model to better optimize the bounding box position, typically resulting in faster convergence during training, especially when there is significant target overlap. Furthermore, based on these improvements to the YOLOv8 model, the model becomes lighter, reducing the number of parameters and enabling better extraction of target features, leading to faster convergence and better regression accuracy. This ultimately improves the efficiency and accuracy of underground drainage pipe defect detection.
[0049] Other features and advantages of the invention will be set forth in the description which follows, and will be apparent in part from the description, or may be learned by practicing the invention. The objects and other advantages of the invention may be realized and obtained by means of the structures particularly pointed out in this application.
[0050] The technical solution of the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. Attached Figure Description
[0051] The accompanying drawings are provided to further illustrate the invention and form part of the specification. They are used in conjunction with embodiments of the invention to explain the invention and do not constitute a limitation thereof. In the drawings:
[0052] Figure 1 This is a flowchart of the underground drainage pipe detection method based on the improved YOLOv8 in an embodiment of the present invention;
[0053] Figure 2 This is a flowchart illustrating the implementation of underground drainage pipe detection based on the improved YOLOv8 algorithm in an embodiment of the present invention.
[0054] Figure 3This is a schematic diagram of the ShuffleNetV2 basic module and downsampling module in an embodiment of the present invention;
[0055] Figure 4 This is a schematic diagram illustrating the channel rearrangement comparison principle in an embodiment of the present invention;
[0056] Figure 5 This is a structural diagram of the LSKA in an embodiment of the present invention. Detailed Implementation
[0057] The preferred embodiments of the present invention will be described below with reference to the accompanying drawings. It should be understood that the preferred embodiments described herein are for illustration and explanation only and are not intended to limit the present invention.
[0058] Example 1:
[0059] This invention provides a method for detecting underground drainage pipes based on an improved YOLOv8, with reference to... Figure 1 ,include:
[0060] S1: Capture images of underground drainage pipes and preprocess them to obtain preprocessed images of underground drainage pipes.
[0061] S2: A defect detection model for underground drainage pipes was built based on a YOLOv8 convolutional neural network that integrates ShuffleNetV2 and LSKA attention mechanisms and adopts the DIoU loss function.
[0062] S3: Input the preprocessed underground drainage pipe image into the underground drainage pipe defect detection model to obtain the underground drainage pipe defect image.
[0063] In this embodiment, reference Figure 2 The implementation process for underground drainage pipe detection based on the improved YOLOv8 algorithm is as follows:
[0064] Step 1: Data Preparation
[0065] Using a publicly available dataset, the dataset was divided into three independent subsets: training set, validation set, and test set, with a ratio of 7:2:1. A PC was selected as the image recognition processing terminal, configured with an i7-12700H CPU, a 64-bit Windows 11 operating system, and an NVIDIA RTX 3050 Ti GPU. The experimental environment also included a GPU server configured with an NVIDIA Tesla A404 8GB 300W GPU card.
[0066] Step 2: Data Preprocessing
[0067] Data augmentation is performed on the training set to expand the training data, including operations such as random rotation, flipping, and dehazing, to increase the model's generalization ability.
[0068] Standardize or normalize the validation and test sets to ensure that the pixel values of the images are within the same scale range.
[0069] Step 3: Model Building
[0070] Load the pre-trained weights of YOLOv8, replace the feature extraction network with ShuffleNetV2, and introduce the LSKA attention mechanism in the head to build an improved YOLOv8 model.
[0071] Step 4: Training the model:
[0072] Configure the training hyperparameters, setting the batch size to 32 and the number of iterations to 300; begin training the model using the training set data. In each training iteration, calculate the loss and update the model weights.
[0073] At the end of each training cycle, use the validation set to evaluate the model's performance. Monitor metrics such as loss and accuracy on the validation set to stop training in a timely manner to prevent overfitting.
[0074] Step 5: Model Evaluation
[0075] The model's performance is ultimately evaluated using a test set. Metrics such as accuracy and F1 score are calculated on the test set, and a confusion matrix is plotted to visualize the evaluation results and determine its performance in real-world scenarios.
[0076] In this embodiment, the underground drainage pipe images are raw images of the underground drainage pipes captured by specific equipment (such as CCTV cameras). These images contain various information about the pipe's appearance and are the basis for subsequent processing and analysis. For example, a clear image showing the inner wall, interfaces, and surrounding environment of the underground drainage pipe. In this embodiment, the underground drainage pipe defect detection model is a model built based on a YOLOv8 convolutional neural network that integrates ShuffleNetV2 and LSKA attention mechanisms and uses the DIoU loss function to detect defects in underground drainage pipes. For example, a model that, after training and optimization, can accurately identify defects such as pipe cracks and corrosion.
[0077] In this embodiment, the underground drainage pipe defect image is an image of an underground drainage pipe that has been analyzed and processed by the underground drainage pipe defect detection model, and the defective areas are marked. For example, in an original image of an underground drainage pipe, the cracked parts are outlined with a specific color or marker to indicate that this is a defective area.
[0078] The beneficial effects of the above techniques include: providing a clear and effective data foundation for subsequent detection by capturing and preprocessing images of underground drainage pipes; improving the model's ability to extract and focus on features of underground drainage pipes by integrating ShuffleNetV2 and LSKA attention mechanisms, thus enhancing detection accuracy; optimizing the model's training process using the DIoU loss function, enabling the model to converge to better results more quickly; and efficiently analyzing the preprocessed images to accurately detect defects in underground drainage pipes. This method effectively improves the efficiency and accuracy of underground drainage pipe detection, helping to promptly identify and address pipe defects and ensure the normal operation of the drainage system.
[0079] Example 2:
[0080] Based on Example 1, an improved YOLOv8-based method for detecting underground drainage pipes is described in S1: This involves capturing images of underground drainage pipes and preprocessing these images to obtain preprocessed images, including:
[0081] Images of the underground drainage pipes under test are obtained by capturing images of the underground drainage pipes using CCTV cameras.
[0082] The image of the underground drainage pipe is preprocessed to obtain the preprocessed image of the underground drainage pipe.
[0083] The beneficial effects of the above technologies are as follows: capturing images of underground drainage pipes using CCTV cameras provides a direct and comprehensive view of the pipe's internal condition. Image preprocessing helps eliminate noise and enhance image quality, providing clearer and more accurate information for subsequent defect detection. This capture-then-preprocessing approach ensures high-quality and usable image data input into the detection model. It improves the accuracy and efficiency of subsequent detection, reducing the possibility of false positives and false negatives. This lays a solid data foundation for the effective detection of defects in underground drainage pipes.
[0084] Example 3:
[0085] Based on Example 2, and using an improved YOLOv8 method for detecting underground drainage pipes, the underground drainage pipe images are preprocessed to obtain preprocessed images, including:
[0086] The pipeline outline in the underground drainage pipeline image is identified, and the underground drainage pipeline image is divided into regions based on the pipeline outline to obtain the clean pipeline image and background image of the underground drainage pipeline image.
[0087] The background image of the underground drainage pipe image is converted to grayscale to obtain a grayscale background image. The contrast of the grayscale background image is then compressed until the pixel value of all pixels in the grayscale background image is within the preset grayscale value, thus obtaining the preprocessed background image.
[0088] Pixel enhancement is performed on the clean image of the underground drainage pipe to obtain a preprocessed image of the underground drainage pipe.
[0089] In this embodiment, the pipe outline refers to the lines used to define the shape and boundaries of an underground drainage pipe in an image. It is a key identifier distinguishing the pipe from its surroundings. For example, continuous lines clearly outlining the edges of the pipe in an image.
[0090] In this embodiment, a clean image of the pipeline refers to an image portion that, after processing, contains only the underground drainage pipe itself and removes other irrelevant information. For example, an image may show only the clear main body of the pipe, without any background clutter.
[0091] In this embodiment, the background image, which is the portion of the underground drainage pipe image other than the pipe itself, typically includes the surrounding environment, debris, etc. For example, the image area consisting of soil, rocks, etc., surrounding the pipe.
[0092] In this embodiment, the grayscale background image undergoes contrast compression until the pixel values of all pixels in the grayscale background image are within a preset grayscale value, thus obtaining a preprocessed background image: first, the background image is grayscaled, then its contrast is reduced, causing the pixel values to gradually decrease until the pixel values of all pixels do not exceed the preset grayscale value, thereby obtaining the processed background image. For example, if the preset grayscale value is 50, and the original background image's pixel value range is 0-255, after processing, all pixel values are within 50.
[0093] The beneficial effects of the above technologies include: by identifying the pipe outline and dividing the area, the main body of the pipe can be effectively separated from the background, highlighting key detection areas. Grayscale processing and contrast compression of the background image reduce interference from background information and lower the complexity of data processing. Controlling the pixel values in the grayscale background image within a preset grayscale value makes the background more uniform and stable, facilitating subsequent processing. Pixel enhancement of the clean pipe image highlights the pipe's detailed features and improves the sensitivity of defect detection. This preprocessing method improves image quality and usability, providing strong support for the accurate detection of defects in underground drainage pipes.
[0094] Example 4:
[0095] Based on Example 3, and using an improved YOLOv8 method for detecting underground drainage pipes, pixel enhancement is performed on the clean image of the underground drainage pipe to obtain a preprocessed image of the underground drainage pipe, including:
[0096] Obtain the pixel stretch range ladder table;
[0097] Based on the stretching range of each pixel in the stretching range ladder table, the clean image of the underground drainage pipe is subjected to multiple contrast stretches to obtain a high-contrast pipe image under each pixel stretching range.
[0098] The high-contrast pipeline image under the stretching range of each pixel is grayscaled to obtain the grayscale pipeline image under the stretching range of each pixel, and the frequency of occurrence of each grayscale value in the grayscale pipeline image under the stretching range of each pixel is counted.
[0099] The cumulative distribution probability of each gray value in the grayscale pipeline image under each pixel stretching range is determined based on the occurrence frequency of all gray values in the grayscale pipeline image under each pixel stretching range.
[0100] Based on the cumulative distribution probability of each gray value in the grayscale pipeline image under each pixel stretching range and the maximum gray value of the grayscale pipeline image under each pixel stretching range, the grayscale pipeline image under each pixel stretching range is uniformly stretched to obtain the grayscale equalized pipeline image under each pixel stretching range.
[0101] Based on the grayscale equalization of the pipeline image under all pixel stretching ranges, a preprocessed image of the underground drainage pipeline is obtained.
[0102] In this embodiment, the pixel stretching range ladder table is a table that lists different pixel stretching ranges to guide multiple contrast stretching operations on the image. For example, the table may contain a series of pixel value ranges such as 0-50, 50-100, and 100-150.
[0103] In this embodiment, the pixel stretching range refers to a specific range of pixel values set when processing the image. For example, the range of 50-100 is a pixel stretching range.
[0104] In this embodiment, based on the stretching range of each pixel in the stretching range ladder table, the clean image of the underground drainage pipe is subjected to multiple contrast stretches to obtain a high-contrast pipe image within each pixel stretching range. Contrast enhancement is performed on the clean pipe image according to each pixel value range specified in the pixel stretching range ladder table, thereby obtaining a pipe image with strong contrast after processing in each specific range. For example, a contrast stretch is performed once according to the range of 0-50 in the ladder table to obtain a high-contrast pipe image within this range; then another stretch is performed according to the range of 50-100, and so on.
[0105] In this embodiment, the frequency of each grayscale value in the grayscale pipeline image under each pixel stretching range is statistically determined: the proportion of the number of times each grayscale value appears in the grayscale pipeline image to the total number of pixels within each specific pixel stretching range is calculated. For example, if the grayscale value 100 appears 100 times within a certain pixel stretching range, and the total number of pixels is 1000, then the frequency of the grayscale value 100 in this range is 0.1.
[0106] In this embodiment, the cumulative distribution probability of each grayscale value in the grayscale pipeline image within each pixel stretching range is determined based on the frequency of occurrence of all grayscale values in the grayscale pipeline image within each pixel stretching range: the cumulative distribution probability of each grayscale value within each pixel stretching range is calculated by progressively accumulating the frequency of occurrence of each grayscale value. For example, if the frequency of occurrence of grayscale value 0 is 0.2 and the frequency of occurrence of grayscale value 1 is 0.003 within a certain pixel stretching range, then the cumulative distribution probability of grayscale value 1 is 0.2 + 0.003 = 0.203.
[0107] The beneficial effects of the above techniques include: obtaining a pixel stretching range ladder table, providing clear parameters and ranges for multiple contrast stretching operations; highlighting detailed features of the clean pipe image within different stretching ranges through multiple contrast stretching and grayscale processing; statistically analyzing the frequency and cumulative distribution probability of grayscale values, which helps to more accurately understand the grayscale distribution of the image; and performing uniform stretching based on the cumulative distribution probability and the maximum grayscale value, resulting in a more balanced grayscale distribution and avoiding overly bright or dark areas. By combining grayscale-balanced pipe images across all pixel stretching ranges, the final preprocessed underground drainage pipe image is of higher quality and more conducive to subsequent defect detection. This refined pixel enhancement processing method can significantly improve the quality and recognizability of the clean pipe image, thereby improving the accuracy and reliability of underground drainage pipe defect detection.
[0108] Example 5:
[0109] Based on Example 4, and using an improved YOLOv8 method for detecting underground drainage pipes, the grayscale pipe image under each pixel stretching range is uniformly stretched based on the cumulative distribution probability of each grayscale value in the grayscale pipe image under each pixel stretching range and the maximum grayscale value of the grayscale pipe image under each pixel stretching range, to obtain a grayscale balanced pipe image under each pixel stretching range, including:
[0110] The product of the difference between the maximum gray value and 1 in the grayscale pipeline image under the stretching range of each pixel and the cumulative distribution probability of each gray value in the grayscale pipeline image under the stretching range of the corresponding pixel is used as the new gray value of each gray value in the grayscale equalization pipeline image under the stretching range of the corresponding pixel.
[0111] Based on the new gray values of all gray values in the grayscale equalization pipeline image under each pixel stretching range, obtain the grayscale equalization pipeline image under each pixel stretching range.
[0112] The beneficial effects of the above techniques include: determining new grayscale values through explicit calculation methods enables precise and uniform stretching of grayscale pipe images. The calculation of cumulative distribution probability and maximum grayscale value ensures the stretching process is scientific and rational. It effectively balances grayscale distribution, enhances image contrast and clarity, and highlights pipe features. The resulting grayscale-balanced pipe image better displays pipe details, contributing to improved defect detection accuracy. This precise grayscale equalization processing method improves image quality and analyzability, providing strong support for accurate detection of underground drainage pipes.
[0113] Example 6:
[0114] Based on Example 4, and using an improved YOLOv8 method for detecting underground drainage pipes, a preprocessed image of the underground drainage pipe is obtained based on a grayscale-equalized pipe image across all pixel stretching ranges, including:
[0115] Calculate the image display effect evaluation value of the grayscale equalization pipeline image under the stretching range of each pixel:
[0116]
[0117] In the formula, AM IQ I is the evaluation value of the image display effect of the grayscale equalization pipeline image under the currently calculated pixel stretching range. max Let I be the maximum grayscale value of the grayscale equalization pipeline image within the currently calculated pixel stretching range, and let n be the total number of pixels in the grayscale equalization pipeline image within the currently calculated pixel stretching range. iorg Let I be the grayscale value of the i-th pixel in the clean image of the underground drainage pipe.iproc Let μ be the grayscale value of the i-th pixel in the grayscale equalization pipeline image within the currently calculated pixel stretching range, m be the total number of image display attributes, and μ be the grayscale value of the i-th pixel in the pipeline image. jproc Let μ be the mean value of the j-th visible attribute of the clean image of the underground drainage pipe. jproc The mean value of the j-th visible attribute of the grayscale equalization pipeline image under the current pixel stretching range;
[0118] The grayscale equalized pipe image corresponding to the maximum display effect evaluation value among all grayscale equalized pipe images within the pixel stretching range is taken as the preprocessed underground drainage pipe image.
[0119] In this embodiment, the grayscale equalization pipeline image display effect evaluation value is a quantitative indicator used to evaluate the display effect of underground drainage pipeline images after grayscale equalization processing. It is calculated using a specific mathematical formula, comprehensively considering factors such as the maximum grayscale value of the image, the total number of pixels, the grayscale values of pixels in the clean pipeline image, and the average values of multiple display attributes. This evaluation value reflects the quality and display effect of the image after grayscale equalization processing. A higher value indicates a better display effect, suggesting higher image quality after processing, which is more conducive to subsequent defect detection and analysis.
[0120] The beneficial effects of the above technologies include: calculating the image display effect evaluation value through a clear mathematical formula, which quantitatively evaluates the display effect of the grayscale equalized pipe image under the stretching range of each pixel. Considering grayscale values, total number of pixels, and the average of multiple image display attributes makes the evaluation more comprehensive and accurate. Selecting the grayscale equalized pipe image corresponding to the maximum image display effect evaluation value as the preprocessed underground drainage pipe image ensures that the final image used for detection has the best display effect and quality. This improves the accuracy and reliability of subsequent underground drainage pipe defect detection and reduces the possibility of misjudgment. This selection method based on image display effect evaluation value effectively improves the quality and usability of the preprocessed underground drainage pipe image, providing more favorable conditions for accurate defect detection.
[0121] Example 7:
[0122] Based on Example 1, an improved YOLOv8-based underground drainage pipe detection method is implemented. S2: A YOLOv8 convolutional neural network model for detecting defects in underground drainage pipes is constructed, based on a fusion of ShuffleNetV2 and LSKA attention mechanisms and employing the DIoU loss function. This model includes:
[0123] Images of underground drainage pipes were captured using CCTV cameras and preprocessed to obtain a dataset.
[0124] The images in the dataset are preprocessed and corresponding real labels are established to obtain the preprocessed dataset, which is then divided into training set, test set and validation set.
[0125] We selected a YOLOv8 convolutional neural network that combines ShuffleNetV2 and LSKA attention mechanisms and uses the DIoU loss function as the pre-trained model.
[0126] The training set is input into the pre-trained model for training to obtain a trained detection model;
[0127] The trained detection model is used to detect defects on the test set and validation set. The recognition accuracy of the trained detection model is optimized by the algorithm until the defect detection model of underground drainage pipe is obtained.
[0128] In this embodiment, the dataset consists of a collection of underground drainage pipe images captured by CCTV cameras and preprocessed (the preprocessing process is the same as the method for preprocessing underground drainage pipe images in embodiments 3-6), used for model training and testing. For example, it could contain a collection of 1000 images of underground drainage pipes in different states.
[0129] In this embodiment, the images in the dataset are preprocessed and corresponding real labels are established to obtain a preprocessed dataset: a series of processing operations, such as noise reduction and enhancement, are performed on the original images in the dataset, and each image is labeled with its true condition, such as whether there are defects and the type of defects, thereby forming a new dataset. For example, 1000 original images are preprocessed, and each image is labeled with labels such as "has crack defects and their locations" and "no defects" to obtain a preprocessed dataset.
[0130] In this embodiment, a trained detection model is used to detect defects on a test set and a validation set. The accuracy of the trained detection model is optimized using algorithms until a defect detection model for underground drainage pipes is obtained. The trained model is used to detect defects in specially defined test set images. Based on the detection results and relevant algorithms, the model parameters are continuously adjusted and improved to enhance the accuracy of defect identification, ultimately resulting in a high-performance underground drainage pipe defect detection model. For example, the trained model is used to detect defects in 200 test set images. The accuracy is found to be 80%. The model parameters are further optimized using algorithms, and the accuracy is increased to 90%. This process is repeated until the model reaches the ideal accuracy. Finally, the validation set is used to verify whether the detection accuracy of the final model is 90%. If yes, the underground drainage pipe defect detection model is output; otherwise, the above steps are repeated until the detection accuracy of the final model is verified to be 90% using the validation set, at which point the underground drainage pipe defect detection model is output.
[0131] The beneficial effects of the above technologies include: utilizing CCTV camera capture and preprocessing to obtain datasets provides a rich data source for model training. Preprocessing and partitioning the dataset ensures the rationality and effectiveness of the training, test, and validation sets. Choosing a YOLOv8 convolutional neural network that integrates specific mechanisms and loss functions as the pre-trained model lays a solid foundation for model performance. Training the pre-trained model by inputting the training set allows for continuous optimization of model parameters, improving detection capabilities. Using the test set for defect detection and accuracy optimization ensures that the final underground drainage pipe defect detection model has high accuracy and reliability. This systematic model building method can effectively construct high-performance underground drainage pipe defect detection models, providing strong support for practical detection work.
[0132] Example 8:
[0133] Based on Example 7, and using an improved YOLOv8 method for detecting underground drainage pipes, a YOLOv8 convolutional neural network that integrates ShuffleNetV2 and LSKA attention mechanisms and employs the DIoU loss function is selected as the pre-trained model, including:
[0134] Load the pre-trained weights of the YOLOv8 model, replace the feature extraction network in the YOLOv8 model with ShuffleNetV2, introduce the LSKA attention mechanism in the head of the YOLOv8 model, and replace the loss function of the YOLOv8 model with the DIoU loss function to obtain the pre-trained model.
[0135] In the pre-trained model, the input channels of the basic unit blocks and the downsampling units are all equal, and the corresponding output channels are all equal.
[0136] In this embodiment, the feature extraction module C2f can be replaced with C2f_DBB to further enhance the feature extraction and expression capabilities of the model, thereby improving the accuracy of target detection.
[0137] In this embodiment, to enhance the network's feature learning ability without significantly increasing detection time while ensuring detection accuracy, a lightweight network architecture—ShuffleNetV2—is introduced. This network significantly reduces computation and parameter count through depthwise separable convolution and channel shuffling techniques. Specifically, depthwise separable convolution decomposes standard convolution into depthwise convolution and pointwise convolution, greatly reducing computational complexity; channel shuffling rearranges feature channels, promoting cross-channel information exchange and feature recombination, enhancing information interaction between features. These innovations enable ShuffleNetV2 to significantly improve model efficiency while maintaining high detection accuracy.
[0138] Therefore, this embodiment optimizes the YOLOv8 network structure by integrating ShuffleNetV2 into the YOLOv8 framework; the C2f module in the YOLOv8 backbone network is replaced with the basic module of ShuffleNetV2. Although the C2f module performs excellently in feature extraction, its computational complexity is high; while the basic module of ShuffleNetV2 reduces computational complexity while still possessing powerful feature extraction capabilities. Through this replacement, the number of model parameters and computational cost are effectively controlled, significantly reducing the demand for computing resources. The structure of ShuffleNetV2 is as follows: Figure 3 As shown.
[0139] The reason for introducing the basic module and downsampling module in ShuffleNetV2 is primarily to improve feature extraction capabilities and overall performance while maintaining a lightweight model. These two modules each perform different functions to suit different needs.
[0140] The basic module extracts features while maintaining the same feature map size. It captures detailed information in shallow layers of the network, which is crucial for tasks such as image classification. Through residual connections, the basic module effectively transfers information, mitigating the vanishing gradient problem in deep networks and promoting model convergence. The downsampling module is designed to reduce computational complexity by decreasing the spatial size of the feature map while increasing the number of channels to maintain feature expressiveness. This is essential for capturing higher-level features and contextual information. In deep networks, large feature map sizes can lead to excessive computation, while the downsampling module effectively reduces computation while increasing the number of channels, enhancing feature diversity and expressiveness.
[0141] In convolutional neural networks, features are typically extracted progressively from low to high layers. Basic modules are suitable for extracting low-level features (such as edges and textures), while downsampling modules are suitable for extracting higher-level features (such as shapes and objects). By using different modules at different layers, ShuffleNetV2 can effectively learn features at different levels, improving the overall performance of the model.
[0142] The main idea behind ShuffleNetV2 is to reduce computational complexity through efficient channel rearrangement and grouped convolutions. Its core concept is to rearrange the channels of feature maps to make grouped convolutions more effective, thereby improving information flow and feature fusion capabilities. Standard convolutions are broken down into multiple smaller grouped convolutions to reduce computation and the number of parameters. Convolution operations are decomposed into depthwise convolutions and pointwise convolutions, and input and output features are added through residual connections to enhance the model's expressive power, further improving efficiency.
[0143] Image channel width equalization can minimize memory access cost (MAC). Analyzing pointwise convolution, which bears most of the computational overhead, assuming the number of input channels C1 and output channels C2, and the spatial size of the feature map passing through each network layer is h×ω, then the computational cost (FLOPs) of the convolution kernel is B = hωC1C2. Since this assumes sufficient memory, its memory consumption is C1C2 = hω(C1+C2) + C1C2. Therefore, the formula for B is:
[0144]
[0145] when hour);
[0146] That is, MAC reaches its minimum value only when C1 = C2. Therefore, the input and output channels of the basic unit block and the downsampling unit in this model are equal.
[0147] Grouped convolution can be expressed by the following formula, where g is the number of groups and C is the number of input channels. in The kernel size is K×K:
[0148]
[0149] Where g represents the number of groups, C in K is the number of input channels, and K is the size of the convolution kernel.
[0150] Pointwise convolution, also known as 1x1 convolution, is used to linearly combine information from each channel and can be expressed by the following formula:
[0151]
[0152] Where Weight(k) is a 1x1 convolution kernel for pointwise convolution, and the weighting value for each input channel K.
[0153] A problem with grouped convolutions is that the groups are independent of each other, lacking feature fusion. Channel rearrangement addresses this by enabling cross-group information fusion. It allows information to be shared between different groups, resolving the issue of group independence in traditional grouped convolutions. This feature fusion allows the model to better learn complex feature representations, improving its expressive power. Channel rearrangement effectively enhances the model's feature diversity, thereby improving the accuracy of classification or recognition tasks. In lightweight models, fewer parameters and computational costs can lead to performance degradation, a problem that channel rearrangement helps mitigate.
[0154] Without channel rearrangement, Figure 4 As shown in the first figure, the convolutional kernels are divided into three groups, generating three groups of feature maps. Each group only interacts internally; there is no information exchange between groups. Channel rearrangement is as follows: Figure 4 As shown in the second and third figures, the first part of each group is collected to form the next group; the second part of each group is collected to form the next group.
[0155] Residual connections are used to directly add input features to the output features after a series of operations, thereby mitigating gradient vanishing and enhancing information flow. Its mathematical expression is:
[0156] Output = F(x) + x
[0157] Where F(x) is the feature map obtained through operations such as grouped convolution, channel rearrangement, and pointwise convolution, and x is the input feature map.
[0158] In this embodiment, the detection of underground drainage pipes faces challenges such as complex background textures, uneven lighting, and noise interference, making defect identification difficult. Traditional convolutional operations typically focus only on local areas, lacking a comprehensive grasp of overall information. To address these issues, especially for minute cracks, attention mechanisms can enhance feature extraction capabilities. By adding a hybrid attention mechanism within and at the end of the base model and improving the sampling layers of the neural network, the model can strengthen important feature information while suppressing irrelevant or secondary information. This approach not only helps the model better understand contextual relationships but also improves the detection accuracy of drainage pipe defects.
[0159] The LSKA (Local Semantic Knowledge Attention) attention mechanism captures extensive contextual information from images by utilizing large, separable convolutional kernels and spatially dilated convolutions. It generates an attention map, which is then used to weight the original features, thereby enhancing the network's attention to important features and improving model performance. LSKA decomposes the two-dimensional convolutional kernels of deep convolutional layers into cascaded horizontal and vertical one-dimensional convolutional kernels. Compared to the standard LKA design, this decomposition allows the direct use of deep convolutional layers with large kernels within the attention module, eliminating the need for additional blocks. In the YOLOv8 model, LSKA applies an attention mechanism to the extracted feature maps, enabling the model to better capture important information in the image. This helps improve the model's ability to detect small, overlapping, or complex targets. By considering the semantic relationships between local features, LSKA better utilizes contextual information. This is crucial for target detection tasks, as the appearance and location of targets are often influenced by their surroundings. By enhancing feature representations and utilizing contextual information, LSKA effectively improves the detection accuracy of the YOLOv8 model in different scenarios, reducing false negatives and false positives.
[0160] The LSKA model first extracts local features from the input image. This process is typically achieved by initializing convolutional layers (conv0h and conv0v), which are responsible for extracting horizontal and vertical information from the feature map, respectively. The generated feature map contains information from different regions of the image and lays the foundation for subsequent attention map generation. After obtaining the initial attention map, LSKA further extracts features using spatially dilated convolutions with different dilation rates. These convolutional layers can cover a larger receptive field without increasing computational cost, thereby capturing broader contextual information. By operating along the horizontal and vertical directions respectively, the model can process image features more finely and enhance its understanding of spatial relationships within the image. Next, LSKA models the semantic relationships between local features by calculating the similarity between features. This process is typically implemented through a self-attention mechanism, enabling the model to focus on other features related to the current feature. Based on these semantic relationships, LSKA calculates the attention weight for each local feature, reflecting the importance of each feature in the current context and helping the model focus on more relevant local information. Finally, LSKA applies the calculated attention weights to the local features, weighting and fusing them to generate a more semantically informative feature representation. These weighted features will be used in subsequent object detection tasks, thereby improving the model's performance and accuracy when processing images. Its structure is as follows: Figure 5As shown, the YOLOv8 head structure is directly responsible for generating the final detection results. By introducing the LSKA mechanism into the head, important features can be selectively enhanced in the initial feature fusion stage, thereby improving the subsequent detection accuracy.
[0161] In this embodiment, loading the pre-trained weights of the YOLOv8 model refers to acquiring the parameter values stored in a YOLOv8 model that has already been trained on large-scale data. These weights contain general features and patterns learned by the model from a large amount of data. Utilizing this existing knowledge, they can be used as initial values in new specific tasks (such as underground drainage pipe defect detection), accelerating the training speed of the new model and improving its performance. For example, it's like standing on the shoulders of giants, directly using the weight information of the previously trained YOLOv8 model in image recognition, instead of training a new model from scratch.
[0162] The beneficial effects of the above techniques include: loading pre-trained weights from the YOLOv8 model, utilizing existing training results, and accelerating the training speed of the new model; replacing the feature extraction network with ShuffleNetV2, which reduces the computational cost and number of parameters, improving the model's operational efficiency; introducing the LSKA attention mechanism in the head, enhancing the model's focus on key features and improving detection accuracy; replacing the loss function with the DIoU loss function, optimizing the model's training process, resulting in faster convergence and better performance; and ensuring that the input and output channels of basic unit blocks and downsampling units are equal, ensuring the consistency and stability of the model structure. These improvements make the pre-trained model more efficient, accurate, and stable, providing a stronger model foundation for underground drainage pipe defect detection.
[0163] Example 9:
[0164] Based on Example 8, and using an improved YOLOv8 method for detecting underground drainage pipes, the feature extraction network in the YOLOv8 model is replaced with ShuffleNetV2, including:
[0165] ShuffleNetV2 is integrated into the YOLOv8 framework; the C2f module in the YOLOv8 backbone network is replaced with the basic module of ShuffleNetV2.
[0166] The beneficial effects of the above technologies include: integrating ShuffleNetV2 into the YOLOv8 framework combines the advantages of different models, improving model performance; replacing the C2f module in the YOLOv8 backbone network with the basic module of ShuffleNetV2 reduces model complexity and computational cost; it helps improve the model's running speed and efficiency, making it more suitable for real-time detection scenarios; and it reduces resource consumption while maintaining a certain level of detection accuracy. This module replacement method optimizes the model structure, providing a more efficient and accurate model solution for underground drainage pipe detection.
[0167] Example 10:
[0168] Based on Example 8, and using the improved YOLOv8 method for detecting underground drainage pipes, the formula for the DIoU loss function is as follows:
[0169]
[0170]
[0171] In the formula, IoU is the intersection-union ratio of the predicted box and the ground truth box, Area of Intersection is the area of the intersection between the predicted box and the ground truth box, Area of Union is the area of the union between the predicted box and the ground truth box, DIOU is the output value of the DIoU loss function, d is the Euclidean distance between the center point of the predicted box and the center point of the ground truth box, and c is the diagonal length of the minimum bounding box of the predicted box and the ground truth box.
[0172] In this embodiment, using IoU (Intersection over Union) or CIoU (Complete Intersection over Union) loss in the original YOLOv8 may be highly sensitive to small changes in bounding boxes, especially in cases of small targets or overlapping targets. A more robust localization loss function could be considered, such as the DIoU (Distance-IoU) loss function, which performs better in handling target overlap and bounding box regression. DIoU pays particular attention to the distance between the center points, thus improving localization accuracy. DIoU further incorporates the distance between the center points of the predicted and ground truth boxes compared to GIoU. By including the center point distance in the loss calculation, the model focuses not only on overlapping areas but also on the center position of the boxes, allowing for better optimization of bounding box positions and typically faster convergence during training, especially when there is significant target overlap.
[0173] In this embodiment, the minimum bounding box of the predicted and ground truth boxes is the smallest rectangular box that can completely contain both the predicted and ground truth boxes. The size and position of this bounding box depend on the relative position and size of the predicted and ground truth boxes. For example, if the shapes and positions of the predicted and ground truth boxes are irregular, but there exists a rectangle that can just enclose them all with the smallest area, this rectangle is the minimum bounding box.
[0174] The beneficial effects of the above techniques are: the DIOU loss function introduces a squared term for the distance from the center point. This allows predicted boxes with smaller center point distances to achieve lower losses under the same IoU, thus converging to the ground truth boxes faster. DIOU is adopted as a novel loss metric to significantly improve the training performance of bounding box regression, while accelerating the model's convergence process and increasing regression accuracy. Unlike traditional methods, DIOU considers not only the overlap between bounding boxes but also the distance between their center points, making similarity assessment more comprehensive. This characteristic makes DIOU perform well in handling both overlapping and non-overlapping bounding boxes, helping the model accurately learn the location of the bounding boxes. Therefore, in computer vision tasks, DIOU can effectively replace Cross-Union Ratio (CURBR), improving the evaluation of performance metrics and ensuring the model's superior performance in localization tasks. This results in faster convergence speed and better regression accuracy, improving the accuracy and efficiency of defect detection in underground drainage pipes.
[0175] Obviously, those skilled in the art can make various modifications and variations to this invention without departing from its spirit and scope. Therefore, if these modifications and variations fall within the scope of the claims of this invention and their equivalents, this invention also intends to include these modifications and variations.
Claims
1. A method for detecting underground drainage pipes based on an improved YOLOv8, characterized in that, include: S1: Capture images of underground drainage pipes and preprocess them to obtain preprocessed images of underground drainage pipes, including: Based on the grayscale equalized pipe image across all pixel stretching ranges, a preprocessed image of the underground drainage pipe is obtained, including: Calculate the image display effect evaluation value of the grayscale equalization pipeline image under the stretching range of each pixel: In the formula, This is the evaluation value for the display effect of the grayscale equalization pipeline image under the currently calculated pixel stretching range. This represents the maximum grayscale value of the grayscale equalization pipeline image within the currently calculated pixel stretching range. This represents the total number of pixels in the grayscale equalization pipeline image within the currently calculated pixel stretching range. The first image of the underground drainage pipe is a clean image of the pipe. The grayscale value of each pixel For the grayscale equalization pipeline image under the currently calculated pixel stretching range, the first... The grayscale value of each pixel This represents the total number of attributes displayed in the graph. The first clean image of the underground drainage pipe. The item chart shows the attribute mean of the displayed attributes. For the grayscale equalization pipeline image under the currently calculated pixel stretching range, the first... The item chart displays the attribute mean of the attribute; The grayscale equalized pipe image corresponding to the maximum display effect evaluation value among all grayscale equalized pipe images under the stretching range of all pixels is taken as the preprocessed underground drainage pipe image. S2: A YOLOv8 convolutional neural network based on the fusion of ShuffleNetV2 and LSKA attention mechanisms and employing the DIoU loss function is used to build a defect detection model for underground drainage pipes, including: Load the pre-trained weights of the YOLOv8 model, replace the feature extraction network in the YOLOv8 model with ShuffleNetV2, introduce the LSKA attention mechanism in the head of the YOLOv8 model, and replace the loss function of the YOLOv8 model with the DIoU loss function to obtain the pre-trained model. In the pre-trained model, the input channels of the basic unit blocks and the downsampling units are all equal, and the corresponding output channels are all equal. The training set is input into the pre-trained model for training to obtain a trained detection model; The trained detection model is used to detect defects on the test set and validation set, and the recognition accuracy of the trained detection model is optimized by the algorithm until the defect detection model of underground drainage pipe is obtained. S3: Input the preprocessed underground drainage pipe image into the underground drainage pipe defect detection model to obtain the underground drainage pipe defect image.
2. The underground drainage pipe detection method based on improved YOLOv8 according to claim 1, characterized in that, S1: Used to capture images of underground drainage pipes and preprocess them to obtain preprocessed images of underground drainage pipes, including: Images of the underground drainage pipes under test are obtained by capturing images of the underground drainage pipes using CCTV cameras. The image of the underground drainage pipe is preprocessed to obtain the preprocessed image of the underground drainage pipe.
3. The underground drainage pipe detection method based on the improved YOLOv8 according to claim 2, characterized in that, Preprocessing is performed on the underground drainage pipe images to obtain preprocessed underground drainage pipe images, including: The pipeline outline in the underground drainage pipeline image is identified, and the underground drainage pipeline image is divided into regions based on the pipeline outline to obtain the clean pipeline image and background image of the underground drainage pipeline image. The background image of the underground drainage pipe image is converted to grayscale to obtain a grayscale background image. The contrast of the grayscale background image is then compressed until the pixel value of all pixels in the grayscale background image is within the preset grayscale value, thus obtaining the preprocessed background image. Pixel enhancement is performed on the clean image of the underground drainage pipe to obtain a preprocessed image of the underground drainage pipe.
4. The underground drainage pipe detection method based on improved YOLOv8 according to claim 3, characterized in that, Pixel enhancement is performed on the clean image of the underground drainage pipe to obtain a preprocessed image of the underground drainage pipe, including: Obtain the pixel stretch range ladder table; Based on the stretching range of each pixel in the stretching range ladder table, the clean image of the underground drainage pipe is subjected to multiple contrast stretches to obtain a high-contrast pipe image under each pixel stretching range. The high-contrast pipeline image under the stretching range of each pixel is grayscaled to obtain the grayscale pipeline image under the stretching range of each pixel, and the frequency of occurrence of each grayscale value in the grayscale pipeline image under the stretching range of each pixel is counted. The cumulative distribution probability of each gray value in the grayscale pipeline image under each pixel stretching range is determined based on the occurrence frequency of all gray values in the grayscale pipeline image under each pixel stretching range. Based on the cumulative distribution probability of each gray value in the grayscale pipeline image under each pixel stretching range and the maximum gray value of the grayscale pipeline image under each pixel stretching range, the grayscale pipeline image under each pixel stretching range is uniformly stretched to obtain the grayscale equalized pipeline image under each pixel stretching range. Based on the grayscale equalization of the pipeline image under all pixel stretching ranges, a preprocessed image of the underground drainage pipeline is obtained.
5. The underground drainage pipe detection method based on the improved YOLOv8 according to claim 4, characterized in that, Based on the cumulative distribution probability of each grayscale value in the grayscale pipeline image within each pixel stretching range and the maximum grayscale value of the grayscale pipeline image within each pixel stretching range, the grayscale pipeline image within each pixel stretching range is uniformly stretched to obtain a grayscale equalized pipeline image within each pixel stretching range, including: The product of the difference between the maximum gray value and 1 in the grayscale pipeline image under the stretching range of each pixel and the cumulative distribution probability of each gray value in the grayscale pipeline image under the stretching range of the corresponding pixel is used as the new gray value of each gray value in the grayscale equalization pipeline image under the stretching range of the corresponding pixel. Based on the new gray values of all gray values in the grayscale equalization pipeline image under each pixel stretching range, obtain the grayscale equalization pipeline image under each pixel stretching range.
6. The method for detecting underground drainage pipes based on the improved YOLOv8 according to claim 1, characterized in that, Replace the feature extraction network in the YOLOv8 model with ShuffleNetV2, including: ShuffleNetV2 is integrated into the YOLOv8 framework; the C2f module in the YOLOv8 backbone network is replaced with the basic module of ShuffleNetV2.
7. The method for detecting underground drainage pipes based on the improved YOLOv8 according to claim 1, characterized in that, The formula for the DIoU loss function is: In the formula, The intersection-union ratio (IU) of the predicted bounding box and the ground truth bounding box. This is the area of the intersection between the predicted bounding box and the ground truth bounding box. This is the area of the union between the predicted bounding box and the ground truth bounding box. The output value of the DIoU loss function. To predict the Euclidean distance between the center point of the bounding box and the center point of the ground truth bounding box. It is the diagonal length of the smallest bounding box between the predicted box and the ground truth box.