Pavement crack identification method and system based on Yolov7 model
By improving the YOLOv7 model, adding the EMA attention mechanism and dynamic serpentine convolution, and replacing the loss function, the problems of low efficiency and poor accuracy of traditional detection methods are solved, and the efficiency and accuracy of identifying road cracks are improved.
Patent Information
- Application Number
- CN202410656010.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-24
- Publication Date
- 2024-09-03
AI Technical Summary
Traditional road crack detection methods have problems such as low inspection efficiency, high cost, and strong subjectivity. Especially when identifying small target scenes, the YOLOv7 model has poor detection results and is prone to false detections or missed detections.
By improving the YOLOv7 model, adding the EMA attention mechanism, adding dynamic serpentine convolution, and replacing the IOU loss function with the N-IOU loss function, training is conducted based on the labeled road crack image data set to improve the multi-dimensional perception ability of the model and multi-scale feature extraction capabilities.
It improves the efficiency and accuracy of identifying irregular cracks, enhances the accuracy of small target detection, and reduces false detections and missed detections.
Smart Images

Figure CN118587172A
Abstract
Description
Technical Field
[0001] The present application belongs to the field of artificial intelligence, and in particular, relates to a method and system for pavement crack identification based on the Yolov7 model. Background Art
[0002] As my country continues to advance its goals, transportation infrastructure plays a vital role as an important part of supporting the country's economic development. However, with the continuous increase in the mileage of highways open to traffic, the problem of difficulty in detecting road cracks in my country has become increasingly prominent. Road crack detection technology is an important part of traffic safety and road maintenance. Its main task is to quickly and accurately detect road damage to improve road maintenance efficiency.
[0003] At present, conventional road crack detection mainly relies on traditional manual detection and detection methods based on image processing technology. These methods have the limitations of low inspection efficiency, high cost, strong subjectivity, and cannot meet the needs of large-scale maintenance. Therefore, in the field of target recognition, we can make full use of technical means based on big data and deep learning to improve the efficiency and accuracy of road crack recognition. Among them, YOLOv7 (You Only Look Once) is a classic and efficient target detection algorithm, but due to the particularity and diversity of road cracks, traditional YOLOv7 has certain limitations when detecting such scenes. For example, when identifying small target scenes such as pothole cracks, its detection effect is poor, and it is easy to have false detection or missed detection.
[0004] Therefore, the present invention aims to propose an intelligent recognition method for road cracks based on the YOLOv7 algorithm to improve the accuracy and efficiency of side road crack detection. Summary of the invention
[0005] The main purpose of the embodiments of the present invention is to provide a method and system for pavement crack identification based on the Yolov7 model, so that the pavement crack identification is fast and accurate, and in particular, the recognition efficiency of irregular cracks is improved through dynamic serpentine convolution.
[0006] In a first aspect, a method for identifying pavement cracks based on a Yolov7 model is provided, the method comprising:
[0007] The basic Yolov7 model is improved through a preset improvement mechanism to obtain an improved Yolov7 model, wherein the improvement mechanism includes: adding an EMA attention mechanism, adding a dynamic snake convolution, and replacing an IOU loss function;
[0008] Training the improved Yolov7 model based on an image dataset of annotated pavement crack images to obtain a trained Yolov7 model;
[0009] Crack recognition is performed on the road surface crack image to be recognized by using the trained Yolov7 model to obtain the crack recognition result.
[0010] In a possible implementation, the step of improving the basic Yolov7 model by using a preset improvement mechanism to obtain an improved Yolov7 model includes:
[0011] The following improvements are made in the basic Yolov7 model: adding an EMA attention mechanism at the end of the head network of the basic Yolov7 model; adding dynamic snake convolution to the backbone network of the basic Yolov7 model and performing multi-feature fusion; and replacing the IOU loss function in the basic network of the basic Yolov7 model with an N-IOU loss function that fuses the NWD metric and the IOU metric.
[0012] In a possible implementation, the step of training the improved Yolov7 model based on the image dataset of the annotated pavement crack images to obtain the trained Yolov7 model includes:
[0013] Obtain an image dataset of annotated pavement crack images;
[0014] Dividing the image dataset into a training set and a validation set;
[0015] The improved Yolov7 model is trained by using the training set to obtain an initial training Yolov7 model;
[0016] The initially trained Yolov7 model is verified by using the verification set to obtain a verified Yolov7 model.
[0017] In a possible implementation, verifying the initially trained Yolov7 model by using the verification set, and if the verification passes, determining the initially trained Yolov7 model as a verified Yolov7 model, includes:
[0018] The accuracy, recall, harmonic mean F1 of the accuracy and recall, and average precision mAP of each category of the initially trained Yolov7 model are verified by the validation set, including: Obtain the accuracy; and, by formula Obtain the recall rate; and, by formula Obtain the harmonic mean of the precision and recall; and, by formula Get the average precision of each category;
[0019] Comparing the accuracy, recall, harmonic mean of precision and recall, and average precision of each category with preset thresholds respectively, including: comparing the accuracy with a preset accuracy threshold; and, comparing the recall with a preset recall threshold; and, comparing the harmonic mean of precision and recall with a preset harmonic mean threshold of precision and recall; and, comparing the average precision of each category with a preset average precision threshold of each category;
[0020] If the accuracy, recall, harmonic mean of precision and recall, and average precision of each category are all better than corresponding thresholds, the verification is passed, and the initially trained Yolov7 model is determined as a verified Yolov7 model.
[0021] In a possible implementation, obtaining an image dataset of annotated pavement crack images includes:
[0022] Acquire road crack image data captured by a handheld camera and / or an unmanned camera, wherein the crack types include: transverse cracks, vertical cracks, mesh cracks, and potholes;
[0023] Cleaning the road crack image data to obtain cleaned road crack image data, wherein the cleaning includes: removing incomplete or unclearly focused road crack image data;
[0024] Annotating the cleaned road crack image data with the crack type using a preset annotation tool to obtain an annotated road crack image;
[0025] Different types of annotated pavement crack images are encoded using a preset encoding tool.
[0026] In a possible implementation, after encoding different types of annotated pavement crack images using a preset encoding tool, the method further includes:
[0027] Rotating, adjusting brightness and contrast of the annotated pavement crack image to obtain an enhanced pavement crack image;
[0028] Applying a preset data enhancement strategy to the enhanced pavement crack image to generate a pseudo disease image;
[0029] A one-to-one correspondence is established between the pseudo disease image and the code.
[0030] In a possible implementation, the dynamic snake convolution is added to the backbone network of the basic Yolov7 model, and multi-feature fusion is performed, including:
[0031] Acquire multiple crack features extracted from the same pavement crack by the dynamic serpentine convolution from multiple different directions;
[0032] The multiple crack features are fused to obtain a fused feature of the same road surface crack.
[0033] In a second aspect, a system for identifying pavement cracks based on the Yolov7 model is provided, the system comprising:
[0034] An improved Yolov7 model acquisition module is used to improve the basic Yolov7 model through a preset improvement mechanism to obtain an improved Yolov7 model. The improvement mechanism includes: adding an EMA attention mechanism, adding a dynamic snake convolution, and replacing an IOU loss function;
[0035] A trained Yolov7 model acquisition module is used to train the improved Yolov7 model based on an image dataset of annotated pavement crack images to acquire a trained Yolov7 model;
[0036] The crack recognition result acquisition module is used to perform crack recognition on the pavement crack image to be identified by using the trained Yolov7 model to obtain the crack recognition result.
[0037] In a third aspect, an electronic device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the method for identifying pavement cracks based on the Yolov7 model as provided in the first aspect is implemented.
[0038] In a fourth aspect, a non-transitory computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the method for identifying pavement cracks based on the Yolov7 model as provided in the first aspect is implemented.
[0039] In the present application, a method and system for pavement crack recognition based on the Yolov7 model enables rapid and accurate recognition of pavement cracks, and in particular improves the recognition efficiency of irregular cracks through dynamic serpentine convolution. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in describing the embodiments of the present application are briefly introduced below.
[0041] Figure 1 A flow chart of a method for identifying pavement cracks based on the Yolov7 model provided by one embodiment of the present invention;
[0042] Figure 2 A schematic diagram of the structure of the EMA attention mechanism provided by an embodiment of the present invention;
[0043] Figure 3 A flowchart of a method for identifying pavement cracks based on the Yolov7 model provided by another embodiment of the present invention;
[0044] Figure 4 A flowchart of a method for identifying pavement cracks based on the Yolov7 model provided by another embodiment of the present invention;
[0045] Figure 5 A schematic diagram of the network structure of the improved YOLOv7 model provided in an embodiment of the present invention;
[0046] Figure 6 A structural diagram of a system for identifying pavement cracks based on the Yolov7 model provided by one embodiment of the present invention;
[0047] Figure 7 A structural diagram of a system for identifying pavement cracks based on the Yolov7 model provided by another embodiment of the present invention;
[0048] Figure 8 A structural diagram of a system for identifying pavement cracks based on the Yolov7 model provided by another embodiment of the present invention;
[0049] Fig. 9 The figure is a schematic diagram of the physical structure of an electronic device of the present invention.
[0050] Specific implementation method
[0051] The embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar modules or modules with the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present application, and cannot be interpreted as limiting the present invention.
[0052] It will be understood by those skilled in the art that, unless expressly stated, the singular forms "a", "an", "said" and "the" used herein may also include plural forms. It should be further understood that the term "comprising" used in the specification of the present application refers to the presence of the features, integers, steps, operations, modules and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, modules, components and / or groups thereof. It should be understood that when we refer to a module as being "connected" or "coupled" to another module, it may be directly connected or coupled to the other modules, or there may be intermediate modules. In addition, the "connection" or "coupling" used herein may include wireless connection or wireless coupling. The term "and / or" used herein includes all or any modules and all combinations of one or more associated listed items.
[0053] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation method of the present application will be further described in detail below in conjunction with the accompanying drawings.
[0054] The technical solution of the present application and how to solve the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0055] like Figure 1 FIG. 1 is a flow chart of a method for identifying pavement cracks based on the Yolov7 model provided by an embodiment of the present invention, wherein the method comprises:
[0056] Step S101, improving the basic Yolov7 model through a preset improvement mechanism to obtain an improved Yolov7 model, wherein the improvement mechanism includes: adding an EMA attention mechanism, adding a dynamic snake convolution, and replacing an IOU loss function;
[0057] Step S102, training the improved Yolov7 model based on the image dataset of annotated pavement crack images to obtain a trained Yolov7 model;
[0058] Step S103, performing crack recognition on the road surface crack image to be recognized by using the trained Yolov7 model to obtain the crack recognition result.
[0059] In an embodiment of the present invention, the improvement of the basic Yolov7 model is mainly achieved in the following ways: adding several improvement mechanisms in different modules of the basic Yolov7 model, collectively including: adding EMA attention mechanism, adding dynamic snake convolution, replacing IOU loss function, and after the above improvements, the improved Yolov7 model is obtained.
[0060] The improved Yolov7 model cannot be used directly for pavement crack recognition. It needs to be trained with labeled pavement crack images to form a trained Yolov7 model with higher pavement crack recognition capability.
[0061] The pavement crack image to be identified is input into the trained Yolov7 model, and the recognition result of the pavement crack image to be identified is obtained through the attention module, dynamic snake convolution and IOU loss function of the trained Yolov7 model.
[0062] The step of improving the basic Yolov7 model by a preset improvement mechanism to obtain an improved Yolov7 model includes:
[0063] The following improvements are made in the basic Yolov7 model: adding an EMA attention mechanism at the end of the head network of the basic Yolov7 model; adding dynamic snake convolution to the backbone network of the basic Yolov7 model and performing multi-feature fusion; and replacing the IOU loss function in the basic network of the basic Yolov7 model with an N-IOU loss function that fuses the NWD metric and the IOU metric.
[0064] In the embodiment of the present invention, the role of the EMA (Efficient Multi-Scale Attention) attention mechanism is to encode global information to recalibrate the channel weights in each parallel branch, and further aggregate the output features of the two parallel branches through cross-dimensional interaction, which can improve the multi-dimensional perception ability and multi-scale feature extraction ability of the Yolov7 model, and thus better extract large-scale crack features and small target crack features in the pavement crack detection task. Figure 2 Shown is a schematic diagram of the structure of the EMA attention mechanism provided by an embodiment of the present invention.
[0065] When extracting the features of road cracks, since most cracks present a mesh structure, the structures of the horizontal cracks and vertical cracks in the mesh structure are slender and tortuous, and the horizontal cracks may be connected to the vertical cracks, dynamic snake convolution is added to the Yolov7 backbone network. Due to the continuity constraint in the convolution kernel of the convolution, each convolution freely chooses the swing direction according to the position of the previous convolution, so that the Yolov7 model can learn the crack features in accordance with the pavement crack structure, and will not deviate greatly from the pavement cracks through the effect of the constraints. At the same time, after completing the feature extraction from multiple perspectives, multi-perspective feature fusion is required to achieve the integrity of the crack features.
[0066] The method of adding dynamic snake convolution to the backbone network of the basic Yolov7 model and performing multi-feature fusion includes:
[0067] Acquire multiple crack features extracted from the same pavement crack by the dynamic serpentine convolution from multiple different directions;
[0068] The multiple crack features are fused to obtain a fused feature of the same road surface crack.
[0069] The principles of dynamic snake convolution include:
[0070] Given the standard two-dimensional convolution coordinates as K, the center coordinates are K i =(x i ,y i ), a 3*3 convolution kernel, expressed as:
[0071] K={(x-1,y-1),(x,y),...,(x+1,y+1)}
[0072] Dynamic snake convolution straightens the standard convolution kernel in the x-axis and y-axis directions. Consider a convolution kernel of size 9. Taking the x-axis direction as an example, the specific position of each grid in K is expressed as: K i±c =(x i±c ,y i±c ), where c = {0, 1, 2, 3, 4} represents the horizontal distance from the center grid. i At the beginning, the position of the grid away from the center depends on the position of the previous grid: K increases an offset Δ = {δ|δ∈[-1,1]} compared to K, then the convolution kernel can be expressed by the following formula:
[0073]
[0074]
[0075] The principle of multi-view feature fusion includes:
[0076] For each snake-shaped dynamic convolution K, two feature maps f of layer l are extracted from the x-axis and y-axis respectively. l (K x ) and f l (K y ), expressed as: f l (K) = {∑ i w(K i )·f l (K i ),∑ j w(K i )·f l (K j )}, where w(K i ) represents K i The weight of .
[0077] The N-IOU loss function can improve the detection accuracy of small cracks and potholes while ensuring that the detection accuracy of large-span crack targets is not reduced. The IOU loss function calculates the loss based on the intersection-over-union ratio of the real box and the predicted box, which usually makes its loss very sensitive to tiny targets. Often a single-digit deviation will lead to a reversal of the label, which in turn makes model training difficult. NWD is insensitive to objects of different scales and is therefore more suitable for measuring the similarity between tiny objects. NWD can model the bounding box as a two-dimensional Gaussian distribution, and the similarity between bounding boxes A and B can be converted into the distribution distance between two Gaussian distributions. Therefore, the loss function that integrates the NWD metric and the IOU metric can ensure that the detection accuracy of large-span crack targets is not reduced while improving the detection accuracy of small cracks and potholes.
[0078] The fusion loss function is expressed by the following formula: N-IOU=λNWD+(1-λ)IOU, where λ represents the fusion coefficient.
[0079] NWD loss can be expressed by the following formula:
[0080]
[0081]
[0082] Among them, the true bounding box is expressed as: N a =(cx a ,cy a ,w a ,h a ), the predicted bounding box is represented as: N b =(cx b ,cy b ,w b ,h b ), C represents a constant related to the data set. The IOU loss function is expressed by the following formula: Among them, A represents the real box and B represents the predicted box.
[0083] In the embodiment of the present invention, the basic Yolov7 model is improved by a preset improvement mechanism to obtain an improved Yolov7 model; the improved Yolov7 model is trained based on the labeled pavement crack image to obtain a trained Yolov7 model; the pavement crack image to be identified is identified by the trained Yolov7 model to obtain the crack identification result. The pavement crack identification is fast and accurate, and the recognition efficiency of irregular cracks is improved in particular by dynamic serpentine convolution.
[0084] like Figure 3The flowchart of the method for identifying pavement cracks based on the Yolov7 model provided by another embodiment of the present invention is shown, wherein the improved Yolov7 model is trained based on the image data set of annotated pavement crack images to obtain the trained Yolov7 model, including:
[0085] Step S301, obtaining an image dataset of annotated pavement crack images;
[0086] Step S302, dividing the image data set into a training set and a validation set;
[0087] Step S303, training the improved Yolov7 model using the training set to obtain an initial training Yolov7 model;
[0088] Step S304: verify the initially trained Yolov7 model using the verification set to obtain a verified Yolov7 model.
[0089] In an embodiment of the present invention, firstly, an image data set of annotated pavement crack images is obtained, which may be an image data set directly downloaded from the Internet, or an image data set obtained after annotating a plurality of pavement crack images captured and accumulated, and the image data set is divided into a training set and a verification set according to a preset ratio, and the improved Yolov7 model is trained through the training set, and the training content includes: adjusting the training parameters of the Yolov7 model, obtaining the optimal weight file, and when the loss value of the initial training Yolov7 model reaches the minimum and converges, the weight of the Yolov7 model is optimal, and the training of the training set is completed. Finally, the initial training Yolov7 model is verified through the verification set to obtain the verified Yolov7 model.
[0090] The step of verifying the initially trained Yolov7 model by using the verification set, and if the verification passes, determining the initially trained Yolov7 model as a verified Yolov7 model, comprises:
[0091] The accuracy, recall, harmonic mean F1 of the accuracy and recall, and average precision mAP of each category of the initially trained Yolov7 model are verified by the validation set, including: Obtain the accuracy; and, by formula Obtain the recall rate; and, by formula Obtaining the harmonic mean of the precision and recall; and, by Get the average precision of each category;
[0092] Comparing the accuracy, recall, harmonic mean of precision and recall, and average precision of each category with preset thresholds respectively, including: comparing the accuracy with a preset accuracy threshold; and, comparing the recall with a preset recall threshold; and, comparing the harmonic mean of precision and recall with a preset harmonic mean threshold of precision and recall; and, comparing the average precision of each category with a preset average precision threshold of each category;
[0093] If the accuracy, recall, harmonic mean of precision and recall, and average precision of each category are all better than corresponding thresholds, the verification is passed, and the initially trained Yolov7 model is determined as a verified Yolov7 model.
[0094] like Figure 4 FIG. 1 is a flow chart of a method for identifying pavement cracks based on the Yolov7 model provided by another embodiment of the present invention, wherein the step of obtaining an image dataset of annotated pavement crack images includes:
[0095] Step S401, acquiring road crack image data captured by a handheld camera and / or an unmanned camera, wherein the crack types include: transverse cracks, vertical cracks, mesh cracks, and potholes;
[0096] Step S402, cleaning the road crack image data to obtain cleaned road crack image data, wherein the cleaning includes: removing incomplete or unclearly focused road crack image data;
[0097] Step S403, annotating the cleaned road crack image data with the crack type using a preset annotation tool to obtain an annotated road crack image;
[0098] Step S404: Encode different types of annotated pavement crack images using a preset encoding tool.
[0099] Specifically, the encoding tool represents each type of crack as a vector of length 4, in which only one element is 1 and the rest are 0, such as a mesh crack can be represented as [1,0,0,0]. After the encoding is completed, a corresponding XML format annotation file can also be generated to facilitate the subsequent process to call the annotation file.
[0100] The encoding tool can be selected according to actual use needs, and the present application does not limit the selection of the encoding tool. Preferably, the encoding tool is One-hot encoding.
[0101] As an optional embodiment of the present invention, after encoding different types of annotated pavement crack images by using a preset encoding tool, the method further includes:
[0102] Rotating, adjusting brightness and contrast of the annotated pavement crack image to obtain an enhanced pavement crack image;
[0103] Applying a preset data enhancement strategy to the enhanced pavement crack image to generate a pseudo disease image;
[0104] A one-to-one correspondence is established between the pseudo disease image and the code.
[0105] In the embodiment of the present invention, the rotation operation of the annotated road crack image can be implemented by the flip image function flip and the rotate image function rotate in the Opencv library of Python, the brightness adjustment operation is implemented by the brightness adjustment function convertScaleAbs, and the contrast adjustment operation is implemented by the contrast adjustment function addWeighted. By simulating road detection scenes under different lighting conditions, the generalization of the data set can be improved while enriching the data set.
[0106] Among them, the data enhancement strategy can be selected according to the needs of actual use, and this application does not limit the specific data enhancement strategy. Preferably, the data enhancement strategy is a CutPaste data enhancement strategy. The implementation method of this data enhancement strategy is: cutting the abnormal disease area, and then pasting the abnormal disease area to a random area of the normal image, thereby generating a pseudo crack image similar to the real crack image, so as to improve the diversity of pavement cracks.
[0107] like Figure 5 FIG. 1 is a schematic diagram of the network structure of the improved YOLOv7 model provided in an embodiment of the present invention.
[0108] like Figure 6 FIG. 1 is a structural diagram of a system for identifying pavement cracks based on the Yolov7 model provided by an embodiment of the present invention, wherein the system comprises:
[0109] An improved Yolov7 model acquisition module 601 is used to improve the basic Yolov7 model through a preset improvement mechanism to obtain an improved Yolov7 model, wherein the improvement mechanism includes: adding an EMA attention mechanism, adding a dynamic snake convolution, and replacing an IOU loss function;
[0110] A trained Yolov7 model acquisition module 602 is used to train the improved Yolov7 model based on the image dataset of the annotated pavement crack images to acquire the trained Yolov7 model;
[0111] The crack identification result acquisition module 603 is used to perform crack identification on the pavement crack image to be identified by using the trained Yolov7 model to obtain the crack identification result.
[0112] In an embodiment of the present invention, the improvement of the basic Yolov7 model is mainly achieved in the following ways: adding several improvement mechanisms in different modules of the basic Yolov7 model, collectively including: adding EMA attention mechanism, adding dynamic snake convolution, replacing IOU loss function, and after the above improvements, the improved Yolov7 model is obtained.
[0113] The improved Yolov7 model cannot be used directly for pavement crack recognition. It needs to be trained with labeled pavement crack images to form a trained Yolov7 model with higher pavement crack recognition capability.
[0114] The pavement crack image to be identified is input into the trained Yolov7 model, and the recognition result of the pavement crack image to be identified is obtained through the attention module, dynamic snake convolution and IOU loss function of the trained Yolov7 model.
[0115] The step of improving the basic Yolov7 model by a preset improvement mechanism to obtain an improved Yolov7 model includes:
[0116] The following improvements are made in the basic Yolov7 model: adding an EMA attention mechanism at the end of the head network of the basic Yolov7 model; adding dynamic snake convolution to the backbone network of the basic Yolov7 model and performing multi-feature fusion; and replacing the IOU loss function in the basic network of the basic Yolov7 model with an N-IOU loss function that fuses the NWD metric and the IOU metric.
[0117] In an embodiment of the present invention, the role of the EMA (Efficient Multi-Scale Attention) attention mechanism is to encode global information to recalibrate the channel weights in each parallel branch, and further aggregate the output features of the two parallel branches through cross-dimensional interaction, which can enhance the multi-dimensional perception and multi-scale feature extraction capabilities of the Yolov7 model, and thus better extract large-scale crack features and small target crack features at the same time in the pavement crack detection task.
[0118] When extracting the features of road cracks, since most cracks present a mesh structure, the structures of the horizontal cracks and vertical cracks in the mesh structure are slender and tortuous, and the horizontal cracks may be connected to the vertical cracks, dynamic snake convolution is added to the Yolov7 backbone network. Due to the continuity constraint in the convolution kernel of the convolution, each convolution freely chooses the swing direction according to the position of the previous convolution, so that the Yolov7 model can learn the crack features in accordance with the pavement crack structure, and will not deviate greatly from the pavement cracks through the effect of the constraints. At the same time, after completing the feature extraction from multiple perspectives, multi-perspective feature fusion is required to achieve the integrity of the crack features.
[0119] The method of adding dynamic snake convolution to the backbone network of the basic Yolov7 model and performing multi-feature fusion includes:
[0120] Acquire multiple crack features extracted from the same pavement crack by the dynamic serpentine convolution from multiple different directions;
[0121] The multiple crack features are fused to obtain a fused feature of the same road surface crack.
[0122] The principles of dynamic snake convolution include:
[0123] Given the standard two-dimensional convolution coordinates as K, the center coordinates are K i =(x i ,y i ), a 3*3 convolution kernel, expressed as:
[0124] K={(x-1,y-1),(x,y),...,(x+1,y+1)}
[0125] Dynamic snake convolution straightens the standard convolution kernel in the x-axis and y-axis directions. Consider a convolution kernel of size 9. Taking the x-axis direction as an example, the specific position of each grid in K is expressed as: K i±c =(x i±c ,y i±c ), where c = {0, 1, 2, 3, 4} represents the horizontal distance from the center grid. i At the beginning, the position of the grid away from the center depends on the position of the previous grid: K increases an offset Δ = {δ|δ∈[-1,1]} compared to K, then the convolution kernel can be expressed by the following formula:
[0126]
[0127]
[0128] The principle of multi-view feature fusion includes:
[0129] For each snake-shaped dynamic convolution K, two feature maps f of layer l are extracted from the x-axis and y-axis respectively. l (K x ) and f l (K y ), expressed as: f l (K) = {∑ i w(K i )·f l (K i ),∑ j w(K i )·f l (K j )}, where w(K i ) represents K i The weight of .
[0130] The O-IOU loss function can improve the detection accuracy of small cracks and potholes while ensuring that the detection accuracy of large-span crack targets is not reduced. The IOU loss function calculates the loss based on the intersection-over-union ratio of the real box and the predicted box, which usually makes its loss very sensitive to tiny targets. Often a single-digit deviation will lead to a reversal of the label, which in turn makes model training difficult. NWD is insensitive to objects of different scales and is therefore more suitable for measuring the similarity between tiny objects. NWD can model the bounding box as a two-dimensional Gaussian distribution, and the similarity between bounding boxes A and B can be converted into the distribution distance between two Gaussian distributions. Therefore, the loss function that integrates the NWD metric and the IOU metric can ensure that the detection accuracy of large-span crack targets is not reduced while improving the detection accuracy of small cracks and potholes.
[0131] The fusion loss function is expressed by the following formula: N-IOU=λNWD+(1-λ)IOU, where λ represents the fusion coefficient.
[0132] NWD loss can be expressed by the following formula:
[0133]
[0134]
[0135] Among them, the true bounding box is expressed as: N a =(cx a ,cy a ,w a ,h a ), the predicted bounding box is represented as: N b =(cx b ,cy b ,w b ,h b ), C represents a constant related to the data set. The IOU loss function is expressed by the following formula: Among them, A represents the real box and B represents the predicted box.
[0136] In the embodiment of the present invention, the basic Yolov7 model is improved by a preset improvement mechanism to obtain an improved Yolov7 model; the improved Yolov7 model is trained based on the labeled pavement crack image to obtain a trained Yolov7 model; the pavement crack image to be identified is identified by the trained Yolov7 model to obtain the crack identification result. The pavement crack identification is fast and accurate, and the recognition efficiency of irregular cracks is improved in particular by dynamic serpentine convolution.
[0137] like Figure 7 FIG. 6 is a structural diagram of a system for identifying pavement cracks based on a Yolov7 model according to another embodiment of the present invention. The trained Yolov7 model acquisition module 602 includes:
[0138] An image data set acquisition unit 701 is used to acquire an image data set of annotated pavement crack images;
[0139] An image data set division unit 702, configured to divide the image data set into a training set and a validation set;
[0140] An initial training Yolov7 model acquisition unit 703 is used to train the improved Yolov7 model through the training set to acquire an initial training Yolov7 model;
[0141] The verified Yolov7 model acquisition unit 704 verifies the initially trained Yolov7 model through the verification set to obtain a verified Yolov7 model.
[0142] In an embodiment of the present invention, firstly, an image data set of annotated pavement crack images is obtained, which may be an image data set directly downloaded from the Internet, or an image data set obtained after annotating a plurality of pavement crack images captured and accumulated, and the image data set is divided into a training set and a verification set according to a preset ratio, and the improved Yolov7 model is trained through the training set, and the training content includes: adjusting the training parameters of the Yolov7 model, obtaining the optimal weight file, and when the loss value of the initial training Yolov7 model reaches the minimum and converges, the weight of the Yolov7 model is optimal, and the training of the training set is completed. Finally, the initial training Yolov7 model is verified through the verification set to obtain the verified Yolov7 model.
[0143] The step of verifying the initially trained Yolov7 model by using the verification set, and if the verification passes, determining the initially trained Yolov7 model as a verified Yolov7 model, comprises:
[0144] The accuracy, recall, harmonic mean F1 of the accuracy and recall, and average precision mAP of each category of the initially trained Yolov7 model are verified by the validation set, including: Obtain the accuracy; and, by formula Obtain the recall rate; and, by formula Obtain the harmonic mean of the precision and recall; and, by formula Get the average precision of each category;
[0145] Comparing the accuracy, recall, harmonic mean of precision and recall, and average precision of each category with preset thresholds respectively, including: comparing the accuracy with a preset accuracy threshold; and, comparing the recall with a preset recall threshold; and, comparing the harmonic mean of precision and recall with a preset harmonic mean threshold of precision and recall; and, comparing the average precision of each category with a preset average precision threshold of each category;
[0146] If the accuracy, recall, harmonic mean of precision and recall, and average precision of each category are all better than corresponding thresholds, the verification is passed, and the initially trained Yolov7 model is determined as a verified Yolov7 model.
[0147] like Figure 8 FIG. 7 is a structural diagram of a road crack recognition system based on the Yolov7 model provided by another embodiment of the present invention. The image data set acquisition unit 701 includes:
[0148] The road crack image data acquisition unit 801 is used to acquire road crack image data captured by a handheld camera and / or an unmanned camera, wherein the crack types include: transverse cracks, vertical cracks, mesh cracks, and potholes;
[0149] The cleaned road crack image data acquisition unit 802 is used to clean the road crack image data to acquire cleaned road crack image data, wherein the cleaning includes: removing incomplete or unclear road crack image data;
[0150] The annotated road crack image acquisition unit 803 is used to annotate the cleaned road crack image data with the crack type using a preset annotation tool to acquire an annotated road crack image.
[0151] The encoding unit 804 is used to encode different types of annotated pavement crack images using a preset encoding tool.
[0152] Specifically, the encoding tool represents each type of crack as a vector of length 4, in which only one element is 1 and the rest are 0, such as a mesh crack can be represented as [1,0,0,0]. After the encoding is completed, a corresponding XML format annotation file can also be generated to facilitate the subsequent process to call the annotation file.
[0153] The encoding tool can be selected according to actual use needs, and the present application does not limit the selection of the encoding tool. Preferably, the encoding tool is One-hot encoding.
[0154] As an optional embodiment of the present invention, after encoding different types of annotated pavement crack images by using a preset encoding tool, the method further includes:
[0155] Rotating, adjusting brightness and contrast of the annotated pavement crack image to obtain an enhanced pavement crack image;
[0156] Applying a preset data enhancement strategy to the enhanced pavement crack image to generate a pseudo disease image;
[0157] A one-to-one correspondence is established between the pseudo disease image and the code.
[0158] In the embodiment of the present invention, the rotation operation of the annotated road crack image can be implemented by the flip image function flip and the rotate image function rotate in the Opencv library of Python, the brightness adjustment operation is implemented by the brightness adjustment function convertScaleAbs, and the contrast adjustment operation is implemented by the contrast adjustment function addWeighted. By simulating road detection scenes under different lighting conditions, the generalization of the data set can be improved while enriching the data set.
[0159] Among them, the data enhancement strategy can be selected according to the needs of actual use, and this application does not limit the specific data enhancement strategy. Preferably, the data enhancement strategy is a CutPaste data enhancement strategy. The implementation method of this data enhancement strategy is: cutting the abnormal disease area, and then pasting the abnormal disease area to a random area of the normal image, thereby generating a pseudo crack image similar to the real crack image, so as to improve the diversity of pavement cracks.
[0160] Fig. 9 An example of a physical structure diagram of an electronic device is shown in FIG. Fig. 9As shown, the electronic device may include: a processor (processor) 901, a communication interface (Communications Interface) 902, a memory (memory) 903 and a communication bus 904, wherein the processor, the communication interface and the memory communicate with each other through the communication bus. The processor may call the logic instructions in the memory to execute the method for pavement crack recognition based on the Yolov7 model, the method comprising: improving the basic Yolov7 model through a preset improvement mechanism to obtain an improved Yolov7 model, the improvement mechanism comprising: adding an EMA attention mechanism, adding a dynamic snake convolution, and replacing an IOU loss function; training the improved Yolov7 model based on an image data set of annotated pavement crack images to obtain a trained Yolov7 model; performing crack recognition on the pavement crack image to be recognized through the trained Yolov7 model to obtain the crack recognition result.
[0161] In addition, the logic instructions in the above-mentioned memory can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0162] On the other hand, an embodiment of the present invention further provides a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium, and the computer program includes program instructions. When the program instructions are executed by a computer, the computer can execute the method for pavement crack identification based on the Yolov7 model provided by the above-mentioned method embodiments, the method including: improving the basic Yolov7 model through a preset improvement mechanism to obtain an improved Yolov7 model, the improvement mechanism including: adding an EMA attention mechanism, adding a dynamic serpentine convolution, and replacing an IOU loss function; training the improved Yolov7 model based on an image data set of annotated pavement crack images to obtain a trained Yolov7 model; performing crack identification on the pavement crack image to be identified through the trained Yolov7 model to obtain the result of the crack identification.
[0163] On the other hand, an embodiment of the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, it is implemented to execute the method for pavement crack identification based on the Yolov7 model provided in the above-mentioned embodiments, the method comprising: improving the basic Yolov7 model through a preset improvement mechanism to obtain an improved Yolov7 model, the improvement mechanism comprising: adding an EMA attention mechanism, adding a dynamic serpentine convolution, and replacing an IOU loss function; training the improved Yolov7 model based on an image data set of annotated pavement crack images to obtain a trained Yolov7 model; performing crack identification on the pavement crack image to be identified through the trained Yolov7 model to obtain the crack identification result.
[0164] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0165] The above is only a partial implementation of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. A method for identifying pavement cracks based on the Yolov7 model. It is characterized in that The method comprises: The basic Yolov7 model is improved through a preset improvement mechanism to obtain an improved Yolov7 model, wherein the improvement mechanism includes: adding an EMA attention mechanism, adding a dynamic snake convolution, and replacing an IOU loss function; Training the improved Yolov7 model based on an image dataset of annotated pavement crack images to obtain a trained Yolov7 model; Crack recognition is performed on the road surface crack image to be recognized by using the trained Yolov7 model to obtain the crack recognition result.
2. The method according to claim 1, It is characterized in that The method of improving the basic Yolov7 model by a preset improvement mechanism to obtain an improved Yolov7 model includes: The following improvements are made in the basic Yolov7 model: adding an EMA attention mechanism at the end of the head network of the basic Yolov7 model; adding dynamic snake convolution to the backbone network of the basic Yolov7 model and performing multi-feature fusion; and replacing the IOU loss function in the basic network of the basic Yolov7 model with an N-IOU loss function that fuses the NWD metric and the IOU metric.
3. The method according to claim 1, It is characterized in that The step of training the improved Yolov7 model based on the image dataset of the annotated pavement crack images to obtain the trained Yolov7 model includes: Obtain an image dataset of annotated pavement crack images; Dividing the image dataset into a training set and a validation set; The improved Yolov7 model is trained by using the training set to obtain an initial training Yolov7 model; The initially trained Yolov7 model is verified by using the verification set to obtain a verified Yolov7 model.
4. The method according to claim 3, It is characterized in that The verifying the initially trained Yolov7 model by the verification set, and if the verification passes, determining the initially trained Yolov7 model as a verified Yolov7 model, comprises: The accuracy, recall, harmonic mean F1 of the accuracy and recall, and average precision mAP of each category of the initially trained Yolov7 model are verified by the validation set, including: Obtain the accuracy; and, by formula Obtain the recall rate; and, by formula Obtain the harmonic mean of the precision and recall; and, by formula Get the average precision of each category; Comparing the accuracy, recall, harmonic mean of precision and recall, and average precision of each category with preset thresholds respectively, including: comparing the accuracy with a preset accuracy threshold; and, comparing the recall with a preset recall threshold; and, comparing the harmonic mean of precision and recall with a preset harmonic mean threshold of precision and recall; and, comparing the average precision of each category with a preset average precision threshold of each category; If the accuracy, recall, harmonic mean of precision and recall, and average precision of each category are all better than corresponding thresholds, the verification is passed, and the initially trained Yolov7 model is determined as a verified Yolov7 model.
5. The method according to claim 1, It is characterized in that The step of obtaining an image dataset of annotated pavement crack images comprises: Acquire road crack image data captured by a handheld camera and / or an unmanned camera, wherein the crack types include: transverse cracks, vertical cracks, mesh cracks, and potholes; Cleaning the road crack image data to obtain cleaned road crack image data, wherein the cleaning includes: removing incomplete or unclearly focused road crack image data; Annotating the cleaned road crack image data with the crack type using a preset annotation tool to obtain an annotated road crack image; Different types of annotated pavement crack images are encoded using a preset encoding tool.
6. The method according to claim 5, It is characterized in that After encoding the different types of annotated pavement crack images by using a preset encoding tool, the method further includes: Rotating, adjusting brightness and contrast of the annotated pavement crack image to obtain an enhanced pavement crack image; Applying a preset data enhancement strategy to the enhanced pavement crack image to generate a pseudo disease image; A one-to-one correspondence is established between the pseudo disease image and the code.
7. The method according to claim 2, It is characterized in that The dynamic snake convolution is added to the backbone network of the basic Yolov7 model, and multi-feature fusion is performed, including: Acquire multiple crack features extracted from the same pavement crack by the dynamic serpentine convolution from multiple different directions; The multiple crack features are fused to obtain a fused feature of the same road surface crack.
8. A system for identifying pavement cracks based on the Yolov7 model. It is characterized in that The system comprises: An improved Yolov7 model acquisition module is used to improve the basic Yolov7 model through a preset improvement mechanism to obtain an improved Yolov7 model. The improvement mechanism includes: adding an EMA attention mechanism, adding a dynamic snake convolution, and replacing an IOU loss function; A trained Yolov7 model acquisition module is used to train the improved Yolov7 model based on an image dataset of annotated pavement crack images to acquire a trained Yolov7 model; The crack recognition result acquisition module is used to perform crack recognition on the pavement crack image to be identified by using the trained Yolov7 model to obtain the crack recognition result.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, It is characterized in that When the processor executes the program, the method for identifying pavement cracks based on the Yolov7 model as described in any one of claims 1 to 6 is implemented.
10. A non-transitory computer-readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the method for identifying pavement cracks based on the Yolov7 model as described in any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Non-negative sample small target detection method in transformer substation intelligent identification system
CN116823750A
PCB defect detection method based on improved YOLO v5 algorithm
CN117351288A
Road crack detection method based on improved YOLOv7
CN117437201A
