A general robust reinforcement method and system for a circuit board solder joint defect recognition model
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- HUNAN KUANGAN NETWORK TECH CO LTD
- Filing Date
- 2026-03-19
- Publication Date
- 2026-06-26
Smart Images

Figure CN122289761A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the fields of circuit manufacturing, computer vision and artificial intelligence technology, and more specifically, relates to a general robustness enhancement method and system for a circuit board solder joint defect identification model. Background Technology
[0002] Circuit board solder joint defect identification is a core component of automated optical inspection systems in electronic manufacturing. It aims to automatically classify and locate defects such as missing solder joints, cold solder joints, and bridging on solder pads using computer vision algorithms. Deep learning-based convolutional neural networks and VisionTransformers (ViTs) have been widely applied to solder joint inspection, significantly improving production efficiency. However, due to lighting fluctuations, camera noise, and minute variations in circuit board production batches in industrial settings, deep learning architectures exhibit significant vulnerabilities. Even minor external disturbances or targeted adversarial perturbations can cause the model to produce incorrect classification results, leading to false positives or false negatives, seriously threatening the quality consistency of electronic products. Therefore, researching methods to generate high-quality adversarial examples for solder joint images and thereby enhance the general robustness of the model has significant industrial application value.
[0003] Currently, methods to improve the robustness of circuit board solder joint defect identification models mainly focus on adversarial training, and can be categorized into three main types: The first type is adversarial training methods based on pixel-space iterative generation, such as Projected Gradient Descent (PGD). This method directly seeks perturbations that maximize the classification loss at the image pixel level and adds them to the training set to force the model to learn robust features through repeated training. The second type is adversarial example generation methods based on Generative Adversarial Networks (GANs) or Variational Autoencoders (VAEs). These methods utilize generative models to learn the data distribution of real solder joint images, thereby mapping adversarial examples in the latent space that are more semantically consistent than pixel perturbations. The third type is based on transfer attacks. This method generates adversarial examples on one or more white-box models and utilizes the commonalities in the decision boundaries between different models to attempt to transfer the adversarial nature to the target model to be strengthened through data augmentation.
[0004] However, all of the above-mentioned existing methods have some significant drawbacks: First, the perturbations generated by the adversarial training method based on pixel space iteration often contain a lot of high-frequency noise, which not only easily destroys the original structural information of the solder joint image, making the generated adversarial samples visually unnatural, but also such perturbations are easily filtered out by simple image preprocessing (such as smoothing filtering), resulting in the enhanced model lacking generalization ability. Second, when optimizing latent variables, the aforementioned adversarial sample generation methods based on generative adversarial networks or variational autoencoders often use norm sphere mapping to constrain latent vectors. Latent vectors are prone to severe high-frequency fluctuations during the iteration process, causing the generated adversarial samples to deviate from the real manifold of the weld point image, producing serious visual artifacts, thereby interfering with the model's learning of real defect features. Third, the aforementioned methods based on migration attacks can often only perform loss calculations on a limited number of white-box models, resulting in the generated adversarial examples being overfitted to certain specific model parameters. When the intersection of the decision boundaries between the target model and the white-box model is small, the previously generated adversarial examples cannot reflect the impact of the sample distribution shift in the actual production environment on the model's decision-making, and cannot provide continuous and general robustness gains. Fourth, the three adversarial sample-based enhancement methods mentioned above are often deeply tied to specific pixel locations. Once the image undergoes a slight scaling or translation shift, the originally generated adversarial perturbations will fail due to misalignment, resulting in significant limitations in the performance of the enhanced defect recognition model when facing dynamic and changing real-world production environments. Summary of the Invention
[0005] To address the aforementioned deficiencies or improvement needs of existing technologies, this invention provides a general robustness enhancement method and system for circuit board solder joint defect identification models. Its purpose is to solve the technical problems of existing adversarial training methods based on pixel-space iterative generation, which often generate perturbations containing a large amount of high-frequency noise. This not only easily destroys the original structural information of the solder joint image, resulting in visually unnatural generated adversarial examples, but also makes such perturbations easily filtered out by simple image preprocessing, leading to a lack of generalization ability in the enhanced model's robustness. Furthermore, it addresses the technical problem that existing adversarial example generation methods based on generative adversarial networks or variational autoencoders often use norm sphere mapping to constrain latent vectors when optimizing latent variables. This can cause latent vectors to exhibit severe high-frequency fluctuations during iteration, leading to generated adversarial examples deviating from the true manifold of the solder joint image and producing severe visual artifacts, thereby interfering with the model's learning of real defect features. The problems include: existing methods based on transfer attacks can only perform loss calculations for a limited number of white-box models, resulting in the generated adversarial examples overfitting to certain specific model parameters; when the intersection of the decision boundaries between the target model and the white-box model is small, the previously generated adversarial examples cannot reflect the impact of sample distribution shifts in the actual production environment on model decisions, and cannot provide continuous and general robust gains; and the fact that the three adversarial example-based enhancement methods mentioned above are often deeply bound to specific pixel locations, so once the image undergoes a slight scaling or translation shift, the originally generated adversarial perturbations will fail due to misalignment, resulting in the enhanced defect recognition model exhibiting significant performance limitations when facing dynamically changing actual production environments.
[0006] To achieve the above objectives, according to one aspect of the present invention, a general robustness enhancement method for a circuit board solder joint defect identification model is provided, comprising the following steps: (1) Obtain the target model training set The training set Average score Individual Training Set The size of each sub-training set is 1. training set Each training sample in the dataset is of size 1. grayscale image, where This indicates the number of pixels horizontally in the grayscale image. This indicates the number of pixels vertically in a grayscale image. The value range is from 10 to 20; (2) Set up a counter ; (3) Obtain the target model The weight parameter vector of each fully connected network and bias parameter vector The sizes of the two are respectively and and set a counter ; (4) The first one obtained from step (1) Individual Training Set Get the first training samples and its corresponding tags and the first training samples Input diffusion model encoder To obtain the first Hidden vectors ; (5) Set up a counter and initialize the gradient mean. Initialize the squared average gradient ; (6) The first step obtained in step (4) Hidden vectors Input diffusion model decoder To obtain the first One generated sample ; (7) The first step obtained in step (6) One generated sample Nine transformations are performed to obtain the 0th, 1st, 2nd, ..., 8th transformation samples, respectively. (8) For each transformed sample obtained in step (7) In other words, replicating the target model For the perturbation model For the weight parameter vector obtained in step (3) and bias parameter vector conduct The process of randomly setting the result to zero is repeated several times to obtain the 1st, 2nd, ..., ... A new weight vector and the new bias parameter vector Together, they constitute the perturbation model. ,in , is the set of positive integers, The value range is from 5 to 20; (9) Based on the transformed sample obtained in step (7) The perturbation model obtained in step (8) , obtain the Hidden vectors Output loss : (10) The first one obtained from step (9) Hidden vectors Output loss , obtain the first Hidden vectors single update value ; (11) Using the first step (10) obtained Hidden vectors single update value Update # Hidden vectors ; (12) Determine if there is a counter. Less than the total number of optimization iterations If true, then set. And return to step (6), otherwise the first step will be... Hidden vectors Input diffusion model decoder To obtain the first One adversarial example Then proceed to step (13), where Represents the number of smoothing periods, and has ; (13) Determine the counter Is it smaller than the size of each sub-training set obtained in step (1)? If so, then set And return to step (4), otherwise all the results obtained in step (12) will be returned. One adversarial example The combination is the first One adversarial training set Then proceed to step (14); (14) Based on the result obtained in step (13), One adversarial training set And use mini-batch gradient descent to model the target model. Train the network to update its parameters and obtain the target model with updated parameters. ; (15) Determine the counter Is it less than If so, then set If the process ends, return to step (3) or otherwise the process ends.
[0007] Preferably, the target model It is a circuit board solder joint defect identification model that needs to be robustly enhanced.
[0008] Preferably, a diffusion model It is a general image generation task diffusion model based on a large-scale dataset pre-trained.
[0009] Preferably, step (7) specifically involves first, placing the first... One generated sample Reduced to their original size respectively , , and Then, bilinear interpolation was used to enlarge the four reduced samples to... To obtain the 1st, 2nd, 3rd, and 4th transformed samples. , then the first One generated sample Move in the four directions: up, down, left, and right. Pixels were used to obtain the 5th, 6th, 7th, and 8th transform samples, respectively. ;in This represents the floor function; finally, the first... One generated sample Copy as the 0th transformed sample .
[0010] Preferably, in step (8), the weight parameter vector obtained in step (3) is... The process of performing the first random zeroing is specifically as follows: First, calculate the weight parameter vector. The Middle element Output weights And there are , Indicates based on target model The loss function is then applied to the weight parameter vector in descending order of all output weights. All parameters are rearranged to obtain a vector. After that, the vector Uniformly divided into 4 weight parameter vectors Finally, Bernoulli distribution was used respectively. , , and For the weight parameter vector Each element in the array is randomly set to zero, and then the result is processed according to the weight parameter vector. All elements in the weight parameter vector Recombined to obtain a new weight parameter vector; probability parameters , , and They are respectively and .
[0011] Preferably, in step (8), the bias parameter vector is... The process of performing the first random zeroing is specifically as follows: First, calculate the bias parameter vector. The Middle element Output weights Then, the weight parameter vector is processed in descending order of all output weights. All parameters are rearranged to obtain a vector. After that, the vector Uniformly divided into 4 weight parameter vectors Finally, Bernoulli distribution was used respectively. , , and For the weight parameter vector Each element in the vector is randomly set to zero, and the result is then processed according to the bias parameter vector. All elements in the bias parameter vector Recombined to obtain a new bias parameter vector, probability parameter , , and They are respectively and .
[0012] Preferably, step (9) is to obtain the first step using the following formula. Hidden vectors Output loss : ; in Represents the cross-entropy loss function; Indicates the first training samples The Line number The value of the column pixel, Indicates the first One generated sample The Line number The value of the column pixel; As a hidden constraint factor, It is a hidden penalty factor.
[0013] Preferably, step (10) specifically involves first updating the gradient average using the following formula. and gradient squared mean : ; ; Among the fixed parameters , ; Then, based on the updated gradient average and the updated gradient squared mean And use the following formula to obtain the first Hidden vectors single update value : ; Among the fixed parameters , .
[0014] Preferably, step (11) involves updating the first step using the following formula. Hidden vectors : ; Among them, fixed parameters , It indicates a smooth period, and has =100.
[0015] According to another aspect of the present invention, a general robustness enhancement system for a circuit board solder joint defect identification model is provided, comprising the following modules: The first module is used to obtain the target model. training set The training set Average score Individual Training Set The size of each sub-training set is 1. training set Each training sample in the dataset is of size 1. grayscale image, where This indicates the number of pixels horizontally in the grayscale image. This indicates the number of pixels vertically in a grayscale image. The value range is from 10 to 20; The second module is used to set the counter. ; The third module is used to obtain the target model. The weight parameter vector of each fully connected network and bias parameter vector The sizes of the two are respectively and and set a counter ; The fourth module is used to obtain the first module. Individual Training Set Get the first training samples and its corresponding tags and the first training samples Input diffusion model encoder To obtain the first Hidden vectors ; The fifth module is used to set the counter. and initialize the gradient mean. Initialize the squared average gradient ; The sixth module is used to process the results obtained from the fourth module. Hidden vectors Input diffusion model decoder To obtain the first One generated sample ; Module 7 is used to process the results obtained from Module 6. One generated sample Nine transformations are performed to obtain the 0th, 1st, 2nd, ..., 8th transformation samples, respectively. The eighth module is used for each transformed sample obtained from the seventh module. In other words, replicating the target model For the perturbation model The weight parameter vector obtained from the third module and bias parameter vector conduct The process of randomly setting the result to zero is repeated several times to obtain the 1st, 2nd, ..., ... A new weight vector and the new bias parameter vector Together, they constitute the perturbation model. ,in , is the set of positive integers, The value range is from 5 to 20; The ninth module is used to transform the samples obtained from the seventh module. The perturbation model obtained from the eighth module , obtain the Hidden vectors Output loss : Module 10 is used to derive the first module from Module 9. Hidden vectors Output loss , obtain the first Hidden vectors single update value ; Module 11 is used to obtain the result from Module 10. Hidden vectors single update value Update # Hidden vectors ; The twelfth module is used to determine whether a counter exists. Less than the total number of optimization iterations If true, then set. And return to the sixth module, otherwise return to the first module. Hidden vectors Input diffusion model decoder To obtain the first One adversarial example Then proceed to module thirteen, in which... Represents the number of smoothing periods, and has ; Module 13 is used to determine the counter. Is it smaller than the size of each sub-training set obtained from the first module? If so, then set And return to the fourth module, otherwise return all the results obtained from the twelfth module. One adversarial example The combination is the first One adversarial training set Then proceed to module fourteen; Module fourteen is used to build upon the results obtained from module thirteen. One adversarial training set And use mini-batch gradient descent to model the target model. Train the network to update its parameters and obtain the target model with updated parameters. ; Module 15 is used to determine the counter. Is it less than If so, then set If the process fails, it returns to the third module; otherwise, the process ends.
[0016] In summary, compared with the prior art, the above-described technical solutions conceived by this invention can achieve the following beneficial effects: (1) Since the present invention adopts steps (4) to (6), it inputs the sample to be identified into a pre-trained diffusion model and searches for adversarial perturbations in the latent space of the model instead of operating directly in the pixel space. The powerful structural prior of the diffusion model ensures that the generated adversarial sample conforms to the real distribution structure of the solder joint image. Therefore, it can solve the technical problem that the perturbations generated by the existing adversarial training method based on pixel space contain high-frequency noise and do not conform to the structural features of the solder joint image, resulting in weak robustness and generalization ability of the enhanced model. (2) Since the present invention adopts steps (9) and (11), it not only introduces a smoothing period during the iteration process, but also uses a smoothing strategy based on historical averages to periodically update the latent variables in order to filter out high-frequency components in the optimization trajectory; at the same time, a flexible penalty term based on the ReLU function is introduced in the loss function to constrain the perturbation range, in order to replace the existing hard truncation operation. The latent variables are guided to evolve smoothly within a reasonable manifold range through the differentiable loss gradient, avoiding gradient breakage and drastic jumps in pixel values caused by hard truncation. This significantly enhances the stability, continuity and visual naturalness of the latent space search and the generated samples. Therefore, it can solve the technical problem that the latent variables exhibit drastic high-frequency fluctuations and produce visual artifacts due to the lack of trajectory constraints in the latent space optimization process, which in turn interferes with the model's learning of real defect features. (3) Since the present invention adopts steps (8) to (9), it simulates the dynamic changes of the model during the training process by randomly setting the weights of the target model to zero multiple times. Based on this dual diversity of model and data, it obtains more transferable attack gradients. Therefore, it can solve the technical problem that the generated adversarial samples fail after the model is updated due to the adversarial generation strategy overfitting to the parameter snapshot of a single static target model, making it difficult to provide general robust gain. (4) In this invention, step (7) is adopted. Before inputting the sample into the model to calculate the loss function, a set of samples to be detected with spatial geometric diversity is constructed by scaling at different scales and corresponding interpolation and restoration operations, as well as multi-directional pixel translation transformation. This guides the calculation of adversarial gradients, so that the generated adversarial perturbations can cover the size deviations and displacement perturbations commonly encountered in industrial imaging. Therefore, it can solve the problem that existing enhancement methods based on adversarial samples are limited in performance when facing the actual production environment with dynamic changes in pixel space. (5) The implementation of this invention is simple and can be completed using existing pre-trained diffusion models and gradient optimization frameworks. There is no need to train a complex generative network from scratch, and the computational cost is controllable. (6) The present invention has wide applicability. It is not only applicable to weld joint defect identification models of various neural network structures, but its latent space-based smoothing and model perturbation strategies can also be extended to other industrial vision inspection tasks with high precision requirements. Attached Figure Description
[0017] Figure 1 This is a flowchart of a general robustness enhancement method for the circuit board solder joint defect identification model of the present invention. Detailed Implementation
[0018] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention. Furthermore, the technical features involved in the various embodiments of this invention described below can be combined with each other as long as they do not conflict with each other.
[0019] The basic idea of this invention is to improve the general robustness of the circuit board solder joint defect identification model from four aspects. First, training samples are input into a pre-trained general diffusion generation model to extract latent variables, and a flexible penalty term based on the ReLU property is used to replace the hard truncation to constrain the perturbation range. This leverages the strong structural prior of the diffusion model to ensure that the generated latent space adversarial samples highly conform to the distribution of real solder joint images. Second, a smoothing period is introduced during the adversarial optimization iteration of latent variables, and a strategy based on historical averages is used to periodically update the optimization trajectory to filter out high-frequency components, thereby effectively avoiding visual artifacts caused by drastic fluctuations in latent variables and interference with the learning of real features. Finally, before calculating the adversarial loss, the generated samples are subjected to multi-scale scaling and multi-directional translation, and the target model weights are randomly zeroed multiple times to simulate the training blind zone, so that the calculation of the adversarial gradient covers the uncertainty of spatial geometric transformation and model dynamic evolution.
[0020] like Figure 1 As shown, this invention provides a general robustness enhancement method for a circuit board solder joint defect identification model, comprising the following steps: (1) Obtain the target model training set The training set Average score Individual Training Set The size of each sub-training set is 1. training set Each training sample in the dataset is of size 1. grayscale image, where This indicates the number of pixels horizontally in the grayscale image. This indicates the number of pixels vertically in a grayscale image. The value range is 10 to 20, preferably 10; Among them, the target model It is a circuit board solder joint defect identification model that needs to be robustly enhanced.
[0021] (2) Set up a counter ; (3) Obtain the target model The weight parameter vector of each fully connected network and bias parameter vector The sizes of the two are respectively and and set a counter ; (4) The first one obtained from step (1) Individual Training Set Get the first training samples and its corresponding tags and the first training samples Input diffusion model encoder To obtain the first Hidden vectors ; Specifically, diffusion model It is a general image generation task diffusion model based on a large-scale dataset pre-trained. (5) Set up a counter and initialize the gradient mean. Initialize the squared average gradient ; (6) The first step obtained in step (4) Hidden vectors Input diffusion model decoder To obtain the first One generated sample ; The advantages of steps (4) to (6) above are that they can make full use of the powerful structural prior knowledge of the general diffusion model after large-scale data training, effectively avoid the sudden high-frequency noise that is easily introduced in traditional pixel-level adversarial generation strategies, and ensure that the latent space adversarial samples generated in the end are highly consistent with the natural distribution and physical structure of the real circuit board solder joint images.
[0022] (7) The first step obtained in step (6) One generated sample Nine transformations are performed to obtain the 0th, 1st, 2nd, ..., 8th transformation samples, respectively. Specifically, this step involves first, setting the first... One generated sample Reduced to their original size respectively , , and Then, bilinear interpolation was used to enlarge the four reduced samples to... To obtain the 1st, 2nd, 3rd, and 4th transformed samples. , then the first One generated sample Move in the four directions: up, down, left, and right. Pixels were used to obtain the 5th, 6th, 7th, and 8th transform samples, respectively. .in This represents the floor function; finally, the first... One generated sample Copy as the 0th transformed sample .
[0023] The advantage of this step (7) is that it can cover a wide range of spatial geometric diversity through multi-scale scaling and multi-directional pixel translation operations. This effectively avoids the problem that traditional adversarial perturbations are prone to failure when encountering small-scale scaling or translation due to their deep binding with fixed pixel positions. It ensures that the adversarial samples generated in the final guidance fully cover the size deviations and displacement fluctuations commonly seen in actual industrial imaging.
[0024] (8) For each transformed sample obtained in step (7) In other words, replicating the target model For the perturbation model For the weight parameter vector obtained in step (3) and bias parameter vector conduct The process of randomly setting the result to zero is repeated several times to obtain the 1st, 2nd, ..., ... A new weight vector and the new bias parameter vector Together, they constitute the perturbation model. ,in , is the set of positive integers, The value range is from 5 to 20, preferably 10; Specifically, setting a parameter to zero means that the backpropagation process of that parameter is blocked.
[0025] In this step, the weight parameter vector obtained in step (3) is... The process of performing the first random zeroing is specifically as follows: First, calculate the weight parameter vector. The Middle element Output weights And there are ( (It is the set of integers) Indicates based on target model The loss function is then applied to the weight parameter vector in descending order of all output weights. All parameters are rearranged to obtain a vector. After that, the vector Uniformly divided into 4 weight parameter vectors Finally, Bernoulli distribution was used respectively. , , and For the weight parameter vector Each element in the array is randomly set to zero, and then the result is processed according to the weight parameter vector. All elements in the weight parameter vector Recombined to obtain a new weight parameter vector; in this invention, probability parameters , , and They are respectively and .
[0026] In this step, the weight parameter vector obtained in step (3) is... The process of performing the second random zeroing is exactly the same as the first random zeroing process described above, and the subsequent processes are the same, so they will not be repeated here.
[0027] In this step, the bias parameter vector is... The process of performing the first random zeroing is specifically as follows: First, calculate the bias parameter vector. The Middle element Output weights Then, the weight parameter vector is processed in descending order of all output weights. All parameters are rearranged to obtain a vector. After that, the vector Uniformly divided into 4 weight parameter vectors Finally, Bernoulli distribution was used respectively. , , and For the weight parameter vector Each element in the vector is randomly set to zero, and the result is then processed according to the bias parameter vector. All elements in the bias parameter vector Recombined to obtain a new bias parameter vector, in this invention, the probability parameter , , and They are respectively and .
[0028] In this step, the bias parameter vector obtained in step (3) is... The process of performing the second random zeroing is exactly the same as the first random zeroing process described above, and the subsequent processes are the same, so they will not be repeated here.
[0029] The advantage of this step (8) is that it can simulate the dynamic changes and inference blind spots of the model during the training process by randomly setting the network parameters of the target model to zero multiple times. This effectively avoids the failure problem caused by the traditional adversarial sample generation strategy being overfitted to a single static model parameter snapshot, and brings continuous and universal robustness gains to the defect identification model.
[0030] (9) Based on the transformed sample obtained in step (7) The perturbation model obtained in step (8) And use the following formula to obtain the first Hidden vectors Output loss : ; in This represents the cross-entropy loss function. Indicates the first training samples The Line number The value of the column pixel, Indicates the first One generated sample The Line number The value of the column pixel. As a hidden constraint factor, It is a hidden penalty factor.
[0031] The advantage of this step (9) is that it uses a flexible penalty term based on the ReLU function to replace the hard truncation to constrain the perturbation range, which effectively avoids the gradient breakage and severe high-frequency fluctuation of latent variables caused by hard truncation in traditional latent space optimization.
[0032] (10) The first one obtained from step (9) Hidden vectors Output loss , obtain the first Hidden vectors single update value ; Specifically, this step involves first updating the gradient mean using the following formula. and gradient squared mean : ; ; Among the fixed parameters , ; Then, based on the updated gradient average and the updated gradient squared mean And use the following formula to obtain the first Hidden vectors single update value : ; Among the fixed parameters , ; (11) Using the first step (10) obtained Hidden vectors single update value Update # Hidden vectors ; Specifically, ; Among them, fixed parameters , It indicates a smooth period, and has =100; The advantages of the above steps (10) to (11) are that the latent variables can be updated using the momentum gradient estimation, dynamic learning rate estimation and periodic historical average smoothing strategy. This not only stabilizes the iteration direction of the dependent variable, but also filters out high-frequency components in the optimization trajectory, guides the latent variables to achieve smooth and continuous evolution within a reasonable range of real data manifold, further enhances the visual naturalness of the generated adversarial examples, and ensures that the model can learn the real circuit board solder joint defect features without interference.
[0033] (12) Determine if there is a counter. Less than the total number of optimization iterations If true, then set. And return to step (6), otherwise the first step will be... Hidden vectors Input diffusion model decoder To obtain the first One adversarial example Then proceed to step (13), where Represents the number of smoothing periods, and has ; (13) Determine the counter Is it smaller than the size of each sub-training set obtained in step (1)? If so, then set And return to step (4), otherwise all the results obtained in step (12) will be returned. One adversarial example The combination is the first One adversarial training set Then proceed to step (14); (14) Based on the result obtained in step (13), One adversarial training set And use mini-batch gradient descent (i.e., the Mini-batch gradient descent algorithm) on the target model. Train the network to update its parameters and obtain the target model with updated parameters. ; (15) Determine the counter Is it less than If so, then set If the process ends, return to step (3) or otherwise the process ends.
[0034] The advantages of the above steps (14) to (15) are that by dividing the total training set into multiple parts and using a single subset for adversarial training in turn, the dynamic game mechanism between model parameter update and adversarial sample generation is fully stimulated. This effectively avoids the problem of excessive computational overhead and severe overfitting of the model to early specific static disturbances that is easily caused by traditional single global adversarial training. It also ensures that the target model can continuously adapt to high-quality adversarial samples generated based on its latest state in multiple rounds of alternating iterations, thereby comprehensively and deeply learning the more generalized essential characteristics of real circuit board solder joint defects.
[0035] Those skilled in the art will readily understand that the above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A general robustness enhancement method for a circuit board solder joint defect identification model, characterized in that, Includes the following steps: (1) Obtain the target model training set The training set Average score Individual training set The size of each sub-training set is 1. training set Each training sample in the dataset is of size 1. grayscale image, where This indicates the number of pixels horizontally in the grayscale image. This indicates the number of pixels vertically in a grayscale image. The value range is from 10 to 20; (2) Set up a counter ; (3) Obtain the target model The weight parameter vector of each fully connected network and bias parameter vector The sizes of the two are respectively and and set a counter ; (4) The first one obtained from step (1) Individual training set Get the first training samples and its corresponding tags and the first training samples Input diffusion model encoder To obtain the first Hidden vectors ; (5) Set up a counter and initialize the gradient mean. Initialize the squared average gradient ; (6) The first step obtained in step (4) Hidden vectors Input diffusion model decoder To obtain the first One generated sample ; (7) The first step obtained in step (6) One generated sample Nine transformations are performed to obtain the 0th, 1st, 2nd, ..., 8th transformation samples, respectively. (8) For each transformed sample obtained in step (7) In other words, replicating the target model For the perturbation model For the weight parameter vector obtained in step (3) and bias parameter vector conduct The process of randomly setting the result to zero is repeated to obtain the 1st, 2nd, ..., ... A new weight vector and the new bias parameter vector Together, they constitute the perturbation model. ,in , is the set of positive integers, The value range is from 5 to 20; (9) Based on the transformed sample obtained in step (7) The perturbation model obtained in step (8) , obtain the Hidden vectors Output loss : (10) The first one obtained from step (9) Hidden vectors Output loss , obtain the first Hidden vectors single update value ; (11) Using the first step (10) obtained Hidden vectors single update value Update # Hidden vectors ; (12) Determine if there is a counter. Less than the total number of optimization iterations If true, then set. And return to step (6), otherwise the first step will be... Hidden vectors Input diffusion model decoder To obtain the first One adversarial example Then proceed to step (13), where Represents the number of smoothing periods, and has ; (13) Determine the counter Is it smaller than the size of each sub-training set obtained in step (1)? If so, then set And return to step (4), otherwise all the results obtained in step (12) will be returned. One adversarial example The combination is the first One adversarial training set Then proceed to step (14); (14) Based on the result obtained in step (13), the first One adversarial training set And use mini-batch gradient descent to model the target model. Train the network to update its parameters and obtain the target model with updated parameters. ; (15) Determine the counter Is it less than If so, then set If the process ends, return to step (3) or otherwise the process ends.
2. The general robustness enhancement method for the circuit board solder joint defect identification model according to claim 1, characterized in that, Target Model It is a circuit board solder joint defect identification model that needs to be robustly enhanced.
3. The general robustness enhancement method for the circuit board solder joint defect identification model according to claim 1 or 2, characterized in that, diffusion model It is a general image generation task diffusion model based on a large-scale dataset pre-trained.
4. The general robustness enhancement method for the circuit board solder joint defect identification model according to any one of claims 1 to 3, characterized in that, Step (7) specifically involves, firstly, placing the first... One generated sample Reduced to their original size respectively , , and Then, bilinear interpolation was used to enlarge the four reduced samples to... To obtain the 1st, 2nd, 3rd, and 4th transformed samples. , then the first One generated sample Move in the four directions: up, down, left, and right. Pixels were used to obtain the 5th, 6th, 7th, and 8th transformation samples, respectively. ;in This represents the floor function; finally, the first... One generated sample Copy as the 0th transformed sample .
5. The general robustness enhancement method for the circuit board solder joint defect identification model according to claim 4, characterized in that, In step (8), the weight parameter vector obtained in step (3) is... The process of performing the first random zeroing is specifically as follows: First, calculate the weight parameter vector. The Middle element Output weights And there are , Indicates based on target model The loss function is then applied to the weight parameter vector in descending order of all output weights. All parameters are rearranged to obtain a vector. After that, the vector Uniformly divided into 4 weight parameter vectors Finally, Bernoulli distribution was used respectively. , , and For the weight parameter vector Each element in the array is randomly set to zero, and then the result is processed according to the weight parameter vector. All elements in the weight parameter vector Recombined to obtain a new weight parameter vector; probability parameters , , and They are respectively and .
6. The general robustness enhancement method for the circuit board solder joint defect identification model according to claim 5, characterized in that, In step (8), the bias parameter vector The process of performing the first random zeroing is specifically as follows: First, calculate the bias parameter vector. The Middle element Output weights Then, the weight parameter vector is processed in descending order of all output weights. All parameters are rearranged to obtain a vector. After that, the vector Uniformly divided into 4 weight parameter vectors Finally, Bernoulli distribution was used respectively. , , and For the weight parameter vector Each element in the vector is randomly set to zero, and the result is then processed according to the bias parameter vector. All elements in the bias parameter vector Recombined to obtain a new bias parameter vector, probability parameter , , and They are respectively and .
7. The general robustness enhancement method for the circuit board solder joint defect identification model according to claim 6, characterized in that, Step (9) is to obtain the first step using the following formula. Hidden vectors Output loss : ; in Represents the cross-entropy loss function; Indicates the first training samples The Line number The value of the column pixel, Indicates the first One generated sample The Line number The value of the column pixel; As a hidden constraint factor, This is a hidden penalty factor.
8. The general robustness enhancement method for the circuit board solder joint defect identification model according to claim 7, characterized in that, Step (10) specifically involves first updating the gradient mean using the following formula. and gradient squared mean : ; ; Among the fixed parameters , ; Then, based on the updated gradient average and the updated gradient squared mean And use the following formula to obtain the first Hidden vectors single update value : ; Among the fixed parameters , .
9. The general robustness enhancement method for the circuit board solder joint defect identification model according to claim 8, characterized in that, Step (11) is to update the first step using the following formula. Hidden vectors : ; Among them, fixed parameters , It indicates a smooth period, and has =100.
10. A general robustness enhancement system for a circuit board solder joint defect identification model, characterized in that, Includes the following modules: The first module is used to obtain the target model. training set The training set Average score Individual training set The size of each sub-training set is 1. training set Each training sample in the dataset is of size 1. grayscale image, where This indicates the number of pixels horizontally in the grayscale image. This indicates the number of pixels vertically in a grayscale image. The value range is from 10 to 20; The second module is used to set the counter. ; The third module is used to obtain the target model. The weight parameter vector of each fully connected network and bias parameter vector The sizes of the two are respectively and and set a counter ; The fourth module is used to obtain the first module. Individual training set Get the first training samples and its corresponding tags and the first training samples Input diffusion model encoder To obtain the first Hidden vectors ; The fifth module is used to set the counter. and initialize the gradient mean. Initialize the squared average gradient ; The sixth module is used to process the results obtained from the fourth module. Hidden vectors Input diffusion model decoder To obtain the first One generated sample ; Module 7 is used to process the results obtained from Module 6. One generated sample Nine transformations are performed to obtain the 0th, 1st, 2nd, ..., 8th transformation samples, respectively. The eighth module is used for each transformed sample obtained from the seventh module. In other words, replicating the target model For the perturbation model The weight parameter vector obtained from the third module and bias parameter vector conduct The process of randomly setting the result to zero is repeated to obtain the 1st, 2nd, ..., ... A new weight vector and the new bias parameter vector Together, they constitute the perturbation model. ,in , is the set of positive integers, The value range is from 5 to 20; The ninth module is used to transform the samples obtained from the seventh module. The perturbation model obtained from the eighth module , obtain the Hidden vectors Output loss : Module 10 is used to derive the first module from Module 9. Hidden vectors Output loss , obtain the first Hidden vectors single update value ; Module 11 is used to obtain the result from Module 10. Hidden vectors single update value Update # Hidden vectors ; The twelfth module is used to determine whether a counter exists. Less than the total number of optimization iterations If true, then set. And return to the sixth module, otherwise return to the first module. Hidden vectors Input diffusion model decoder To obtain the first One adversarial example Then proceed to module thirteen, in which... Represents the number of smoothing periods, and has ; Module 13 is used to determine the counter. Is it smaller than the size of each sub-training set obtained from the first module? If so, then set And return to the fourth module, otherwise return all the results obtained from the twelfth module. One adversarial example The combination is the first One adversarial training set Then proceed to module fourteen; Module fourteen is used to build upon the results obtained from module thirteen. One adversarial training set And use mini-batch gradient descent to model the target model. Train the network to update its parameters and obtain the target model with updated parameters. ; Module 15 is used to determine the counter. Is it less than If so, then set If the process fails, it returns to the third module; otherwise, the process ends.