Lithium battery surface defect detection method and system and storage medium

CN121810696BActive Publication Date: 2026-08-18ANHUI UNIV
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202610289402.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2026-03-11
Publication Date
2026-08-18
Estimated Expiration
2046-03-11

AI Technical Summary

Technical Problem

[0009]本发明所要解决的技术问题在于如何克服现有标签分配策略在场景适应性方面的不足,提高锂电池表面缺陷检测的精度和稳定性

Benefits of technology

(1)本发明在模型训练过程中综合考虑分类和交并比定位两方面的信息,并针对交并比项进行场景自适应调制,为每个真实目标自适应地生成动态调节阈值,从而动态调整分配策略以适应不同场景,通过利用动态调整后的交并比与网络输出的分类置信度计算任务对齐度量,并根据任务对齐度量进行正负样本分配,对于目标密集、整体匹配质量较高的场景,本发明能够收紧有效IoU区间,突出真正高质量样本;对于缺陷稀少或匹配质量偏低的场景,则适当放宽要求,保证正样本数量,从而有效提升锂电池表面缺陷检测网络对不同工况的适应能力和泛化性能。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121810696B_ABST
    Figure CN121810696B_ABST
Patent Text Reader

Abstract

The application discloses a kind of lithium battery surface defect detection method, system and storage medium, including the image of the surface of lithium battery is collected, the defect data set of battery surface is constructed;Defect detection network is trained using defect data set, the original intersection-over-union of all prediction boxes output by network and real target is calculated in each training iteration;Based on the matching degree between each real target and all prediction boxes, the scene statistical characteristics of each real target are determined;The original intersection-over-union corresponding to the corresponding real target is adjusted using scene statistical characteristics, and the adjusted intersection-over-union is obtained;Using the classification confidence of network output and adjusted intersection-over-union, task alignment measure is calculated, and positive and negative sample distribution is carried out according to task alignment measure;When model training iteration meets the set condition, the trained defect detection network is obtained for lithium battery surface defect detection;The application can effectively improve the adaptability and generalization performance of lithium battery defect detection network to different working conditions.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the technical field of computer vision and artificial intelligence, specifically to a method, system, and storage medium for detecting surface defects in lithium batteries. Background Technology

[0002] Surface defect detection in cylindrical lithium batteries is a crucial step in battery production quality control. Even minor surface defects (such as scratches, dents, and stains) can affect battery consistency and safety, and must be accurately detected and identified before shipment. Currently, industrial inspection of battery appearance defects mainly relies on manual visual inspection, which is not only costly in terms of manpower and time, but also has high rates of missed detections and false detections, making it difficult to meet the demands of modern high-speed, high-precision production lines. With the improvement of computer hardware computing power and the development of deep learning algorithms, convolutional neural network-based target detection methods have shown significant advantages in the field of defect detection, and the use of machine vision for automatic detection of battery appearance defects has become a mainstream trend. Among these, one-stage target detection algorithms (such as the YOLO series) are more suitable for defect detection tasks in industrial settings where both real-time performance and accuracy are critical, and are therefore widely used in industrial defect detection scenarios.

[0003] For example, the patent application document with publication number CN117765335A proposes to use YOLO lithium battery appearance detection technology based on random convolution enhancement to detect the appearance of lithium batteries. It focuses on data augmentation / consistency training such as random convolution to improve generalization, but does not involve the label allocation mechanism in the training stage.

[0004] Furthermore, patent application CN121121160A proposes a dynamic label allocation strategy. This strategy generates a combined IoU by combining the predicted IoU and the anchor box IoU, and uses the mean and standard deviation of the combined IoU as a dynamic threshold to adaptively divide positive and negative samples and potentially construct soft labels. However, this type of threshold determination method based on global statistics is susceptible to outliers and sample distribution fluctuations in industrial defect scenarios with significant variations in target density, defect scale, and background complexity. This leads to threshold jitter, unstable positive and negative sample numbers, and consequently introduces noise supervision, affecting training convergence stability and recall of minor defects.

[0005] In actual production line inspection of cylindrical lithium batteries, the curved surface of the battery casing easily generates high reflectivity and high-brightness bands, resulting in significant variations in image distribution under different workstations and lighting conditions. Simultaneously, minor defects (such as shallow scratches, micro-dimples, and dirt) often exhibit small targets or weak texture features, leading to a severe imbalance between positive and negative samples, large fluctuations in candidate box quality, and the generation of numerous similar candidate boxes within the same target's neighborhood. In such complex scenarios, if traditional fixed threshold or fixed weight label allocation strategies are used during the training phase, it is prone to insufficient utilization of high-quality positive samples or the introduction of too many noisy positive samples, thus affecting the model's convergence stability and final detection accuracy. This is because traditional label allocation typically uses a fixed Intersection over Union (IoU) threshold or simple rules based on geometric distance to divide predicted boxes into positive and negative samples. This static strategy lacks adaptability to different scenarios, and if applied to lithium battery surface defect detection, it may lead to the following problems:

[0006] Existing label assignment strategies struggle to adapt to varying image scenarios: Current methods typically employ pre-defined matching rules, such as directly incorporating the Intersection over Union (IoU) into the task alignment metric in a fixed form, or setting uniform sample selection criteria based on the overall distribution of candidate box IoU. These rules themselves do not explicitly adjust to the number, scale distribution, or background complexity of defect targets in the current image. However, due to the diverse morphologies of defects on the surface of cylindrical lithium batteries, the number and size of defects vary significantly across different images. When there are many defect targets or a complex background, the existing rules often result in insufficient high-quality positive samples, leading to a weak training signal. Conversely, when targets are sparse or the scene is simple, too many average or even poor-quality samples may be introduced, increasing training noise. This lack of adaptive adjustment based on scene statistics limits the model's generalization ability across various working conditions.

[0007] Furthermore, although some improved algorithms, such as ATSS (Adaptive Training Sample Selection), attempt to improve the rationality of allocation to some extent by utilizing the IoU distribution to adjust the sample selection strategy, they generally still rely primarily on the single metric of geometric IoU. For example, the patent application document with publication number CN121121160A focuses on dividing positive and negative samples based on statistical thresholds of IoU correlation and may construct soft labels, without fully combining information such as classification confidence to comprehensively measure the quality of the predicted bounding box. Therefore, it still has shortcomings in the alignment of classification-localization tasks. In addition, although the Task Alignment Learning (TAL) label allocation strategy considers both classification score and intersection-union ratio (IU) during the label allocation process and combines them into a task alignment metric, its combination form and sample selection criteria do not explicitly depend on scene statistics such as target density and overall matching quality in the current image. The way IU participates in the metric remains unchanged in different scenarios. This leads to situations where the detection network still suffers from insufficient utilization of high-quality samples and significant interference from noisy samples when facing subtle defects or complex backgrounds, thus limiting the recognition rate and accuracy of subtle defects. Therefore, TAL still suffers from insufficient task alignment and lack of scene adaptation in cylindrical lithium battery defect detection tasks.

[0008] Therefore, to solve the above problems, it is necessary to provide a new label allocation method that comprehensively considers information from both classification and localization during the training process, and adaptively adjusts the contribution of cross-union ratio based on scene statistical features, thereby dynamically adjusting the allocation strategy to adapt to different scenarios and improving the accuracy and robustness of lithium battery surface defect detection. Summary of the Invention

[0009] The technical problem to be solved by this invention is how to overcome the shortcomings of existing tag allocation strategies in terms of scenario adaptability and improve the accuracy and stability of lithium battery surface defect detection.

[0010] The present invention solves the above-mentioned technical problems through the following technical means: A method for detecting surface defects in lithium batteries is proposed, the method comprising: Images of the lithium battery surface are collected to construct a defect dataset of the battery surface; The defect detection network is trained using a defect dataset, and the original intersection-union ratio (IUU) of all predicted boxes output by the network with the real target is calculated in each training iteration. Based on the degree of matching between each real target and all predicted boxes, the scene statistical features of each real target are determined; The original crossover ratio (CRO) corresponding to the real target is adjusted using scene statistical features to obtain the adjusted CRO; The task alignment metric is calculated using the adjusted intersection-union ratio and the classification confidence of the network output, and positive and negative samples are assigned based on the task alignment metric. When the model training iterations meet the set conditions, the trained defect detection network is obtained and used for lithium battery surface defect detection.

[0011] Furthermore, determining the scene statistical features of each real target based on the degree of matching between each real target and all predicted boxes includes: Based on the degree of matching between each ground truth target and all predicted bounding boxes, determine the candidate mask for each ground truth target in the anchor space; Based on the candidate mask of each real target in the anchor point space, the scene statistical features of each real target are calculated, including the candidate anchor point distribution density and the average matching quality.

[0012] Further, determining the candidate mask for each real target in the anchor space based on the degree of matching between each real target and all predicted bounding boxes includes: For each real target, select a prediction box whose center falls within the box containing the real target as a candidate anchor point, or select a prediction box whose intersection-union ratio with the real target ranks in the top N among all prediction boxes as a candidate anchor point, where N is a preset threshold. The candidate anchor point is encoded as 1, and all prediction boxes except the candidate anchor point are encoded as 0 to obtain the candidate mask corresponding to the real target.

[0013] Furthermore, based on the candidate mask of each real target in the anchor point space, the scene statistical features of each real target are calculated. These scene statistical features include the candidate anchor point distribution density and the average matching quality, including: Based on the candidate mask of each real target in the anchor point space, the candidate anchor point distribution density of that real target is calculated, as expressed by the formula:

[0014] In the formula, For the first The first image The distribution density of candidate anchor points for each real target. As a candidate mask, it represents The first image The first real goal and the first A binary label indicating whether the candidate conditions are met between the prediction boxes (1 for candidates, 0 for non-candidates); This represents the total number of candidate anchor points. For the prediction box index, =1,…, .

[0015] Based on the candidate mask of each real target in the anchor point space and the original intersection-union ratio corresponding to that real target, the average matching quality is calculated, expressed by the formula:

[0016] In the formula, For the first The first image The average matching quality of each real target For the first The first image The first real goal and the first The original crossover ratio between the predicted boxes.

[0017] Furthermore, the adjustment of the original intersection-over-union ratio (IoU) corresponding to the real target using scene statistical features to obtain the adjusted IoU includes: Based on the scene statistical characteristics corresponding to each real target, a dynamic adjustment threshold is generated for each real target. The original cross-union ratio (CUI) of each real target is adjusted using the dynamic adjustment threshold corresponding to that real target to obtain the adjusted CUI.

[0018] Furthermore, the dynamic adjustment threshold for each real target is generated based on the scene statistical features corresponding to each real target, expressed by the formula:

[0019] In the formula, For the first The first image The dynamic adjustment threshold corresponding to each real target Based on Threshold, For the first The first image The distribution density of candidate anchor points for each real target. For the first The first image The average matching quality of each real target and For adjustment coefficients, The maximum allowable offset, This indicates that the threshold is limited to an interval. Inside.

[0020] Further, the step of adjusting the original cross-union ratio (CUI) of each real target using a dynamic adjustment threshold to obtain the adjusted CUI includes: By using soft gating, the original cross-union ratio (CUI) of each real target is adjusted using a dynamic adjustment threshold corresponding to that real target, resulting in the adjusted CUI, expressed by the formula:

[0021] In the formula, This is the adjusted intersection-union ratio. For the first The first image The first real goal and the first The original crossover ratio between the predicted boxes For the first The first image The dynamic adjustment threshold corresponding to each real target To control the constant of the gating slope, This is the Sigmoid function.

[0022] Further, the step of calculating the task alignment metric using the adjusted intersection-union ratio and the classification confidence of the network output, and assigning positive and negative samples based on the task alignment metric, includes: The task alignment metric is calculated using the adjusted intersection-over-union ratio (IoU) and the classification confidence score of the network output. The formula is as follows:

[0023] In the formula, This represents the classification confidence of the predicted bounding box output by the network on the true target category. This is the adjusted intersection-union ratio. and These are hyperparameters used to control the weights of the classification branch and the localization branch, respectively. For each real target, the predicted bounding boxes in its candidate anchor set are sorted from largest to smallest according to the task alignment metric. The top-K predicted bounding boxes are selected as positive samples and assigned the label of the real target. The rest are treated as negative samples or ignored samples.

[0024] Furthermore, the method also includes: If the same predicted bounding box is selected as a candidate anchor point by multiple real targets, then the predicted bounding box is assigned to the real target with the highest task alignment metric as a positive sample.

[0025] Furthermore, the defect detection network employs a YOLO network or an RT-DETR detector.

[0026] Furthermore, this invention also proposes a lithium battery surface defect detection system, the system comprising: The dataset building module is used to collect images of the lithium battery surface and build a defect dataset of the battery surface; The iterative training module is used to train the defect detection network using the defect dataset and calculate the original intersection-union ratio (IUU) of all predicted boxes output by the network with the real target in each training iteration. The scene statistical feature calculation module is used to determine the scene statistical features of each real target based on the degree of matching between each real target and all predicted boxes; The dynamic adjustment module is used to adjust the original crossover ratio (CRO) of the corresponding real target using scene statistical features, so as to obtain the adjusted CRO. The label assignment module is used to calculate the task alignment metric using the adjusted intersection-over-union ratio and the classification confidence of the network output, and to assign positive and negative samples based on the task alignment metric. The detection module is used to obtain a trained defect detection network for detecting surface defects in lithium batteries when the model training iterations meet the set conditions.

[0027] Furthermore, the present invention also proposes a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the lithium battery surface defect detection method as described above.

[0028] The advantages of this invention are: (1) In the model training process, this invention comprehensively considers information from both classification and cross-union ratio (IU) localization, and performs scene-adaptive modulation for the IU term. It adaptively generates a dynamic adjustment threshold for each real target, thereby dynamically adjusting the allocation strategy to adapt to different scenarios. By using the dynamically adjusted IU and the classification confidence of the network output, the task alignment metric is calculated, and positive and negative samples are allocated according to the task alignment metric. For scenarios with dense targets and high overall matching quality, this invention can tighten the effective IoU interval and highlight truly high-quality samples. For scenarios with few defects or low matching quality, the requirements are appropriately relaxed to ensure the number of positive samples, thereby effectively improving the adaptability and generalization performance of the lithium battery surface defect detection network to different working conditions.

[0029] (2) By performing scene-adaptive modulation on the cross-union ratio term, the cross-union ratio participating in the alignment metric not only reflects the geometric overlap between the predicted box and the real target, but also indirectly encodes the distribution density and overall matching quality of the target in the current scene. This provides more explicit reinforcement for high-quality predicted boxes and suppresses low-quality predicted boxes, making the selection of positive samples more refined and more in line with actual detection needs. This further enhances the coordination between the classification branch and the localization branch and reduces duplicate detection or missed detection caused by the inconsistency between the two predictions.

[0030] (3) This invention employs a soft-gating mechanism based on the Sigmoid function to smoothly weight the Intersection over Union (IoU) ratio (IoU) instead of using a hard threshold for binary truncation. For predicted boxes that are much higher than the scene adaptive threshold, their IoU contribution is basically preserved; for predicted boxes that are significantly lower than the threshold, their IoU contribution is significantly suppressed; for edge samples close to the threshold, they are flexibly processed using continuous weights, effectively avoiding the training oscillation problem caused by the hard threshold frequently changing the sample category near the boundary. By using soft gating, the influence of IoU on alignment metrics is changed from "on / off" to "strong / weak" continuous adjustment, which is beneficial for smoothing the loss surface and improving the stability and convergence of the model training process.

[0031] (4) This invention only adjusts the IoU calculation and sample selection strategy during the training process, without changing the network structure and inference process used for the lithium battery surface defect detection model. Therefore, it will not introduce additional inference time overhead. As long as the detection model can output candidate boxes and classification confidence and can calculate the IoU between the predicted box and the real box, the new label allocation method of this invention can be used for model training, and it has good model adaptability.

[0032] Additional aspects and advantages of the invention will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention. Attached Figure Description

[0033] The accompanying drawings, which form part of this invention, are used to provide a further understanding of the invention. The illustrative embodiments of the invention and their descriptions are used to explain the invention and do not constitute an improper limitation of the invention.

[0034] Figure 1 This is a schematic flowchart of a lithium battery surface defect detection method according to an embodiment of the present invention; Figure 2 This is a flowchart of a tag allocation strategy in one embodiment of the present invention; Figure 3 This is a schematic diagram of the structure of a defect detection network using a YOLOv11 network in one embodiment of the present invention; Figure 4 This is a diagram showing the effect of lithium battery surface defect detection using a trained defect detection network according to an embodiment of the present invention. Figure 5 This is a schematic diagram of the structure of a lithium battery surface defect detection system proposed in an embodiment of the present invention. Detailed Implementation

[0035] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below in conjunction with the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0036] like Figure 1 As shown, the first embodiment of the present invention proposes a method for detecting surface defects in lithium batteries, the method comprising the following steps: S10. Collect images of the lithium battery surface and construct a defect dataset of the battery surface; It should be noted that in this embodiment, a high-resolution camera was used to capture images of the cylindrical lithium battery surface during the data acquisition process. Defects in each image were labeled, including the type of defect (e.g., scratches, stains, dents, etc.) and its location. Image labeling was performed using LabelImg software to generate standard VOC format label files, thereby constructing a defect dataset for the battery surface.

[0037] S20. Train the defect detection network using the defect dataset, and calculate the original intersection-union ratio (IUU) of all predicted boxes output by the network with the real target in each training iteration. S30. Based on the degree of matching between each real target and all predicted boxes, determine the scene statistical features of each real target; S40. Adjust the original crossover ratio (CRO) of the corresponding real target using scene statistical features to obtain the adjusted CRO; It should be noted that in traditional techniques, the intersection-over-union (IoU) ratio participates in task alignment measurement in a fixed form, and its contribution remains unchanged across different images, targets, and scenarios. However, this embodiment introduces scene statistical features to adaptively generate a dynamic IoU adjustment threshold for each real target, enabling adaptive adjustment of the effective participation range and weights of the IoU ratio in different scenarios. For scenarios with dense targets and high overall matching quality, this embodiment tightens the effective IoU range, highlighting truly high-quality samples. For scenarios with few defects or low matching quality, the requirements are appropriately relaxed to ensure a sufficient number of positive samples, improving the model's adaptability and generalization performance under different conditions.

[0038] S50. Calculate the task alignment metric using the adjusted crossover ratio and the classification confidence of the network output, and assign positive and negative samples based on the task alignment metric. It should be noted that, by jointly constructing a task alignment metric using classification confidence and localization intersection-union ratio (IU), this embodiment of the invention not only achieves basic alignment between classification and localization tasks, but also provides more explicit reinforcement to high-quality prediction boxes and suppresses low-quality prediction boxes by scene-adaptive modulation of the IU term. This makes the selection of positive samples more refined and more in line with actual detection needs, further improving the coordination between the classification branch and the localization branch and reducing duplicate detections or missed detections caused by inconsistencies in their predictions.

[0039] S60. When the model training iteration meets the set conditions, the trained defect detection network is obtained and used for lithium battery surface defect detection.

[0040] It should be noted that in the actual training process, the defect dataset is divided into a training set, a validation set, and a test set in a ratio of 8:1:1. After training the defect detection network using the training set, the trained defect detection network is then validated and tested using the validation set and the test set, respectively, to ensure the effectiveness of training and evaluation.

[0041] It should be noted that, during the data preparation process, this embodiment can perform data augmentation operations on the images, such as cropping, mirroring, rotating, translating, adding noise, adjusting brightness, etc., to expand the sample size and improve the robustness of the model.

[0042] As a further preferred technical solution, step S30: determining the scene statistical features of each real target based on the matching degree between each real target and all predicted boxes, specifically includes the following steps: S31. Based on the degree of matching between each real target and all predicted boxes, determine the candidate mask of each real target in the anchor space; Specifically, the defect detection network outputs predicted bounding boxes and classification confidence scores. First, it calculates the original intersection-union ratio (IUU) of all predicted bounding boxes with the ground truth targets. For example, the first... The first image The first real goal and the first The original cross-union ratio between the predicted boxes is: Then, construct a candidate mask according to the candidate selection rules. The candidate mask can be obtained as follows: The first image A real goal In the prediction boxes, the predicted boxes whose centers fall within the actual target's box are selected as candidate anchor points, or the predicted boxes with the highest intersection-union ratio (IoU) with the actual target are selected as candidate anchor points, where N is a preset threshold. If the... Each predicted bounding box represents the true target. The candidate anchor point is then let the first one be... The first image A real goal Corresponding candidate anchor points ,otherwise .

[0043] It should be noted that the value of N in this embodiment can be a threshold determined based on experience, and this embodiment does not impose specific limitations on its value.

[0044] S32. Based on the candidate mask of each real target in the anchor point space, calculate the scene statistical features of each real target, including the candidate anchor point distribution density and the average matching quality.

[0045] As a further preferred technical solution, step S32: Based on the candidate mask of each real target in the anchor point space, calculate the scene statistical features of each real target. The scene statistical features include the candidate anchor point distribution density and the average matching quality, specifically including the following steps: S321. Based on the candidate mask of each real target in the anchor point space, calculate the candidate anchor point distribution density of that real target, specifically as follows: Let the... The first image The candidate masks for each real target in the anchor space are: Then the distribution density of candidate anchor points for the target Defined as:

[0046] In the formula, For the first The first image The distribution density of candidate anchor points for each real target. As a candidate mask, it represents The first image The first real goal and the first A binary label indicating whether the candidate conditions are met between the prediction boxes (1 for candidates, 0 for non-candidates); The total number of candidate anchor points, i.e., predicted bounding boxes, in the candidate anchor point set. For the prediction box index, =1,…, .

[0047] S322. Based on the candidate mask of each real target in the anchor point space and the original intersection-union ratio corresponding to the real target, calculate the average matching quality of the real target on the candidate anchor point set, expressed by the formula:

[0048] In the formula, For the first The first image The average matching quality of each real target For the first The first image The first real goal and the first The original crossover ratio between the predicted boxes.

[0049] As a further preferred technical solution, step S40: adjusting the original intersection-union ratio corresponding to the real target using scene statistical features to obtain the adjusted intersection-union ratio, specifically including: S41. Generate a dynamic adjustment threshold for each real target based on the scene statistical characteristics corresponding to each real target. Specifically, the formula for calculating the dynamic adjustment threshold is:

[0050] In the formula, For the first The first image The dynamic adjustment threshold corresponding to each real target Based on Threshold, For the first The first image The distribution density of candidate anchor points for each real target. For the first The first image The average matching quality of each real target and For adjustment coefficients, The maximum allowable offset, This indicates that the threshold is limited to an interval. This is to avoid drastic fluctuations in the threshold that could cause training instability.

[0051] Furthermore, the basic IoU threshold A value of [0.3, 0.7] (e.g., 0.5) can be chosen to balance recall and sample purity in scenarios with minor defects; maximum offset A value of [0.05, 0.20] (more preferably about 0.10) can be used to limit threshold fluctuations and avoid training instability; adjustment coefficient and The values ​​[-0.3, 0.3] can be used to control the intensity of the scene statistics' adjustment of the threshold; the above parameters can be selected based on the validation set or adaptively tuned.

[0052] S42. Adjust the original crossover ratio (CRO) of each real target using the dynamic adjustment threshold corresponding to that real target to obtain the adjusted CRO.

[0053] As a further preferred technical solution, step S42: adjusting the original crossover ratio (CVR) of each real target using a dynamic adjustment threshold to obtain the adjusted CVR, specifically: By using soft gating, the original cross-union ratio (CUI) of each real target is adjusted using a dynamic adjustment threshold corresponding to that real target, resulting in the adjusted CUI, expressed by the formula:

[0054] In the formula, This is the adjusted intersection-union ratio. For the first The first image The first real goal and the first The original crossover ratio between the predicted boxes For the first The first image The dynamic adjustment threshold corresponding to each real target To control the constant of the gating slope, This is the Sigmoid function.

[0055] Furthermore, the gating slope constant [5,20] (e.g., 10) can be used to control the steepness of the Sigmoid soft-gated transition.

[0056] It should be noted that, through the aforementioned soft gating, when When the contribution is above the threshold, it is preserved; when it is below the threshold, it is suppressed; and when it approaches the threshold, it transitions continuously. Significantly higher than the dynamic threshold When the corresponding weight is close to 1, the crossover ratio contribution of the predicted box is basically preserved; when When the value is significantly below the dynamic threshold, the weight is close to 0, and the cross-union contribution of the predicted box is greatly suppressed; while when When the weights approach the threshold, they change continuously between 0 and 1, thereby smoothing out edge samples and avoiding training instability caused by hard threshold truncation.

[0057] As a further preferred technical solution, step S50: calculating the task alignment metric using the adjusted intersection-union ratio and the classification confidence score output by the network, and assigning positive and negative samples based on the task alignment metric, specifically includes the following steps: S51. Calculate the task alignment metric using the adjusted intersection-over-union ratio and the classification confidence score output by the network. The formula is as follows:

[0058] In the formula, This represents the classification confidence of the predicted bounding box output by the network on the true target category. This is the adjusted intersection-union ratio. and These are hyperparameters used to control the weights of the classification branch and the localization branch, respectively. S52. For each real target, sort the predicted bounding boxes in its candidate anchor set from largest to smallest according to the task alignment metric, select the Top-K predicted bounding boxes as positive samples and assign them the label of the real target, and treat the rest as negative samples or ignore them.

[0059] It should be noted that this embodiment uses classification confidence. and Combinatorial construction of task alignment metrics Finally, for each real target In its candidate anchor set ( In the prediction box Sort the data from largest to smallest, select the top-K as positive samples and assign them the corresponding ground truth labels, and treat the rest as negative samples or ignore them. If the same predicted bounding box is selected as a candidate by multiple ground truth targets, it is preferable to assign that predicted bounding box to the task alignment metric. The most important real objective is to avoid multi-objective conflicts.

[0060] It should be noted that K is a preset number of positive samples (Top-K), used to control the upper limit of positive samples corresponding to each real target; preferably, K can be 5 to 20 (e.g., 10), and can be set according to the total number of candidate anchors A, the scale of the real target and the effect of the validation set, but the present invention is not limited thereto.

[0061] The novel label assignment method proposed in this embodiment can be considered as Scene-adaptive Task Alignment Label Assignment (STAL), such as... Figure 2 As shown, the process mainly includes several important parts such as candidate box selection, IoU distribution calculation, dynamic IoU threshold generation, cross-union ratio adjustment, and task alignment metric calculation. Each step is adaptively adjusted based on the characteristics of the target distribution, optimizing the label allocation process. Therefore, the STAL strategy proposed in this embodiment improves the detection accuracy of subtle defects by providing a higher quality and more stable set of positive samples and continuous weight (soft gating) supervision signals, without changing the basic form of the loss function, thereby reducing noise gradients and improving convergence stability. This overcomes the shortcomings of existing label allocation strategies in terms of scene adaptability and improves the accuracy and stability of surface defect detection in cylindrical lithium batteries.

[0062] As a further preferred technical solution, the detection loss function used during training can be expressed as a weighted sum of bounding box regression loss, classification loss, and target confidence loss:

[0063] in, , , These are the weighting coefficients. For bounding box regression loss, For classifying losses, The target confidence loss.

[0064] As a further preferred technical solution, the defect detection network adopts a YOLO network or an RT-DETR detector.

[0065] It should be noted that this embodiment only adjusts the IoU calculation and sample selection strategy during the training process, without changing the network structure and inference process used for the lithium battery surface defect detection model. Therefore, it does not introduce additional inference time overhead. As long as the detection model can output candidate boxes and classification confidence and can calculate the IoU between the predicted box and the real box, the new label allocation method of this invention can be used for model training, and it has good model adaptability.

[0066] Furthermore, the YOLO series models have undergone multiple generations of development (YOLOv1~YOLOv11, etc.) and have continuously improved in target detection performance. As a new generation of detection algorithm, YOLOv11 has been further optimized in terms of network structure and detection accuracy, making it expected to achieve better results in industrial defect detection. However, in the scenario of detecting small defects on the surface of cylindrical lithium batteries, the existing YOLOv11 algorithm still has shortcomings in the label allocation strategy during the training process. In this embodiment, YOLOv11 is specifically selected as the defect detection network. A battery defect target detection network based on the YOLOv11 model is built as the basic model for defect detection; then, the YOLOv11 detection network is trained using the defect dataset, and the scene-adaptive task-aligned label allocation (STAL) strategy is used for sample label allocation during the training process. This strategy dynamically adjusts the IoU threshold by calculating the task alignment metric of predicted samples and introduces a soft gating mechanism to adaptively distinguish between positive and negative samples, thereby completing the label assignment. A Scene Adaptive Task Alignment Label Assignment (STAL) strategy is introduced to replace the original YOLOv11 label assignment scheme during YOLOv11 network training. Specifically, in each training iteration, candidate predicted boxes generated by the YOLOv11 detection head are labeled according to the following method: First, the task alignment metric of each predicted box relative to each ground truth is calculated to quantify the combined quality of its classification confidence and localization accuracy; then, the IoU threshold for positive sample determination is dynamically adjusted based on the alignment metric value of the predicted box, allowing the threshold to adapt to changes in scene and target difficulty; next, samples near the threshold are smoothed using a soft gating mechanism to avoid abrupt truncation in label assignment; finally, positive and negative samples are divided according to the adjusted strategy, and the loss function is calculated to update the model parameters. The trained YOLOv11 defect detection model is applied to the surface image of the battery to be detected, outputting the category and location information of the defects.

[0067] As a further preferred technical solution, the YOLOv11 defect detection network comprises three parts: a backbone network, a network neck, and a detection head. First, the input battery image size is uniformly adjusted to 640×640×3, and then input into the YOLOv11 backbone network to extract multi-scale features. Then, high- and low-level features are fused through the feature pyramid structure to generate defect candidates at different scales. Finally, the YOLOv11 detection head outputs the predicted defect boxes and classification confidence scores at each scale. YOLOv11, as the basic detection model used in this invention, inherits the end-to-end, high-speed, and efficient characteristics of the one-stage detection network, providing a foundation for the implementation of subsequent label allocation strategies. This network can adopt current advanced backbones (such as CSP or Transformer structures) to ensure the extraction of effective defect features in complex backgrounds. It should be noted that the improvements of this invention mainly lie in the label allocation and sample selection process during the training phase, which can be implemented without changing the inference structure of the basic detection network, thus not increasing the computational complexity of the inference phase.

[0068] This embodiment introduces a scene-adaptive task alignment label allocation mechanism, utilizing comprehensive quality metrics and dynamic threshold adjustment to address the misalignment between classification and localization tasks, as well as the lack of adaptability of fixed thresholds. Without altering the basic structure of YOLOv11, this method significantly optimizes the sample selection strategy during training, enabling the model to adaptively adjust its learning strategy for defect targets in different scenarios, thereby improving its ability to detect subtle defects.

[0069] This embodiment utilizes the proposed detection method to detect surface defects in cylindrical lithium batteries. By more effectively using high-quality positive samples and suppressing interference from low-quality samples, the model achieves a higher detection rate and a lower false alarm rate in the task of detecting small surface defects in cylindrical lithium batteries. Figure 4 As shown, the experimental results demonstrate that the model trained using the method of this invention can significantly improve the ability to identify minute defects and the reliability of detection results while ensuring real-time detection speed, which helps to improve the quality control level and operational safety in the battery production process.

[0070] It should be noted that this embodiment focuses on the label assignment / positive and negative sample selection strategy (STAL) during the training phase. It relies on candidate boxes, classification confidence and IoU statistics, and does not rely on prior knowledge of battery geometry. Therefore, it is applicable to cylindrical lithium batteries, and can also be extended to prismatic / pouch lithium batteries and general industrial surface defect detection scenarios.

[0071] In addition, such as Figure 5 As shown, the second embodiment of the present invention also proposes a lithium battery surface defect detection system, the system comprising: Dataset construction module 10 is used to collect images of the lithium battery surface and construct a defect dataset of the battery surface; The iterative training module 20 is used to train the defect detection network using the defect dataset and to calculate the original intersection-union ratio of all predicted boxes output by the network with the real target in each training iteration. The scene statistical feature calculation module 30 is used to determine the scene statistical features of each real target based on the degree of matching between each real target and all predicted boxes; The dynamic adjustment module 40 is used to adjust the original crossover ratio (CRO) of the corresponding real target using scene statistical features, so as to obtain the adjusted CRO. The label assignment module 50 is used to calculate the task alignment metric using the adjusted intersection-union ratio and the classification confidence of the network output, and to assign positive and negative samples based on the task alignment metric. The detection module 60 is used to obtain a trained defect detection network for lithium battery surface defect detection when the model training iteration meets the set conditions.

[0072] As a further preferred technical solution, the scene statistical feature calculation module 30 specifically includes: The candidate mask calculation unit is used to determine the candidate mask of each real target in the anchor point space based on the degree of matching between each real target and all predicted boxes; The scene statistical feature calculation unit is used to calculate the scene statistical features of each real target based on the candidate mask of each real target in the anchor point space. The scene statistical features include the candidate anchor point distribution density and the average matching quality.

[0073] As a further preferred technical solution, the candidate mask calculation unit is specifically used for: for each real target, selecting a prediction box whose center falls within the box containing the real target as a candidate anchor point, or selecting a prediction box whose intersection-union ratio with the real target ranks in the top N among all prediction boxes as a candidate anchor point, where N is a preset threshold; encoding the candidate anchor point as 1, and encoding all prediction boxes except the candidate anchor point as 0, to obtain the candidate mask corresponding to the real target.

[0074] As a further preferred technical solution, the dynamic adjustment module 40 specifically includes: The dynamic adjustment threshold generation unit is used to generate a dynamic adjustment threshold for each real target based on the scene statistical characteristics corresponding to each real target. The cross-union ratio (CUI) adjustment unit is used to adjust the original CUI of each real target using the dynamic adjustment threshold corresponding to that real target, so as to obtain the adjusted CUI.

[0075] As a further preferred technical solution, the cross-over-union ratio adjustment unit is specifically used to: adjust the original cross-over-union ratio corresponding to each real target using a dynamic adjustment threshold corresponding to each real target through a soft gating method, so as to obtain the adjusted cross-over-union ratio.

[0076] As a further preferred technical solution, the tag allocation module 50 specifically includes: The task alignment metric calculation unit is used to calculate the task alignment metric using the adjusted crossover ratio and the classification confidence of the network output; The label assignment unit is used to select the top-K predicted boxes from the candidate anchor set for each real target, sort them in descending order of task alignment metric, and assign the label to the real target. The rest are treated as negative samples or ignored.

[0077] Furthermore, the third embodiment of the present invention also proposes a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the lithium battery surface defect detection method as described in the first embodiment above.

[0078] It should be noted that other embodiments or specific implementation methods of the lithium battery surface defect detection system and computer-readable storage medium described in this invention can refer to the above-described method embodiments, and will not be repeated here.

[0079] It should be noted that the computer-readable medium disclosed in this embodiment may be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium may be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, and portable compact disk read-only memory (CD-ROM). ROM, optical storage devices, magnetic storage devices, or any suitable combination thereof. In this disclosure, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in connection with an instruction execution system, apparatus, or device. In this disclosure, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium can also be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wires, optical fibers, RF (radio frequency), etc., or any suitable combination thereof.

[0080] The aforementioned computer-readable medium may be included in the aforementioned electronic device; or it may exist independently and not assembled into the electronic device. The aforementioned computer-readable medium carries one or more programs, which, when executed by the electronic device, cause the electronic device to perform a zero-sample image anomaly detection method according to the above embodiments.

[0081] Computer program code for performing the operations of this disclosure can be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, and C++, and conventional procedural programming languages ​​such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server.

[0082] In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0083] It should be understood that various parts of the present invention can be implemented in hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented in software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.

[0084] In the description of this specification, references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of the invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.

[0085] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this invention, "a plurality of" or "several" means at least two, such as two, three, etc., unless otherwise explicitly specified.

[0086] Although embodiments of the present invention have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting the present invention. Those skilled in the art can make changes, modifications, substitutions and variations to the above embodiments within the scope of the present invention.

Claims

1. A method for detecting surface defects in lithium batteries, characterized in that, include: Images of the lithium battery surface are collected to construct a defect dataset of the battery surface; The defect detection network is trained using a defect dataset, and the original intersection-union ratio (IUU) of all predicted boxes output by the network with the real target is calculated in each training iteration. Based on the matching degree between each real target and all predicted boxes, the scene statistical features of each real target are determined, including: based on the matching degree between each real target and all predicted boxes, the candidate mask of each real target in the anchor space is determined; based on the candidate mask of each real target in the anchor space, the scene statistical features of each real target are calculated, wherein the scene statistical features include the candidate anchor distribution density and the average matching quality. The original intersection-over-union ratio (IoU) for each real target is adjusted using scene statistical features to obtain the adjusted IoU. This includes generating a dynamic adjustment threshold for each real target based on the scene statistical features corresponding to each real target, expressed by the formula: In the formula, For the first The first image The dynamic adjustment threshold corresponding to each real target Based on Threshold, For the first The first image The distribution density of candidate anchor points for each real target. For the first The first image The average matching quality of each real target and For adjustment coefficients, The maximum allowable offset, This indicates that the threshold is limited to an interval. Inside; The original cross-union ratio (CUI) for each real target is adjusted using a dynamic adjustment threshold corresponding to that real target to obtain the adjusted CUI. Specifically, this is achieved by using a soft-gating method to adjust the original CUI of each real target using its corresponding dynamic adjustment threshold, as expressed by the formula: In the formula, This is the adjusted intersection-union ratio. For the first The first image The first real goal and the first The original crossover ratio between the predicted boxes To control the constant of the gating slope, For the Sigmoid function; The task alignment metric is calculated using the adjusted intersection-union ratio and the classification confidence of the network output, and positive and negative samples are assigned based on the task alignment metric. When the model training iterations meet the set conditions, the trained defect detection network is obtained and used for lithium battery surface defect detection.

2. The lithium battery surface defect detection method as described in claim 1, characterized in that, The process of determining the candidate mask for each ground truth target in the anchor space based on the degree of matching between each ground truth target and all predicted bounding boxes includes: For each real target, select a prediction box whose center falls within the box containing the real target as a candidate anchor point, or select a prediction box whose intersection-union ratio with the real target ranks in the top N among all prediction boxes as a candidate anchor point, where N is a preset threshold. The candidate anchor point is encoded as 1, and all prediction boxes except the candidate anchor point are encoded as 0 to obtain the candidate mask corresponding to the real target.

3. The lithium battery surface defect detection method as described in claim 1, characterized in that, The process involves calculating scene statistical features for each real target based on its candidate mask in the anchor point space. These scene statistical features include candidate anchor point distribution density and average matching quality, including: Based on the candidate mask of each real target in the anchor point space, the candidate anchor point distribution density of that real target is calculated, as expressed by the formula: In the formula, For the first The first image The distribution density of candidate anchor points for each real target. As a candidate mask, it represents The first image The first real goal and the first A binary label indicating whether the candidate conditions are met between the predicted boxes. The total number of candidate anchor points. For the prediction box index, =1,…, ; Based on the candidate mask of each real target in the anchor point space and the original intersection-union ratio corresponding to that real target, the average matching quality is calculated, expressed by the formula: In the formula, For the first The first image The average matching quality of each real target For the first The first image The first real goal and the first The original crossover ratio between the predicted boxes.

4. The lithium battery surface defect detection method as described in claim 1, characterized in that, The step of calculating the task alignment metric using the adjusted intersection-union ratio and the classification confidence score output by the network, and assigning positive and negative samples based on the task alignment metric, includes: The task alignment metric is calculated using the adjusted intersection-over-union ratio (IoU) and the classification confidence score of the network output. The formula is as follows: In the formula, For task alignment metrics, This represents the classification confidence of the predicted bounding box output by the network on the true target category. This is the adjusted intersection-union ratio. and These are hyperparameters used to control the weights of the classification branch and the localization branch, respectively. For each real target, the predicted bounding boxes in its candidate anchor set are sorted from largest to smallest according to the task alignment metric. The top-K predicted bounding boxes are selected as positive samples and assigned the label of the real target. The rest are treated as negative samples or ignored samples.

5. The lithium battery surface defect detection method as described in claim 4, characterized in that, The method further includes: If the same predicted bounding box is selected as a candidate anchor point by multiple real targets, then the predicted bounding box is assigned to the real target with the highest task alignment metric as a positive sample.

6. The lithium battery surface defect detection method as described in claim 1, characterized in that, The defect detection network uses a YOLO network or an RT-DETR detector.

7. A lithium battery surface defect detection system, characterized in that, include: The dataset building module is used to collect images of the lithium battery surface and build a defect dataset of the battery surface; The iterative training module is used to train the defect detection network using the defect dataset and calculate the original intersection-union ratio (IUU) of all predicted boxes output by the network with the real target in each training iteration. The scene statistical feature calculation module is used to determine the scene statistical features of each real target based on the degree of matching between each real target and all predicted boxes; The dynamic adjustment module is used to adjust the original crossover ratio (CRO) of the corresponding real target using scene statistical features, so as to obtain the adjusted CRO. The label assignment module is used to calculate the task alignment metric using the adjusted intersection-over-union ratio and the classification confidence of the network output, and to assign positive and negative samples based on the task alignment metric. The detection module is used to obtain a trained defect detection network for detecting defects on the surface of lithium batteries when the model training iterations meet the set conditions. The scene statistical feature calculation module specifically includes: a candidate mask calculation unit, used to determine the candidate mask of each real target in the anchor point space based on the matching degree between each real target and all predicted boxes; and a scene statistical feature calculation unit, used to calculate the scene statistical features of each real target based on the candidate mask of each real target in the anchor point space, wherein the scene statistical features include the candidate anchor point distribution density and the average matching quality. The dynamic adjustment module includes: a dynamic adjustment threshold generation unit, used to generate a dynamic adjustment threshold for each real target based on the scene statistical features corresponding to each real target, expressed by the formula: In the formula, For the first The first image The dynamic adjustment threshold corresponding to each real target Based on Threshold, For the first The first image The distribution density of candidate anchor points for each real target. For the first The first image The average matching quality of each real target and For adjustment coefficients, The maximum allowable offset, This indicates that the threshold is limited to an interval. Inside; The Cross-Union Ratio (CUI) adjustment unit is used to adjust the original CUI of each real target using a dynamic adjustment threshold, thereby obtaining an adjusted CUI. Specifically, it adjusts the original CUI of each real target using a soft-gating method, as expressed by the formula: In the formula, This is the adjusted intersection-union ratio. For the first The first image The first real goal and the first The original crossover ratio between the predicted boxes To control the constant of the gating slope, This is the Sigmoid function.

8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the lithium battery surface defect detection method as described in any one of claims 1-6.

Citation Information

Patent Citations

  • YOLO lithium battery appearance detection method based on random convolution enhancement

    CN117765335A

  • Real-time target detection model and method fusing multi-scale feature enhancement and dynamic label distribution

    CN121121160A

  • Lithium battery defect detection method based on improved YOLOv4

    CN114049313A

  • Perovskite cell panel surface defect detection method based on improved Yolov9

    CN121616527A