UNet crack detection model and method based on image
By improving the UNet crack detection model, reducing the number of deep convolution kernel channels, introducing attention multi-scale convolution blocks and flexible F1 loss function, the problems of detection accuracy and efficiency of existing models on resource-constrained devices are solved, and lightweight and efficient crack detection is achieved.
Patent Information
- Application Number
- CN202510838428.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-23
- Publication Date
- 2025-09-23
AI Technical Summary
Existing crack detection models cannot achieve both lightweight and high efficiency while ensuring sufficient detection accuracy. They are particularly difficult to deploy on resource-constrained edge devices, and they cannot adequately handle the slender and sparse characteristics of cracks and background interference.
An improved UNet crack detection model is adopted. By reducing the number of deep convolution kernel channels, introducing attention multi-scale convolution blocks, improving the flexible F1 loss function and dynamic learning rate adjustment mechanism, and combining spatial and channel attention mechanisms, the model structure and training process are optimized.
It reduces the number of model parameters and computational complexity, improves detection accuracy, adapts to resource-constrained devices, balances the impact of positive and negative sample training, and improves training efficiency and detection results.
Smart Images

Figure CN120689677A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of image processing technology, and in particular relates to an image-based UNet crack detection model and method. Background Art
[0002] Road cracks are a significant factor affecting road safety and service life. They can lead to further deterioration of pavement structures and even traffic accidents, threatening the safety of pedestrians and vehicles. With the rapid development of infrastructure and the continuous expansion of road networks, road maintenance and management tasks are becoming increasingly burdensome. Traditional crack detection methods rely primarily on manual inspections, which are inefficient and highly subjective, making them inadequate for monitoring large-scale road networks. Consequently, automated crack detection technology based on image processing has become a research hotspot. By collecting road surface images and analyzing them using computer vision techniques, efficient and objective crack identification and assessment can be achieved. To meet practical application requirements, detection models must balance scale and accuracy to ensure reliable detection results while also adapting to the hardware computing power limitations and timeliness requirements of on-site testing.
[0003] In recent years, deep learning technology has made significant progress in image segmentation and object detection, but existing crack detection models still face numerous challenges. On the one hand, because road cracks are typically elongated, sparse, and irregular in shape, and the background is complex and varied, existing models still have room for improvement in accuracy. On the other hand, many high-performance models are computationally intensive, making them difficult to deploy directly on resource-constrained edge devices. This trade-off between accuracy and efficiency limits the practical application of automated crack detection technology.
[0004] The prior art includes: a road crack detection method, which discloses: 1) collecting road crack images, constructing a road crack dataset, and performing preprocessing operations to form a training set and a test set; 2) constructing an improved U-Net neural network model; 3) training the improved U-Net neural network model based on the training set; 4) testing the trained improved U-Net neural network model based on the test set, outputting detection results, and evaluating the model to obtain model performance. Although the introduction of dilation-rate-containing atrous convolution reduces the number of convolutional layers and parameters, and a batch normalization (BN) layer is added after each convolutional layer, which saves computing resources and reduces computing costs, there is no attention mechanism, and the loss function uses binary cross entropy, which has relatively weak ability to suppress background interference, and cannot handle the imbalance of positive and negative samples well, and the learning rate adjustment mechanism is not flexible enough. It also includes a feasible road segmentation method, which discloses modifying the convolutional layer in the Unet training model into a ResNet residual module, and using the cross entropy loss function and the Lovász hinge loss function for backpropagation training respectively; the trained model is used to perform feasible area segmentation on road scenes without segmentation labels; the training images and the corresponding segmentation mask annotations are scaled, contrasted, and normalized, and the training samples are enhanced. The average histogram of the training data is used as a template, and the test data is tested after histogram matching, and the result of road segmentation is output. Although the convolutional layers of Unet were replaced with ResNet residual modules, cascade training with cross-entropy and Lovász hinge loss functions was used, and preprocessing such as histogram matching was performed to improve road segmentation accuracy, the method still lacked an attention mechanism and was not sufficiently optimized for crack detection, failing to consider the slender and sparse characteristics of cracks.
[0005] Therefore, designing a lightweight and efficient detection model while ensuring sufficient detection accuracy is a key issue in current road crack detection research. This research will not only help promote the development of intelligent transportation systems but also provide strong technical support for road maintenance. Summary of the Invention
[0006] The purpose of the present invention is to address the problems that existing crack detection models and methods cannot achieve both lightweight and high efficiency while ensuring sufficient detection accuracy. An image-based UNet crack detection model and method are proposed to at least partially solve the above technical problems.
[0007] In order to achieve the above-mentioned purpose, the present invention adopts the following technical solutions.
[0008] As a first aspect of the present invention, an image-based UNet crack detection model is proposed, comprising: Input convolution block, which is used to output the input image as a feature map ; downsampling blocks, the feature map Pass by in sequence Downsampling blocks … Get the feature maps respectively … ; upsampling blocks, the feature map … Correspondence and feature maps … , through the sampling block … Get feature map … ; as well as Output convolution block for input feature map To obtain the prediction mask.
[0009] is the UNet depth parameter, and the value of M ranges from 2 to 8.
[0010] The downsampling block includes a downsampling layer and an attention convolution block connected in series, the kernel size of the downsampling layer is set to 2x2, the step size is set to 2, and the maximum pooling layer with the number of channels maintained. The upsampling block includes an upsampling layer and an attention convolution block connected in series, the kernel size of the upsampling layer is set to 2x2, the step size is set to 2, and a transposed convolution layer with the number of channels halved. The input convolution block has the same structure as the attention convolution block.
[0011] The attention convolution block includes convolution layer C1, convolution layer C21, hole convolution layer C22, spatial attention layer A1, channel attention layer A2, batch normalization layer B1, batch normalization layer B2, activation function layer R1 and activation function layer R2, through the downsampling block The output is used as the input feature map, which is sequentially passed through the convolution layer C1, the spatial attention layer A1, the batch normalization layer B1 and the activation function layer R1 to obtain the first feature map. The first feature map is passed through the convolution layer C21 to obtain the second feature map. The first feature map is passed through the hole convolution layer C22 to obtain the third feature map. The second feature map and the third feature map are spliced by channel to obtain the fourth feature map. The fourth feature map is sequentially passed through the channel attention layer A2, the batch normalization layer B2, and the activation function layer R2 to obtain the feature map .
[0012] As a second aspect of the present invention, an image-based UNet crack detection method is also proposed, comprising the following steps: S2. Combine the constructed dataset with the improved flexible F1 loss function to train and obtain an improved UNet crack detection model, which specifically includes the following steps; S21, divide the data set into training set, validation set and test set; S22, setting training parameters; S23, sending the preprocessed image of the training set to the improved UNet crack detection model to obtain a prediction mask; S24, inputting the label mask and the prediction mask into the improved flexible F1 loss function to obtain a loss value; the label mask is obtained through the dataset construction process; S25. Update the loss value through gradient backpropagation to improve the UNet crack detection model; S26. Obtain the prediction mask and verification loss value of the verification set according to the verification set to perform model verification; S27. After the training is completed, determine and send the test set images to the trained improved UNet crack detection model for evaluation.
[0013] The training parameters in S22 are set as follows: the training process is divided into a warm-up phase and a formal training phase, and the current training phase is set to the warm-up phase; the initial learning rate R, the learning rate attenuation coefficient K, and the waiting iteration number N are set; the current learning rate r is set to R; where the value of K is 0 to 1.
[0014] The S24 comprises the following steps: S241. For pixels marked as positive examples in the label mask, extract the pixel values at the corresponding positions in the prediction mask, calculate 1-(1-pixel value) to the power of a, and sum them to obtain the number of soft true positives; where a is an adjustable parameter with a value of 1 to 4; S242. For pixels marked as positive examples in the label mask, extract the pixel values at the corresponding positions in the prediction mask, calculate the power of (1-pixel value) a and sum them to obtain the number of soft false negative examples; S243. For pixels marked as negative examples in the label mask, extract the pixel values at corresponding positions in the prediction mask, calculate the a-th power of the pixel values, and sum them to obtain the number of soft false positive examples. S244. Calculate the number of flexible true positives / (the number of flexible true positives + the number of flexible false positives) to obtain the flexible precision. S245. Calculate the number of flexible true positives / (number of flexible true positives + number of flexible false negatives) to obtain the flexible recall rate. S246. Calculate the harmonic mean of the flexible precision and the flexible recall to obtain the flexible F1 score. S247. Calculate 1-flexible F1 score to obtain a loss value.
[0015] S26 includes: S261, using the improved UNet crack detection model based on the validation set to obtain the prediction mask of the validation set; S262, applying the improved flexible F1 loss function to the validation set prediction mask and the validation set label mask to obtain a validation loss value; S263. If the validation loss value is lower than the validation loss value of any previous iteration, temporarily save the current model; S264. When the current stage is the warm-up stage, if the verification loss value is lower than the verification loss value of the previous iteration, the current learning rate is increased by R and the process jumps to S23; if the verification loss value is not lower than the verification loss value of the previous iteration, the current stage is set to the formal training stage and the process jumps to S23; when the current stage is the formal training stage, if the verification loss value is lower than the verification loss value of the previous iteration, the process jumps to S23; if the verification loss value is not lower than the verification loss value of the previous iteration, but the current lowest loss value is included in the last N iterations, the current learning rate is multiplied by K times and the process jumps to S23; if the verification loss value is not lower than the verification loss value of the previous iteration, and the current lowest loss value is not included in the last N iterations, the training is ended and the process jumps to S27.
[0016] Before step S2, step S1 is included, and the data set is constructed, which specifically includes the following steps: S11, using images in the CRACK500 dataset as original images; S12, preprocessing the original image to obtain a preprocessed image; S13. Organize the annotation information in the CRACK500 dataset to obtain a label mask; match the label mask with the preprocessed image one by one to complete the dataset construction.
[0017] It also includes S3 using the trained improved UNet crack detection model to perform crack detection, which specifically includes the following steps: S31, collecting original images of the road; S32, preprocessing the original image to obtain a preprocessed image; S33, obtaining a prediction mask using the trained improved UNet crack detection model according to the preprocessed image; S34. Binarize the predicted mask to obtain the crack detection result.
[0018] Based on the above technical solutions, the image-based UNet crack detection model and method of the present invention have at least one of the following beneficial effects compared to the existing technology: 1. An improved UNet crack detection model is used as the crack detection model. Given the characteristics of crack detection tasks, which are rich in shallow texture features but few in deep semantic features, the number of channels in the traditional UNet network is reduced from 32, 64, 128, and 256 to 32, 32, 64, and 128, respectively. By reducing the number of channels in the deep convolution kernel, the number of model parameters and computational complexity is greatly reduced, making it easier to deploy on edge devices and embedded devices.
[0019] 2. The improved crack detection model addresses the characteristics of cracks being long, thin, sparse, and subject to significant background interference. The two-layer convolutional block in the traditional UNet is replaced with an attention-based multi-scale convolutional block. By inserting a dilated convolutional layer, the model captures the contextual information of long, thin cracks while suppressing background interference through channel-wise and spatial-attention mechanisms, improving the model's detection accuracy.
[0020] 3. The fixed learning rate adjustment mechanism used in traditional UNet network training is improved to a dynamic learning rate adjustment mechanism based on the validation set performance. This suppresses the instability in the early stage of training, accelerates the convergence speed with a higher learning rate in the middle stage of training, and dynamically decays the learning rate in the late stage of training to finely search for the optimal solution. By observing the performance of the validation set, the impact of the initial learning rate setting on the training process is reduced, while improving the training efficiency.
[0021] 4. In view of the fact that the number of crack pixels in crack scenes is significantly lower than the number of normal pixels, when training the model, the cross-entropy loss or weighted cross-entropy loss sampled in the traditional binary segmentation model is replaced with an improved flexible F1 loss function; when evaluating the training loss, the precision and recall rates are comprehensively considered to avoid the impact of the imbalance of positive and negative samples in the dataset on training.
[0022] 5. The improved flexible F1 loss function is used to train the model. Compared with the traditional flexible F1 loss function, a nonlinear flexible function is introduced to calculate the number of true positive examples, false positive examples, and false negative examples. While making the loss function differentiable, the training gradient focuses on erroneous samples and difficult-to-classify samples, which improves the training efficiency and the performance of the trained model. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0024] Figure 1 is a model structure diagram of the improved UNet crack detection model of the present invention; Figure 2This is a structural diagram of the attention multi-scale convolution block in the improved UNet crack detection model described in the present invention; Figure 3 It is a flow chart of the model training of the present invention; Figure 4 (a) is a graph showing the change in the loss function during model training of the present invention; Figure 4 (b) is a curve diagram of the change of the validation set performance index during the model training process of the present invention; Figure 5 (a) is an original image acquired during the crack detection process S31 of the present invention; Figure 5 (b) is another original image acquired during the crack detection process S31 of the present invention; Figure 5 (c) is obtained in S34 during the crack detection process of the present invention and Figure 4 (a) Corresponding crack detection result image; Figure 5 (d) is obtained in S34 during the crack detection process of the present invention and is Figure 4 (b) Corresponding crack detection result image. DETAILED DESCRIPTION
[0025] In order to make the objectives, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with specific embodiments and with reference to the accompanying drawings.
[0026] The terms used in the present invention are only for the purpose of describing specific embodiments and are not intended to limit the embodiments of the present invention. The singular forms "a", "an", "the" and "the" used in the embodiments of the present invention and the appended claims are also intended to include plural forms unless the context clearly indicates otherwise.
[0027] The inventors discovered that existing technologies for road crack detection suffer from high computational power consumption, imbalanced positive and negative samples in model training, significant impact of background interference on detection accuracy, and difficulty deploying models on resource-constrained devices. After in-depth research, they discovered that by constructing an improved UNet crack detection model, employing attention multi-scale convolution blocks, an improved flexible F1 loss function, a dynamic learning rate adjustment mechanism, and reducing the number of convolution kernel channels, it is possible to reduce the number of model parameters and computational complexity, improve detection accuracy, balance the impact of positive and negative sample training, and enhance training efficiency. Therefore, Figure 1 As shown, the inventors proposed an image-based UNet crack detection model, including: Input convolution block, which is used to output the input image as a feature map ; Downsampling block , for the feature map Pass by in sequence Downsampling blocks Get feature map ; Upsampling block , used to convert the feature map With the feature map Send them to the upsampling block respectively , get the feature map The characteristic graph With feature map Input through sampling block Get feature map ; Until the feature map is obtained 、 … ;as well as Output convolution block for input feature map To obtain the prediction mask.
[0028] Set as the UNet depth parameter, M value ranges from 2 to 8.
[0029] The downsampling block It includes a downsampling layer and an attention convolution block connected in series, the kernel size of the downsampling layer is set to 2x2, the step size is set to 2, and the maximum pooling layer with the number of channels maintained. The upsampling block includes an upsampling layer and an attention convolution block connected in series, the kernel size of the upsampling layer is set to 2x2, the step size is set to 2, and a transposed convolution layer with the number of channels halved. The input convolution block has the same structure as the attention convolution block.
[0030] The attention convolution block includes a convolution layer C1, a hole convolution layer C22, a spatial attention layer A1, a channel attention layer A2, a batch normalization layer B1, a batch normalization layer B2, an activation function layer R1 and an activation function layer R2, and is connected to the downsampling block. The output is used as the input feature map, which is sequentially passed through the convolution layer C1, the spatial attention layer A1, the batch normalization layer B1 and the activation function layer R1 to obtain the first feature map. The first feature map is passed through the convolution layer C21 to obtain the second feature map. The first feature map is passed through the hole convolution layer C22 to obtain the third feature map. The second feature map and the third feature map are spliced by channel to obtain the fourth feature map. The fourth feature map is sequentially passed through the channel attention layer A2, the batch normalization layer B2, and the activation function layer R2 to obtain the feature map .
[0031] The present invention will be further described below through specific examples. It should be noted that the following examples are merely illustrative and are not intended to limit the present invention. Based on the embodiments of the present invention shown below, all other embodiments obtained by those of ordinary skill in the art without creative work are within the scope of protection of the embodiments of the present invention.
[0032] Example 1 In this embodiment, further, Figure 1 This is the model structure diagram of the improved UNet crack detection model of the present invention; as can be seen from the figure, in this embodiment, the UNet depth parameter Set to 4, then the specific structure of the improved UNet crack detection model is: The input image (1×320×640) passes through the input convolution block to obtain the feature map (32×320×640); Feature Map After downsampling layers and input attention multi-scale convolutional blocks , get the feature map (32×160×320); Feature Map After downsampling layers and input attention multi-scale convolutional blocks , get the feature map (64×80×160); Feature Map After downsampling layers and input attention multi-scale convolutional blocks , get the feature map (128×40×80); Feature Map After downsampling layers and input attention multi-scale convolutional blocks , get the feature map (256×20×40); Feature Map After upsampling layer , and the feature map After splicing by channel, it is fed into the input attention multi-scale convolution block , get the feature map (128×40×80); Feature Map After upsampling layer , and the feature map After splicing by channel, it is fed into the input attention multi-scale convolution block , get the feature map (64×80×160); Feature Map After upsampling layer , and the feature map After splicing by channel, it is fed into the input attention multi-scale convolution block , get the feature map (32×160×320); Feature Map After upsampling layer , and the feature map After splicing by channel, it is fed into the input attention multi-scale convolution block , get the feature map (32×320×640); Feature Map After the output convolution block, the prediction mask is obtained.
[0033] Figure 2 It is a model structure diagram of the attention multi-scale convolution block of the present invention. It can be seen from the figure that the configuration parameters of the attention multi-scale convolution block include the number of input channels IC and the number of output channels OC; the attention multi-scale convolution block includes a convolution layer C1, a void convolution layer C22, a spatial attention layer A1, a channel attention layer A2, a batch normalization layer B1, a batch normalization layer B2, an activation function layer R1 and an activation function layer R2.
[0034] The input feature map (IC×H×W) passes through the convolution layer C1, spatial attention layer A1, batch normalization layer B1, and activation function layer R1 in sequence to obtain the first feature map (OC×H×W); the spatial attention layer A1 generates spatial attention weights by calculating the mean and maximum value of the feature map in the spatial dimension, focusing on areas where cracks may exist (such as linear areas on the road surface) and suppressing irrelevant background (such as vehicles, road signs, etc.), thereby reducing false detections and improving the accuracy of crack positioning.
[0035] The first feature map passes through the convolution layer C21 to obtain the second feature map (OC / 2×H×W); the convolution layer C21 is used to capture local detail features and is sensitive to crack edges and subtle structures; The second feature map passes through the dilated convolution layer C22 to obtain the third feature map (OC / 2×H×W); the dilated convolution layer C22 expands the receptive field without increasing parameters, captures long-distance dependencies, and is suitable for detecting slender and irregular crack morphologies.
[0036] The second feature map and the third feature map are spliced by channel to obtain the fourth feature map (OC×H×W); information of different scales is retained to avoid information loss, and the complementary fusion of multi-scale features is achieved under the premise of efficient parameters.
[0037] The fourth feature map passes through the channel attention layer A2, batch normalization layer B2, and activation function layer R2 in sequence to obtain the output feature map (OC×H×W). The channel attention layer A2 calculates the statistical characteristics of each channel and adaptively adjusts the channel weights, enhancing channels that are highly expressive of crack characteristics and suppressing irrelevant channels, thereby highlighting the semantic characteristics of cracks and improving the model's ability to identify cracks. The model can simultaneously focus on local crack details and global context, improving the detection accuracy of cracks of different widths, lengths, and shapes.
[0038] The configuration parameter of the spatial attention layer A1 is the number of channels C, and the specific structure is: The input feature map (C×H×W) takes the maximum value by channel to obtain the maximum value feature map (1×H×W); The input feature map (C×H×W) is averaged by channel to obtain the mean feature map (1×H×W); The maximum feature map and the mean feature map are concatenated by channel, and then passed through the convolution layer and the Sigmoid activation function layer in sequence to obtain the attention map (1×H×W); The attention map is expanded to the same size as the input feature map and multiplied element-wise with the input feature map to obtain the output feature map (C×H×W); The configuration parameter of the channel attention layer A2 is the number of channels C, and its specific structure is: The input feature map (C×H×W) takes the maximum value in the plane to obtain the channel maximum value (C×1×1); The input feature map (C×H×W) is averaged by plane to obtain the channel mean (C×1×1); After the channel maximum and channel mean are concatenated, they are fed into a multi-layer perceptron to obtain an attention map (C×1×1). The attention map is expanded to the same size as the input feature map and multiplied element-wise with the input feature map to obtain the output feature map (C×H×W).
[0039] Example 2 Figure 3 This is a flow chart of the method of the present invention for model training and crack detection. Figure 3 As can be seen from the figure, an image-based UNet crack detection method is used for model training and reasoning, which includes the following steps: S2. Using the data set and the improved flexible F1 loss function to train the improved UNet crack detection model to obtain the trained improved UNet crack detection model, specifically including the following steps; S21. Divide the dataset into a training set, a validation set, and a test set. Here, the division ratio is set to 0.7:0.15:0.15, resulting in 1874 training set samples, 402 validation set samples, and 401 test set samples. S22. Set training parameters: Divide the training process into a warm-up phase and a formal training phase, and set the current training phase to the warm-up phase; set the initial learning rate R = 0.00016, the learning rate decay coefficient K = 0.7, and the waiting iteration number N = 10; set the current learning rate r to R; S23, sending the preprocessed image of the training set to the improved UNet crack detection model to obtain a prediction mask; S24: Send the label mask and the prediction mask to the improved flexible F1 loss function to obtain the loss value, which specifically includes the following steps: S241. For the pixels marked as positive examples in the label mask, extract the pixel values of the corresponding positions in the prediction mask. , calculate the number of flexible true positive cases according to the following formula : in It is an adjustable parameter, and the value here is 1.5; S242. For pixels marked as positive in the label mask, calculate the number of soft false negatives according to the following formula: : S243. For pixels marked as negative in the label mask, calculate the number of soft false positives according to the following formula: : S244, calculate the flexibility accuracy : S245, calculate the flexible recovery rate : S246. Calculate the harmonic mean of the flexible precision and the flexible recall to obtain the flexible F1 score. : S247, calculating 1-flexible F1 score to obtain a loss value; S25. Based on the current learning rate r, the loss value is updated through gradient backpropagation to improve the UNet crack detection model; S26. Model verification, specifically including the following steps: S261. Send the validation set to the improved UNet crack detection model to obtain the validation set prediction mask S262, inputting the validation set prediction mask and the validation set label mask into the improved flexible F1 loss function to obtain a validation loss value; S263. If the validation loss value is lower than the validation loss value of any previous iteration, temporarily save the current model; S264. When the current stage is the warm-up stage, if the validation loss value is lower than the validation loss value of the previous iteration, the current learning rate is increased by R and the process jumps to S23. If the validation loss value is not lower than the validation loss value of the previous iteration, the current stage is set to the formal training stage and the process jumps to S23. When the current stage is the formal training stage, if the validation loss value is lower than the validation loss value of the previous iteration, the process jumps to S23. If the validation loss value is not lower than the validation loss value of the previous iteration, but the current lowest loss value is included in the last N iterations, the current learning rate is multiplied by K and the process jumps to S23. If the validation loss value is not lower than the validation loss value of the previous iteration, and the current lowest loss value is not included in the last N iterations, the training is terminated and the process jumps to S27. S27, model testing: After the training is completed, the model temporarily stored in S263 is the trained improved UNet crack detection model; the test set images are sent to the trained improved UNet crack detection model to evaluate the model performance.
[0040] S3. Perform crack detection using the trained improved UNet crack detection model, specifically including the following steps: S31, photographing the road with a camera to collect original images; S32, preprocessing the original image to obtain a preprocessed image; the preprocessing method is the same as the preprocessing method in S12; S33, model inference: the preprocessed image is fed into the trained improved UNet crack detection model to obtain the predicted mask; S34, post-processing: binarize the predicted mask to obtain the crack detection result.
[0041] Figure 4The graph (4a) showing the change of loss function and the graph (4b) showing the change of validation set performance index in the training process using the method of the present invention is shown; as can be seen from Figure (4a), the model converges to a high level of validation loss value of 0.259 at a relatively fast speed in the 5th iteration, and further reduces the validation loss value to the optimal level of 0.209 at the 26th iteration through fine search with a small learning rate, and then stops training at the 36th iteration after waiting for 10 cycles; it has the characteristics of fast convergence speed and high training efficiency; as can be seen from Figure (4b), at the beginning of training, the accuracy and recall rate of the model are unbalanced, and the model is overly biased towards positive samples, resulting in poor crack detection effect; during the training process, the improved flexible F1 loss function automatically balances the accuracy and recall rate, so that the two fluctuate around the F1 score and gradually converge, avoiding the impact of the imbalance of positive and negative samples in the data set on the training.
[0042] Table 1 shows the scale and test set performance indicators of the model trained using the method of the present invention, compared with the traditional UNet model and other existing models. As can be seen from the table, thanks to the improvement of the loss function, the method of the present invention has a more balanced precision and recall rate compared with other existing models. At the same time, thanks to the selective reduction of the number of channels of the convolution kernel and the structural design of the attention multi-scale convolution block, the method of the present invention has the characteristics of lower parameter and computational complexity and better crack detection effect compared with the traditional UNet model and other existing models.
[0043] Table 1 Performance Index Figure 5 The figures show the effect of the method of the present invention in practical application. (a) and (c) are a set of original images and crack images, (b) and (d) are another set of original images and crack images. The crack areas identified by the method are marked in white. It can be seen that the identified crack areas are consistent with the actual crack areas, and the actual effect is good.
[0044] Example 3 This embodiment describes the process of using the method of the present invention, after training the model according to the second embodiment, deploying it to the embedded computer on the drone to perform actual crack inspection, which specifically includes the following steps: T1. Deploy the trained improved UNet crack detection model to the airborne embedded drone; T2. The drone patrols along the road based on GPS positioning and built-in maps. During the patrol, it takes original images of the ground at specified intervals. T3. Preprocess the original image to obtain a preprocessed image; the preprocessing specifically includes the following steps: T31, average the R, G, and B channels of the original image set to obtain a grayscale image; T32. Perform median filtering on the grayscale image set to denoise it and obtain the denoised image. Here, the filter size is set to 5x5. T33, performing histogram equalization on the denoised image to obtain a preprocessed image; T4. Send the preprocessed image to the trained improved UNet crack detection model to obtain the prediction mask; T5. Binarize the predicted mask to obtain the crack detection result; T6. For crack detection results, the orthogonal skeleton method is used to obtain the crack skeleton and the pixel length of the skeleton ; T7, get the current flight altitude of the drone based on the laser ranging sensor installed vertically towards the ground , combined with the known lens focal length , and pixel size , calculate the physical length of the skeleton based on the pinhole imaging model : T8, if the physical length If the crack detection result is greater than a given threshold, the original image and crack detection results are saved to the internal memory of the onboard computer, and the current position of the drone is recorded. At this time, if the communication between the drone and the ground station is normal, the original image, crack detection results and drone position are simultaneously transmitted to the ground station. Here, the threshold is set to 0.5m. T9. Return to S2 and continue the inspection flight until the inspection mission is completed.
[0045] By reducing the number of deep UNet channels (e.g., from 32 to 32 to 64 to 128) and designing multi-scale convolutional blocks with attention, the model significantly reduces both parameter count and computational complexity, adapting to the limited computing power of drone embedded computers (e.g., CPU / GPU resource constraints) and avoiding detection failures due to insufficient hardware performance. The model, trained with dynamic learning rate adjustment and a flexible F1 loss function, maintains high detection accuracy (F1 score of 0.792) even with low computing power, balancing efficiency and accuracy. Standardization is achieved throughout the entire process, from data preprocessing to model inference and post-processing, reducing parameter tuning costs during deployment and improving system reliability. This deployment approach not only addresses the pain points of traditional detection but also, by combining the mobility of drones with the intelligence of the model, promotes the transformation of road maintenance from "reactive repair" to "proactive prevention."
[0046] The foregoing description describes specific embodiments of the present invention. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims can be performed in an order different from that described in the embodiments and still achieve the desired results. Furthermore, the processes depicted in the accompanying drawings do not necessarily require the specific order shown or sequential order to achieve the desired results. In certain embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0047] In the description of the embodiments of the present invention, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the embodiments of the present invention. In the embodiments of the present invention, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine different embodiments or examples described in the embodiments of the present invention and the features of different embodiments or examples, unless they are mutually inconsistent.
[0048] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be understood to indicate or imply relative importance or implicitly specify the number of the technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of such features. In the description of the embodiments of the present invention, "plurality" means at least two, for example, two, three, etc., unless otherwise specifically defined.
[0049] Any process or method description in a flowchart or otherwise described herein may be understood to represent a module, segment or portion of code comprising one or more executable instructions for implementing the steps of a custom logical function or process, and the scope of the preferred implementation of the embodiments of the invention includes alternative implementations in which functions may be performed out of the order shown or discussed, including performing functions in a substantially simultaneous manner or in reverse order depending on the functions involved, which should be understood by those skilled in the art to which the embodiments of the invention pertain.
[0050] The above description is only a preferred embodiment of the embodiment of the present invention and is not intended to limit the embodiment of the present invention. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the embodiment of the present invention should be included in the scope of protection of the embodiment of the present invention.
Claims
1. An image-based UNet crack detection model, characterized in that: include: Input convolution block, which is used to output the input image as a feature map ; downsampling blocks, the feature map Pass by in sequence Downsampling blocks … Get the feature maps respectively … ; upsampling blocks, the feature map … Correspondence and feature maps … , through the sampling block … Get feature map … ; as well as Output convolution block for input feature map To obtain the prediction mask.
2. The image-based UNet crack detection model according to claim 1, characterized in that: is the UNet depth parameter, and the value of M ranges from 2 to 8.
3. The image-based UNet crack detection model according to claim 1, characterized in that: The downsampling block includes a downsampling layer and an attention convolution block connected in series, the kernel size of the downsampling layer is set to 2x2, the step size is set to 2, and the maximum pooling layer with the number of channels maintained. The upsampling block includes an upsampling layer and an attention convolution block connected in series, the kernel size of the upsampling layer is set to 2x2, the step size is set to 2, and a transposed convolution layer with the number of channels halved. The input convolution block has the same structure as the attention convolution block.
4. The image-based UNet crack detection model according to claim 3, characterized in that: The attention convolution block includes convolution layer C1, convolution layer C21, hole convolution layer C22, spatial attention layer A1, channel attention layer A2, batch normalization layer B1, batch normalization layer B2, activation function layer R1 and activation function layer R2, through the downsampling block The output is used as the input feature map, which is sequentially passed through the convolution layer C1, the spatial attention layer A1, the batch normalization layer B1 and the activation function layer R1 to obtain the first feature map. The first feature map is passed through the convolution layer C21 to obtain the second feature map. The first feature map is passed through the hole convolution layer C22 to obtain the third feature map. The second feature map and the third feature map are spliced by channel to obtain the fourth feature map. The fourth feature map is sequentially passed through the channel attention layer A2, the batch normalization layer B2, and the activation function layer R2 to obtain the feature map .
5. An image-based UNet crack detection method, using an image-based UNet crack detection model according to any one of claims 1 to 4, characterized in that: The steps include: S2. Combine the constructed dataset with the improved flexible F1 loss function to train and obtain an improved UNet crack detection model, which specifically includes the following steps; S21, divide the data set into training set, validation set and test set; S22, setting training parameters; S23, the preprocessed images of the training set are used to obtain prediction masks by improving the UNet crack detection model; S24, determining a loss value using an improved flexible F1 loss function according to the label mask and the prediction mask; the label mask is obtained through the dataset construction process; S25. Update the loss value through gradient backpropagation to improve the UNet crack detection model; S26. Obtain the prediction mask and verification loss value of the verification set according to the verification set; S27. Determine the improved UNet crack detection model after training and evaluate it using the test set images.
6. The image-based UNet crack detection method according to claim 5, characterized in that: The training parameters in S22 are set as follows: the training process is divided into a warm-up phase and a formal training phase, and the current training phase is set to the warm-up phase; the initial learning rate R, the learning rate attenuation coefficient K, and the waiting iteration number N are set; the current learning rate r is set to R; where the value of K is 0 to 1.
7. The image-based UNet crack detection method according to claim 5, characterized in that: S24 includes the following steps: S241. For pixels marked as positive examples in the label mask, extract the pixel values at the corresponding positions in the prediction mask, calculate 1-(1-pixel value) to the power of a, and sum them to obtain the number of soft true positives; where a is an adjustable parameter with a value of 1 to 4; S242. For pixels marked as positive examples in the label mask, extract the pixel values at the corresponding positions in the prediction mask, calculate the power of (1-pixel value) a and sum them to obtain the number of soft false negative examples; S243. For pixels marked as negative examples in the label mask, extract the pixel values at corresponding positions in the prediction mask, calculate the a-th power of the pixel values, and sum them to obtain the number of soft false positive examples. S244. Calculate the number of flexible true positives / (the number of flexible true positives + the number of flexible false positives) to obtain the flexible precision. S245. Calculate the number of flexible true positives / (number of flexible true positives + number of flexible false negatives) to obtain the flexible recall rate. S246. Calculate the harmonic mean of the flexible precision and the flexible recall to obtain the flexible F1 score. S247. Calculate 1-flexible F1 score to obtain a loss value.
8. The image-based UNet crack detection method according to claim 5, characterized in that: S26 includes: S261, using the improved UNet crack detection model based on the validation set to obtain the prediction mask of the validation set; S262, applying the improved flexible F1 loss function to the validation set prediction mask and the validation set label mask to obtain a validation loss value; S263. If the validation loss value is lower than the validation loss value of any previous iteration, temporarily save the current model; S264. When the current stage is the warm-up stage, if the verification loss value is lower than the verification loss value of the previous iteration, the current learning rate is increased by R and the process jumps to S23; if the verification loss value is not lower than the verification loss value of the previous iteration, the current stage is set to the formal training stage and the process jumps to S23; when the current stage is the formal training stage, if the verification loss value is lower than the verification loss value of the previous iteration, the process jumps to S23; if the verification loss value is not lower than the verification loss value of the previous iteration, but the current lowest loss value is included in the last N iterations, the current learning rate is multiplied by K times and the process jumps to S23; if the verification loss value is not lower than the verification loss value of the previous iteration, and the current lowest loss value is not included in the last N iterations, the training is ended and the process jumps to S27.
9. The image-based UNet crack detection method according to claim 5, characterized in that: Before step S2, step S1 is included, and the data set is constructed, which specifically includes the following steps: S11, using images in the CRACK500 dataset as original images; S12, preprocessing the original image to obtain a preprocessed image; S13. Organize the annotation information in the CRACK500 dataset to obtain a label mask; match the label mask with the preprocessed image one by one to complete the dataset construction.
10. The image-based UNet crack detection method according to claim 5, characterized in that: It also includes S3 using the trained improved UNet crack detection model to perform crack detection, which specifically includes the following steps: S31, collecting original images of the road; S32, preprocessing the original image to obtain a preprocessed image; S33, obtaining a prediction mask using the trained improved UNet crack detection model according to the preprocessed image; S34. Binarize the predicted mask to obtain the crack detection result.