Circuit board welding defect detection method and system based on image recognition
Through the circuit board welding defect detection method based on image recognition, edge detection and residual network are used to identify welding defect types, which solves the problems of low efficiency and high cost of traditional detection methods, and achieves efficient and accurate welding defect detection.
Patent Information
- Application Number
- CN202410851360.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-28
- Publication Date
- 2024-09-10
- Estimated Expiration
- 2044-06-28
AI Technical Summary
Traditional welding defect detection methods are inefficient and highly subjective. Although X-ray detection is accurate, it is costly and complex to operate, and cannot meet the high efficiency and high precision requirements of modern electronic manufacturing.
A circuit board welding defect detection method based on image recognition is used to calculate the gradient amplitude and direction through edge detection operators, construct a weighted undirected graph, and combine jump connections and residual networks to conduct iterative learning training to identify welding defect types.
It improves the accuracy and efficiency of welding defect detection, reduces costs, simplifies the operation process, can more carefully capture edge features and identify subtle changes in the welding area, and enhances the accuracy of identification and classification of welding defects.
Smart Images

Figure CN118397006B
Abstract
Description
Technical Field
[0001] This invention relates to the field of image recognition technology, and in particular to a method and system for detecting poor soldering on circuit boards based on image recognition. Background Art
[0002] With the rapid development of the electronics manufacturing industry, the production and application of circuit boards are becoming increasingly widespread. The soldering quality of circuit boards directly affects the performance and reliability of electronic products. However, traditional methods for detecting soldering defects cannot fully meet the high efficiency and high precision requirements of modern electronics manufacturing. In recent years, the rapid development of deep learning and image recognition technologies has provided new solutions for automated inspection.
[0003] CN202310499957.4 discloses a target detection method for welding images. The method includes: acquiring a welding image sample set; annotating the welding image sample set to obtain an annotated image set; wherein the annotated image set includes welding images and annotation information; obtaining a processed dataset and cropping information for the annotated image set through multi-scale sliding overlap cropping; obtaining a processed welding target detection result corresponding to the processed dataset based on the processed dataset and a welding target detection model based on a target detection model; and obtaining a welding target detection result based on the processed welding target detection result and the cropping information. This method effectively improves the performance of the model, especially for small-sized defects, showing a significant improvement.
[0004] In summary, manual inspection is inefficient and highly subjective in the existing technology, while X-ray detection is accurate but costly and complex to operate. The application of this invention can at least solve some of the problems of the existing technology. Summary of the Invention
[0005] This invention provides a method and system for detecting poor soldering on circuit boards based on image recognition, which can at least solve some of the problems in the prior art.
[0006] A first aspect of the present invention,
[0007] A method for detecting soldering defects on circuit boards based on image recognition is provided, including:
[0008] Images of the soldering area of the circuit board are collected. An edge detection operator is used to calculate the gradient magnitude and gradient direction of each pixel in the soldering area image. Based on the difference in gradient magnitude and gradient direction between adjacent pixels, edge weights are calculated to determine the edge coherence evaluation value. Based on the edge coherence evaluation value, the edges of the soldering area are extracted to obtain an edge enhancement map.
[0009] Based on a pre-configured unit configuration and combined with skip connections, residual units are constructed. These residual units are then stacked in a shallow-to-deep order, and dimension matching layers are set between them to construct a defect detection network.
[0010] The edge enhancement map is input into the trained defect detection network to determine the welding defect type. The training of the defect detection network includes determining defect labels based on the edge enhancement map, constructing a training map set, inputting the training map set into the defect detection network, determining the accuracy by calculating the value of the loss function, and iteratively learning and training to minimize the value of the loss function, thereby completing the training of the defect detection network.
[0011] In an optional embodiment,
[0012] Using an edge detection operator, the gradient magnitude and gradient direction of each pixel in the welding area image are calculated. Based on the differences in gradient magnitude and gradient direction between adjacent pixels, edge weights are calculated, and the edge coherence evaluation value is determined, including:
[0013] Based on the resolution and detail features of the welding area image, a Gaussian kernel and standard deviation are determined, and a convolution operation is performed on the welding area image to remove image noise and obtain a smooth image.
[0014] The gradient is calculated in the horizontal and vertical directions using an edge detection operator to obtain the gradient magnitude and gradient direction of each pixel in the smoothed image.
[0015] Using each pixel in the smoothed image as a vertex and the relationship between the pixels as an edge, and determining the edge weights corresponding to the edges based on the gradient magnitude and gradient direction of the pixels, a weighted undirected graph is constructed.
[0016] Based on any vertex in the weighted undirected graph, determine the edge weights of all edges associated with the vertex, calculate the mean of the edge weights, and determine the edge coherence evaluation value of the vertex.
[0017] In an optional embodiment,
[0018] The method for calculating the edge coherence evaluation value includes:
[0019] The formula for determining the edge weight between two vertices is as follows:
[0020] ;
[0021] in, i Represents a vertex. j Represents another vertex, wij Represents vertices i and vertex j The edge weights between them, exp represents the exponential function, Δ θ ij Represents vertices i and vertex j Difference in gradient direction between them σ 1 represents the directional scale parameter that controls the influence of gradient direction differences. G i Represents vertices i gradient magnitude, G j Represents vertices j gradient magnitude, σ 2 represents the magnitude scale parameter that controls the influence of gradient magnitude differences;
[0022] The mean of the edge weights is calculated to determine the edge coherence evaluation value of the vertex, using the following formula:
[0023] ;
[0024] in, C i Indicates a vertex i Edge coherence assessment value, N i Represents the vertex i The total number of all adjacent vertices.
[0025] In an optional embodiment,
[0026] Based on a pre-configured unit configuration and skip connections, residual units are constructed. These residual units are stacked in a shallow-to-deep order, and dimension matching layers are set between them to build a defect detection network, including:
[0027] The unit configuration includes the number of convolutional layers, the number of activation layers, and the total number of residual units in each residual unit;
[0028] The convolutional layers in the residual unit consist of depthwise convolution and pointwise convolution;
[0029] Based on each channel corresponding to the input edge enhancement map, the depthwise convolution slides the convolution kernel on a single channel to perform a convolution operation and extract the channel feature map;
[0030] The pointwise convolution application unit point convolution kernel performs a fusion operation on the channel feature map to obtain a fused feature map;
[0031] The residual units are matched and stacked by a dimension matching layer built based on 1×1 convolution operations to construct an defect detection network.
[0032] In an optional embodiment,
[0033] Also includes:
[0034] After the residual units are matched and stacked, a global average pooling layer is set to perform average pooling operation. Then, after passing through a fully connected layer, the pooled feature vector is mapped to the output node with the same number of welding defect types. The output of the fully connected layer is processed using the softmax activation function to obtain the probability of each type that matches the welding defect type.
[0035] In an optional embodiment,
[0036] Based on the edge enhancement map, defect labels are determined, a training map set is constructed, and the training map set is input into the defect detection network. The accuracy is determined by calculating the value of the loss function. Through iterative learning and training, the value of the loss function is minimized, thus completing the training of the defect detection network.
[0037] Based on the type of welding defect, defect labels are set for the edge enhancement map to determine the training map set;
[0038] A defect detection loss function is constructed based on the cross-entropy loss function. The difference between the probability distribution of the welding defect type and the defect label is determined according to the value of the defect detection loss function. A difference assessment is set to determine the accuracy.
[0039] By combining a preset iteration learning rate and backpropagation, the hyperparameters in the defective detection loss function are adjusted so that the value of the defective detection loss function gradually decreases until the preset total number of iterations is reached. The defective detection loss function is then determined, and the defective detection network training is completed.
[0040] If, after continuous iterations, the value of the defect detection loss function decreases by less than a preset iteration change threshold, the iteration ends early, and the defect detection network training is completed.
[0041] In an optional embodiment,
[0042] By combining a preset iterative learning rate and backpropagation, the hyperparameters in the defective detection loss function are adjusted as follows:
[0043] The iterative learning rate adopts a dynamic learning rate adjustment method;
[0044] Set a maximum and a minimum learning rate. After each iteration, adjust the learning rate based on a cosine function, using the following formula:
[0045] ;
[0046] in, lr This represents the current learning rate. lr min This represents the minimum learning rate. lr max This represents the maximum learning rate. t Indicates the t iteration T This indicates the preset number of iterations.
[0047] A second aspect of the present invention,
[0048] A circuit board soldering defect detection system based on image recognition is provided, comprising:
[0049] The first unit is used to collect images of the soldering area of the circuit board, use an edge detection operator to calculate the gradient magnitude and gradient direction of each pixel in the soldering area image, calculate edge weights based on the differences in gradient magnitude and gradient direction between adjacent pixels, determine the edge coherence evaluation value, and extract the edges of the soldering area based on the edge coherence evaluation value to obtain an edge enhancement map.
[0050] The second unit is used to construct residual units based on a pre-set unit configuration and by combining skip connections. The residual units are stacked in order of increasing depth, and a dimension matching layer is set between the residual units to construct a defect detection network.
[0051] The third unit is used to input the edge enhancement map into the trained defect detection network to determine the welding defect type. The training of the defect detection network includes determining defect labels based on the edge enhancement map, constructing a training map set, inputting the training map set into the defect detection network, determining the accuracy by calculating the value of the loss function, and minimizing the value of the loss function through iterative learning training to complete the training of the defect detection network.
[0052] A third aspect of the present invention,
[0053] An electronic device is provided, comprising:
[0054] processor;
[0055] a memory for storing processor-executable instructions;
[0056] The processor is configured to invoke instructions stored in the memory to execute the aforementioned method.
[0057] Fourth aspect of the embodiments of the present invention,
[0058] A computer-readable storage medium is provided, having stored thereon computer program instructions that, when executed by a processor, implement the aforementioned method.
[0059] In this embodiment of the invention, the edges are further refined and non-edge points are suppressed through a non-maximum suppression process, making the edges of the weld defect area more prominent and clear, which facilitates accurate identification of the real edges in the dual-threshold detection step. By converting the image into a weighted undirected graph and calculating the gradient direction difference and gradient magnitude difference between pixels as edge weights, the connection strength of each part in the image can be more accurately reflected, enabling more detailed capture of the image's edge features and improving the accuracy of edge recognition. Based on the core concept of residual networks, the designed model effectively solves the gradient vanishing problem in deep network training by introducing skip connections, enabling the model to learn deeper features and improve the accuracy of weld defect identification and classification. To address the characteristics of the edge detection results, the convolutional layers are adjusted... The number and size of filters enable the model to better capture subtle feature changes in the welding area, further improving recognition accuracy. By replacing standard convolutional layers with depthwise separable convolutions, the number of model parameters is significantly reduced. Depthwise convolutions only perform convolution operations on each input channel, while pointwise convolutions are used to combine features. Compared with traditional convolutions, fewer parameters are required. In addition to reducing parameters, depthwise separable convolutions can also significantly reduce the computational complexity of the model, making the model more lightweight and faster. In the later stages of training, a smaller learning rate allows the model to perform more detailed searches in the parameter space, increasing the likelihood of finding good local optima. Cosine dynamic learning rate scheduling helps improve the model's generalization ability by exploring different parameter space regions in different periods. Attached Figure Description
[0060] Figure 1 This is a flowchart illustrating the circuit board soldering defect detection method based on image recognition according to an embodiment of the present invention.
[0061] Figure 2 This is a schematic diagram of the circuit board soldering defect detection system based on image recognition, according to an embodiment of the present invention. Detailed Implementation
[0062] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0063] The technical solution of the present invention will be described in detail below with reference to specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments.
[0064] Figure 1 This is a flowchart illustrating the circuit board soldering defect detection method based on image recognition according to an embodiment of the present invention. Figure 1 As shown, the method includes:
[0065] S101. Collect images of the soldering area of the circuit board, use an edge detection operator to calculate the gradient magnitude and gradient direction of each pixel in the soldering area image, calculate edge weights based on the gradient magnitude and gradient direction differences between adjacent pixels, determine the edge coherence evaluation value, and extract the edges of the soldering area based on the edge coherence evaluation value to obtain an edge enhancement map.
[0066] S102. Based on the pre-set unit configuration and combined with skip connections, construct residual units, stack the residual units in order from shallow to deep, and set dimension matching layers between the residual units to construct a defect detection network;
[0067] S103. Input the edge enhancement map into the trained defect detection network to determine the welding defect type. The training of the defect detection network includes determining defect labels based on the edge enhancement map, constructing a training map set, inputting the training map set into the defect detection network, determining the accuracy by calculating the value of the loss function, and minimizing the value of the loss function through iterative learning training to complete the training of the defect detection network.
[0068] In an optional embodiment,
[0069] Using an edge detection operator, the gradient magnitude and gradient direction of each pixel in the welding area image are calculated. Based on the differences in gradient magnitude and gradient direction between adjacent pixels, edge weights are calculated, and the edge coherence evaluation value is determined, including:
[0070] Based on the resolution and detail features of the welding area image, a Gaussian kernel and standard deviation are determined, and a convolution operation is performed on the welding area image to remove image noise and obtain a smooth image.
[0071] The gradient is calculated in the horizontal and vertical directions using an edge detection operator to obtain the gradient magnitude and gradient direction of each pixel in the smoothed image.
[0072] Using each pixel in the smoothed image as a vertex and the relationship between the pixels as an edge, and determining the edge weights corresponding to the edges based on the gradient magnitude and gradient direction of the pixels, a weighted undirected graph is constructed.
[0073] Based on any vertex in the weighted undirected graph, determine the edge weights of all edges associated with the vertex, calculate the mean of the edge weights, and determine the edge coherence evaluation value of the vertex.
[0074] In an optional embodiment,
[0075] The method for calculating the edge coherence evaluation value includes:
[0076] The formula for determining the edge weight between two vertices is as follows:
[0077] (1);
[0078] in, i Represents a vertex. j Represents another vertex, w ij Represents vertices i and vertex j The edge weights between them, exp represents the exponential function, Δ θ ij Represents vertices i and vertex j Difference in gradient direction between them σ 1 represents the directional scale parameter that controls the influence of gradient direction differences. G i Represents vertices i gradient magnitude, G j Represents vertices j gradient magnitude, σ 2 represents the magnitude scale parameter that controls the influence of gradient magnitude differences;
[0079] The mean of the edge weights is calculated to determine the edge coherence evaluation value of the vertex, using the following formula:
[0080] (2);
[0081] in, C i Indicates a vertex i Edge coherence assessment value, N i Represents the vertex i The total number of all adjacent vertices.
[0082] In an optional embodiment,
[0083] Based on a pre-configured unit configuration and skip connections, residual units are constructed. These residual units are stacked in a shallow-to-deep order, and dimension matching layers are set between them to build a defect detection network, including:
[0084] The unit configuration includes the number of convolutional layers, the number of activation layers, and the total number of residual units in each residual unit;
[0085] The convolutional layers in the residual unit consist of depthwise convolution and pointwise convolution;
[0086] Based on each channel corresponding to the input edge enhancement map, the depthwise convolution slides the convolution kernel on a single channel to perform a convolution operation and extract the channel feature map;
[0087] The pointwise convolution application unit point convolution kernel performs a fusion operation on the channel feature map to obtain a fused feature map;
[0088] The residual units are matched and stacked by a dimension matching layer built based on 1×1 convolution operations to construct an defect detection network.
[0089] In an optional embodiment,
[0090] Also includes:
[0091] After the residual units are matched and stacked, a global average pooling layer is set to perform average pooling operation. Then, after passing through a fully connected layer, the pooled feature vector is mapped to the output node with the same number of welding defect types. The output of the fully connected layer is processed using the softmax activation function to obtain the probability of each type that matches the welding defect type.
[0092] In an optional embodiment,
[0093] Based on the edge enhancement map, defect labels are determined, a training map set is constructed, and the training map set is input into the defect detection network. The accuracy is determined by calculating the value of the loss function. Through iterative learning and training, the value of the loss function is minimized, thus completing the training of the defect detection network.
[0094] Based on the type of welding defect, defect labels are set for the edge enhancement map to determine the training map set;
[0095] A defect detection loss function is constructed based on the cross-entropy loss function. The difference between the probability distribution of the welding defect type and the defect label is determined according to the value of the defect detection loss function. A difference assessment is set to determine the accuracy.
[0096] By combining a preset iteration learning rate and backpropagation, the hyperparameters in the defective detection loss function are adjusted so that the value of the defective detection loss function gradually decreases until the preset total number of iterations is reached. The defective detection loss function is then determined, and the defective detection network training is completed.
[0097] If, after continuous iterations, the value of the defect detection loss function decreases by less than a preset iteration change threshold, the iteration ends early, and the defect detection network training is completed.
[0098] In an optional embodiment,
[0099] By combining a preset iterative learning rate and backpropagation, the hyperparameters in the defective detection loss function are adjusted as follows:
[0100] The iterative learning rate adopts a dynamic learning rate adjustment method;
[0101] Set a maximum and a minimum learning rate. After each iteration, adjust the learning rate based on a cosine function, using the following formula:
[0102] (3);
[0103] in, lr This represents the current learning rate. lr min This represents the minimum learning rate. lr max This represents the maximum learning rate. t Indicates the t iteration T This indicates the preset number of iterations.
[0104] One specific embodiment of this application is as follows:
[0105] Edge detection is a fundamental method in image processing, designed to identify points in an image where brightness changes significantly. These points typically represent the boundaries of objects. Edge detection algorithms are used to accurately identify the edges of soldered areas on circuit boards. These algorithms employ multi-stage operations to improve edge detection performance.
[0106] The first step is to select an appropriate Gaussian kernel size and standard deviation. Based on the resolution and detail features of the circuit board image, an appropriate Gaussian kernel size and standard deviation are selected. Preferably, the Gaussian kernel size, such as 3x3 or 5x5, can effectively remove noise without losing too much detail. Apply Gaussian filtering by performing a convolution operation on the input circuit board image using the selected Gaussian kernel to smooth the image and reduce the impact of noise.
[0107] The second step is gradient calculation. Using an edge detection operator, preferably the Sobel operator, the gradient magnitude and direction are calculated. For the denoised image, the Sobel operator is used to calculate the gradient in the horizontal and vertical directions to obtain the gradient magnitude and direction of each pixel. The gradient magnitude and direction are combined. The calculated gradient magnitude and direction will serve as an important basis for edge detection and provide necessary information for non-maximum suppression.
[0108] The third step is non-maximum suppression, which involves comparing the gradient magnitude at each pixel with the gradient magnitudes of its two neighboring pixels along its gradient direction. This suppresses non-edge points. If the gradient magnitude of the current pixel is not a local maximum, its gradient magnitude is set to 0. This can suppress those non-edge points and make the edges more refined.
[0109] The fourth step is dual-threshold detection and edge connection. High and low thresholds are set, and appropriate high and low thresholds are selected to identify strong edges and weak edges. The gradient magnitude of strong edges is higher than the high threshold, while the gradient magnitude of weak edges is between the two thresholds. By analyzing the connection between weak edge points and strong edge points, it is decided whether to retain the weak edge points as part of the real edge. This is done through recursion or iteration to ensure that all strong edges and weak edges connected to strong edges are detected.
[0110] In this embodiment, by selecting an appropriate Gaussian kernel size and standard deviation for Gaussian filtering, noise in the circuit board image is effectively removed while retaining important soldering area details. This ensures that subsequent processing steps can be based on clearer and more accurate image data, thereby improving detection accuracy. Edge detection operators are used to calculate the gradient magnitude and direction of the denoised image, enabling the system to more accurately identify the edges of the circuit board soldering area. This not only enhances edge features but also provides necessary information for non-maximum suppression, thus achieving refined edge processing. Through the non-maximum suppression process, edges are further refined, and non-edge points are suppressed, making the edges of poorly soldered areas more prominent and clear, facilitating accurate identification of true edges in the dual-threshold detection step.
[0111] In an optional embodiment, a weighted undirected graph is constructed, and the image is transformed into a weighted undirected graph, with the pixels in the image as vertices and the connections between pixels as edges. The weight of the edge is determined by the difference in gradient direction and gradient magnitude of adjacent pixels. By calculating the difference in gradient direction and the corresponding difference in gradient magnitude of pixels, combined with regularization parameters, the edge weight is calculated as described in formula (1). For any vertex in the graph, the edge coherence corresponding to the vertex can be comprehensively evaluated by considering the weights of all edges connected to the vertex, as described in formula (2). Using graph theory algorithms, preferably graph cutting algorithms, the graph is optimized according to edge coherence to identify and retain the edges most likely to represent the real physical boundaries.
[0112] In this embodiment, by converting the image into a weighted undirected graph and calculating the gradient direction and magnitude differences between pixels as edge weights, the connection strength of each part of the image can be more accurately reflected, and the edge features of the image can be captured more meticulously, thus improving the accuracy of edge recognition. By considering the weights of all edges connected to each vertex to comprehensively evaluate the edge coherence of the vertex, edge detection not only combines local features but also incorporates global coherence information, which helps to effectively distinguish between real physical boundaries and accidental noise in complex backgrounds or with a lot of noise. By using a graph cutting algorithm to optimize the weighted undirected graph, the optimal edge is found globally, effectively identifying and retaining the edges most likely to represent real physical boundaries, which helps to reduce false positives and false negatives, and improve the accuracy and reliability of welding defect detection.
[0113] Each type of welding defect has its specific morphological characteristics and influencing factors, including:
[0114] 1. Cold soldering: Cold soldering occurs when the solder is not completely melted, resulting in a weak connection between the solder joint and the pad or component lead. The characteristics of cold soldering are a rough solder joint surface and poor wettability.
[0115] 2. Cold solder joint: A cold solder joint is caused by the solder failing to form an effective connection, resulting in the failure of some or all of the solder joints. Cold solder joints usually lack luster and sometimes cracks can be seen.
[0116] 3. Over-soldering: When over-soldering occurs, too much solder covers the solder joint, which may cause bridging between adjacent solder joints. The characteristics of over-soldering are that the solder joint is too large and the solder overflows from the normal solder pad area.
[0117] 4. Bridging: Bridging refers to an unintentional connection between two solder pads that should be independent. The main manifestation of bridging is a noticeable solder joint between the two pads.
[0118] 5. Solder balls: Solder balls are small metal balls that form during the soldering process. They usually occur around the pads or on the PCB. Solder balls can cause short circuits, especially between closely spaced solder joints.
[0119] The steps for constructing an ill-detection network and training a model based on ResNet are as follows:
[0120] Step 1: Data preparation and preprocessing;
[0121] Edge detection: In the aforementioned steps, images of welding defects are collected and edge detection algorithms are applied to highlight the edge features of the welding defects; Data labeling: Ensure that each image processed by edge detection has an accurate defect type label; Data augmentation: Apply data augmentation techniques, such as rotation, scaling, and flipping, to the images after edge detection to increase the diversity and robustness of model training.
[0122] Step 2: Construct a defect detection network architecture;
[0123] Based on the core concept of residual networks, a model framework is designed. By introducing skip connections, the residual network allows gradients to flow directly to deeper network layers, effectively solving the gradient vanishing problem during the training of deep networks. It also constructs a deep convolutional neural network specifically for the identification and classification of welding defects.
[0124] Each residual unit consists of several convolutional layers and is equipped with skip connections that span two or more layers. Special attention is paid to adjusting the number and size of the convolutional layer filters to maximize the adaptation to the features of the edge detection results. Preferably, considering that the edge detection results highlight the boundary information of the poor welding area, a smaller filter size, such as 3×3, is selected to capture subtle feature changes.
[0125] At the end of the defect detection network, a global average pooling layer is integrated to reduce the number of model parameters while preserving the global information of spatial features. Then, a fully connected layer is used to map the pooled features to an output node with an equal number of weld defect types. Finally, through the softmax activation function, the defect detection network outputs the predicted probability of each type of weld defect.
[0126] Step 3: Network model compilation and training;
[0127] Model compilation: Preferably, the model is constructed using the cross-entropy loss function and an initial learning rate is set; Training and validation: The dataset is divided into an 80% training set and a 20% validation set. The model is trained using the training set and its performance is evaluated on the validation set to monitor and prevent overfitting; Early stopping and parameter tuning: An early stopping strategy is applied to prevent overfitting, and the model parameters and training strategy are adjusted based on the performance feedback on the validation set.
[0128] Step 4: Performance evaluation and optimization;
[0129] Test set evaluation: Evaluate the final performance of the network model, calculate key performance indicators such as accuracy, recall, and F1 score, and preferably determine the prediction accuracy; Model optimization: Analyze the classification errors of the network model, identify the weaknesses of the model, and based on the analysis results, further adjust the network model structure and training parameters, such as increasing or decreasing the number of residual blocks and adjusting the learning rate; Iterative improvement: Repeat the training and evaluation process until the model performance reaches a satisfactory level and achieves the best classification effect;
[0130] In this embodiment, based on the core concept of residual networks, the designed model effectively solves the gradient vanishing problem in deep network training by introducing skip connections, enabling the model to learn deeper features and improve the accuracy of weld defect identification and classification. Considering the characteristics of edge detection results, the number and size of convolutional layer filters are adjusted to allow the model to better capture subtle feature changes in the welding area, further improving the identification accuracy. A global average pooling layer is integrated at the end of the network to replace the traditional fully connected layer, effectively reducing the number of model parameters, lowering the risk of overfitting, and preserving global information about spatial features. By applying the softmax activation function at the end of the model, the predicted probability of each type of weld defect can be output, providing a probabilistic basis for the final classification decision, making the decision-making process more accurate and reliable.
[0131] In one alternative embodiment, depth fine-tuning is performed on each residual unit. Depthwise separable convolution divides the traditional convolution operation into two independent layers: depthwise convolution and pointwise convolution, where pointwise convolution is a 1×1 convolution, which can significantly reduce model parameters and computational complexity. Implementation: In each residual unit, the standard convolutional layer is replaced with a depthwise separable convolution. First, spatial features are extracted independently for each channel of the input through depthwise convolution, and then all features are fused through pointwise convolution, thereby improving the performance and efficiency of the model.
[0132] In this embodiment, by replacing standard convolutional layers with depthwise separable convolutions, the number of model parameters is significantly reduced. Depthwise convolutions only perform convolution operations on each input channel, while pointwise convolutions are used to combine features. Compared with traditional convolutions, fewer parameters are required. In addition to reducing parameters, depthwise separable convolutions can also significantly reduce the computational complexity of the model, making the model more lightweight and faster. Although the model's parameters and computational load are reduced, the combination of depthwise and pointwise convolutions can effectively extract and fuse spatial features without sacrificing model performance. Learning the spatial features of each channel independently and fusing features between channels helps the model capture richer feature information and enhances the model's ability to recognize complex patterns.
[0133] In one optional embodiment, a dynamic learning rate adjustment strategy is employed to optimize the training process and accelerate convergence. Preferably, a cosine dynamic learning rate scheduling method is used, including:
[0134] Cosine dynamic learning rate scheduling is a learning rate adjustment method that mimics the temperature changes during annealing. In each cycle, the learning rate gradually decreases in the form of a cosine function, which helps to find more detailed local optima in the later stages of training and can prevent the model from getting trapped in local minima too early.
[0135] Cosine dynamic learning rate scheduling divides the entire training process into multiple iterations. At the beginning of each iteration, the learning rate is high, and then it gradually decreases to a lower value according to the form of a cosine function.
[0136] Within each cycle, the learning rate changes according to the shape of a cosine function, thus achieving a smooth transition from the initial learning rate to the minimum learning rate;
[0137] At the end of each cycle, the learning rate is "heated" to a higher value, which may be the initial learning rate or a value determined according to a certain strategy, and then reduced again in the next cycle. This is similar to the "annealing" and "reheating" process in simulated annealing, which helps to explore the parameter space and avoid getting trapped in local optima.
[0138] In this embodiment, by periodically adjusting the learning rate, the model can rapidly decrease in the early stages of training, while fine-tuning with a smaller learning rate in the later stages helps to avoid getting trapped in local minima too early. In the later stages of training, a smaller learning rate allows the model to perform a more detailed search in the parameter space, increasing the likelihood of finding a good local optimum. Cosine dynamic learning rate scheduling helps to improve the model's generalization ability by exploring different regions of the parameter space in different periods.
[0139] Figure 2 This is a schematic diagram of the circuit board soldering defect detection system based on image recognition according to an embodiment of the present invention, as shown below. Figure 2 As shown, the system includes:
[0140] The first unit is used to collect images of the soldering area of the circuit board, use an edge detection operator to calculate the gradient magnitude and gradient direction of each pixel in the soldering area image, calculate edge weights based on the differences in gradient magnitude and gradient direction between adjacent pixels, determine the edge coherence evaluation value, and extract the edges of the soldering area based on the edge coherence evaluation value to obtain an edge enhancement map.
[0141] The second unit is used to construct residual units based on a pre-set unit configuration and by combining skip connections. The residual units are stacked in order of increasing depth, and a dimension matching layer is set between the residual units to construct a defect detection network.
[0142] The third unit is used to input the edge enhancement map into the trained defect detection network to determine the welding defect type. The training of the defect detection network includes determining defect labels based on the edge enhancement map, constructing a training map set, inputting the training map set into the defect detection network, determining the accuracy by calculating the value of the loss function, and minimizing the value of the loss function through iterative learning training to complete the training of the defect detection network.
[0143] A third aspect of the present invention,
[0144] An electronic device is provided, comprising:
[0145] processor;
[0146] a memory for storing processor-executable instructions;
[0147] The processor is configured to invoke instructions stored in the memory to execute the aforementioned method.
[0148] Fourth aspect of the embodiments of the present invention,
[0149] A computer-readable storage medium is provided, having stored thereon computer program instructions that, when executed by a processor, implement the aforementioned method.
[0150] This invention can be a method, apparatus, system, and / or computer program product. The computer program product may include a computer-readable storage medium having computer-readable program instructions loaded thereon for performing various aspects of the invention.
[0151] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the above embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. Circuit board welding defect detection method based on image recognition, It is characterized in that include: Collecting a welding area image of a circuit board, using an edge detection operator to calculate the gradient amplitude and gradient direction of each pixel in the welding area image, calculating an edge weight based on the gradient amplitude difference and gradient direction difference between adjacent pixels, determining an edge coherence evaluation value, extracting the welding area edge based on the edge coherence evaluation value, and obtaining an edge enhancement map; Based on the preset unit configuration, combined with the jump connection, a residual unit is constructed, the residual units are stacked in order from shallow to deep, and a dimension matching layer is set between the residual units to construct a bad detection network; Inputting the edge enhancement map into the trained defect detection network to determine the type of welding defects, wherein the training of the defect detection network includes determining defect labels based on the edge enhancement map, constructing a training atlas, inputting the training atlas into the defect detection network, determining the accuracy by calculating the value of the loss function, and minimizing the value of the loss function through iterative learning and training to complete the training of the defect detection network; Using an edge detection operator, calculating the gradient amplitude and gradient direction of each pixel in the welding area image, calculating the edge weight based on the gradient amplitude difference and gradient direction difference between adjacent pixels, and determining the edge coherence evaluation value includes: Based on the resolution and detail features of the welding area image, a Gaussian kernel and a standard deviation are determined, and a convolution operation is performed on the welding area image to remove image noise and obtain a smooth image; Using an edge detection operator to calculate gradients in the horizontal and vertical directions, obtaining a gradient magnitude and a gradient direction for each pixel in the smoothed image; Taking each pixel point in the smoothed image as a vertex and the association relationship between the pixels as an edge, and determining the edge weight corresponding to the edge according to the gradient amplitude and gradient direction of the pixel point, a weighted undirected graph is constructed; Based on any of the vertices in the weighted undirected graph, determining edge weights of all edges associated with the vertex, calculating a mean of the edge weights, and determining an edge coherence evaluation value of the vertex; The calculation method of the edge coherence evaluation value includes: Determine the edge weight between two vertices, the formula is as follows: ; Among them, i represents a vertex, j represents another vertex, and w ij represents the edge weight between vertex i and vertex j, exp represents the exponential function, Δθ ij represents the difference in gradient direction between vertex i and vertex j, σ 1 represents the direction scale parameter that controls the influence of gradient direction difference, G i represents the gradient magnitude of vertex i, G j represents the gradient magnitude of vertex j, σ 2 represents the amplitude scale parameter that controls the effect of gradient amplitude differences; The mean of the edge weights is calculated to determine the edge continuity evaluation value of the vertex, and the formula is as follows: ; Among them, C i represents the edge coherence evaluation value for vertex i, N i represents the total number of vertices adjacent to vertex i; Based on the preset unit configuration, combined with the jump connection, a residual unit is constructed, the residual units are stacked in order from shallow to deep, and a dimension matching layer is set between the residual units. The construction of the fault detection network includes: The unit configuration includes the number of convolutional layers, the number of activation layers, and the total number of residual units in each residual unit; The convolutional layer in the residual unit consists of depthwise convolution and pointwise convolution; Based on each channel corresponding to the input edge enhancement map, the deep convolution slides the convolution kernel on a single channel to perform a convolution operation and extract a channel feature map; The point-by-point convolution applies a unit point convolution kernel to perform a fusion operation on the channel feature map to obtain a fused feature map; The residual units are matched and stacked through a dimension matching layer constructed based on a 1×1 convolution operation to construct a bad detection network; Also includes: After the residual unit matching and stacking, a global average pooling layer is set to perform an average pooling operation, and then the pooled feature vector is mapped to output nodes equal to the number of poor welding types through a fully connected layer. The output of the fully connected layer is processed using a softmax activation function to obtain the probabilities of each type that matches the poor welding type.
2. The method according to claim 1, It is characterized in that Based on the edge enhancement map, a bad label is determined, a training atlas is constructed, the training atlas is input into the bad detection network, the accuracy is determined by calculating the value of the loss function, and the value of the loss function is minimized through iterative learning and training. The bad detection network training is completed, including: Based on the type of poor welding, a poor label is set for the edge enhancement image to determine a training atlas; Constructing a defect detection loss function based on the cross entropy loss function, determining the difference between the probability distribution of the defective welding type and the defective label according to the value of the defect detection loss function, setting a difference evaluation, and determining the accuracy rate; In combination with a preset iterative learning rate, the hyperparameters in the bad detection loss function are adjusted through back propagation, so that the value of the bad detection loss function is gradually reduced until a preset total number of iterations is reached, the bad detection loss function is determined, and the bad detection network training is completed; If after continuous iterations, the value of the bad detection loss function decreases by less than a preset iterative change threshold, the iteration is terminated in advance and the bad detection network training is completed.
3. The method according to claim 2, It is characterized in that Combined with the preset iterative learning rate, through back propagation, the hyper parameters in the bad detection loss function are adjusted to include: The iterative learning rate adopts a dynamic learning rate adjustment method; Set the maximum and minimum learning rates. After each iteration, adjust the learning rate based on the cosine function. The formula is as follows: ; Among them, lr represents the current learning rate, lr min Indicates the minimum learning rate, lr max represents the maximum learning rate, t represents the tth iteration, and T represents the preset number of iterations.
4. A circuit board welding defect detection system based on image recognition, used to implement the circuit board welding defect detection method based on image recognition as described in any one of claims 1 to 3. It is characterized in that include: The first unit is used to collect a welding area image of a circuit board, calculate the gradient amplitude and gradient direction of each pixel in the welding area image using an edge detection operator, calculate an edge weight based on the gradient amplitude difference and gradient direction difference between adjacent pixels, determine an edge coherence evaluation value, extract the welding area edge based on the edge coherence evaluation value, and obtain an edge enhancement map; The second unit is used to construct a residual unit based on a preset unit configuration and in combination with a jump connection, stack the residual units in order from shallow to deep, and set a dimension matching layer between the residual units to construct a bad detection network; The third unit is used to input the edge enhancement image into the trained defect detection network to determine the type of welding defects, wherein the training of the defect detection network includes determining defect labels based on the edge enhancement image, constructing a training atlas, inputting the training atlas into the defect detection network, determining the accuracy by calculating the value of the loss function, minimizing the value of the loss function through iterative learning and training, and completing the training of the defect detection network.
5. An electronic device, It is characterized in that include: processor; a memory for storing processor-executable instructions; The processor is configured to call the instructions stored in the memory to execute the method described in any one of claims 1 to 3.
6. A computer-readable storage medium having computer program instructions stored thereon, It is characterized in that When the computer program instructions are executed by a processor, the method according to any one of claims 1 to 3 is implemented.
