Loss function determination method, defect identification method and related equipment

By constructing a target loss function that combines a transfer cost matrix and a cross-entropy loss function, the problem of not considering the differences in class importance in multi-class industrial defect detection in existing technologies is solved, which improves the model's recognition accuracy and robustness, and significantly reduces false positives, especially in high-cost error scenarios.

CN121637137APending Publication Date: 2026-03-10BOE TECHNOLOGY GROUP CO LTD
View PDF 9 Cites 0 Cited by

Patent Information

Application Number
CN202411224666.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-02
Publication Date
2026-03-10

AI Technical Summary

Technical Problem

Existing industrial defect detection methods struggle to adequately consider the actual differences in importance between different categories in multi-class classification problems, resulting in poor identification performance when some categories are more important than others. Furthermore, existing FocalLoss improvement algorithms are primarily applicable to binary classification scenarios and cannot effectively solve specific problems in multi-class scenarios.

Method used

A transfer cost matrix is ​​constructed, and the target loss function is determined by combining the cross-entropy loss function. The model is trained by using positive reward, no reward, and negative penalty elements to adjust the cost value of the model for different class classification errors, thereby enhancing the model's adaptability and robustness in multi-class classification problems.

Benefits of technology

It improves the model's recognition accuracy in multi-class industrial defect detection, especially in the presence of noise or high inter-class similarity, significantly reduces false positives, enhances the model's robustness and practicality, and can more effectively reduce the probability of high-cost errors.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121637137A_ABST
    Figure CN121637137A_ABST
Patent Text Reader

Abstract

The invention discloses a loss function determination method, a defect identification method and related equipment, and relates to the field of industrial defect detection.The method comprises the steps that a transfer cost matrix is constructed according to the attention of a target user on different defect categories; obtaining a cross entropy loss function; and determining a target loss function based on the transfer cost matrix and the cross entropy loss function.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This specification relates to the field of industrial defect detection; more specifically, this application relates to a loss function determination method, a defect identification method, and related equipment. Background Technology

[0002] In the field of industrial defect detection, accurate identification and classification of product defects are crucial for improving product quality and production efficiency. However, existing classification methods often fail to adequately consider the actual differences in importance between different categories when dealing with multi-category classification problems.

[0003] Some methods achieve classification by adjusting the classification distance in cosine space, but these methods typically treat all classes uniformly, failing to differentiate the importance of specific classes. This is insufficient when some classes are more important than others. Furthermore, existing FocalLoss improvements are mainly applicable to binary classification scenarios and only scale the cross-entropy loss, failing to effectively address specific problems in multi-class scenarios. Other methods in industrial defect detection differentiate defect severity using label smoothing loss, but these methods usually only handle single-type defects, making it difficult to meet the overall detection needs of multi-class defects. Summary of the Invention

[0004] The summary section introduces a series of simplified concepts, which will be further explained in detail in the detailed description section. This summary section is not intended to limit the key and essential technical features of the claimed technical solution, nor is it intended to determine the scope of protection of the claimed technical solution.

[0005] In a first aspect, this application proposes a method for determining a loss function for industrial defect identification, characterized by comprising:

[0006] Construct a transfer cost matrix based on the target users' attention to different defect categories;

[0007] Obtain the cross-entropy loss function;

[0008] The target loss function is determined based on the aforementioned transfer cost matrix and cross-entropy loss function.

[0009] In one feasible implementation, the aforementioned transfer cost matrix includes positive reward elements, no reward elements, and negative penalty elements. The positive reward elements are used to reward correct judgments of defect type and no defect, the no reward elements are used to maintain the correct judgment of defect type but incorrect judgment of defect presence or absence, and the negative penalty elements are used to penalize incorrect judgments of defect presence or absence.

[0010] In one feasible implementation, the transfer cost matrix is ​​a square matrix, the positive reward element is the diagonal element of the square matrix, the negative penalty element is located on the adjacent outer edge of the square matrix, and the corner element of the adjacent outer edge is the positive reward element.

[0011] In one feasible implementation, among the above positive reward elements, the reward magnitude corresponding to the positive reward element when the category defect type is correctly judged is less than the reward magnitude corresponding to the positive reward element when the defect-free type is correctly judged.

[0012] In one feasible implementation, all negative penalty elements are equal.

[0013] In one feasible implementation, obtaining the cross-entropy loss function includes:

[0014] Use the pre-training data of the target deep learning model to obtain the model's classification output;

[0015] The cross-entropy loss function described above is constructed based on the element values ​​output by the model classification.

[0016] Secondly, embodiments of this application also propose an industrial defect identification method, including:

[0017] Obtain the identification feature information of the product to be identified;

[0018] The aforementioned feature information to be identified is input into the target deep learning model to obtain the defect identification result. The target deep learning model updates its parameters based on the gradient obtained by backpropagation of the target loss function. The target loss function is determined based on the method for determining the loss function described in the first aspect.

[0019] Thirdly, embodiments of this application also propose an industrial defect identification device, comprising:

[0020] The acquisition unit is used to acquire the identification feature information of the product to be identified.

[0021] The identification unit is used to input the aforementioned feature information to be identified into the target deep learning model to obtain the defect identification result. The target deep learning model updates its parameters based on the gradient obtained by backpropagation of the target loss function. The target loss function is determined based on the method for determining the loss function described in the first aspect.

[0022] Fourthly, an electronic device includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program stored in the memory to implement the steps of the industrial defect identification method of the second aspect described above.

[0023] Fifthly, this application also proposes a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the industrial defect identification method of the second aspect.

[0024] In summary, the method for determining the loss function for industrial defect identification in this application includes: constructing a transfer cost matrix based on the target user's attention to different defect categories; obtaining a cross-entropy loss function; and determining a target loss function based on the transfer cost matrix and the cross-entropy loss function. By constructing the transfer cost matrix, this method can target and control classification errors according to the target user's attention to different defect categories. Unlike the uniform processing approach in traditional methods, the transfer cost matrix allows setting different cost values ​​for classification errors of specific categories. For example, for errors that users consider more serious, a higher cost can be set, thereby making the model more focused on avoiding these high-cost errors during training. This method enhances the model's adaptability in practical applications, making it more in line with actual business needs. Using the cross-entropy loss function as the basic loss function ensures its broad applicability in multi-class classification problems. The cross-entropy loss function can effectively measure the difference between the predicted probability distribution of the model output and the true label distribution, and is a standard choice in multi-class classification problems. By combining the transfer cost matrix with the model, this method not only retains the advantages of the cross-entropy loss function but also further enhances the ability to distinguish between different categories of errors, enabling the model to exhibit superior performance when handling complex multi-class industrial defect detection tasks. By combining the transfer cost matrix and the cross-entropy loss function to determine the target loss function, this method significantly improves the model's robustness. During model training, the target loss function weights errors of different categories, allowing the model to make more reliable predictions when faced with different types of defects. Especially in the presence of noise or high inter-class similarity, the additional control provided by the transfer cost matrix effectively reduces misclassifications and improves overall recognition accuracy. Through a carefully designed target loss function, this method ensures that the model considers the differences in classification error costs between different categories during training, thereby more effectively reducing the probability of high-cost errors. For example, in some cases, misclassifying a serious defect as a minor defect or no defect may lead to significant losses; therefore, by increasing the penalty for these errors in the loss function, the model can proactively learn to avoid such errors. This approach significantly enhances the model's application value in practical industrial inspection, especially in scenarios requiring high reliability and high accuracy. In this method, the transfer cost matrix, as part of hyperparameter tuning, allows algorithm developers to adjust it on the validation set to find the optimal settings. This flexibility enables the model to be customized for different application scenarios, maximizing its recognition capabilities. Through repeated tuning, the model can gradually reach the optimal balance point, reducing the overall error rate while paying particular attention to controlling high-cost errors, further improving the model's practicality and effectiveness. Attached Figure Description

[0025] Various other advantages and benefits will become apparent to those skilled in the art upon reading the following detailed description of preferred embodiments. The accompanying drawings are for illustrative purposes only and are not intended to limit this specification. Furthermore, the same reference numerals denote the same parts throughout the drawings. In the drawings:

[0026] Figure 1 A flowchart illustrating a method for determining a loss function for industrial defect identification, provided in an embodiment of this application;

[0027] Figure 2 This is a schematic diagram illustrating the process of an industrial defect identification method proposed in an embodiment of this application;

[0028] Figure 3 This is a structural schematic diagram of an industrial defect identification device provided in an embodiment of this application;

[0029] Figure 4 This is a schematic diagram of an electronic device structure provided in an embodiment of this application. Detailed Implementation

[0030] The terms "first," "second," "third," "fourth," etc. (if present) in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus. The technical solutions of the embodiments of this application will now be clearly and completely described in conjunction with the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them.

[0031] In deep learning recognition tasks, cross-entropy is generally used as the loss function, or its variants, such as label smoothing loss, to address the problem of inaccurate labeling. These types of losses treat each category equally. However, in defect detection scenarios, the margin between each category is different, making cross-entropy loss or its variants a suboptimal solution.

[0032] In industrial defect detection, there are typically multiple defect categories and one no-defect category. In most scenarios, classifying a defect as no-defect is a serious error, potentially leading to defective products reaching the end consumer and causing adverse effects. However, incorrectly classifying a defect as a different defect is a minor error with minimal negative impact. Commonly used cross-entropy loss methods are unsuitable for this scenario.

[0033] Based on this, please refer to Figure 1 This is a schematic diagram of a loss function determination method for industrial defect identification provided in an embodiment of this application, which may specifically include:

[0034] S110. Construct a transfer cost matrix based on the target user's attention to different defect categories;

[0035] For example, the first step is to understand the target users' level of attention to each defect category. Based on user feedback or business needs, different cost values ​​are assigned to different categories of classification errors. Setting up this matrix based on user attention to different categories is a key step in hyperparameter tuning.

[0036] S120. Obtain the cross-entropy loss function;

[0037] For example, we choose the cross-entropy loss function as the base loss function. The cross-entropy loss function measures the difference between the predicted probability distribution of the model output and the true label distribution. In classification problems, the cross-entropy loss function is one of the most commonly used loss functions, suitable for evaluating the model's predictive performance across different categories. Specifically, the cross-entropy loss function calculates the log probability for each category and performs a weighted sum to generate a scalar value representing the degree of mismatch between the model's predictions and the true labels.

[0038] S130. Determine the target loss function based on the above transfer cost matrix and the above cross-entropy loss function.

[0039] For example, the final target loss function is determined by combining the transition cost matrix and the cross-entropy loss function from the first two steps. Specifically, the target loss function combines the output of the cross-entropy loss function with the transition cost matrix. The final target loss function will be a weighted loss value, ensuring that the model takes into account the differences in classification error costs between different categories during training, thereby more effectively reducing the probability of high-cost errors.

[0040] In summary, by constructing a transfer cost matrix, this method can target classification errors based on the user's focus on different defect categories. Unlike the uniform approach in traditional methods, the transfer cost matrix allows setting different cost values ​​for classification errors of specific categories. For example, higher costs can be set for errors that users consider more serious, thus making the model more focused on avoiding these high-cost errors during training. This method enhances the model's adaptability in practical applications, making it more aligned with actual business needs. Using the cross-entropy loss function as the base loss function ensures its broad applicability in multi-class classification problems. The cross-entropy loss function effectively measures the difference between the predicted probability distribution of the model output and the true label distribution, making it a standard choice for multi-class classification problems. By combining this with the transfer cost matrix, this method not only retains the advantages of the cross-entropy loss function but also further improves the ability to distinguish between different categories of errors, enabling the model to exhibit superior performance when handling complex multi-class industrial defect detection tasks. By combining the transfer cost matrix and the cross-entropy loss function to determine the target loss function, this method significantly improves the model's robustness. During model training, the objective loss function weights errors across different categories, enabling the model to make more reliable predictions when faced with various types of defects. Especially in the presence of noise or high inter-class similarity, the additional tuning capability provided by the transfer cost matrix effectively reduces misclassifications and improves overall recognition accuracy. Through a carefully designed objective loss function, this method ensures that the model considers the differences in classification error costs between different categories during training, thereby more effectively reducing the probability of high-cost errors. For example, in some cases, misclassifying a serious defect as a minor defect or no defect may lead to significant losses. Therefore, by increasing the penalty for these errors in the loss function, the model can proactively learn to avoid such errors. This approach significantly enhances the model's application value in practical industrial inspection, especially in scenarios requiring high reliability and accuracy. The transfer cost matrix in this method, as part of hyperparameter tuning, allows algorithm developers to adjust it on the validation set to find the optimal settings. This flexibility enables the model to be customized for different application scenarios, maximizing its recognition capabilities. Through repeated optimization, the model can gradually reach the optimal balance point, reducing the overall error rate while paying special attention to controlling high-cost errors, thereby further improving the model's practicality and effectiveness.

[0041] In some examples, the aforementioned transfer cost matrix includes positive reward elements, no reward elements, and negative penalty elements. The positive reward elements are used to reward correct judgments of defect type and no defect, the no reward elements are used to maintain the status quo when the defect type is incorrectly judged but the defect type is incorrectly judged, and the negative penalty elements are used to penalize incorrect judgments of defect type.

[0042] For example, positive reward elements are designed to give the model a positive reward when it correctly classifies a category. For instance, these positive reward elements are activated when the model correctly identifies a defect type as its corresponding defect category or correctly identifies it as no defect (OK category). Through this positive reward, the model can strengthen its ability to classify correctly during training, making it more inclined to make accurate judgments. Positive rewards are typically represented by negative values, such as -1, because in the calculation of the loss function, a smaller loss value indicates better model performance.

[0043] The no-reward element is used to maintain the model's current state without imposing additional rewards or penalties when the model makes partially correct and partially incorrect judgments. Specifically, the no-reward element comes into play when the model correctly determines whether a sample is a defect (i.e., determines whether it is defective or not), but incorrectly identifies the specific defect category. This design allows the model to avoid being heavily penalized for small errors when facing categories that are difficult to distinguish, thus maintaining the stability of its learning. The value of the no-reward element is typically set to 0, indicating that it neither increases nor decreases the loss.

[0044] The negative penalty element is used to penalize the model when it makes a serious error. For example, the negative penalty element will be activated when the model misclassifies a defective sample as a non-defective sample (OK class) or a non-defective sample as a defective sample. Through this penalty mechanism, the model is forced to reduce these high-cost errors during training, thereby improving its ability to distinguish key classes. The value of the negative penalty element is usually positive, such as 0.3, indicating that this error will increase the loss value when calculating the loss, thus increasing the learning pressure on the model.

[0045] By introducing a transition cost matrix that includes positive reward elements, no reward elements, and negative penalty elements, this scheme can dynamically adjust the model's loss calculation during training. This allows the model to be rewarded when it correctly classifies, maintain its current state when it makes partial errors, and be penalized when it makes serious errors. This design makes it easier for the model to achieve ideal classification results in real-world applications, especially in preventing and handling high-cost errors, thereby improving the model's practicality and reliability.

[0046] In some examples, the aforementioned transfer cost matrix is ​​a square matrix, the aforementioned positive reward element is the diagonal element of the aforementioned square matrix, the aforementioned negative penalty element is located on the adjacent outer edge of the aforementioned square matrix, and the corner element of the aforementioned adjacent outer edge is the aforementioned positive reward element.

[0047] For example, the transfer cost matrix is ​​designed as a square matrix with an equal number of rows and columns, where each row and column corresponds to a classification category of the model. In this square matrix, each element M... ij This represents the cost or reward of classifying category i into category j.

[0048] Positive reward elements are placed on the diagonal of the matrix. Diagonal element M ii These represent cases where the model correctly classifies class i as class i. Because this represents a completely correct classification, these elements are designed as positive reward elements. Typically, these diagonal elements are set to negative values ​​(such as -1) to represent a positive reward for the model in the loss function, encouraging the model to classify as correctly as possible.

[0049] The negative penalty element is located on the adjacent outer edge of the matrix. Specifically, the negative penalty element is usually set to a positive value (e.g., 0.3) to increase the loss value caused by this error, forcing the model to reduce such errors.

[0050] Corner elements are positive reward elements, ensuring that even at the edge of the matrix, the model can still receive rewards for correct classification of certain key categories, and the importance of correct classification is not ignored due to edge position.

[0051] Through this structured matrix design, the transfer cost matrix possesses hierarchy and discriminative power when handling misclassifications of different categories. Positive reward elements on the diagonal reinforce the model's correct classification ability, while negative penalty elements on the outer edges effectively punish severe errors. The positive reward design of the corner elements ensures the model's correctness in marginal categories. Overall, this design guides the model's learning more precisely, helping it make more reasonable distinctions and judgments between different categories, thereby improving the model's classification performance and application effectiveness.

[0052] In some examples, among the positive reward elements mentioned above, the reward magnitude corresponding to the positive reward element when the category defect type is correctly judged is less than the reward magnitude corresponding to the positive reward element when the defect-free type is correctly judged.

[0053] For example, when the model correctly identifies a sample as belonging to a specific defect type, the corresponding diagonal element (positive reward element) will receive a reward. These reward values ​​are designed to be small negative values, such as -1. This means that although the model correctly identifies the defect category, the strength of the reward is appropriately reduced due to the relative complexity and diversity of defect type identification, to prevent the model from focusing excessively on correctly classifying these categories and neglecting other more important classification tasks.

[0054] When the model correctly classifies a sample as defect-free (OK), the corresponding diagonal element (positive reward element) will receive a larger reward magnitude. This reward magnitude is typically set to a larger negative value, such as -2.2. This is because in many applications, correctly classifying a sample as defect-free (i.e., avoiding misclassification as defective) is of greater importance, especially in sensitive scenarios such as production quality control. Therefore, by setting a larger reward magnitude, we can guide the model to place greater emphasis on correctly classifying the defect-free category during training, thereby reducing misclassifications as defective.

[0055] By introducing a differentiated reward magnitude design into the positive reward element, this scheme aims to assign different reward strengths to the model when it correctly classifies different types of defects. The reward magnitude is smaller when the defect type is correctly identified, which prevents the model from over-optimizing on defect classification. Conversely, the reward magnitude is larger when the defect-free category is correctly identified, encouraging the model to more accurately classify defect-free categories in practical applications and reducing the risk of misclassification. Overall, this differentiated positive reward design can more effectively guide the model's learning direction, ensuring superior performance on key tasks.

[0056] In some examples, all negative penalty elements are equal.

[0057] For example, in the transfer cost matrix, negative penalty elements are used to penalize the model when it misclassifies. To ensure that the model receives consistent penalties for misclassification across different categories, this embodiment chooses to set all negative penalty elements to equal values.

[0058] All negative penalty elements (i.e., off-diagonal elements) are set to the same positive value, such as 0.3. This means that the model will be penalized the same way regardless of which other category it misclassifies. Through this uniform negative reward design, the model will no longer be biased towards avoiding errors in a particular category during training, but will instead reduce all types of misclassifications holistically.

[0059] A uniform negative penalty element value helps the model maintain balance during training. It ensures that the model follows the same penalty rule when dealing with misclassifications across all classes, thus avoiding over-focusing on certain specific classification errors. This design is particularly suitable for applications with broad task objectives, such as multi-class classification tasks where a balanced penalty is needed for classification errors across different classes.

[0060] By setting all negative penalty elements to equal values, this embodiment simplifies the design of the transfer cost matrix while ensuring consistency in the penalties for misclassification across different classes during training. This design effectively prevents the model from becoming biased in certain classes, maintaining a balance across classification errors and thus improving the overall classification performance and stability of the model. In practical applications, this unified negative reward setting helps the model perform more reliably and fairly in multi-class classification tasks.

[0061] In some examples, the above-mentioned methods for obtaining the cross-entropy loss function include:

[0062] Use the pre-training data of the target deep learning model to obtain the model's classification output;

[0063] The cross-entropy loss function described above is constructed based on the element values ​​output by the model classification.

[0064] For example, training data is first input into the target deep learning model for forward propagation. Forward propagation refers to passing the input data layer by layer through the model, ultimately generating the model's output. In this process, the model uses its learned weights and features to process the input data and generate a set of unnormalized outputs, which are called logits.

[0065] For the example in this scheme, assume ConvNext is used as the base model, loaded with ImageNet-based pre-trained weights. The model accepts input data and performs a forward pass, ultimately outputting logits. It's important to note that these logits are shaped [C], where C is the number of classes. At this point, the logits are simply the model's raw scores for each class, not yet processed by activation functions such as softmax or sigmoid.

[0066] After obtaining the model's classification output logits, the next step is to construct the cross-entropy loss function based on the element values ​​of these logits.

[0067] The cross-entropy loss function measures the difference between the probability distribution predicted by the model and the true label distribution. Although logits are not yet converted to a probability distribution, we can directly use the element-wise values ​​of these logits to calculate the cross-entropy loss.

[0068] For a given training sample, assuming its true label is class i, the cross-entropy loss is calculated using the element-wise values ​​of the logits. The calculation of the cross-entropy loss function involves the exponential and logarithmic operations of the logits to calculate the log probability predicted by the model. Although the logits are not processed by softmax, we can still construct the cross-entropy loss function using their element-wise values ​​and use it as the objective function for model training.

[0069] In some examples, the cross-entropy loss function may be used in conjunction with the transition cost matrix to further adjust the loss value. This combination allows the cross-entropy loss function to go beyond a simple calculation based on the logits element values, reflecting the differences in classification costs between different categories, thus better guiding the model's learning direction.

[0070] In some examples, the corresponding transfer cost matrix is ​​set according to the user's attention to different categories. It's important to note that the setting of the cost transfer matrix depends on the algorithm developer's understanding of the relationships between the categories and is a set of hyperparameters. The optimal hyperparameters usually differ for different tasks, and algorithm developers can fine-tune the hyperparameters using a validation set. For example, in an industrial project, categories 0, 1, 2, 3, and 4 represent the corresponding defect categories, and category 5 represents the defect-free category. Since users consider misclassifying a defect category into another defect category a small error, while misclassifying a defect category into a defect-free category is a large error, and vice versa, the transfer cost matrix M can be set as follows:

[0071]

[0072] Taking the first row as an example, the first -1 indicates that the cost of classifying a defect from category 0 to category 5 is -1. The data network has a negative cost in correctly classifying the target defect, which is equivalent to having a positive reward. The second to fifth 0s indicate that the cost of classifying a defect from category 0 to category 2, 3, and 4 is 0. There is no additional loss (but no positive reward) in misclassifying a defect from one category to another. The last 0.3 indicates that the cost of classifying a defect from category 0 to category 5 (OK category) is 0.3. Compared to misclassifying a defect from one category to another, the network will incur additional costs in misclassifying a defect into the OK category.

[0073] Using the deep learning model model as a pre-training data, we obtain the model classification output logits. It should be noted that the logits here do not need to be processed by softmax or sigmoid. The shape of the logits is set to [C]. For ease of description, the batch size dimension is omitted. For example, in an industrial project, ConvNext can be used as the base model. During training, ConvNext loads pre-trained weights based on ImageNet.

[0074] Let the label class value corresponding to the current training step logits be i, then the corresponding objective loss function is:

[0075]

[0076] Where x j This represents the value of the j-th element of logits, and M is the transfer cost matrix that we predefined in the first step.

[0077] Backpropagation is used to calculate the gradient of the loss with respect to each parameter. The target loss function affects the gradient calculation and guides the network to avoid mispredicting classes with large distances.

[0078] The model parameters are updated using the gradients propagated back.

[0079] It should be noted that the usual method for calculating cross-entropy loss is as follows:

[0080]

[0081] If Noted as p i (Similar to p) j express That is, the probability value of softmax activation, then the loss for x i The gradient of (logits corresponding to ground truth) is:

[0082]

[0083] And loss for x j The gradient of (where i ≠ j, i.e., the logits corresponding to other categories) is:

[0084]

[0085] The suppression experienced by category i when it is classified into any other category is equal and cannot be adjusted according to the user's attention to different categories. The target loss function proposed in this application affects x.i The gradient of (logits corresponding to ground truth) is:

[0086]

[0087] If we use the category transfer cost matrix from the example above:

[0088]

[0089] So M ii =-1, that is:

[0090]

[0091] The gradient is consistent with that used in calculating the cross-entropy loss.

[0092] The target loss function proposed in this application embodiment applies to x. j The gradient of (where i ≠ j, i.e., the logits corresponding to other categories) is:

[0093]

[0094] Generally, when designing the transfer cost matrix, the sum of the first row is kept to a negative constant value K, such as K = -0.7 in step 1 above. Then the gradient can be simplified to:

[0095]

[0096] This shows that for x j The gradient increases by an element M. ij If M ij A larger value indicates that the cost of classifying category i into category j is high, and vice versa.

[0097]

[0098] Taking the first row of the transformation cost matrix above as an example (corresponding to category 0), category 0 will not suffer additional suppression if it is classified into categories 1, 2, 3, or 4. In our demonstration project, this means that if defect 0 is misclassified into defect 1, 2, 3, or 4, there will be no additional suppression. However, if defect 0 is misclassified into the OK category, additional loss will be incurred. Conversely, if it is classified into category 5 (i.e., the OK category), it will suffer an additional suppression of 0.3. Therefore, the network will ultimately be more inclined to reduce the likelihood of classifying category 0 into category 5.

[0099] The second aspect, please refer to Figure 2 This is a schematic diagram illustrating the process of an industrial defect identification method proposed in an embodiment of this application. This application also proposes an industrial defect identification method, including:

[0100] S210. Obtain the identification feature information of the product to be identified;

[0101] For example, feature information to be identified is extracted from the product to be identified. This feature information may include the texture, color, and shape of the product surface, which are key indicators for determining whether the product has defects. Feature information can be acquired through various means, such as using a camera to acquire image information or using sensors to acquire physical feature information. The core of this step is to ensure that the acquired information fully represents the state of the product so that the subsequent deep learning model can accurately identify defects based on this information.

[0102] S220. Input the above-mentioned feature information to be identified into the target deep learning model to obtain the defect identification result. The target deep learning model updates its parameters based on the gradient obtained by backpropagation of the target loss function. The target loss function is determined based on the method for determining the loss function described in the first aspect.

[0103] For example, after acquiring the feature information to be identified, this information is input into the target deep learning model for processing. The target deep learning model analyzes this input feature information to generate defect identification results, determining whether the product has defects and the specific type of defect.

[0104] The aforementioned target deep learning model was not chosen arbitrarily, but rather trained and optimized using specific methods. Specifically, this model updates its parameters based on the gradients obtained through backpropagation of the target loss function. Backpropagation is a crucial step in deep learning model training; it calculates the gradients of the loss function relative to the model parameters and uses these gradients to adjust the model parameters, thereby progressively optimizing the model's performance.

[0105] This target loss function is determined based on the method described in the first aspect. When defining the target loss function, specific requirements in industrial defect identification were considered, such as the difference in classification costs between categories, and the setting of positive reward elements and negative penalty elements. This loss function design enables the model to more accurately identify defects in products during training and reduces the possibility of misjudgments.

[0106] In summary, the target loss function proposed in this application is not a general loss function, but rather designed and optimized based on specific industrial defect identification needs. When defining the target loss function, key factors such as the difference in classification costs between categories and the setting of positive and negative reward elements were considered. This customized loss function design enables the model to more accurately identify defects in products during training, especially when facing multi-class or high-cost errors, effectively reducing the possibility of misjudgment and improving the model's application value in real industrial environments. Through the optimized target deep learning model and the specifically designed loss function, this application can effectively reduce misjudgments in the defect identification process. Because targeted cost difference adjustments are introduced in the loss function design, the model differentiates the processing of errors of different categories during identification, prioritizing the reduction of high-cost errors that have a greater impact on production, thereby significantly improving the overall accuracy and reliability of detection. The method in this application, by combining acquired feature information, an optimized deep learning model, and a customized loss function, improves the model's adaptability and robustness in different detection tasks. This method performs exceptionally well in complex industrial inspection scenarios and when dealing with different types of product defects, ensuring efficient and reliable defect detection even in dynamic production environments. By improving the accuracy of defect identification and reducing false positives, this method not only enhances product quality but also effectively reduces additional costs incurred due to defects during production. Furthermore, efficient defect detection shortens inspection time, improves the overall efficiency of the production line, and delivers significant economic benefits.

[0107] In some examples, the method proposed in this application can reduce the probability of misclassifying OK / NEG. In a test project, the project contains 6 categories, of which the first 5 categories are the corresponding defect categories (NEG) and the 5th category is the OK category. The results of comparing cross-entropy and the loss of this patent are shown in Table 1:

[0108]

[0109]

[0110] Table 1

[0111] In defect identification tasks, binary classification errors (OK / NEG) can lead to serious consequences. For example, if a defective product is classified as non-defective, it may reach the end user, causing significant harm; this type of classification error is therefore considered a serious error. However, if a defect is simply misclassified into another defect category, the product will still undergo manual verification, preventing it from reaching the end user; thus, this error is considered minor. Therefore, the binary classification result is a more important metric, while the multi-class classification result (i.e., the specific defect category) is secondary. Misclassification may not lead to severe consequences. In experiments, this algorithm significantly outperforms cross-entropy loss in binary classification tasks and is comparable to cross-entropy loss in multi-class classification tasks.

[0112] Third aspect, such as Figure 3 As shown in the embodiments, this application also proposes an industrial defect identification device, comprising:

[0113] Acquisition unit 21 is used to acquire the identification feature information of the product to be identified;

[0114] The identification unit 22 is used to input the aforementioned feature information to be identified into the target deep learning model to obtain the defect identification result. The target deep learning model updates its parameters based on the gradient obtained by backpropagation of the target loss function. The target loss function is determined based on the method for determining the loss function described in the first aspect.

[0115] like Figure 4 As shown, this application embodiment also provides an electronic device 300, including a memory 310, a processor 320, and a computer program 311 stored in the memory 310 and executable on the processor. When the processor 320 executes the computer program 311, it implements the steps of any of the above-described methods for industrial defect identification.

[0116] Since the electronic device described in this embodiment is the device used to implement an industrial defect identification device in the embodiments of this application, those skilled in the art can understand the specific implementation method and various variations of the electronic device in this embodiment based on the method described in the embodiments of this application. Therefore, how the electronic device implements the method in the embodiments of this application will not be described in detail here. Any device used by those skilled in the art to implement the method in the embodiments of this application falls within the scope of protection of this application.

[0117] In practical implementation, when the computer program 311 is executed by the processor, it can achieve the following: Figure 2 Any of the corresponding implementation methods in the embodiments.

[0118] It should be noted that the descriptions of each embodiment in the above embodiments have different focuses. For parts that are not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.

[0119] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0120] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create a machine for implementing the flowchart illustrations. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0121] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0122] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0123] This application also provides a computer program product, which includes computer software instructions that, when executed on a processing device, cause the processing device to perform the industrial defect identification process in the corresponding embodiment.

[0124] A computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the flow or function according to the embodiments of this application is generated. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a server or data center that integrates one or more available media. The available medium may be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state disk (SSD)).

[0125] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.

[0126] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces, or indirect coupling or communication connection between apparatuses or units, and may be electrical, mechanical, or other forms.

[0127] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0128] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0129] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0130] The above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit it. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.

Claims

1. A method for determining a loss function for industrial defect recognition, characterized in that, The method comprises the following steps: constructing a transition cost matrix according to the attention degree of the target user to different defect categories; obtaining a cross-entropy loss function; determining a target loss function based on the transition cost matrix and the cross-entropy loss function.

2. The method for determining a loss function for industrial defect recognition according to claim 1, characterized in that, The transition cost matrix comprises positive reward elements, no reward elements and negative penalty elements, the positive reward elements are used to make rewards when the category defect type is correctly judged and the no defect is correctly judged, the no reward elements are used to keep when the no defect is correctly judged but the defect type is incorrectly judged, and the negative penalty elements are used to punish when the no defect is incorrectly judged.

3. The method for determining a loss function for industrial defect recognition according to claim 2, characterized in that, The transition cost matrix is a square matrix, the positive reward elements are diagonal elements of the square matrix, the negative penalty elements are located on adjacent outer sides of the square matrix, and the corner elements of the adjacent outer sides are the positive reward elements.

4. The method for determining a loss function for industrial defect recognition according to claim 2, characterized in that, In the positive reward elements, the reward amplitude corresponding to the positive reward element corresponding to the category defect type correctly judged is smaller than the reward amplitude corresponding to the positive reward element corresponding to the no defect correctly judged.

5. The method for determining a loss function for industrial defect recognition according to claim 2, wherein, All negative penalty elements are equal.

6. The method for determining a loss function for industrial defect recognition according to claim 2, wherein, The method comprises the following steps: using the forward training data of the target deep learning model to obtain model classification output; constructing the cross-entropy loss function based on the element values of the model classification output.

7. An industrial defect recognition method characterized by, The method comprises the following steps: obtaining the to-be-recognized feature information of a to-be-recognized product; inputting the to-be-recognized feature information into a target deep learning model to obtain a defect recognition result, wherein the target deep learning model is parameter-updated based on the gradient obtained by back propagation of a target loss function, and the target loss function is a target loss function determined based on the determination method of the loss function in any one of claims 1 to 6.

8. An industrial defect recognition apparatus characterized by comprising: The method comprises the following steps: an obtaining unit, configured to obtain to-be-recognized feature information of a to-be-recognized product; an identifying unit, configured to input the to-be-recognized feature information into a target deep learning model to obtain a defect recognition result, wherein the target deep learning model is parameter-updated based on the gradient obtained by back propagation of a target loss function, and the target loss function is a target loss function determined based on the determination method of the loss function in any one of claims 1 to 6.

9. An electronic device comprising: A memory and a processor, characterized in that the processor is configured to implement the steps of the industrial defect recognition method in claim 7 when executing the computer program stored in the memory.

10. A computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program is executed by the processor to implement the steps of the industrial defect recognition method in claim 7.

Citation Information

Patent Citations

  • Pest image classification method based on fine-grained classification technology

    CN113239947A

  • Industrial flow line production state detection method based on Gap-loss function

    CN113360851A

  • Circuit board plug hole defect detection method and device based on deep learning

    CN113516650A

  • Defect detection model training method and device and electronic equipment

    CN116188432A

  • Image classification method based on improved cross entropy loss function

    CN116310542A