Weld defect detection method and system based on WGOA-HHO improved YOLOv8

Through the improved YOLOv8 method combining WGOA-HHO optimization algorithm and Canny edge detection, the problem of manual operation and hyperparameter setting in weld defect detection is solved, and efficient and accurate weld defect detection is achieved.

CN119251588AInactive Publication Date: 2025-01-03NANJING UNIV OF INFORMATION SCI & TECH
View PDF 0 Cites 4 Cited by

Patent Information

Application Number
CN202411510280.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-28
Publication Date
2025-01-03
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

The existing weld defect detection methods rely on manual operations and are easily affected by human fatigue and subjective judgment differences. The hyperparameter settings of deep learning models require manual adjustment, making it difficult to adjust adaptively, resulting in insufficient detection accuracy and consistency.

Method used

Using the improved YOLOv8 method based on WGOA-HHO, weld images are preprocessed through the Canny edge detection algorithm, and the hyperparameters are dynamically adjusted using the WGOA-HHO optimization algorithm, and weld defect detection is carried out in combination with the YOLOv8 model to realize adaptive hyperparameter optimization. and improve detection accuracy.

Benefits of technology

It enhances the robustness and adaptability of weld defect detection, reduces missed inspection and missed inspection problems, improves detection efficiency and accuracy, and solves the uncertainty in the manual parameter adjustment process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119251588A_ABST
    Figure CN119251588A_ABST
Patent Text Reader

Abstract

The invention discloses a welding seam defect detection method and system based on WGOA-HHO improved YOLOv8, and relates to the technical field of deep learning, and the method comprises the following steps: receiving a welding seam image data set, employing a Canny edge detection algorithm to carry out the preprocessing of the welding seam image data set, and obtaining a preprocessed welding seam image data set; the preprocessed weld seam image data set is input into a pre-established YOLOv8 weld seam defect detection model for training, and based on a WGOA-HHO optimization algorithm, an Improved-YOLOv8 model is obtained through output; and acquiring a to-be-detected welding seam image, inputting the to-be-detected welding seam image into the Improved-YOLOv8 model, and outputting to obtain a welding seam defect detection result image.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of deep learning technology, and specifically to a weld defect detection method and system based on WGOA-HHO improved YOLOv8. Background Art

[0002] Weld connections are a key part of many structures and are directly related to the strength and stability of the overall structure. Welds of substandard quality may cause structural failures and increase safety hazards, especially in industries involving high loads and high stresses, such as buildings, pipelines, and vehicles. Common weld defect detection methods such as ultrasonic testing usually rely on manual operation and are easily affected by factors such as human fatigue and subjective judgment differences, resulting in missed detection. Deep learning can achieve automated real-time detection, eliminate human errors, and improve detection accuracy and consistency.

[0003] Before using deep learning to train a dataset, hyperparameters must be set appropriately. Hyperparameters are parameters in deep learning models that cannot be learned directly through training data. They are often artificially set before model training, and these parameters often determine the training and reasoning performance of the model. YOLOv8 contains many hyperparameters. Setting reasonable hyperparameters can improve the accuracy, convergence speed, and overall performance of the model. In practical applications, it is usually necessary to manually tune hyperparameters through experiments to find the best configuration for specific tasks. Therefore, how to adaptively adjust hyperparameters has also become a difficult problem. Summary of the invention

[0004] In order to solve the deficiencies mentioned in the above background technology, the purpose of the present invention is to provide a weld defect detection method and system based on WGOA-HHO improved YOLOv8.

[0005] In the first aspect, the purpose of the present invention can be achieved by the following technical scheme: a weld defect detection method based on WGOA-HHO improved YOLOv8, the method comprising the following steps:

[0006] receiving a weld image data set, and preprocessing the weld image data set using a Canny edge detection algorithm to obtain a preprocessed weld image data set;

[0007] The preprocessed weld image dataset is input into the pre-established YOLOv8 weld defect detection model for training, and based on the WGOA-HHO optimization algorithm, the Improved-YOLOv8 model is output;

[0008] Obtain the weld image to be detected, input the weld image to be detected into the Improved-YOLOv8 model, and output the weld defect detection result image.

[0009] In combination with the first aspect, in certain implementations of the first aspect, the method also includes: the process of preprocessing the weld image data set using the Canny edge detection algorithm includes: Gaussian filtering, calculating image gradients, non-maximum suppression, dual threshold detection, and edge connection and hysteresis thresholds.

[0010] In combination with the first aspect, in some implementations of the first aspect, the method further includes: the Gaussian filtering process:

[0011] The formula for Gaussian filtering is:

[0012]

[0013] Where: G(x,y) is a Gaussian function, which represents the Gaussian value at the position (x,y); is the standard deviation;

[0014] The image gradient is calculated by using the Sobel operator to calculate the gradient in the horizontal and vertical directions;

[0015] The dual threshold detection is achieved by setting two thresholds T high and T low :

[0016] If the gradient magnitude of a pixel G ≥ T high , then the pixel is considered a strong edge;

[0017] If T low ≤G<T high , then the pixel is considered a weak edge;

[0018] If G<T high , then the pixel is considered as a non-edge.

[0019] In combination with the first aspect, in some implementations of the first aspect, the method further includes: the steps of the WGOA-HHO optimization algorithm include: a WGOA global search phase, an HHO predation phase, and a phase of constructing a bidirectional optimization algorithm of WGOA-HHO.

[0020] In combination with the first aspect, in some implementations of the first aspect, the method further includes: the WGOA global search phase process is as follows:

[0021] First, determine the hyperparameters that need to be optimized and their value ranges. The number of hyperparameters is denoted as m.

[0022] Initialize the parameters of WGOA: number of geese in the flock n, current number of iterations t1, maximum number of iterations T1;

[0023] Randomly generate n goose positions, each position corresponds to a set of hyperparameter combinations, then the goose position matrix is ​​expressed as:

[0024]

[0025] Apply the hyperparameter combination of each goose to the YOLOv8 model for training, evaluate the performance on the validation set, and calculate its fitness value; the fitness of n geese is represented as a vector of length n:

[0026] F=[f1,f2,f3…f n ]

[0027] After each round of iteration, the WGOA optimization algorithm selects the goose with the best fitness in the goose flock. The position of this goose represents the current optimal hyperparameter combination, and the positions of the remaining geese are adjusted according to specific update rules. The core of the update process is to gradually move the position of each goose to a better position.

[0028] set up:

[0029] The updated position of the i-th goose is used as the new hyperparameter combination;

[0030] The position of the i-th goose before updating is used as the current hyperparameter combination;

[0031] The wild goose flock optimization algorithm includes two update rules:

[0032] Rule 1: Follow the Leader

[0033] Once the leader goose is determined, the remaining geese will move closer to the leader goose's hyperparameter combination, simulating group following behavior to update their own positions. In the hyperparameter space, the geese will move toward the optimal hyperparameter combination while retaining random perturbations. The update formula is:

[0034]

[0035] in:

[0036] x lea d er is the position of the leader goose; α is the weight for controlling the following of the leader goose, β is the weight for controlling random disturbance; randn() is a standard normal distribution random number;

[0037] Rule 2: Group Behavior

[0038] The behavior form includes two core parts: mutual attraction and keeping distance;

[0039] Distance maintenance: In group behavior, geese will maintain a certain distance to prevent individuals from over-concentrating. The mathematical expression is:

[0040]

[0041] Among them: λ is the weight of distance maintenance, which controls the strength of repulsion; δ ij is the distance measure to neighbor i, defined according to the Euclidean distance;

[0042] Repulsive Prevent individuals from becoming too concentrated;

[0043] The mathematical expression of mutual attraction is:

[0044]

[0045] in:

[0046] x j is the hyperparameter combination of the jth goose, which belongs to the neighbor set N(i) of the i-th goose;

[0047] γ ij is the weight factor;

[0048] Combining the behavior of following the leader with the group influence, we get a comprehensive formula for group behavior:

[0049]

[0050] In the formula represents the behavior of following the leader goose; βgrandn() is randomness; It’s the attraction of the neighborhood; It is the repulsive force;

[0051] In each iteration, the current optimal fitness value and the corresponding hyperparameter combination are recorded.

[0052] In combination with the first aspect, in certain implementations of the first aspect, the method further includes: the HHO predation phase process is as follows:

[0053] Initialize the parameters of HHO: Harris Hawk group number k, current iteration number t2, maximum iteration number T2; initialize the position of Harris Hawk according to the prey position

[0054] x init_hunter =x target

[0055] Where: x target is the position of the prey; x init_hunter It is the initial position of Harris Hawk;

[0056] Add a small random disturbance near the prey to generate k initial positions of the eagle, that is:

[0057] x init_eagle =x target +ηgrandn()

[0058] in:

[0059] η is a constant; randn() is a standard normal distribution random number;

[0060] Each hawk in the Harris hawk group will make a reasonable choice among the four hunting strategies based on the energy E(t) and escape probability P of the wild goose. The energy E(t) of the prey gradually decays with the number of iterations, simulating the exhaustion of the prey's physical strength during the escape process. As the number of iterations increases, the energy of the prey decreases, and the ability to escape becomes weaker, making it easier for the Harris hawk to capture it.

[0061] Prey energy is defined as:

[0062]

[0063] Where E0 is a random number and E0∈[-1,1];

[0064] The escape probability P of the prey is a random number and P∈[0,1]. When P<0.5, the prey escapes successfully, and when P≥0.5, the prey fails to escape.

[0065] Reasonable selection of the four predation strategies is as follows:

[0066] Strategy 1: Soft siege

[0067] When E(t)≥0.5,P≥0.5, Harris's hawk will choose to hover to consume the prey's energy and then catch the prey in the best position. The position update formula is as follows:

[0068] x new =x target -E(t)g|Jgx target -x eagel |

[0069] Where: x new It's the new location for Harris Hawk;x target is the current position of the prey; x eagel is the current position of the Harris Hawk; J is a random constant and J∈[0,1];

[0070] Strategy 2: Hard Siege

[0071] When E(t)<0.5,P≥0.5, the Harris Hawk will choose to attack quickly, and the position update formula is as follows:

[0072] x new =x target -E(t)g|x target -x eagel |

[0073] Strategy 3: Dive and Soft Siege

[0074] When E(t)≥0.5, P<0.5, Harris's hawk will dive to catch prey: Levy flight formula; Harris's hawk will dive while gradually approaching the prey, using irregular dive routes to confuse the prey and increase the chance of successful capture; the position update formula is as follows:

[0075] x new =x target -E(t)g|Jgx target -x eagel |

[0076] x new =x new +sgL(m)

[0077] in:

[0078] L(m) is the Levy flight formula, m is the dimension of the Harris Hawk position, that is, the number of hyperparameters;

[0079] s is an m-dimensional random row vector, that is, s = [s1, s2…, s m ], each element in s conforms to the standard normal distribution with mean 0 and variance 1;

[0080] Strategy 4: Dive and Siege

[0081] When E(t)<0.5,P<0.5, the eagle conducts local search and development of prey and quickly captures prey. The position update formula is as follows:

[0082] x new =x target -E(t)g|x target -x eagel |

[0083] x new =x new +sgL(m)

[0084] Levy's flight formula is as follows:

[0085]

[0086]

[0087] in:

[0088] u and v are both random numbers that follow a standard normal distribution; τ is the control parameter of the Levy distribution; σ is the scaling factor of the Levy distribution;

[0089] Through continuous iterations, the Harris Hawk with the highest fitness value in the Harris Hawk group is the optimal hyperparameter combination.

[0090] In combination with the first aspect, in some implementations of the first aspect, the method further includes: the process of constructing the bidirectional optimization algorithm of WGOA-HHO is as follows:

[0091] Initial stage: WGOA-led, HHO-assisted:

[0092] First, the fitness value of each goose in the total number of n geese is calculated, and the goose with the highest fitness value is the leader goose x leader , the goose with the lowest fitness value is x worst ;

[0093] During the global search of WGOA, HHO-assisted hunting will be based on P HHO Probability trigger;

[0094] When HHO assisted hunting is triggered, HHO will regard the current leader goose as prey and update its position according to the four strategies of Harris Hawk. The updated position is marked as x change ;

[0095] Repeat the steps and continue iterative optimization until the termination condition is reached;

[0096] Dynamic Switch Control:

[0097] After each iteration, it is determined whether the population diversity is lower than the set threshold. If the calculated diversity value is less than the threshold, the later stage is triggered. The diversity is the difference between the highest fitness value and the lowest fitness value in the current iteration result.

[0098] Late stage: WGOA leads, HHO assists:

[0099] The leader goose is used as the prey, and the HHO algorithm is used to update the position of each Harris hawk of the total number of k Harris hawks, and the fitness value is calculated. The hawk with the highest fitness value will be used as the prey of the subsequent iteration, that is, x target ;

[0100] During the HHO search, WGOA assistance will be based on P WGOA trigger;

[0101] When WGOA auxiliary is triggered, WGOA will target As the leader goose, update the positions of the k' hawks with the lowest fitness values ​​in the Harris hawk group;

[0102] Repeat the steps and continue iterative optimization until the termination condition is reached.

[0103] In combination with the first aspect, in some implementations of the first aspect, the method further includes: the calculation process of inputting the weld image to be detected into the Improved-YOLOv8 model and outputting the weld defect detection result image is as follows:

[0104] Improved-YOLOv8 draws the predicted bounding box on the original weld image based on the decoded coordinates. Each defect category and the corresponding confidence score are displayed on the border, and an image containing the weld defect detection results is output. The weld defect detection result image shows all defect locations and category information predicted by the model.

[0105] In the second aspect, in order to achieve the above-mentioned object, the present invention discloses a weld defect detection system based on WGOA-HHO improved YOLOv8, comprising:

[0106] An image processing module is used to receive a weld image data set, and preprocess the weld image data set using a Canny edge detection algorithm to obtain a preprocessed weld image data set;

[0107] The model optimization module is used to input the preprocessed weld image dataset into the pre-established YOLOv8 weld defect detection model for training, and output the Improved-YOLOv8 model based on the WGOA-HHO optimization algorithm;

[0108] The defect detection module is used to obtain the weld image to be detected, input the weld image to be detected into the Improved-YOLOv8 model, and output the weld defect detection result image.

[0109] In another aspect of the present invention, in order to achieve the above-mentioned purpose, a terminal device is disclosed, including a memory, a processor, and a computer program stored in the memory and capable of running on the processor, wherein the memory stores a computer program capable of running on the processor, and when the processor loads and executes the computer program, the weld defect detection method based on WGOA-HHO improved YOLOv8 as described above is adopted.

[0110] Beneficial effects of the present invention:

[0111] The present invention:

[0112] 1. Enhanced weld defect detection

[0113] In view of the problem that weld types are difficult to detect automatically, the present invention uses a combination of Canny edge detection and YOLOv8 for automatic detection. Weld defect detection faces challenges such as uneven weld surface and environmental noise interference. The Canny edge detection algorithm can accurately capture the boundary features of welds, especially effectively segment the weld area under complex backgrounds, and reduce errors caused by noise. At the same time, a small target detection head and an attention mechanism module are added to YOLOv8, so that it can quickly process various weld shapes and accurately locate even on irregular or inconspicuous welds. This welding defect detection method greatly enhances the robustness and adaptability of the system in industrial weld defect detection, and reduces the problems of missed detection and false detection in traditional methods.

[0114] 2. Adaptive Hyperparameter Optimization

[0115] Traditional weld defect detection methods usually rely on fixed hyperparameter settings and are difficult to adapt to different weld types and industrial scenarios. The present invention organically combines WGOA and HHO, and the system can adaptively optimize hyperparameters. Specifically, WGOA is used to explore the best hyperparameter combination globally, while HHO performs local refined optimization through a predation strategy. This dynamic adjustment method not only improves the edge recognition accuracy of Canny edge detection, but also enables more efficient target detection in the YOLOv8 model. This optimization method solves the uncertainty in the manual parameter adjustment process and improves detection efficiency and accuracy.

[0116] 3. Dynamic balance between global and local search

[0117] WGOA and HHO are not simply sequential splicing, but an organic combination of the two, simulating the flight of wild geese and the hunting behavior of Harris's hawks, and achieving a dynamic balance between global and local search in the hyperparameter optimization of the weld defect detection model. WGOA emphasizes global exploration to ensure that the hyperparameter combination can find the potential optimal solution in the global scope, while HHO uses its local search mechanism to perform detailed optimization in the local area and quickly approach the optimal solution. At the same time, for the WGOA algorithm, the present invention optimizes the original fixed value to a dynamic adjustment to improve the generalization ability of the model. BRIEF DESCRIPTION OF THE DRAWINGS

[0118] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0119] Figure 1 It is a schematic flow chart of the method of the present invention;

[0120] Figure 2 It is a Canny-YOLOv8 structure diagram in an embodiment of the present invention;

[0121] Figure 3 It is a structural diagram of the YOLOv8 detection model used in the embodiment of the present invention;

[0122] Figure 4 is a structural diagram of the WGOA-HHO optimization algorithm in an embodiment of the present invention;

[0123] Figure 5 1 is a graph showing the detection results of different weld defects under the same environment in an embodiment of the present invention;

[0124] Figure 6 is a schematic diagram of weld defect detection results under other environments of the present invention;

[0125] Figure 7 It is a schematic diagram of the system structure of the present invention. DETAILED DESCRIPTION

[0126] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0127] Embodiment 1:

[0128] like Figure 1 As shown, a weld defect detection method based on WGOA-HHO improved YOLOv8 includes the following steps:

[0129] S101: receiving a weld image dataset, and preprocessing the weld image dataset using a Canny edge detection algorithm to obtain a preprocessed weld image dataset;

[0130] The process of preprocessing the weld image dataset using the Canny edge detection algorithm includes: Gaussian filtering, calculating image gradient, non-maximum suppression, dual threshold detection, and edge connection and hysteresis threshold.

[0131] Specific:

[0132] Download the JPEGWD weld dataset.

[0133] Gaussian filtering.

[0134] First, convert the input color image to a grayscale image. Canny edge detection is usually performed on grayscale images because edge detection focuses on the change in pixel intensity and does not require the use of color information. The pixel conversion formula is based on a linear combination of the RGB color model:

[0135] Gray=0.2989gR+0.5780gG+0.1140gB

[0136] Among them, R, G, and B represent the values ​​of the red, green, and blue channels respectively, and the value of the grayscale image is the weighted average of these three color channels.

[0137] Then, in order to reduce noise, the image is Gaussian filtered. Gaussian filtering is to smooth the image through a standard normally distributed convolution kernel. The formula for Gaussian filtering is:

[0138]

[0139] in:

[0140] G(x,y) is a Gaussian function, which represents the Gaussian value at the position (x,y);

[0141] is the standard deviation, which determines the smoothness of the filter.

[0142] Calculate image gradient

[0143] After Gaussian filtering, the edges are detected by calculating the gradient of the image. The Sobel operator is used to calculate the gradient in the horizontal and vertical directions.

[0144] The convolution kernels of the Sobel operator in two directions are:

[0145]

[0146] Calculate the horizontal and vertical gradients G through convolution x and G y , and then calculate the magnitude and direction of the gradient by the following formula:

[0147] Gradient Magnitude:

[0148]

[0149] Gradient direction:

[0150]

[0151] Non-maximum suppression

[0152] In order to obtain the precise edge position, non-maximum suppression is used to remove inconspicuous edge points. For each pixel, its gradient value is compared with the gradient values ​​of its two neighbors along the gradient direction. If the gradient value of the current pixel is not the local maximum, it is set to 0, otherwise it remains unchanged.

[0153] Dual Threshold Detection

[0154] The edge image after non-maximum suppression may still contain some noise, so double threshold detection is required to divide the pixels into strong edge points, weak edge points, and non-edge points.

[0155] Set two thresholds T high and T low :

[0156] If the gradient magnitude of a pixel G ≥ T high , the pixel is considered to be a strong edge point, and the pixel value is set to 255;

[0157] If T low ≤G<T high , the pixel is considered as a weak edge point;

[0158] If G<T high , the pixel is considered a non-edge point and its value is set to 0.

[0159] Edge Connectivity

[0160] In order to further classify weak edge points, a hysteresis threshold is used to connect weak edge points with strong edge points. Strong edge pixels are directly retained, while weak edge pixels are retained as edge points only when they are connected to strong edge pixels, otherwise they are set to 0. This process can prevent breaks caused by noise or discontinuous edges.

[0161] The edge detection result image is combined with the original image

[0162] The Canny edge detection result is used as an independent layer and superimposed on the original image, so that the edge part is highlighted in different colors in the original image.

[0163] Improve the backbone and head of YOLOv8

[0164] Weld defects usually include tiny cracks, pores, etc. These defects are small in size. The detection head of the YOLOv8 model is based on three feature maps of different sizes, but the smallest is 8×8, which is prone to missed detection or inaccurate positioning of small weld defects. To this end, the present invention adds a 4×4 detection head based on the original YOLOv8 model. At the same time, the GAM attention machine module is added to the backbone of the YOLOv8 model to further enhance its detection capability.

[0165] The YOLOv8 model structure used in this embodiment is as follows Figure 3 shown.

[0166] YOLOv8 training

[0167] The image combined with the edge detection result image and the original image is used as input and iterative training is performed using YOLOv8.

[0168] S102: input the preprocessed weld image data set into a pre-established YOLOv8 weld defect detection model for training, and output an Improved-YOLOv8 model based on the WGOA-HHO optimization algorithm;

[0169] Specifically,

[0170] The structure diagram of the WGOA-HHO optimization algorithm in this embodiment is as follows: Figure 4 shown.

[0171] Specifically, the specific steps for constructing the WGOA-HHO optimization algorithm model are as follows:

[0172] WGOA Search Phase:

[0173] First, determine the hyperparameters that need to be optimized and their value ranges. The number of hyperparameters is denoted as m.

[0174] Initialize the parameters of WGOA: number of wild goose population n, current number of iterations t1, maximum number of iterations T1;

[0175] Randomly generate n positions of geese, each position corresponds to a set of hyperparameter combinations, then the position matrix of the geese can be expressed as:

[0176]

[0177] Apply the hyperparameter combination of each goose to the YOLOv8 model for training, evaluate the performance on the validation set, and calculate its fitness value. The fitness of n geese can be expressed as a vector of length n:

[0178] F=[f1,f2,f3…f n ]

[0179] After each iteration, the WGOA optimization algorithm selects the goose with the best fitness in the flock. The position of this goose represents the current optimal hyperparameter combination, and the positions of the remaining geese are adjusted according to specific update rules. The core of the update process is to gradually move the position of each goose (hyperparameter combination) to a better position, thereby initially improving the performance of the model.

[0180] The specific rules for updating the positions of geese by the WGOA optimization algorithm are as follows:

[0181] Assumptions:

[0182] is the updated position of the i-th goose (i.e., the new hyperparameter combination);

[0183] is the position of the i-th goose before update (i.e. the current hyperparameter combination).

[0184] The new position of each goose is Will be updated according to the following rules:

[0185] Rule 1: Follow the Leader

[0186] Sort the fitness value of each goose, and determine the goose with the highest fitness value as the leader goose.

[0187] Once the leader goose is determined, the rest of the geese will move closer to the leader's hyperparameter combination, simulating group following behavior to update their positions. In the hyperparameter space, the geese will move toward the optimal hyperparameter combination while retaining a certain amount of random disturbance to prevent the algorithm from falling into a local optimum. The update formula is:

[0188]

[0189] in:

[0190] x leader It is the position of the leader goose;

[0191] α is the weight for following the leader goose, and the default value is 0 to 1;

[0192] β is the weight for controlling random disturbances;

[0193] randn() is a standard normally distributed random number used to introduce randomness.

[0194] To ensure that the goose flock optimization algorithm has more random exploration in the early stage and focuses more on following the leader goose in the later stage, α and β are selected using a dynamic adjustment method, and the formula is as follows:

[0195]

[0196]

[0197] Wherein α0 and β0 are initial values, and the values ​​in this embodiment are 0.8 and 0.6 respectively.

[0198] Rule 2: Group Behavior

[0199] In the wild goose flock optimization algorithm, group behavior mainly simulates the interaction between individuals in nature to avoid falling into the local optimal solution. For mathematical formulas, this behavior can be formalized into the following two core parts: mutual attraction and keeping distance.

[0200] Distance maintenance: In group behavior, geese will maintain a certain distance to prevent individuals from over-concentrating and falling into local optimality. This can be expressed by adding a negative force (i.e., the reverse neighbor influence). When two individuals are too close, repulsive force is generated. The mathematical expression is:

[0201]

[0202]

[0203]

[0204] in:

[0205] λ is the weight of distance maintenance, which controls the strength of repulsion. λ0 is the initial value, and the value in this embodiment is 0.5;

[0206] δ ij is the distance measure to neighbor i, calculated using Euclidean geometry;

[0207] δ min is the minimum distance allowed in a flock of geese, and the value in this embodiment is 0.5;

[0208] q is the dimension of the vector (i.e. the number of hyperparameters);

[0209] m is the dimension of the search space (i.e., the total number of hyperparameters), and in this embodiment, the value is 3;

[0210] Repulsive It can prevent individuals from being too concentrated and help the group explore larger search

[0211] Mutual attraction: Geese are not only influenced by the leader, but also by their neighbors (nearby geese). That is, they will refer to the hyperparameter combination of some surrounding geese and adjust their position. The mathematical expression is:

[0212]

[0213] in:

[0214] x j is the hyperparameter combination of the jth goose, which belongs to the neighbor set N(i) of the i-th goose;

[0215] γ ijIt is a small weight factor, usually a random value, which controls the influence of neighbors. This embodiment chooses to use the dynamic distance calculation method to calculate the weight factor. The mathematical expression is as follows:

[0216]

[0217] where δ ij is the distance measure to neighbor i.

[0218] Combining the behavior of following the leader with group influence, we can get a comprehensive formula for group behavior:

[0219]

[0220] The first term in the formula Refers to the behavior of following the leader of the geese.

[0221] The second term βgrandn() in the formula is randomness, which is used to maintain the exploratory nature of the algorithm.

[0222] The third term in the formula is the attraction of neighbors, indicating the cooperation among individuals in group behavior.

[0223] The fourth term in the formula It is a repulsive force used to prevent individuals from over-concentrating.

[0224] In each round of iteration, the goose with the highest fitness value in the goose flock is the leader, which is the optimal hyperparameter combination.

[0225] HHO predation stage

[0226] Initialize the parameters of HHO: Harris Hawk group number k, current iteration number t2, maximum iteration number T2.

[0227] Initialize the position of Harris Hawk based on the prey position:

[0228] x init_hunter =x target

[0229] in:

[0230] x target It is the location of the prey;

[0231] x init_hunter is the Harris Hawk initialization position.

[0232] In order to enhance the global search capability of the HHO algorithm, a small random perturbation is added near the prey to generate the initial position of the Harris Hawk, namely:

[0233] x init_eagle =x target+ηgrandn()

[0234] in:

[0235] η is a small constant that controls the amplitude of the disturbance;

[0236] randn() is a standard normally distributed random number used to increase randomness.

[0237] Each eagle in the Harris hawk group will make a reasonable choice among the four hunting strategies based on the energy E(t) and escape probability P of the prey. Specifically, the energy E(t) of the prey gradually decays with the number of iterations, simulating the exhaustion of the prey's physical strength during the escape process. As the number of iterations increases, the energy of the prey decreases, the ability to escape becomes weaker, and the eagle is more likely to catch it.

[0238] Prey energy is defined as:

[0239]

[0240] Where E0 is a random number and E0∈[-1,1]

[0241] The escape probability P of the prey is a random number and P∈[0,1]. When P<0.5, the prey escapes successfully, and when P≥0.5, the prey fails to escape.

[0242] Since each hawk in a Harris hawk flock is an independent individual, the following will only describe the four hunting strategies of a Harris hawk:

[0243] Strategy 1: Soft siege:

[0244] When E(t)≥0.5,P≥0.5, the prey still has enough energy to jump out of the Harris Hawk's hawk's encirclement, and the Harris Hawk will choose to hover to consume the prey's energy and then catch the prey in the best position. The position update formula is as follows:

[0245] x new =x target -E(t)g|Jgx target -x eagel |

[0246] in:

[0247] x new is the new position (i.e., hyperparameter combination) of the Harris Hawk;

[0248] x target It is the location of the prey;

[0249] x eagel is the current location of Harris Hawk;

[0250] J is a random constant and J∈[0,1].

[0251] Strategy 2: Hard Siege

[0252] When E(t)<0.5,P≥0.5, the prey no longer has enough energy to escape, and the Harris Hawk will choose to attack quickly. The position update formula is as follows:

[0253] x new =x target -E(t)g|x target -x eagel |

[0254] Strategy 3: Dive and Soft Siege

[0255] When E(t)≥0.5, P<0.5, the prey has a higher energy to escape the encirclement and has a high probability of escaping successfully, but the Harris Hawk's hunting method is more complicated, by adding diving hunting behavior. The eagle dives while gradually approaching the prey, using irregular diving routes to confuse the prey and increase the chance of successful capture. The position update formula is as follows:

[0256] x new =x target -E(t)g|Jgx target -x eagel |

[0257] x new =x new +sgL(m)

[0258] in:

[0259] L(m) is the Levy flight formula, m is the dimension of the Harris Hawk position, that is, the number of hyperparameters;

[0260] s is an m-dimensional random row vector, that is, s = [s1, s2…, s m ], each element in s conforms to the standard normal distribution with mean 0 and variance 1.

[0261] Strategy 4: Dive and Siege

[0262] When E(t)<0.5, P<0.5, the prey has low energy and a small probability of escape. Harris's hawk adopts a more intense hunting method, not only approaching the prey directly, but also accelerating the approach speed by diving. At this time, the eagle conducts local search and development of the prey to ensure that the prey is captured quickly. The position update formula is as follows:

[0263] x new =x target -E(t)g|x target -x eagel |

[0264] x new =x new +sgL(m)

[0265] Levy's flight formula is as follows:

[0266]

[0267]

[0268] in:

[0269] Both u and v are random numbers that follow a standard normal distribution;

[0270] τ is the control parameter of Levy distribution, which takes a value of 1.5;

[0271] ω is a scaling factor for the Levy distribution that normalizes the step size of the generation.

[0272] In each round of iteration, the Harris Hawk with the highest fitness value in the Harris Hawk group is the optimal hyperparameter combination.

[0273] Construct the WGOA-HHO bidirectional optimization algorithm, including:

[0274] Initial stage (WGOA-led, HHO-assisted)

[0275] First, calculate the fitness value of each goose (a total of n geese), and the goose with the highest fitness value is the leader goose x leader , the goose with the lowest fitness value is x worst .

[0276] During the global search of WGOA, HHO-assisted hunting will be based on P HHO Probability trigger. HHO ∈[0,1], when P HHO ≥P SET It is triggered when the local search is too frequent, thereby improving the global exploration ability of WGOA. The probability of this embodiment is set to 0.25

[0277] When the HHO assisted hunting is triggered, the HHO will regard the current leader goose as prey and update its position according to the four strategies of the Harris Hawk in step 202. The updated position is marked as x change .

[0278] Repeat the steps to continue iterative optimization until the termination condition is reached.

[0279] Dynamic Switch Control

[0280] After each iteration, it is determined whether the population diversity is lower than the set threshold. If the calculated diversity value is less than the threshold, the later stage is triggered to perform local fine optimization. Diversity is the difference between the highest fitness value and the lowest fitness value in the current iteration result. The mathematical expression is:

[0281] Δf1≤ε1, where ε1 is the minimum threshold of the change value of the fitness, which is set to 0.05 in this embodiment.

[0282] Late stage (WGOA-led, HHO-assisted)

[0283] The leader goose is used as the prey, and the HHO algorithm is used to update the position of each (k) Harris hawk and calculate its fitness value. The hawk with the highest fitness value will be used as the prey in the subsequent iteration, that is, x target .

[0284] During the HHO search, WGOA assistance will be based on P WGOA Trigger, P WGOA ∈[0,1], when P WGOA ≥P SET The probability is set to 0.25 in this embodiment.

[0285] When WGOA auxiliary is triggered, WGOA will target As the leader goose, update the positions of the k' hawks with the lowest fitness values ​​in the Harris hawk group.

[0286] Repeat the steps to continue iterating the optimization until the termination condition is reached. In the later stage, after each iteration of t2 cycles, the best fitness value of the current Harris Hawk group and the best fitness value of the previous 4 Harris Hawk groups are changed by Δf2≤ε2, where ε2 is the minimum threshold of the fitness change value, and the value in this embodiment is 0.05, or the maximum number of HHO iterations T2 is reached, then the optimization algorithm stops iterating. Finally, the position of the hawk with the highest fitness value in the Harris Hawk group is output, that is, the best hyperparameter combination.

[0287] S103: Obtain a weld image to be detected, input the weld image to be detected into the Improved-YOLOv8 model, and output a weld defect detection result image.

[0288] Get the Improved-YOLOv8 model, which includes the following steps:

[0289] Determine the fitness function

[0290] The fitness function selected in this embodiment is mAP, a commonly used evaluation index for target detection.

[0291] Determine the hyperparameters that need to be optimized and their value ranges

[0292] The hyperparameters that need to be optimized in this embodiment are:

[0293] T high :The high threshold in the dual threshold detection part of the Canny edge detection algorithm and T high ∈[100.200];

[0294] T low :The low threshold in the dual threshold detection part of the Canny edge detection algorithm and T low ∈[50,100];

[0295] lrf: final learning rate in YOLOv8 detection model training mode and lrf∈[0.0001,0.01].

[0296] The weld defect detection results of this embodiment are as follows Figure 5 and Figure 6 shown.

[0297] The weld image to be detected is input into the Improved-YOLOv8 model, and the calculation process of outputting the weld defect detection result image is as follows:

[0298] Improved-YOLOv8 draws the predicted bounding box on the original weld image based on the decoded coordinates. Each defect category and the corresponding confidence score are displayed on the border, and an image containing the weld defect detection results is output. The weld defect detection result image shows all defect locations and category information predicted by the model.

[0299] Embodiment 2: In the second aspect, as Figure 7 As shown, in order to achieve the above purpose, the present invention discloses a weld defect detection system based on WGOA-HHO improved YOLOv8, comprising:

[0300] An image processing module 11 is used to receive a weld image data set, and preprocess the weld image data set using a Canny edge detection algorithm to obtain a preprocessed weld image data set;

[0301] The model optimization module 12 is used to input the preprocessed weld image data set into the pre-established YOLOv8 weld defect detection model for training, and output an Improved-YOLOv8 model based on the WGOA-HHO optimization algorithm;

[0302] The defect detection module 13 is used to obtain the weld image to be detected, input the weld image to be detected into the Improved-YOLOv8 model, and output the weld defect detection result image.

[0303] Based on the same inventive concept, the present invention also provides a computer device, which includes: one or more processors, and a memory for storing one or more computer programs; the program includes program instructions, and the processor is used to execute the program instructions stored in the memory. The processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. It is the computing core and control core of the terminal, which is used to implement one or more instructions, specifically for loading and executing one or more instructions in a computer storage medium to implement the above method.

[0304] It needs to be further explained that, based on the same inventive concept, the present invention also provides a computer storage medium, on which a computer program is stored, and the computer program is executed by a processor to execute the above method. The storage medium can adopt any combination of one or more computer-readable media. The computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electrical, magnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system, device or device or used in combination with it.

[0305] In the description of this specification, the description with reference to the terms "one embodiment", "example", "specific example", etc. 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 present disclosure. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described can be combined in any one or more embodiments or examples in a suitable manner.

[0306] The above shows and describes the basic principles, main features and advantages of the present disclosure. Those skilled in the art should understand that the present disclosure is not limited by the above embodiments, and the above embodiments and descriptions are only for explaining the principles of the present disclosure. Without departing from the spirit and scope of the present disclosure, the present disclosure may have various changes and improvements, and these changes and improvements fall within the scope of the present disclosure to be protected.

Claims

1. A weld defect detection method based on WGOA-HHO improved YOLOv8, characterized in that: The method comprises the following steps: receiving a weld image data set, and preprocessing the weld image data set using a Canny edge detection algorithm to obtain a preprocessed weld image data set; The preprocessed weld image dataset is input into the pre-established YOLOv8 weld defect detection model for training, and based on the WGOA-HHO optimization algorithm, the Improved-YOLOv8 model is output; Obtain the weld image to be detected, input the weld image to be detected into the Improved-YOLOv8 model, and output the weld defect detection result image.

2. The weld defect detection method based on WGOA-HHO improved YOLOv8 according to claim 1, characterized in that: The process of preprocessing the weld image data set using the Canny edge detection algorithm includes: Gaussian filtering, calculating image gradient, non-maximum suppression, dual threshold detection, and edge connection and hysteresis threshold.

3. The weld defect detection method based on WGOA-HHO improved YOLOv8 according to claim 2 is characterized in that: The Gaussian filtering process: The formula for Gaussian filtering is: Where: G(x,y) is a Gaussian function, which represents the Gaussian value at the position (x,y); is the standard deviation; The image gradient is calculated by using the Sobel operator to calculate the gradient in the horizontal and vertical directions; The dual threshold detection is achieved by setting two thresholds T high and T low : If the gradient magnitude of a pixel G ≥ T high , then the pixel is considered a strong edge; If T low ≤G<T high , then the pixel is considered a weak edge; If G<T high , then the pixel is considered as a non-edge.

4. The weld defect detection method based on WGOA-HHO improved YOLOv8 according to claim 1, characterized in that: The steps of the WGOA-HHO optimization algorithm include: a WGOA global search phase, an HHO predation phase, and a phase of constructing a bidirectional optimization algorithm of WGOA-HHO.

5. The weld defect detection method based on WGOA-HHO improved YOLOv8 according to claim 4 is characterized in that: The WGOA global search phase process is as follows: First, determine the hyperparameters that need to be optimized and their value ranges. The number of hyperparameters is denoted as m. Initialize the parameters of WGOA: number of geese in the flock n, current number of iterations t1, maximum number of iterations T1; Randomly generate n goose positions, each position corresponds to a set of hyperparameter combinations, then the goose position matrix is ​​expressed as: Apply the hyperparameter combination of each goose to the YOLOv8 model for training, evaluate the performance on the validation set, and calculate its fitness value; the fitness of n geese is represented as a vector of length n: <h2 style=";text-align:left;direction:ltr">F=[f1,f2,f3…f<h2 style=";text-align:left;direction:ltr"> n <h2 style=";text-align:left;direction:ltr"> ] After each round of iteration, the WGOA optimization algorithm selects the goose with the best fitness in the goose flock. The position of this goose represents the current optimal hyperparameter combination, and the positions of the remaining geese are adjusted according to specific update rules. The core of the update process is to gradually move the position of each goose to a better position. set up: The updated position of the i-th goose is used as the new hyperparameter combination; The position of the i-th goose before updating is used as the current hyperparameter combination; The wild goose flock optimization algorithm includes two update rules: Rule 1: Follow the Leader Once the leader goose is determined, the remaining geese will move closer to the leader goose's hyperparameter combination, simulating group following behavior to update their own positions. In the hyperparameter space, the geese will move toward the optimal hyperparameter combination while retaining random perturbations. The update formula is: in: x leader is the position of the leader goose; α is the weight for controlling the following of the leader goose, β is the weight for controlling random disturbance; randn() is a standard normal distribution random number; Rule 2: Group Behavior The behavior form includes two core parts: mutual attraction and keeping distance; Distance maintenance: In group behavior, geese will maintain a certain distance to prevent individuals from over-concentrating. The mathematical expression is: Among them: λ is the weight of distance maintenance, which controls the strength of repulsion; δ ij is the distance measure to neighbor i, defined according to the Euclidean distance; Repulsive Prevent individuals from being too concentrated; The mathematical expression of mutual attraction is: in: x j is the hyperparameter combination of the jth goose, which belongs to the neighbor set N(i) of the i-th goose; γ ij is the weight factor; Combining the behavior of following the leader with the group influence, we get a comprehensive formula for group behavior: In the formula represents the behavior of following the leader goose; βgrandn() is randomness; It’s the attraction of the neighborhood; It is the repulsive force; In each iteration, the current optimal fitness value and the corresponding hyperparameter combination are recorded.

6. The weld defect detection method based on WGOA-HHO improved YOLOv8 according to claim 5, characterized in that: The HHO predation phase process is as follows: Initialize the parameters of HHO: Harris Hawk group number k, current iteration number t2, maximum iteration number T2; Initialize the position of Harris Hawk according to the prey position x init_hunter =x target Where: x target is the position of the prey; x init_hunter It is the initial position of Harris Hawk; Add a small random disturbance near the prey to generate k initial positions of the eagle, that is: x init_eagle =x target +ηgrandn() in: η is a constant; randn() is a standard normal distribution random number; Each hawk in the Harris hawk group will make a reasonable choice among the four hunting strategies based on the energy E(t) and escape probability P of the wild goose. The energy E(t) of the prey gradually decays with the number of iterations, simulating the exhaustion of the prey's physical strength during the escape process. As the number of iterations increases, the energy of the prey decreases, and the ability to escape becomes weaker, making it easier for the Harris hawk to capture it. Prey energy is defined as: Where E0 is a random number and E0∈[-1,1]; The escape probability P of the prey is a random number and P∈[0,1]. When P<0.5, the prey escapes successfully, and when P≥0.5, the prey fails to escape. Reasonable selection of the four predation strategies is as follows: Strategy 1: Soft Siege When E(t)≥0.5,P≥0.5, Harris's hawk will choose to hover to consume the prey's energy and then catch the prey in the best position. The position update formula is as follows: x new =x target -E(t)g|Jgx target -x eagel | Where: x new It's the new location for Harris Hawk;x target is the current position of the prey; x eagel is the current position of the Harris Hawk; J is a random constant and J∈[0,1]; Strategy 2: Hard Siege When E(t)<0.5,P≥0.5, the Harris Hawk will choose to attack quickly, and the position update formula is as follows: x new =x target -E(t)g|x target -x eagel | Strategy 3: Dive and Soft Siege When E(t)≥0.5, P<0.5, Harris's hawk will dive to catch prey: Levy flight formula; Harris's hawk will dive while gradually approaching the prey, using irregular dive routes to confuse the prey and increase the chance of successful capture; the position update formula is as follows: x new =x target -E(t)g|Jgx target -x eagel | x new =x new +sgL(m) in: L(m) is the Levy flight formula, m is the dimension of the Harris Hawk position, that is, the number of hyperparameters; s is an m-dimensional random row vector, that is, s = [s1, s2…, s m ], each element in s conforms to the standard normal distribution with mean 0 and variance 1; Strategy 4: Dive and Siege When E(t)<0.5,P<0.5, the eagle conducts local search and development of prey and quickly captures prey. The position update formula is as follows: x new =x target -E(t)g|x target -x eagel | x new =x new +sgL(m) Levy's flight formula is as follows: in: u and v are both random numbers that follow a standard normal distribution; τ is the control parameter of the Levy distribution; σ is the scaling factor of the Levy distribution; Through continuous iterations, the Harris Hawk with the highest fitness value in the Harris Hawk group is the optimal hyperparameter combination.

7. The weld defect detection method based on WGOA-HHO improved YOLOv8 according to claim 6, characterized in that: The process of constructing the bidirectional optimization algorithm of WGOA-HHO is as follows: Initial stage: WGOA-led, HHO-assisted: First, the fitness value of each goose in the total number of n geese is calculated, and the goose with the highest fitness value is the leader goose x leader , the goose with the lowest fitness value is x worst ; During the global search of WGOA, HHO-assisted hunting will be based on P HHO Probability trigger; When HHO assisted hunting is triggered, HHO will regard the current leader goose as prey and update its position according to the four strategies of Harris Hawk. The updated position is marked as x change ; Repeat the steps and continue iterative optimization until the termination condition is reached; Dynamic Switch Control: After each iteration, it is determined whether the population diversity is lower than the set threshold. If the calculated diversity value is less than the threshold, the later stage is triggered. The diversity is the difference between the highest fitness value and the lowest fitness value in the current iteration result. Late stage: WGOA leads, HHO assists: The leader goose is used as the prey, and the HHO algorithm is used to update the position of each Harris hawk of the total number of k Harris hawks, and the fitness value is calculated. The hawk with the highest fitness value will be used as the prey of the subsequent iteration, that is, x target ; During the HHO search, WGOA assistance will be based on P WGOA trigger; When WGOA auxiliary is triggered, WGOA will target As the leader goose, update the positions of the k' hawks with the lowest fitness values ​​in the Harris hawk group; Repeat the steps and continue iterative optimization until the termination condition is reached.

8. The weld defect detection method based on WGOA-HHO improved YOLOv8 according to claim 1, characterized in that: The process of inputting the weld image to be detected into the Improved-YOLOv8 model and outputting the weld defect detection result image is as follows: Improved-YOLOv8 draws the predicted bounding box on the original weld image based on the decoded coordinates. Each defect category and the corresponding confidence score are displayed on the border, and an image containing the weld defect detection results is output. The weld defect detection result image shows all defect locations and category information predicted by the model.

9. The weld defect detection system based on WGOA-HHO improved YOLOv8 is characterized by: include: An image processing module is used to receive a weld image data set, and preprocess the weld image data set using a Canny edge detection algorithm to obtain a preprocessed weld image data set; The model optimization module is used to input the preprocessed weld image dataset into the pre-established YOLOv8 weld defect detection model for training, and output the Improved-YOLOv8 model based on the WGOA-HHO optimization algorithm; The defect detection module is used to obtain the weld image to be detected, input the weld image to be detected into the Improved-YOLOv8 model, and output the weld defect detection result image.

10. A terminal device, comprising a memory, a processor, and a computer program stored in the memory and capable of running on the processor, characterized in that: The memory stores a computer program that can be run on a processor. When the processor loads and executes the computer program, the weld defect detection method based on WGOA-HHO improved YOLOv8 according to any one of claims 1 to 8 is adopted.

Citation Information

Cited By

  • Tile product surface defect detection method based on SAPC-Net network

    CN119887727A

  • Marine food management method based on big data

    CN119919005A

  • Defect identification and early warning system in additive manufacturing process

    CN119941737A

  • Aluminum alloy heat treatment defect detection method based on machine vision

    CN121049254A