Shore crane defect detection method based on YOLOv5 improvement

By introducing dynamic convolution and CA attention modules in YOLOv5, replacing the detection head with Dyhead, and using the NWD loss function, the problem of missed detection of large spans and small targets in quay crane defect detection has been solved, and detection accuracy and performance have been improved.

CN118691973AInactive Publication Date: 2024-09-24SHANGHAI DIANJI UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410794873.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-19
Publication Date
2024-09-24
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

In the defect detection of quay cranes, there are problems such as target detection and recognition, such as large defect scale span, difficulty in distinguishing similar defects, and easy missed detection of small target defects. The existing technology has poor detection performance, high false detection rate, and insufficient feature extraction capabilities.

Method used

Based on the improved detection method of YOLOv5, dynamic convolution and CA attention modules are introduced, the detection head is replaced by the Dyhead dynamic detection head, and the NWD loss function is used to replace the CIoU loss function to optimize target defect detection.

Benefits of technology

It improves the average accuracy of surface defect detection of quay cranes, enhances the detection ability of small target defects, improves the expression and computing power of the network, and reduces missed detections and false detections.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118691973A
    Figure CN118691973A
Patent Text Reader

Abstract

The invention discloses a quay crane defect detection method based on YOLOv5 improvement, and the method comprises the following steps: S1, introducing dynamic convolution based on a YOLOv5 network structure, and introducing a CA attention module into the dynamic convolution; s2, replacing a detection head part of the YOLOv5s model with a Dyhead dynamic detection head; and S3, replacing the CIoU loss function with an NWD loss function to carry out target defect detection optimization so as to complete optimization. An improved YOLOv5s target detection method is used for detecting the surface defects of the quay crane, based on YOLOv5s as a basic model, self-adaptive adjustment dynamic convolution is introduced to improve the expression ability and the calculation ability of a network, and a CA attention mechanism and a dynamic detection head are introduced to further improve the detection precision of the network, so that the detection accuracy of the quay crane is improved. And finally, replacing a CIoU loss function with an NWD loss function to increase the detection capability of small target defects.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of machine vision detection, and in particular to a quay crane defect detection method improved based on YOLOv5. Background Art

[0002] Quay cranes, also known as shore container cranes, are the main equipment used to load and unload containers between container ships and the front of the wharf. They are generally installed on the shore of the port wharf. Due to the particularity of its environment and work tasks, daily inspection and maintenance are indispensable. However, surface defects are small and difficult to observe directly, so deep learning methods are often used for defect detection.

[0003] After searching, the Chinese patent with announcement number CN115359016A discloses a PCB small target defect detection method and system based on improved YOLOv5. It proposes a technical solution to solve the problems of insufficient feature extraction capability, high false detection rate and poor detection performance by improving the target defect detection algorithm of YOLOv5 to realize PCB small target defect detection;

[0004] The Chinese patent with the announcement number CN115880264A discloses a method for detecting aluminum sheet defects based on YOLOv5, which proposes a technical solution for detecting aluminum sheet defects by image analysis using the YOLOv5 target detection network.

[0005] However, for quay crane defect detection, there are problems in the process of target detection and identification, such as large scale span of quay crane surface defects, difficulty in distinguishing similar defects, and missed detection of small target defects. Therefore, how to improve the average accuracy of detection and solve the missed detection and false detection that may occur in the detection of small target defects is an urgent problem to be solved. Summary of the invention

[0006] The purpose of the present invention is to solve the defects in the prior art and propose a quay crane defect detection method based on improved YOLOv5.

[0007] In order to achieve the above object, the present invention adopts the following technical solutions:

[0008] A quay crane defect detection method based on improved YOLOv5 includes the following steps:

[0009] S1: Introducing dynamic convolution based on the network structure of YOLOv5, and introducing CA attention module in dynamic convolution;

[0010] S2: Replace the detection head of the YOLOv5s model with the Dyhead dynamic detection head;

[0011] S3: Use the NWD loss function to replace the CIoU loss function to optimize the target defect detection and complete the optimization.

[0012] Furthermore, in step 1, the dynamic convolution structure is a 3×3 dynamic convolution. A temperature mechanism is introduced in the dynamic convolution layer, and the optimal solution is obtained through a uniform temperature annealing strategy. The relationship between the attention weight of the kth linear function and variables such as temperature is as follows:

[0013]

[0014] where z k is the kth output of the second fully connected layer in the attention branch, z j is the jth output, τ is the temperature, and the original softmax is equivalent to the case of τ = 1;

[0015] By controlling the initial temperature, number of iterations, annealing rate and termination temperature, the proposed diagnostic network can obtain the global optimal solution within a limited time.

[0016] Furthermore, in step 1, the steps for introducing the CA attention module are as follows:

[0017] First, the input feature map is globally averaged in width and height directions using pooling kernels of size (H, 1) and (1, W) to obtain feature maps in width and height directions.

[0018] Assuming that the width of the input feature map is w and the height is h, the output of the cth channel after average pooling is as follows:

[0019]

[0020] Through this transformation, we get a pair of direction-aware feature maps and in Capture vertical information. Capture information in the horizontal direction;

[0021] Then and After Concat connection, Conv 2d convolution and ReLU activation, an intermediate feature map f is generated, as shown in the following formula:

[0022] f=σ(F1([Z h ,Z ω ]))

[0023] The intermediate feature map f is split into two single tensors along the spatial dimension, and two 1×1 convolutions fh and fw are used for σ transformation. The attention adaptive weights gh and gw of the feature map in the spatial dimension h and the spatial dimension w are obtained through the Sigmoid activation function, as shown in the following formula:

[0024] g h =σ(F h (f h )),g w =δ(F w (f w ));

[0025] Finally, the original feature map is weighted to obtain the feature map yc with attention weights in width and height directions, as shown in the following formula.

[0026]

[0027] Furthermore, in step S2, replacing the dynamic detection head specifically includes adding an attention mechanism to each specific dimension of the feature tensor. The specific process is as follows:

[0028] Redefine the four-dimensional tensor L×H×W×C into a three-dimensional tensor L×S×C;

[0029] Use scale-aware attention, space-aware attention, and task-aware attention in the L, S, and C dimensions, respectively;

[0030] Given a three-dimensional feature tensor F∈R on the detection layer L×S×C ,The calculation formula of the attention function is shown in formula (9):

[0031] W(F)=π C (π S ·(π L (F)·F)·F)·F(9)

[0032] Among them, πL(·), πS(·), and πC(·) are three different attention functions applied on dimensions L, S, and C respectively;

[0033] Three attention sequences are applied to detect heads and can be used multiple times in a stack.

[0034] Furthermore, in step S3, the bounding box is represented by a two-dimensional Gaussian distribution, and the similarity between the predicted box and the true box is calculated by its corresponding Gaussian distribution. The calculation formula of the NWD loss function is as follows:

[0035]

[0036] Where W 2 (N,N GT) represents the Wasserstein distance between the predicted box and the true box; N, N GT are the two-dimensional Gaussian distributions of the predicted box and the true box respectively; C represents a constant set according to the target size in the dataset.

[0037] Compared with the prior art, the present invention has the following beneficial effects:

[0038] By adopting the improved YOLOv5s target detection method for the detection of surface defects of quay cranes, based on YOLOv5s as the basic model, the adaptive dynamic convolution is introduced to improve the network's expression and computing capabilities. The CA attention mechanism and Dyhead dynamic detection head are introduced to further improve the network's detection accuracy. Finally, the NWD loss function is used to replace the CIoU loss function to increase the detection capability of small target defects. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] The accompanying drawings are used to provide further understanding of the present invention and constitute a part of the specification. They are used to explain the present invention together with the embodiments of the present invention and do not constitute a limitation of the present invention.

[0040] Figure 1 It is a schematic diagram of the implementation logic of the improved quay crane defect detection method based on YOLOv5 in an embodiment of the present invention;

[0041] Figure 2 is a structural diagram of a dynamic sensor in this embodiment;

[0042] Figure 3 This is a structural diagram of the CA attention module in an embodiment of the present invention. DETAILED DESCRIPTION

[0043] The technical solutions in the embodiments of the present invention will be described clearly and completely below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments.

[0044] Reference Figure 1 ,The improved quay crane defect detection method based on YOLOv5 includes the following steps:

[0045] S1: Introducing dynamic convolution based on the network structure of YOLOv5, and introducing CA attention module in dynamic convolution;

[0046] S2: Replace the detection head of the YOLOv5s model with the Dyhead dynamic detection head;

[0047] S3: Use the NWD loss function to replace the CIoU loss function to optimize the target defect detection and complete the optimization.

[0048] In this embodiment, the data is the integration of the surface defect data of the quay crane collected by the drone and the magnetic particle inspection image data collected by the magnetic particle inspection robot to produce a complete data set.

[0049] As a preferred embodiment of the present application, it should be noted that in step 1, dynamic convolution is implemented by using the attention mechanism, the input data is sent to an attention module, and for each position of the input data, the attention distribution will give a weight to adjust the shape of the convolution kernel at that position, which can help the model better capture the features of objects of different scales, where:

[0050] The expressions of static perceptron and dynamic perceptron are shown in equations (1) and (2):

[0051] y=g(W T x+b) (1)

[0052]

[0053] Where x is input, y is output; W, b, g are weight, bias and activation function respectively; π k is the attention weight of the kth linear function, 0≤π k (x)≤1, are the weight and bias of the kth input, k = 1, 2, 3…, k; aggregation weight and bias is a function of the input, with the same attention.

[0054] like Figure 2 , Figure 2 This is the structural diagram of the dynamic perceptron. Due to the attention weight π k It changes with the input, and it aggregates the best weights of the input. Therefore, compared with the static perceptron, the dynamic perceptron has a stronger ability to express the characteristics of the overall network.

[0055] π(x) is the attention weight; π1 is the first attention weight of the input; π2 is the second attention weight of the input; π k is the kth attention weight of the input.

[0056] In step 1, the dynamic convolution structure is a 3×3 dynamic convolution. The temperature mechanism is introduced in the dynamic convolution layer, and the optimal solution is obtained through a uniform temperature annealing strategy. The relationship between the attention weight of the kth linear function and variables such as temperature is as follows:

[0057]

[0058] where z kis the kth output of the second fully connected layer in the attention branch, z j is the jth output, τ is the temperature, and the original softmax is equivalent to the case of τ = 1;

[0059] By controlling the initial temperature, number of iterations, annealing rate and termination temperature, the proposed diagnostic network can obtain the global optimal solution within a limited time.

[0060] As a preferred embodiment of the present application, the structure diagram of the CA attention module is as follows: Figure 3 As shown;

[0061] In step 1, the steps to introduce the CA attention module are as follows:

[0062] First, the input feature map is globally averaged in width and height directions using pooling kernels of size (H, 1) and (1, W) to obtain feature maps in width and height directions.

[0063] Assuming that the width of the input feature map is w and the height is h, the output of the cth channel after average pooling is as follows:

[0064]

[0065] Through this transformation, we get a pair of direction-aware feature maps and in Capture vertical information. Capture information in the horizontal direction;

[0066] Then and After Concat connection, Conv 2d convolution and ReLU activation, an intermediate feature map f is generated, as shown in the following formula:

[0067] f=σ(F1([Z h ,Z ω ]))

[0068] The intermediate feature map f is split into two single tensors along the spatial dimension, and two 1×1 convolutions fh and fw are used for σ transformation. The attention adaptive weights gh and gw of the feature map in the spatial dimension h and the spatial dimension w are obtained through the Sigmoid activation function, as shown in the following formula:

[0069] g h =σ(F h (f h )),g w =δ(F w (f w ));

[0070] Finally, the original feature map is weighted to obtain the feature map yc with attention weights in width and height directions, as shown in the following formula.

[0071]

[0072] As a preferred embodiment of the present application, in step S2, replacing the dynamic detection head specifically includes: adding an attention mechanism to each specific dimension of the feature tensor, and the specific process is as follows:

[0073] Redefine the four-dimensional tensor L×H×W×C into a three-dimensional tensor L×S×C;

[0074] Use scale-aware attention, space-aware attention, and task-aware attention in the L, S, and C dimensions, respectively;

[0075] Given a three-dimensional feature tensor F∈R on the detection layer L×S×C ,The calculation formula of the attention function is shown in formula (9):

[0076] W(F)=π C (π S ·(π L (F)·F)·F)·F(9)

[0077] Among them, πL(·), πS(·), and πC(·) are three different attention functions applied on dimensions L, S, and C respectively;

[0078] Three attention sequences are applied to detect heads and can be used multiple times in a stack.

[0079] It should be noted that the three attention mechanisms are as follows:

[0080] 1: The scale-aware attention module fuses features of different scales according to the semantic importance of different scales, as shown in equation (10). Where F is a linear function that approximates a 1×1 convolution. σ(x) is a hard-sigmoid functionσ(x)=max(0,min(1,(x+1) / 2)). The introduction of this mechanism can enhance the scale perception ability of the model.

[0081]

[0082] 2: The spatial perception attention module first uses deformable convolution to learn sparsity, and then aggregates cross-layer features at the same spatial position. Its expression is shown in Equation (11). K is the number of sparse sampling positions, pk+Δpk is the position offset to focus on the discriminative area, and Δmj is an important scalar self-learned at position pj. The introduction of this mechanism can enhance the spatial position perception ability of the model.

[0083]

[0084] 3: Task-aware attention module dynamically opens or closes feature channels and selects different tasks. Its expression is shown in formula (11). The introduction of this model can enhance the model's ability to perceive different tasks.

[0085] π C (F)·F=max(α 1 (F)·F C +β 1 (F),α 2 (F)·F C +β 2 (F)) (11)

[0086] Among them, [α 1 ,β 1 ,α 2 ,β 2 ] is a hyperfunction designed to train the process of learning to control the activation threshold.

[0087] As a preferred embodiment of the present application, in step S3, it should be noted that Intersection over Union (IoU) is a commonly used loss function in target detection, which is often used to evaluate the positional relationship between the real box and the predicted box. The expression is shown in formula (12):

[0088]

[0089] Among them, B is the center point of the prediction box given by the network, B GT is the center point of the real box. If the predicted box and the real box do not overlap, the IoU value will degenerate to 0 and the IoU positioning loss will not be calculated.

[0090] To address this problem, YOLOv5 uses an improved loss function called Complete-IoU (CIoU), which adds two penalty terms, distance and aspect ratio, to the IoU loss function.

[0091] The expressions of CIoU loss function are shown in (13), (14) and (15):

[0092]

[0093] Where: ρ is the Euclidean distance between the two center points of the real box and the predicted box; v is used to calculate the similarity between the width and height of the two boxes; ω GT With h GT are the width and height of the real box respectively; w and h are the width and height of the predicted box; α is the weight factor of the width and height similarity.

[0094] Although CIoU solves the problem of zero gradient when there is no overlap in IoU, and considers the similarity between the distance between the center points of two boxes and the aspect ratio, it is still very sensitive to position offset because it is based on IoU. Under the same distance offset, the IoU decrease rate of small-sized objects is much greater than that of large-sized objects.

[0095] In step S3, the bounding box is represented by a two-dimensional Gaussian distribution, and the similarity between the predicted box and the real box is calculated by its corresponding Gaussian distribution. The calculation formula of the NWD loss function is as follows:

[0096]

[0097]

[0098] Where W 2 (N,N GT ) represents the Wasserstein distance between the predicted box and the true box; N, N GT are the two-dimensional Gaussian distributions of the predicted box and the true box respectively; C represents a constant set according to the target size in the dataset.

[0099] The above description is only a preferred specific implementation manner of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can make equivalent replacements or changes according to the technical scheme and inventive concept of the present invention within the technical scope disclosed by the present invention, which should be covered by the protection scope of the present invention.

Claims

1. An improved quay crane defect detection method based on YOLOv5, It is characterized in that The following steps are involved: S1: Introducing dynamic convolution based on the network structure of YOLOv5, and introducing CA attention module in dynamic convolution; S2: Replace the detection head of the YOLOv5s model with a dynamic detection head; S3: Use the NWD loss function to replace the CIoU loss function for target defect detection optimization, and perform defect detection based on the input defect dataset.

2. According to the improved quay crane defect detection method based on YOLOv5 according to claim 1, It is characterized in that In step 1, the dynamic convolution structure is a 3×3 dynamic convolution. The temperature mechanism is introduced in the dynamic convolution layer, and the optimal solution is obtained through a uniform temperature annealing strategy. The relationship between the attention weight of the kth linear function and variables such as temperature is as follows: where z k is the kth output of the second fully connected layer in the attention branch, z j is the jth output, τ is the temperature, and the original softmax is equivalent to the case of τ = 1; By controlling the initial temperature, number of iterations, annealing rate and termination temperature, the proposed diagnostic network can obtain the global optimal solution within a limited time.

3. According to the improved quay crane defect detection method based on YOLOv5 according to claim 2, It is characterized in that In step 1, the steps to introduce the CA attention module are as follows: First, the input feature map is globally averaged in width and height directions using pooling kernels of size (H, 1) and (1, W) to obtain feature maps in width and height directions. Assuming that the width of the input feature map is w and the height is h, the output of the cth channel after average pooling is as follows: Through this transformation, we get a pair of direction-aware feature maps and in Capture vertical information. Capture information in the horizontal direction; Then and After Concat connection, Conv2d convolution and ReLU activation, an intermediate feature map f is generated, as shown in the following formula: f=σ(F 1 ([WITH h ,WITH ω ])) The intermediate feature map f is split into two single tensors along the spatial dimension, and two 1×1 convolutions fh and fw are used for σ transformation. The attention adaptive weights gh and gw of the feature map in the spatial dimension h and the spatial dimension w are obtained through the Sigmoid activation function, as shown in the following formula: g h =σ(F h (f h )),g w =δ(F w (f w )); Finally, the original feature map is weighted to obtain the feature map yc with attention weights in width and height directions, as shown in the following formula:

4. According to the improved quay crane defect detection method based on YOLOv5 according to claim 3, It is characterized in that In step S2, replacing the dynamic detection head is specifically to add an attention mechanism to each specific dimension of the feature tensor. The specific process is as follows: Redefine the four-dimensional tensor L×H×W×C into a three-dimensional tensor L×S×C; Use scale-aware attention, space-aware attention, and task-aware attention in the L, S, and C dimensions, respectively; Given a three-dimensional feature tensor F∈R on the detection layer L×S×C ,The calculation formula of the attention function is shown in formula (9): W(F)=π C (p S ·(p L (F)·F)·F)·F(9) Among them, πL(·), πS(·), and πC(·) are three different attention functions applied on dimensions L, S, and C respectively; Three attention sequences are applied to detect heads and can be used multiple times in a stack.

5. According to the improved quay crane defect detection method based on YOLOv5 according to claim 4, It is characterized in that In step S3, the bounding box is represented by a two-dimensional Gaussian distribution, and the similarity between the predicted box and the real box is calculated by its corresponding Gaussian distribution. The calculation formula of the NWD loss function is as follows: Where W 2 (N,N GT ) represents the Wasserstein distance between the predicted box and the true box; N, N GT are the two-dimensional Gaussian distributions of the predicted box and the true box respectively; C represents a constant set according to the target size in the dataset.

Citation Information

Patent Citations

  • PCB small target defect detection method and system based on improved YOLOv5

    CN115359016A

  • Aluminum sheet defect detection method based on YOLOv5

    CN115880264A