Defect detection model training method and device, computer equipment and storage medium

In the defect detection model training, the ratio of the target training data set is used to adjust the model parameters, and the problem of traditional training efficiency is solved, and the detection of new defect types is quickly adapted to the detection and improvement of training efficiency and accuracy is achieved.

CN118897992AInactive Publication Date: 2024-11-05SHENZHEN SMARTMORE TECH CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202411399687.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-09
Publication Date
2024-11-05
Estimated Expiration
Not applicable · inactive patent

Smart Images

  • Figure CN118897992A_ABST
    Figure CN118897992A_ABST
Patent Text Reader

Abstract

The invention relates to a defect detection model training method and device, computer equipment and a storage medium. The method comprises the following steps: acquiring a current defect detection model, a current training data set and a historical training data set; the current defect detection model is obtained by training based on a historical training data set; determining a first quantity of current training data in the current training data set and a second quantity of historical training data in the historical training data set as a target training data set; the ratio of the first quantity to the second quantity is within a preset ratio range; based on the target training data set, training the current defect detection model to obtain an initial error loss corresponding to the target training data set; and adjusting parameters of the current defect detection model based on the initial error loss to obtain a target defect detection model. By adopting the method, the training efficiency of the defect detection model can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence technology, and in particular to a defect detection model training method, apparatus, computer equipment and storage medium. Background Art

[0002] With the rapid development of artificial intelligence technology, neural network models have been widely used in various industries. For example, in industrial scenarios, defect detection models are used to detect defects in products. Before the defect detection model is used, a large amount of industrial image data is needed to train the defect detection model to improve the accuracy of the defect detection model.

[0003] In traditional technology, in order to make the defect detection model compatible with the defect detection of new products, it is necessary to use the industrial image data of the new products and a large amount of historical image data to train the defect detection model. The training process takes a lot of time, resulting in low efficiency in defect detection model training. Summary of the invention

[0004] Based on this, it is necessary to provide a defect detection model training method, device, computer equipment, computer readable storage medium and computer program product to address the above technical problems, which can improve the training efficiency of the defect detection model.

[0005] In a first aspect, the present application provides a defect detection model training method, comprising:

[0006] Obtaining a current defect detection model, a current training data set, and a historical training data set; the current defect detection model is obtained by training based on the historical training data set; the defect types corresponding to the training data in the current training data set and the historical training data set are not completely the same;

[0007] Determine a first quantity of current training data in the current training data set and a second quantity of historical training data in the historical training data set as a target training data set; a ratio of the first quantity to the second quantity is within a preset ratio range;

[0008] Based on the target training data set, the current defect detection model is trained to obtain the initial error loss corresponding to the target training data set;

[0009] Based on the initial error loss, the parameters of the current defect detection model are adjusted to obtain the target defect detection model.

[0010] In a second aspect, the present application also provides a defect detection model training device, comprising:

[0011] An acquisition module is used to acquire a current defect detection model, a current training data set, and a historical training data set; the current defect detection model is obtained by training based on the historical training data set; the defect types corresponding to the training data in the current training data set and the historical training data set are not completely the same;

[0012] A selection module is used to determine a first amount of current training data in a current training data set and a second amount of historical training data in a historical training data set as a target training data set; a ratio of the first amount to the second amount is within a preset ratio range;

[0013] A training module is used to train the current defect detection model based on a target training data set to obtain an initial error loss corresponding to the target training data set;

[0014] The adjustment module is used to adjust the parameters of the current defect detection model based on the initial error loss to obtain a target defect detection model.

[0015] In a third aspect, the present application provides a computer device, the computer device comprising a memory and a processor, the memory storing a computer program, and the processor implementing the steps in the above method when executing the computer program.

[0016] In a fourth aspect, the present application provides a computer-readable storage medium having a computer program stored thereon, which implements the steps in the above method when executed by a processor.

[0017] In a fifth aspect, the present application also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps in the above method are implemented.

[0018] The above-mentioned defect detection model training method, apparatus, computer equipment, computer-readable storage medium and computer program product, when a new defect type is added and the current defect detection model needs to be trained, obtains a current training data set and a historical training data set, the current training data set includes current training data corresponding to the new defect type, and determines a first number of current training data in the current training data set and a second number of historical training data in the historical training data set as a target training data set, that is, the number of target training data taken from the current training data set and the number of target training data taken from the historical training data set are equal or similar, compared with only using the current training data set to train the current defect detection model The defect detection model is trained by using the target training data set to train the current defect detection model, which not only enables the current defect detection model to learn the features corresponding to the newly added defect types, but also enables the current defect detection model to learn the features of the historical training data, thereby improving the accuracy of the defect detection model training; compared with using all the current training data in the current training data set and all the historical training data in the historical training data set to train the current defect detection model each time, using the target training data set to train the current defect detection model each time reduces the number of samples used in each training process, shortens the training time of each defect detection model, thereby improving the efficiency of the defect detection model training. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] FIG1 is a diagram of an application environment of a defect detection model training method provided by an embodiment of the present application;

[0020] FIG2 is a flow chart of a defect detection model training method provided in an embodiment of the present application;

[0021] FIG3 is a schematic diagram of a flow chart of steps for determining a target defect detection model provided in an embodiment of the present application;

[0022] FIG4 is a schematic diagram of a flow chart of a defect detection model loss weight determination step provided in an embodiment of the present application;

[0023] FIG5 is a schematic diagram of a defect detection model training process provided by an embodiment of the present application;

[0024] FIG6 is a schematic diagram of a defect detection model training duration provided in an embodiment of the present application;

[0025] FIG7 is a structural block diagram of a defect detection model training device provided in an embodiment of the present application;

[0026] FIG8 is an internal structure diagram of a computer device provided in an embodiment of the present application;

[0027] FIG. 9 is a diagram of the internal structure of a computer-readable storage medium provided in an embodiment of the present application. DETAILED DESCRIPTION

[0028] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0029] The defect detection model training method provided in the embodiment of the present application can be applied to the application environment shown in Figure 1. Among them, the terminal 102 communicates with the server 104 through the network. The data storage system can store the data that the server 104 needs to process. The data storage system can be integrated on the server 104, or it can be placed on the cloud or other network servers. Among them, the terminal 102 can be but is not limited to various personal computers, laptops, smart phones, tablets, Internet of Things devices and portable wearable devices. The Internet of Things devices can be smart speakers, smart TVs, smart air conditioners, smart car-mounted devices, etc. Portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. The server 104 can be implemented with an independent server or a server cluster consisting of multiple servers.

[0030] As shown in FIG2 , the embodiment of the present application provides a defect detection model training method, which is described by taking the method applied to the terminal 102 or the server 104 in FIG1 as an example. It is understandable that the computer device may include at least one of a terminal and a server. The method includes the following steps:

[0031] Step 202, obtaining a current defect detection model, a current training data set and a historical training data set; the current defect detection model is trained based on the historical training data set; the defect types corresponding to the training data in the current training data set and the historical training data set are not completely the same.

[0032] Among them, the current defect detection model refers to the neural network model currently used to detect defects in image data. It can be understood that the initial defect detection model is trained using a historical training data set. After the training is completed, the current defect detection model is obtained. The current defect detection model can be a deep learning model. The deep learning model refers to a neural network model trained using a deep learning method. The current defect detection model includes but is not limited to convolutional neural networks, recurrent neural networks, and generative adversarial networks. The input of the current defect detection model is image data or pictures, and the output includes but is not limited to at least one of the detection results, predicted defect type, defect location, image data mask, and defect level. The detection result refers to the result that characterizes whether there is a defect in the image data. The detection result can be the presence of a defect or the absence of a defect.

[0033] The current training data set refers to a set consisting of multiple current training data and the labeled defect types corresponding to the current training data. The current training data set is used to train the current defect detection model. The current training data can be image data or pictures. The labeled defect types include but are not limited to dirt, foreign matter, breakage, deformation, scratches, abrasions, crushing, bubbles, discoloration, wrinkles, cracks and bumps. The defect types corresponding to the training data in the current training data set and the historical training data set are not completely the same, which means that at least one of the labeled defect types corresponding to the current training data in the current training data set is a newly added defect type, or the labeled defect type corresponding to each current training data in the current training data set is a newly added defect type. The newly added defect type refers to a newly added defect type, which can be understood as a newly added defect type based on the labeled defect types corresponding to all historical training data, that is, the newly added defect type is different from the labeled defect types corresponding to all historical training data in the historical training data set. For example, the labeled defect types corresponding to all historical training data in the historical training data set include dirt, foreign matter, breakage, deformation, scratches, abrasions, crushing and bubbles, and wrinkles are newly added defect types.

[0034] The historical training data set refers to a set consisting of multiple historical training data and the labeled defect types corresponding to the historical training data. The historical training data set is used to train the current defect detection model and to retrain the current defect detection model. The historical training data set may include historical training data corresponding to different products or historical training data corresponding to different industrial scenarios. The historical training data may be image data or pictures. For example, the historical training data set includes pictures of automotive components, glass, tiles, and fabrics. The labeled defect types include but are not limited to dirt, foreign matter, breakage, deformation, scratches, abrasions, crushing, bubbles, discoloration, wrinkles, cracks, and bumps. The number of historical training data in the historical training data set is greater than the number of current training data in the current training data set. For example, the number of current training data in the current training data set is 100, and the number of historical training data in the historical training data set is 10,000.

[0035] Exemplarily, when there is a newly added defect type, the computer device obtains a current defect detection model, a current training data set, and a historical training data set, and a labeled defect type corresponding to at least one current training data in the current training data set is a newly added defect type.

[0036] In some embodiments, obtaining the current training data set includes: a computer device obtains newly added image data and annotated defect types corresponding to the newly added image data, compares the annotated defect types corresponding to the newly added image data with historical defect types in the historical defect set, and when the annotated defect types corresponding to the newly added image data are different from the historical defect types in the historical defect set, determines the annotated defect types corresponding to the newly added image data as the newly added defect types, and composes the current training data set with multiple newly added image data corresponding to the newly added defect types. The historical defect type set refers to a set composed of the annotated defect types corresponding to all historical training data in the historical training data set.

[0037] Step 204: determine a first quantity of current training data in the current training data set and a second quantity of historical training data in the historical training data set as a target training data set; a ratio of the first quantity to the second quantity is within a preset ratio range.

[0038] The first number and the second number may be preset numbers. The preset ratio range refers to a preset ratio range, and the preset ratio range satisfies [1-a, 1+b]. a and b may be the same or different, and both a and b are relatively small decimals and positive numbers, that is, the ratio of the first number to the second number is equal to or close to 1. For example, the first number is 10, the second number is 10, and the ratio of the first number to the second number is 1, or the first number is 15, the second number is 18, and the ratio of the first number to the second number is 5 / 6. The target training data set refers to a sample set used to train the current defect detection model once.

[0039] Step 206 , training the current defect detection model based on the target training data set to obtain an initial error loss corresponding to the target training data set.

[0040] The error loss refers to the value that represents the difference between the predicted value and the true value. The initial error loss refers to the value that represents the difference between the predicted defect type and the labeled defect type corresponding to all the target training data in the target training data set.

[0041] Exemplarily, a computer device inputs the target training data in the target training data set into the current defect detection model to obtain the predicted defect category corresponding to the target training data, and determines the initial error loss corresponding to the target training data set based on the predicted defect category and labeled defect category corresponding to all the target training data.

[0042] Step 208 , based on the initial error loss, adjust the parameters of the current defect detection model to obtain a target defect detection model.

[0043] Among them, parameters refer to the values ​​that the current defect detection model needs to learn and optimize during the training process. The target defect detection model refers to the defect detection model that has been trained based on the current defect detection model. It can be understood that the current defect detection model refers to the one obtained by training the initial defect detection model, and the target defect detection model refers to the one obtained by training the current defect detection model.

[0044] Exemplarily, the computer device adjusts the parameters of the current defect detection model according to the initial error loss, and obtains the target defect detection model when the training stop condition is met.

[0045] In some embodiments, steps 204 to 208 are repeatedly performed until the training stop condition is met to obtain the target defect detection model. That is, each time a first amount of current training data is randomly selected from the current training data set, and a second amount of historical training data is randomly selected from the historical training data set to form a target training data set, and the updated current defect detection model is trained using the target training data set obtained each time, thereby completing multiple trainings of the current defect detection model, and obtaining the target defect detection model when the training stop condition is met.

[0046] In some embodiments, after step 208, the method further includes: adding the current training data in the current training data set to the historical training data set to obtain an updated historical training data set. The updated historical training data set is used to train the target defect detection model when a new defect type appears.

[0047] It can be seen that in the embodiment of the present application, when a new defect type is added and the current defect detection model needs to be trained, the current training data set and the historical training data set are obtained, the current training data set includes the current training data corresponding to the new defect type, and the first number of current training data in the current training data set and the second number of historical training data in the historical training data set are determined as the target training data set, that is, the number of target training data taken from the current training data set is equal to or similar to the number of target training data taken from the historical training data set. Compared with using only the current training data set to train the current defect detection model, using the target training data set to train the current defect detection model Training the current defect detection model with the training data set not only enables the current defect detection model to learn the features corresponding to the newly added defect types, but also enables the current defect detection model to learn the features of the historical training data, thereby improving the accuracy of defect detection model training; compared to using all the current training data in the current training data set and all the historical training data in the historical training data set to train the current defect detection model each time, using the target training data set to train the current defect detection model each time reduces the number of samples used in each training process, shortens the training time of each defect detection model, thereby improving the efficiency of defect detection model training.

[0048] In some embodiments, the parameters of the current defect detection model are initial parameters; based on the initial error loss, the parameters of the current defect detection model are adjusted to obtain a target defect detection model, including:

[0049] Based on the initial error loss, the current defect detection model is trained to obtain an updated current defect detection model; the parameters of the updated current defect detection model are updated parameters;

[0050] The steps of looping and executing: determining a first amount of current training data in a current training data set and a second amount of historical training data in a historical training data set as a target training data set; training a current defect detection model based on the target training data set to obtain an initial error loss corresponding to the target training data set; and adjusting parameters of the current defect detection model based on the initial error loss to obtain an updated current defect detection model;

[0051] Until the training stop condition is met, the target defect detection model is obtained.

[0052] Among them, parameter refers to the parameter of the model. The training stop condition refers to the condition for stopping training. It can be understood that in the process of training the current defect detection model, multiple trainings are required. When the training stop condition is met, the current defect detection model can be stopped to obtain the target defect detection model. The training stop condition can be set according to actual needs. There is no restriction here. The training stop condition can be that the number of trainings is equal to the number threshold, or the initial error loss is less than or equal to the error loss threshold.

[0053] Exemplarily, after step 206, the computer device trains the current defect detection model based on the initial error loss to obtain an updated current defect detection model, and determines whether the training stop condition is met. If the training stop condition is not met, a loop is executed to determine the first number of current training data in the current training data set and the second number of historical training data in the historical training data set as the target training data set; based on the target training data set, the current defect detection model is trained to obtain the initial error loss corresponding to the target training data set; based on the initial error loss, the parameters of the current defect detection model are adjusted to obtain an updated current defect detection model; if the training stop condition is met, the updated current defect detection model is determined as the target defect detection model.

[0054] In some embodiments, based on the initial error loss, the current defect detection model is trained to obtain an updated current defect detection model; the number of training times is updated to obtain an updated number of training times; the updated number of training times is compared with the number threshold, and if the updated number of training times is less than the number threshold, a loop is executed to determine the first number of current training data in the current training data set and the second number of historical training data in the historical training data set as the target training data set; based on the target training data set, the current defect detection model is trained to obtain the initial error loss corresponding to the target training data set; based on the initial error loss, the parameters of the current defect detection model are adjusted to obtain an updated current defect detection model; if the updated number of training times is equal to the number threshold, the updated current defect detection model is determined as the target defect detection model. Updating the number of training times means adding 1 to the number of training times.

[0055] In some embodiments, based on the initial error loss, the current defect detection model is trained to obtain an updated current defect detection model; the initial error loss is compared with the error loss threshold; if the initial error loss is greater than the error loss threshold, a loop is executed to determine a first number of current training data in the current training data set and a second number of historical training data in the historical training data set as a target training data set; based on the target training data set, the current defect detection model is trained to obtain an initial error loss corresponding to the target training data set; based on the initial error loss, the parameters of the current defect detection model are adjusted to obtain an updated current defect detection model; if the initial error loss is less than or equal to the error loss threshold, the updated current defect detection model is determined as the target defect detection model.

[0056] In this embodiment, each time the parameters of the current defect detection model are adjusted to obtain an updated current defect detection model, it is determined whether the training stop condition is met. If the training stop condition is not met, the current defect detection model is trained again. Only when the training stop condition is met, the updated current defect detection model is determined as the target defect detection model. That is, the accuracy of the target defect detection model meets the requirements through multiple trainings, thereby improving the accuracy of the target defect detection model.

[0057] In some embodiments, before training the current defect detection model based on the initial error loss to obtain an updated current defect detection model, the method further includes:

[0058] Removing the current training data included in the target training data set from the current training data set to obtain a first training data set;

[0059] When the number of current training data in the first training data set is greater than or equal to the first number, the first training data set is determined as the updated current training data set; or, when the number of current training data in the first training data set is less than the first number, the acquired current training data set is determined as the updated current training data set;

[0060] Removing the historical training data included in the target training data set from the historical training data set to obtain a second training data set;

[0061] When the number of historical training data in the second training data set is greater than or equal to the second number, the second training data set is determined as an updated historical training data set; or, when the number of historical training data in the second training data set is less than the second number, the acquired historical training data set is determined as an updated historical training data set.

[0062] Among them, the first training data set refers to the set obtained by removing the first number of current training data selected in the current training data set. The second training data set refers to the set obtained by removing the second number of historical training data selected in the historical training data set. For example, the current training data set obtained includes 10 current training data, namely A, B, C, D, E, F, G, H, I and J, and the first number is 3. In the first training process, the 3 current training data selected are A, B and C. After removing the 3 selected current training data A, B and C, the remaining set consisting of D, E, F, G, H, I and J is the first training data set. The number of current training data in the first training data set is 7, and the number of current training data 7 is greater than the first number 3. Therefore, the first training set is determined as the updated current training data set, and the updated current training data set is the set consisting of D, E, F, G, H, I and J; in the second training process, the 3 current training data selected are The training data are D, E and F, then the set consisting of G, H, I and J is the first training data set, the number of current training data in the first training data set is 4, and the number of current training data 4 is greater than the first number 3, therefore, the first training set is determined as the updated current training data set, and the updated current training data set is the set consisting of G, H, I and J; in the third training process, the three current training data selected are G, H and I, then the set consisting of J is the first training data set, the number of current training data in the first training data set is 1, and the number of current training data 1 is less than the first number 3, therefore, the updated current training data set is the set consisting of A, B, C, D, E, F, G, H, I and J.

[0063] Exemplarily, before repeatedly executing the step of determining a first amount of current training data in the current training data set and a second amount of historical training data in the historical training data set as the target training data set, the current training data included in the target training data set in the current training data set is removed to obtain a first training data set. If the amount of current training data in the first training data set is greater than or equal to the first amount, the first training data set is determined as the updated current training data set; or if the amount of current training data in the first training data set is less than the first amount, the current training data set obtained in step 202 is determined as the updated current training data set. The historical training data included in the target training data set in the historical training data set is removed to obtain a second training data set. If the amount of historical training data in the second training data set is greater than or equal to the second amount, the second training data set is determined as the updated historical training data set; or if the amount of historical training data in the second training data set is less than the second amount, the historical training data set obtained in step 202 is determined as the updated historical training data set.

[0064] In this embodiment, before determining the next target training data, the target training data selected this time is removed from the current training data set. If the current training data in the first training data set obtained is sufficient to select the next target training data, the first training data set is used as the updated current training data set. If the current training data in the first training data set obtained is insufficient to select the next target training data, the initially acquired current training data set is used as the updated current training data set, which can ensure that each current training data in the current training data set can be used to train the current defect detection model, and that there are enough current training data in the updated current training data set to select the target training data. Similarly, not only can as much historical training data as possible in the historical training data set be used to train the historical defect detection model, but also there can be enough historical training data in the updated historical training data set to select the target training data.

[0065] In some embodiments, as shown in FIG3 , based on the initial error loss, the parameters of the current defect detection model are adjusted to obtain a target defect detection model, including:

[0066] Step 302, obtaining a reference exponential moving average; the reference exponential moving average is an exponential moving average corresponding to a target training data set immediately preceding the target training data set.

[0067] Among them, if the target training data set does not have the previous adjacent target training data set, the reference exponential moving average is zero, that is, the target training data set is the sample set of the first round of training, and the reference exponential moving average corresponding to the target training data set is zero. The exponential moving average refers to the value calculated using the EMA (Exponential Moving Average) method. EMA is a weighted moving average method that gives greater weight to the latest data and smaller weight to older data, so that EMA more sensitively reflects recent changes in data. The previous adjacent target training data set of the target training data set can be understood as the sample set for training the current defect detection model in this round is the target training data set, and the sample set for training the current defect detection model in the previous round is the previous adjacent target training data set of the target training data set.

[0068] Exemplarily, after obtaining the initial error loss, the computer device obtains the exponential moving average corresponding to the previous adjacent target training data set of the target training data set, and determines the exponential moving average corresponding to the previous adjacent target training data set of the target training data set as the reference exponential moving average.

[0069] Step 304 : determining a loss weight corresponding to the initial error loss based on the initial error loss and the reference exponential moving average.

[0070] Among them, the loss weight refers to the weight used to determine the target error loss. The loss weight is proportional to the initial error loss, that is, the larger the initial error loss, the larger the loss weight, and the smaller the initial error loss, the smaller the loss weight.

[0071] In some embodiments, the computer device obtains all historical initial error losses, sums all historical initial error losses and initial error losses, obtains error loss statistics, and determines the ratio between the initial error loss and the error loss statistics as the loss weight corresponding to the initial error loss. The historical initial error loss refers to the initial error loss obtained in each round of training before the current round of training. The loss weight calculated by the above method, if the initial error loss is larger, the loss weight is larger, the initial error loss is smaller, the loss weight is smaller, it can be understood that the larger the initial error loss, the greater the difference between the predicted defect type and the labeled defect type, reflecting that the current defect detection model has not learned the characteristic distribution of the target training data set, therefore, it is more necessary to use the target error loss obtained by this training to make a larger adjustment to the current defect detection model, and the larger the loss weight, the larger the target error loss calculated by the initial error loss and the loss weight, the larger the target loss, the larger the adjustment of the current defect detection model by the computer device, thereby realizing the use of the target error loss obtained by this training to make a larger adjustment to the current defect detection model, and improving the accuracy of the defect detection model.

[0072] Step 306: Determine a target error loss corresponding to the target training data set based on the initial error loss and its corresponding loss weight.

[0073] Exemplarily, the computer device multiplies the initial error loss by the loss weight to obtain a target error loss corresponding to the target training data set.

[0074] In some embodiments, the target error loss is as follows:

[0075] Formula (1)

[0076] Among them, i is the identifier of the number of training times; is the target error loss for the i-th training; is the loss weight corresponding to the initial error loss obtained from the i-th training; is the predicted defect type corresponding to the target training data in the target training data set used in the i-th training process; is the labeled defect type corresponding to the target training data in the target training data set used in the i-th training process; is the cross entropy loss obtained from the i-th training.

[0077] Step 308 , based on the target error loss, adjust the parameters of the current defect detection model to obtain a target defect detection model.

[0078] In this embodiment, the loss weight corresponding to the initial error loss is determined based on the initial error loss and the reference exponential moving average, and the loss weight is proportional to the initial error loss. The initial error loss is adjusted using the loss weight to obtain the target loss weight, that is, the larger the initial error loss, the larger the target loss weight obtained, the larger the initial error loss, the fewer feature distributions of the target training data set that the current defect detection model has learned, the larger the target loss weight, and the computer device can make larger adjustments to the parameters of the current defect detection model to learn the feature distribution of the target training data set; similarly, the smaller the initial error loss, the smaller the target loss weight obtained, the smaller the initial error loss, the more feature distributions of the target training data set that the current defect detection model has learned, and the smaller the target loss weight, the computer device can make smaller adjustments to the parameters of the current defect detection model to allow the current defect detection model to retain the feature distribution that has been learned, thereby improving the accuracy of the current defect detection model.

[0079] In some embodiments, as shown in FIG. 4 , based on the initial error loss and the reference exponential moving average, determining the loss weight corresponding to the initial error loss includes:

[0080] Step 402: Determine a target exponential moving average value corresponding to the target training data set based on the initial error loss and the reference exponential moving average value.

[0081] The target exponential moving average refers to the exponential moving average corresponding to the target training data set.

[0082] Exemplarily, the computer device multiplies the initial error loss by a preset first constant to obtain a first product, multiplies the reference exponential moving average by a preset second constant to obtain a second product, and adds the first product to the second product to obtain a target exponential moving average. The preset first constant is a preset value, the preset first constant is a smoothing constant, the preset second constant refers to a preset value, the preset second constant can be determined according to the preset first constant, and the preset first constant is greater than the preset second constant.

[0083] In some embodiments, the target exponential moving average is as follows:

[0084] Formula (2)

[0085] in, is the target exponential moving average corresponding to the target training data set used in the i-th training; is the cross entropy loss obtained from the i-th training; K is a smoothing constant, K is a decimal greater than 0.5 and less than 1, K can be set to 0.9; is the target exponential moving average corresponding to the target training data set used in the i-1th training.

[0086] The target exponential moving average calculated by formula (2) has the following characteristics: 1. Emphasis on recent data: EMA gives Larger weights enable the target exponential moving average to reflect recent changes more quickly; 2. Smoothness and adaptability: EMA can adapt to changes in data, but because of the existence of smoothing parameters, it will not respond immediately to extreme values, which helps to reduce the impact of outliers; 3. During the training process of the defect detection model, EMA helps the model better capture the dynamic characteristics of the loss function over time series, which is especially suitable for scenarios that require rapid response to data changes.

[0087] Step 404 : Determine a loss weight corresponding to the initial error loss based on the initial error loss and the target exponential moving average.

[0088] Exemplarily, the computer device obtains a preset index, takes the target exponential moving average as a base, performs an exponential operation on the preset index as a base, obtains an updated exponential moving average, and determines a loss weight based on a ratio between the initial error loss and the updated exponential moving average. The preset index refers to a pre-set index, and the preset index can be set according to experimental data.

[0089] By taking the target exponential moving average as the base and the preset exponent as the base for exponential operation, the updated exponential moving average is obtained. The loss weight is determined based on the ratio between the initial error loss and the updated exponential moving average, which can avoid the loss weight being too large or too small.

[0090] In some embodiments, the loss weights are as follows:

[0091] Formula (3)

[0092] in, is the loss weight corresponding to the initial error loss obtained from the i-th training; is the cross entropy loss obtained from the i-th training; is the target exponential moving average corresponding to the target training data set used in the i-th training; It is a preset index, which can be set according to experimental data.

[0093] In this embodiment, the target exponential moving average corresponding to the target training data set is determined by the initial error loss and the reference exponential moving average, and the loss weight corresponding to the initial error loss is determined by the initial error loss and the target exponential moving average, so that the loss weight is proportional to the initial error loss, thereby providing accurate basic data for the subsequent determination of the target error loss.

[0094] In some embodiments, based on the target training data set, the current defect detection model is trained to obtain an initial error loss corresponding to the target training data set, including:

[0095] For each target training data in the target training data set, based on the current defect detection model, determine the predicted defect type corresponding to the target training data;

[0096] Determine the detection error loss corresponding to the target training data based on the labeled defect type and the predicted defect type corresponding to the target training data;

[0097] Based on the detection error losses respectively corresponding to each target training data in the target training data set, an initial error loss corresponding to the target training data set is determined.

[0098] Among them, the predicted defect type refers to the defect type of the target training data determined by the current defect detection model based on the target training data. It can be understood that the target training data is input into the current defect detection model, and the result output by the current defect detection model is the predicted defect type. The labeled defect type refers to the actual defect type of the target training data. The detection error loss refers to the value that characterizes the difference between the predicted defect type and the labeled defect type.

[0099] Exemplarily, for each target training data in the target training data set, the computer device inputs the target training data into the current defect detection model, obtains the predicted defect type corresponding to the target training data, calculates the similarity between the labeled defect type and the predicted defect type, obtains the detection error loss corresponding to the target training data, calculates the average of the detection error losses corresponding to the target training data in the target training data set, and obtains the initial error loss corresponding to the target training data set.

[0100] In this embodiment, the detection error loss corresponding to the target training data is determined by the labeled defect type and predicted defect type corresponding to the target training data, and then the initial error loss corresponding to the target training data set is obtained based on the detection error loss corresponding to the target training data in the target training data set, thereby providing accurate basic data for subsequent adjustment of the parameters of the current defect detection model.

[0101] In some embodiments, obtaining a current defect detection model, a current training data set, and a historical training data set includes:

[0102] Obtaining a historical training data set and an initial defect detection model;

[0103] Based on the historical training data set, the initial defect detection model is trained to obtain the current defect detection model;

[0104] When a new defect type appears, a plurality of image data corresponding to the new defect type is determined as the current training data set.

[0105] The initial defect detection model refers to an untrained defect detection model, and the image data refers to an image of a product.

[0106] In this embodiment, when a new defect type appears, the current defect detection model needs to be retrained so that the current defect detection model can learn the characteristic distribution of the new defect type, and the multiple image data corresponding to the new defect type are determined as the current training data set to provide basic data for retraining the current defect detection model.

[0107] In some embodiments, for defect detection models used in industrial scenarios, new defects may appear in products due to production technology updates or production line mergers. In order to improve the accuracy of the defect detection model for new defects while maintaining the accuracy of the old defect detection, it is necessary to retrain the currently used defect detection model each time a new defect appears. The training process of the defect detection model is shown in Figure 5 and includes the following steps:

[0108] The computer device obtains a historical training data set and an initial defect detection model, and uses the historical training data set to train the initial defect detection model to obtain a current defect detection model.

[0109] Whenever a new defect type appears, multiple image data corresponding to the new defect type are determined as the current training data set. The computer device randomly obtains a first amount of current training data from the current training data set, and randomly obtains a second amount of historical training data from the historical training data set, and the obtained first amount of current training data and the obtained second amount of historical training data form a target training data set. The ratio of the first amount to the second amount is 1:1.

[0110] For each target training data in the target training data set, the computer device inputs each target training data into the current defect detection model, obtains the predicted defect type corresponding to the target training data, calculates the similarity between the labeled defect type and the predicted defect type corresponding to the target training data, and obtains the detection error loss corresponding to the target training data. Then, the average value of the detection error loss corresponding to all the target training data in the target training data set is calculated to obtain the initial error loss corresponding to the target training data set.

[0111] Obtain the reference exponential moving average, substitute the reference exponential moving average and the initial error loss into formula (2) to obtain the target exponential moving average corresponding to the target training data set; substitute the target exponential moving average and the initial error loss into formula (3) to obtain the loss weight corresponding to the initial error loss; substitute the loss weight corresponding to the initial error loss and the initial error loss into formula (1) to obtain the target error loss corresponding to the target training data set.

[0112] If the initial error loss is equal to or less than the error loss threshold, the computer device determines the current defect detection model as the target defect detection model.

[0113] If the initial error loss is greater than the error loss threshold, the computer device adjusts the parameters of the current defect detection model according to the target error loss to obtain an updated current defect detection model. The computer device removes the current training data included in the target training data set from the current training data set to obtain a first training data set. If the number of current training data in the first training data set is greater than or equal to the first number, the first training data set is determined as the updated current training data set, or if the number of current training data in the first training data set is less than the first number, the initially acquired current training data set is determined as the updated current training data set; remove the historical training data included in the target training data set from the historical training data set to obtain a second training data set. If the number of historical training data in the second training data set is greater than or equal to the second number, the second training data set is determined as the updated historical training data set, or if the number of historical training data in the second training data set is less than the second number, the initially acquired historical training data set is determined as the updated historical training data set. Repeat the above process.

[0114] After determining the target defect detection model, the current training data in the current training data set is added to the historical training data set to obtain an updated historical training data set. The updated historical training data set is used to retrain the target defect detection model when a new defect type appears.

[0115] Two different sets of historical training data sets are used to train the current defect detection model. The training results are shown in Figure 6. Three training methods are used to train the current defect detection model, namely, training the current defect detection model using only the current training data set, retraining (i.e., using the historical training data set and the current training data set to train the current defect detection model each time), and the present technical solution (i.e., using the above training method to train the current defect detection model). When the current defect detection model is trained using the current training data set, although the training time is the shortest, the degree of overlap is low, that is, the accuracy of the target defect detection model obtained by training is the lowest; when the current defect detection model is retrained, the degree of overlap is high, but the training time is long, that is, the efficiency of defect detection model training is the lowest; when the defect detection model is trained using the present technical solution, the degree of overlap is high and the training time is short, that is, on the basis of ensuring the accuracy of the target defect detection model, the efficiency of defect detection model training is high.

[0116] In this embodiment, when a new defect type is added and the current defect detection model needs to be trained, a current training data set and a historical training data set are obtained, the current training data set includes current training data corresponding to the new defect type, and a first number of current training data in the current training data set and a second number of historical training data in the historical training data set are determined as a target training data set, that is, the number of target training data taken from the current training data set and the number of target training data taken from the historical training data set are equal to or similar. Compared with only using the current training data set to train the current defect detection model, using the target training data set to train the current defect detection model not only enables the current defect detection model to learn the features corresponding to the new defect type, but also enables the current defect detection model to learn the features of the historical training data, thereby improving the accuracy of defect detection model training; compared with using all the current training data in the current training data set and all the historical training data in the historical training data set to train the current defect detection model each time, using the target training data set to train the current defect detection model each time reduces the number of samples used in each training process, shortens the training time of each defect detection model, and thereby improves the efficiency of defect detection model training.

[0117] It should be understood that, although the steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.

[0118] Based on the same inventive concept, the embodiment of the present application also provides a defect detection model training device. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in one or more defect detection model training device embodiments provided below can refer to the limitations of the defect detection model training method above, and will not be repeated here.

[0119] As shown in FIG. 7 , an embodiment of the present application provides a defect detection model training device, comprising:

[0120] The acquisition module 702 is used to acquire the current defect detection model, the current training data set and the historical training data set; the current defect detection model is obtained by training based on the historical training data set; the defect types corresponding to the training data in the current training data set and the historical training data set are not completely the same;

[0121] A selection module 704 is used to determine a first amount of current training data in the current training data set and a second amount of historical training data in the historical training data set as a target training data set; a ratio of the first amount to the second amount is within a preset ratio range;

[0122] A training module 706 is used to train the current defect detection model based on the target training data set to obtain an initial error loss corresponding to the target training data set;

[0123] The adjustment module 708 is used to adjust the parameters of the current defect detection model based on the initial error loss to obtain a target defect detection model.

[0124] In some embodiments, the parameters of the current defect detection model are initial parameters; in terms of adjusting the parameters of the current defect detection model based on the initial error loss to obtain the target defect detection model, the adjustment module 708 is specifically used to:

[0125] Based on the initial error loss, the current defect detection model is trained to obtain an updated current defect detection model; the parameters of the updated current defect detection model are updated parameters;

[0126] The steps of looping and executing: determining a first amount of current training data in a current training data set and a second amount of historical training data in a historical training data set as a target training data set; training a current defect detection model based on the target training data set to obtain an initial error loss corresponding to the target training data set; and adjusting parameters of the current defect detection model based on the initial error loss to obtain an updated current defect detection model;

[0127] Until the training stop condition is met, the target defect detection model is obtained.

[0128] In some embodiments, the adjustment module 708 is further configured to:

[0129] Removing the current training data included in the target training data set from the current training data set to obtain a first training data set;

[0130] When the number of current training data in the first training data set is greater than or equal to the first number, the first training data set is determined as the updated current training data set; or, when the number of current training data in the first training data set is less than the first number, the acquired current training data set is determined as the updated current training data set;

[0131] Removing the historical training data included in the target training data set from the historical training data set to obtain a second training data set;

[0132] When the number of historical training data in the second training data set is greater than or equal to the second number, the second training data set is determined as an updated historical training data set; or, when the number of historical training data in the second training data set is less than the second number, the acquired historical training data set is determined as an updated historical training data set.

[0133] In some embodiments, in adjusting the parameters of the current defect detection model based on the initial error loss to obtain the target defect detection model, the adjustment module 708 is specifically used to:

[0134] Obtain a reference exponential moving average value; the reference exponential moving average value is an exponential moving average value corresponding to a target training data set immediately preceding the target training data set;

[0135] Based on the initial error loss and the reference exponential moving average, determine the loss weight corresponding to the initial error loss;

[0136] Based on the initial error loss and its corresponding loss weight, determine the target error loss corresponding to the target training data set;

[0137] Based on the target error loss, the parameters of the current defect detection model are adjusted to obtain the target defect detection model.

[0138] In some embodiments, in determining the loss weight corresponding to the initial error loss based on the initial error loss and the reference exponential moving average, the adjustment module 708 is specifically configured to:

[0139] Determine a target exponential moving average corresponding to the target training data set based on the initial error loss and the reference exponential moving average;

[0140] Based on the initial error loss and the target exponential moving average, the loss weight corresponding to the initial error loss is determined.

[0141] In some embodiments, in training the current defect detection model based on the target training data set to obtain the initial error loss corresponding to the target training data set, the training module 706 is specifically used to:

[0142] For each target training data in the target training data set, based on the current defect detection model, determine the predicted defect type corresponding to the target training data;

[0143] Determine the detection error loss corresponding to the target training data based on the labeled defect type and the predicted defect type corresponding to the target training data;

[0144] Based on the detection error losses respectively corresponding to each target training data in the target training data set, an initial error loss corresponding to the target training data set is determined.

[0145] In some embodiments, in terms of acquiring the current defect detection model, the current training data set, and the historical training data set, the acquisition module 702 is specifically used to:

[0146] Obtaining a historical training data set and an initial defect detection model;

[0147] Based on the historical training data set, the initial defect detection model is trained to obtain the current defect detection model;

[0148] When a new defect type appears, a plurality of image data corresponding to the new defect type is determined as the current training data set.

[0149] Each module in the above defect detection model training device can be implemented in whole or in part by software, hardware, or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute the operations corresponding to each module.

[0150] In some embodiments, a computer device is provided, which may be a terminal, and its internal structure diagram may be shown in FIG8. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit, and an input device. The processor, the memory, and the input / output interface are connected via a system bus, and the communication interface, the display unit, and the input device are connected to the system bus via the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be implemented through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, the steps in the above-mentioned defect detection model training method are implemented. The display unit of the computer device is used to form a visually visible picture, which may be a display screen, a projection device, or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covering the display screen, or a button, trackball or touchpad set on the computer device shell, or an external keyboard, touchpad or mouse.

[0151] Those skilled in the art will understand that the structure shown in FIG. 8 is merely a block diagram of a partial structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different arrangement of components.

[0152] In some embodiments, a computer device is provided. The computer device includes a memory and a processor. The memory stores a computer program. When the processor executes the computer program, the steps in the above method embodiments are implemented.

[0153] In some embodiments, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.

[0154] In some embodiments, a computer-readable storage medium 900 is provided, on which a computer program 902 is stored. When the computer program 902 is executed by a processor, the steps in the above-mentioned method embodiments are implemented, and its internal structure diagram may be shown in FIG. 9 .

[0155] In some embodiments, a computer program product is provided. The computer program product includes a computer program. When the computer program is executed by a processor, the steps in the above method embodiments are implemented.

[0156] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.

[0157] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.

[0158] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0159] The above embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.

Claims

1. A defect detection model training method, characterized in that: include: Obtain the current defect detection model, the current training data set, and the historical training data set; The current defect detection model is trained based on the historical training data set; The defect types corresponding to the training data in the current training data set and the historical training data set are not completely the same; Determine a first amount of current training data in the current training data set and a second amount of historical training data in the historical training data set as a target training data set; The ratio of the first quantity to the second quantity is within a preset ratio range; Based on the target training data set, the current defect detection model is trained to obtain an initial error loss corresponding to the target training data set; Based on the initial error loss, the parameters of the current defect detection model are adjusted to obtain a target defect detection model.

2. The method according to claim 1, characterized in that The parameters of the current defect detection model are initial parameters; the parameters of the current defect detection model are adjusted based on the initial error loss to obtain a target defect detection model, including: Based on the initial error loss, the current defect detection model is trained to obtain an updated current defect detection model; the parameters of the updated current defect detection model are updated parameters; The steps of determining a first number of current training data in the current training data set and a second number of historical training data in the historical training data set as a target training data set, training the current defect detection model based on the target training data set to obtain an initial error loss corresponding to the target training data set, and adjusting parameters of the current defect detection model based on the initial error loss to obtain an updated current defect detection model are executed in a loop; Until the training stop condition is met, the target defect detection model is obtained.

3. The method according to claim 2, characterized in that Before training the current defect detection model based on the initial error loss to obtain an updated current defect detection model, the method further includes: Removing the current training data included in the target training data set from the current training data set to obtain a first training data set; When the number of current training data in the first training data set is greater than or equal to the first number, the first training data set is determined as an updated current training data set; or, when the number of current training data in the first training data set is less than the first number, the acquired current training data set is determined as an updated current training data set; Removing the historical training data included in the target training data set from the historical training data set to obtain a second training data set; When the number of historical training data in the second training data set is greater than or equal to the second number, the second training data set is determined as an updated historical training data set; or, when the number of historical training data in the second training data set is less than the second number, the acquired historical training data set is determined as an updated historical training data set.

4. The method according to claim 1, characterized in that: The adjusting the parameters of the current defect detection model based on the initial error loss to obtain a target defect detection model includes: Obtaining a reference exponential moving average value; the reference exponential moving average value is an exponential moving average value corresponding to a target training data set immediately preceding the target training data set; Determining a loss weight corresponding to the initial error loss based on the initial error loss and the reference exponential moving average; Determining a target error loss corresponding to the target training data set based on the initial error loss and its corresponding loss weight; Based on the target error loss, the parameters of the current defect detection model are adjusted to obtain a target defect detection model.

5. The method according to claim 4, characterized in that The determining, based on the initial error loss and the reference exponential moving average, a loss weight corresponding to the initial error loss includes: Determine a target exponential moving average value corresponding to the target training data set based on the initial error loss and the reference exponential moving average value; Based on the initial error loss and the target exponential moving average, a loss weight corresponding to the initial error loss is determined.

6. The method according to claim 1, characterized in that The training of the current defect detection model based on the target training data set to obtain an initial error loss corresponding to the target training data set includes: For each target training data in the target training data set, determining a predicted defect type corresponding to the target training data based on the current defect detection model; Determining a detection error loss corresponding to the target training data based on the labeled defect type and the predicted defect type corresponding to the target training data; Based on the detection error losses respectively corresponding to the target training data in the target training data set, an initial error loss corresponding to the target training data set is determined.

7. The method according to claim 1, characterized in that The obtaining of the current defect detection model, the current training data set and the historical training data set includes: Obtaining a historical training data set and an initial defect detection model; Based on the historical training data set, the initial defect detection model is trained to obtain a current defect detection model; When a new defect type appears, a plurality of image data corresponding to the new defect type is determined as a current training data set.

8. A defect detection model training device, characterized in that: include: An acquisition module is used to acquire the current defect detection model, the current training data set and the historical training data set; The current defect detection model is obtained by training based on the historical training data set; the defect types corresponding to the training data in the current training data set and the historical training data set are not completely the same; A selection module, configured to determine a first amount of current training data in the current training data set and a second amount of historical training data in the historical training data set as a target training data set; The ratio of the first quantity to the second quantity is within a preset ratio range; A training module, used to train the current defect detection model based on the target training data set to obtain an initial error loss corresponding to the target training data set; An adjustment module is used to adjust the parameters of the current defect detection model based on the initial error loss to obtain a target defect detection model.

9. A computer device, comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • Neural network for welding spot analysis based on welding curve and establishment method

    CN113553762A

  • Image processing model training method and device, computer equipment and storage medium

    CN114332500A

  • Training method and device of equipment defect detection model and equipment defect detection method

    CN116524296A

  • Image classification method and system based on difficulty perception data enhancement and label correction

    CN117636072A

  • Model training method, defect detection method and related device

    CN117975204A