A complex multi-scale adaptive battery casing defect detection method
By improving the YOLOv9 algorithm, the RepDSC_ASKA module, AMF module and LMFLoss loss function were introduced, which solved the problem of insufficient accuracy and robustness of the traditional methods in surface defect detection of dry battery, and achieved efficient and accurate defect detection effects.
Patent Information
- Application Number
- CN202510455139.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-11
- Publication Date
- 2025-08-26
- Estimated Expiration
- 2045-04-11
AI Technical Summary
The existing traditional artificial visual inspection methods are inefficient and costly, and the rules-based detection methods are insufficient in dealing with complex and diverse defects on the surface of dry batteries, making it difficult to meet the needs of modern industry for efficient and accurate defect detection.
Using the improved YOLOv9 algorithm, the model's detection ability to detect complex multi-scale defects and adaptability to complex backgrounds is enhanced by designing the RepDSC_ASKA module, AMF module and improved LMFLoss loss function, and the learning ability to rare category defects is improved.
It significantly improves the accuracy and robustness of dry battery surface defect detection, which is better than the existing YOLO series models, especially in complex background and multi-scale defect detection tasks.
Smart Images

Figure CN119963564B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of battery surface defect detection, and in particular relates to a complex multi-scale adaptive battery shell defect detection method. Background Art
[0002] In industrial manufacturing, dry cell batteries are key components widely used in consumer electronics, medical devices, and new energy sectors. Their surface quality directly impacts product performance and safety. However, due to limitations in production processes, equipment precision, and the operating environment, dry cell batteries inevitably develop a range of surface defects, such as pitting, scratches, and dents, during production. These defects not only reduce the battery's electrical performance and service life but can also cause serious problems such as electrolyte leakage, short circuits, and even explosions, posing potential threats to user safety and device operation. Therefore, efficient and accurate detection of dry cell surface defects is crucial to ensuring product quality and safety.
[0003] Currently, many companies still rely on traditional manual visual inspection methods. However, this method suffers from low efficiency, high cost, and susceptibility to human fatigue and subjective judgment, making it difficult to meet the demands of modern industry for efficient and precise production. Furthermore, the surface defects of dry cell batteries are complex and diverse in morphology, and their indistinguishability from the background is poor. Traditional rule-based inspection methods often exhibit significant limitations when dealing with defects of varying sizes, morphologies, and complex backgrounds. In recent years, with the rapid development of deep learning technology, object detection algorithms based on convolutional neural networks (CNNs) have achieved remarkable results in industrial surface defect detection. For example, the YOLO family of algorithms has been widely used in industrial inspection due to its high efficiency and real-time performance.
[0004] As a new member of the YOLO family, YOLOv9 builds on the strengths of its predecessors by improving the network structure and optimizing the algorithmic process, further enhancing the accuracy and real-time performance of object detection. This has led to significant results in general object detection tasks. However, when directly applied to dry cell surface defect detection, YOLOv9 still faces unique challenges, such as defect morphology diversity, background complexity, and class imbalance. Therefore, further optimization and adjustments to existing object detection methods are necessary to meet the needs of dry cell surface defect detection and enhance their applicability and performance in industrial production scenarios. Summary of the Invention
[0005] In response to the above-mentioned deficiencies in the prior art, the present invention provides a complex multi-scale adaptive battery casing defect detection method that solves the problem that traditional detection methods are insufficient in accuracy and robustness, and are unable to meet the modern industry's demand for efficient and accurate defect detection.
[0006] In order to achieve the above-mentioned purpose of the invention, the technical solution adopted by the present invention is: a complex multi-scale adaptive battery shell defect detection method, comprising the following steps:
[0007] S1. Obtain a dataset of surface defects of dry cell batteries;
[0008] S2. Input the dry cell surface defect dataset into the backbone network to obtain the first to third defect features;
[0009] S3, input the first to third defect features into the bottleneck layer to obtain the first to sixth detection features;
[0010] S4. Input the first to sixth detection features into the decoding prediction end to obtain the battery shell defect detection result.
[0011] Furthermore: In S1, the dry cell surface defect dataset divides the dry cell surface defects into: crush, scratch, pit, U-shape, mouth wrinkle and mouth crack.
[0012] The beneficial effects of the above further scheme are: experimental verification is carried out using a self-made dry cell surface defect dataset Battery-Defects, and cross-domain performance evaluation is carried out using a public steel plate surface defect dataset GC10-DET with similar morphology to dry cell defects, further verifying the generalization ability of the proposed method.
[0013] Further: in S2, the backbone network includes a first convolution module, a second convolution module, an ELAN1 module, a first Aconv module, a first RepDSC_ASKA module, a second Aconv module, a second RepDSC_ASKA module, a third Aconv module and a third RepDSC_ASKA module connected in sequence;
[0014] The dry cell surface defect dataset is input into the backbone network, and the first to third defect features are output through the first RepDSC_ASKA module, the second RepDSC_ASKA module and the third RepDSC_ASKA module respectively.
[0015] The beneficial effects of the above further scheme are: in the backbone network part, a RepDSC_ASKA module is designed for feature extraction, and the model's detection ability for fine local structures and complex global morphology is enhanced through an adaptive multi-scale feature extraction mechanism.
[0016] Furthermore, the structures of the first RepDSC_ASKA module, the second RepDSC_ASKA module and the third RepDSC_ASKA module are the same, and the specific workflow of the structure is as follows:
[0017] S21. Perform convolution on the input feature map of the structure and divide the generated result into components along the channel dimension. and ;
[0018] S22, will Enter the RepNCSP module through two Convolution gets the components and , the amount Pass it to the bottleneck layer for feature extraction to obtain components , and then the amount and Connect in the channel dimension and convolve the connected components to obtain components ;
[0019] S23, the amount Input DSC_ASKA module for feature extraction and obtain components ;
[0020] S24, the amount Input the RepNCSP module and DSC_ASKA module in sequence to obtain the components ;
[0021] S25, the amount 、 、 and After connection, Conv operation is performed to obtain the output feature map of the structure.
[0022] Furthermore, the DSC_ASKA module adjusts the convolution kernel through a learnable offset parameter, which is:
[0023] Expand the convolution kernel K on the grid, starting from the center grid position to the grid position away from the center, and increase the offset of each grid position by a random number , ;
[0024] The DSC_ASKA module includes a ConvM submodule, a first DSConv submodule, a second DSConv submodule, an ASKA submodule, and a feature fusion submodule connected in sequence. The input of the ConvM submodule is also input into the first DSConv submodule and the second DSConv submodule. The output of the ConvM submodule and the first DSConv submodule is also input into the ASKA submodule.
[0025] The specific workflow of the ASKA submodule is as follows:
[0026] A1. Obtain the input feature map of the ASKA submodule, extract features through several convolution branches of different sizes, and obtain a fused feature map;
[0027] A2. Perform global average pooling on the fused feature map to generate a global descriptor;
[0028] A3. Input the global descriptor into two fully connected layers in sequence to generate the weights of each convolution branch;
[0029] A4. Perform weighted summation on the outputs of each convolution branch according to the weights to obtain the output feature map of the ASKA submodule.
[0030] Further: in S3, the bottleneck layer includes a first AMF module, a second AMF module, a fourth RepDSC_ASKA module, a fifth RepDSC_ASKA module, a sixth RepDSC_ASKA module, a seventh RepDSC_ASKA module, an eighth RepDSC_ASKA module, a ninth RepDSC_ASKA module, a fourth Aconv module and a fifth Aconv module;
[0031] The first AMF module, the fourth RepDSC_ASKA module, the fifth RepDSC_ASKA module, the fourth Aconv module, the sixth RepDSC_ASKA module, the fifth Aconv module and the seventh RepDSC_ASKA module are connected in sequence;
[0032] The second AMF module, the eighth RepDSC_ASKA module and the ninth RepDSC_ASKA module are connected in sequence.
[0033] The beneficial effect of the above further solution is: in the bottleneck layer, an AMF module is introduced to improve the model's adaptability to complex backgrounds and multi-scale defects through multi-level feature fusion.
[0034] Further: S3 is specifically:
[0035] The third defect feature is input into the first AMF module, the feature output by the first AMF module is upsampled and then fused with the second defect feature, the fused feature is input into the fourth RepDSC_ASKA module, the feature output by the fourth RepDSC_ASKA module is upsampled and then fused with the first defect feature, the fused feature is input into the fifth RepDSC_ASKA module to obtain a first detection feature, the first detection feature is input into the fourth Aconv module, the feature output by the fourth Aconv module is fused with the feature output by the fourth RepDSC_ASKA module, the fused feature is input into the sixth RepDSC_ASKA module to obtain a second detection feature, the second detection feature is input into the fifth Aconv module, the feature output by the fifth Aconv module is fused, and the fused feature is input into the seventh RepDSC_ASKA module to obtain a third detection feature;
[0036] The third defect feature is input into the second AMF module to obtain the sixth detection feature. The sixth detection feature is upsampled and fused with the second defect feature. The fused feature is input into the eighth RepDSC_ASKA module to obtain the fifth detection feature. The fifth detection feature is upsampled and fused with the first defect feature. The fused feature is input into the ninth RepDSC_ASKA module to obtain the fourth detection feature.
[0037] Furthermore, the structure of the first AMF module and the second AMF module is the same, and the specific workflow of the structure is as follows:
[0038] B1. Input the input feature map of the structure into three parallel branches and one global branch respectively, fuse the output features of all branches, and input the fused features into the channel attention mechanism LSE module;
[0039] Three parallel branches are set up 、 and The convolution kernel of
[0040] B2. The channel attention mechanism LSE module outputs the attention weight of each channel in the input feature map, multiplies the attention weight of each channel with the input feature map channel by channel, and obtains the weighted feature map;
[0041] B3. Input the weighted feature map into the first Convolutional layer, obtain the output feature map of the structure.
[0042] Furthermore: In B2, the workflow of the channel attention mechanism LSE module is as follows:
[0043] The feature map input by the channel attention mechanism LSE module is sequentially input into the global average pooling layer, the second Convolution layer, ReLU activation function layer, third The convolution layer and the Sigmoid activation function layer generate channel weights, which are element-wise multiplied by the feature map input by the channel attention mechanism LSE module to obtain the attention weight of each channel.
[0044] Further: S4 is specifically:
[0045] The first to sixth detection features are input into the decoding prediction end, and based on the preset Ciou loss function and LMFLoss loss function, a defect prediction result of each detection feature is generated to obtain the battery casing defect detection result;
[0046] LMFLoss loss function The specific expression is:
[0047]
[0048] Where, is the first hyperparameter, is the second hyperparameter, is the LDAM loss, It is Focal Loss, and its expression is as follows:
[0049]
[0050]
[0051] Where, For battery shell defect detection category The predicted probability of is the adjustment factor, x is the sample, y is the label corresponding to x, It is a model composed of backbone network, bottleneck layer and prediction end. is the output of the model, is the index value after margin adjustment, where is the margin parameter, For a specific category, is the number of categories.
[0052] The beneficial effect of the above further scheme is: to address the problem of data set category imbalance, an improved LMFLoss loss function is proposed to effectively improve the model's ability to learn rare category defects.
[0053] The beneficial effects of the present invention are:
[0054] (1) This paper proposes a complex multi-scale adaptive battery shell defect detection method based on the improved YOLOv9s for the task of dry cell surface defect detection. By designing the RepDSC_ASKA module, the AMF module and the improved LMFLoss loss function, the model's detection capability for complex multi-scale defects, adaptability to complex backgrounds and learning ability for rare category defects are effectively improved. Experimental results show that the proposed method achieves detection accuracy and robustness superior to existing methods on both the self-made Battery-Defects dataset and the public GC10-DET dataset, verifying its effectiveness and generalization ability in specific tasks and cross-domain scenarios. Experimental results show that the improved method proposed in this paper is superior to existing methods in both detection accuracy and robustness, providing an efficient and reliable solution for dry cell surface defect detection.
[0055] (2) In comparative experiments, the proposed method was comprehensively compared with existing mainstream object detection models (such as YOLOv5s, YOLOv8s, YOLOv9s, YOLOv10s, and YOLOv11s). The experimental results show that the proposed method outperforms the existing YOLO series models in key indicators such as precision, recall, and mAP. In particular, in complex background and multi-scale defect detection tasks, the proposed method demonstrates stronger robustness and higher generalization ability, further demonstrating its application potential in industrial surface defect detection tasks. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] Figure 1 This is a flow chart of a complex multi-scale adaptive battery casing defect detection method of the present invention.
[0057] Figure 2 This is the improved MSA-YOLO network structure diagram.
[0058] Figure 3 This is the structural diagram of the RepDSC_ASKA module.
[0059] Figure 4 Schematic diagram of dynamic feature extraction of DSC_ASKA module.
[0060] Figure 5 This is a schematic diagram of the DSC_ASKA module structure.
[0061] Figure 6 This is the workflow diagram of the ASKA submodule.
[0062] Figure 7 This is a structural diagram of the AMF module.
[0063] Figure 8 Distribution plot of the number of defects for each category. DETAILED DESCRIPTION
[0064] The specific embodiments of the present invention are described below to facilitate understanding of the present invention by those skilled in the art. However, it should be clear that the present invention is not limited to the scope of the specific embodiments. For those skilled in the art, as long as various changes are within the spirit and scope of the present invention as defined and determined by the appended claims, these changes are obvious, and all inventions and creations utilizing the concepts of the present invention are protected.
[0065] like Figure 1 As shown, in one embodiment of the present invention, a complex multi-scale adaptive battery casing defect detection method includes the following steps:
[0066] S1. Obtain a dataset of surface defects of dry cell batteries;
[0067] S2. Input the dry cell surface defect dataset into the backbone network to obtain the first to third defect features;
[0068] S3, input the first to third defect features into the bottleneck layer to obtain the first to sixth detection features;
[0069] S4. Input the first to sixth detection features into the decoding prediction end to obtain the battery shell defect detection result.
[0070] In industrial production, the detection of surface defects of dry cell batteries faces many challenges: various defect types, significant feature differences, complex and irregular shapes, low distinction between defects and backgrounds, and uneven distribution of defect categories. These problems lead to the insufficient performance of traditional detection methods in terms of accuracy and robustness, making it difficult to meet the needs of modern industry for efficient and accurate defect detection. In order to solve these problems, the present invention uses the YOLOv9 algorithm as the baseline network, and makes targeted improvements and optimizations to it. Specifically, the present invention redesigns the feature extraction module, feature fusion strategy and loss function, and proposes a new algorithm framework to improve the accuracy and adaptability of dry cell surface defect detection. The improved network structure is as follows Figure 2 shown.
[0071] In S1, the dry cell surface defect dataset divides the dry cell surface defects into: crush, scratch, pit, U-shaped, mouth wrinkle and mouth crack.
[0072] In S2, the backbone network includes the first convolution module, the second convolution module, the ELAN1 (efficient layer aggregation network) module, the first Aconv (average pooling convolution) module, the first RepDSC_ASKA module, the second Aconv module, the second RepDSC_ASKA module, the third Aconv module, and the third RepDSC_ASKA module, which are connected in sequence;
[0073] The dry cell surface defect dataset is input into the backbone network, and the first to third defect features are output through the first RepDSC_ASKA module, the second RepDSC_ASKA module and the third RepDSC_ASKA module respectively.
[0074] In the task of battery surface defect detection, there are usually significant differences in the morphology, location and size of defects, which makes the role of feature extraction operations in model performance particularly critical. Traditional convolutional neural networks (CNNs) usually use fixed-scale convolution kernels for feature extraction. However, when faced with defects with large scale differences or complex shapes, fixed-scale convolutions are prone to lose important key information, resulting in decreased detection performance. To address this problem, the present invention designs a RepDSC_ASKA module to improve the model's sensitivity to complex structures and multi-scale features. The core of this module is to introduce the deformed convolution (DSC_ASKA) module and the adaptive multi-scale receptive field mechanism (Adaptive Spatial Kernel Attention, ASKA) to dynamically optimize the feature extraction strategy, thereby more accurately capturing the local details and global morphology of the defects. The structural diagram of the RepDSC_ASKA module is shown below. Figure 3 shown.
[0075] The structures of the first RepDSC_ASKA module, the second RepDSC_ASKA module and the third RepDSC_ASKA module are the same, and the specific workflow of the structure is as follows:
[0076] S21. Perform convolution on the input feature map of the structure and divide the generated result into components along the channel dimension. and ;
[0077] S22, will Enter the RepNCSP module through two Convolution gets the components and , the amount Pass it to the bottleneck layer for feature extraction to obtain components , and then the amount and Connect in the channel dimension and convolve the connected components to obtain components ;
[0078] S23, the amount Input DSC_ASKA module for feature extraction and obtain components ;
[0079] S24, the amount Input the RepNCSP module and DSC_ASKA module in sequence to obtain the components ;
[0080] S25, the amount 、 、 and After connection, Conv operation is performed to obtain the output feature map of the structure.
[0081] The DSC_ASKA module adjusts the convolution kernel through learnable offset parameters, which are:
[0082] Expand the convolution kernel K on the grid, starting from the center grid position to the grid position away from the center, and increase the offset of each grid position by a random number , ;
[0083] In this embodiment, the DSC_ASKA module introduces a learnable offset parameter to enable the convolution kernel to adaptively adjust its sampling position, thereby better capturing the characteristics of irregularly shaped defects, such as Figure 4 As shown, the DSC_ASKA module converts the typical The convolution kernel is expanded.
[0084] The coordinates of the center grid are , is the horizontal coordinate of the center grid, The vertical coordinate of the center grid is , the expansion coefficient is 1, and the convolution kernel is straightened in the x-axis and y-axis directions respectively, thereby realizing deformed convolution. The position of each grid is represented as , is the horizontal coordinate of the grid, is the vertical coordinate of the grid, where c = {0,1,2,3,4} represents the distance from the horizontal or vertical position to the center of the convolution kernel, , Indicates the offset of each selected position of the grid, which is a cumulative process. is a decimal, and the coordinates are usually in integer form, so bilinear interpolation is used, expressed as:
[0085]
[0086] Among them, K is the decimal place, To enumerate all integer spatial positions, B is a bilinear interpolation kernel that can be decomposed into two one-dimensional kernels. That is:
[0087]
[0088] Where, is the decimal position on the x-axis, is the decimal position on the y-axis, List all integer spatial positions along the x-axis, List all integer spatial positions along the y-axis;
[0089] From a central location Initially, the position of the grid away from the center depends on the position of the previous grid, compared to , The offset is increased , ensuring that the convolution kernel conforms to the linear morphological structure. Through this cumulative offset mechanism, the convolution kernel can adaptively adjust its sampling position to more accurately capture the local details of the defect.
[0090] like Figure 5 As shown, the DSC_ASKA module includes a ConvM submodule, a first DSConv (dynamic snake convolution) submodule, a second DSConv submodule, an ASKA submodule and a feature fusion submodule connected in sequence. The input of the ConvM submodule is also input into the first DSConv submodule and the second DSConv submodule, and the output of the ConvM submodule and the first DSConv submodule is also input into the ASKA submodule.
[0091] In this embodiment, the DSC_ASKA module integrates an adaptive multi-scale receptive field mechanism. The core idea of the DSC_ASKA module is to extract features through multiple convolution branches of different sizes and dynamically calculate the weight of each branch to accurately fuse multi-scale features. The goal of this process is to capture multi-scale information without significantly increasing the amount of computation.
[0092] like Figure 6 As shown in the figure, the workflow of the ASKA submodule is as follows:
[0093] A1. Obtain the input feature map of the ASKA submodule, extract features through several convolution branches of different sizes, and obtain a fused feature map;
[0094] In this embodiment, the ASKA submodule processes the input feature map through M convolution branches to obtain M feature maps, and adds these feature maps to obtain a fused feature map U, where the convolution kernel of the first convolution branch is 1*1, the second is 3*3, and so on, the mth convolution branch is (2m-1)*(2m-1);
[0095]
[0096] Where y is the input feature map, The convolution operation of the mth convolution branch on the input feature map y;
[0097] A2. Perform global average pooling on the fused feature map to generate a global descriptor S;
[0098]
[0099] Where GAP represents the global average pooling operation, and the obtained S is the average value of each channel;
[0100] A3. Input the global descriptor into two fully connected layers in sequence to generate the weights of each convolution branch;
[0101] Among them, a fully connected layer transformation is performed on the global descriptor S, and an intermediate result Z is output;
[0102]
[0103] Where FC represents the fully connected layer transformation;
[0104] Then, the intermediate results are mapped to the weights of each convolution branch through the second fully connected layer and reshaped into W;
[0105]
[0106] Among them, W represents the weight of each convolution branch. After Softmax normalization, the sum of the weights is guaranteed to be 1.
[0107] A4. Perform weighted summation on the outputs of each convolution branch according to the weights to obtain the output feature map V of the ASKA submodule.
[0108]
[0109] Where, is the weight of the mth convolution branch, is the output of the mth convolution branch. With this method, the module can adaptively assign weights to convolution branches of different sizes, thereby accurately fusing multi-scale features without significantly increasing the amount of computation.
[0110] In S3, the bottleneck layer includes the first AMF module, the second AMF module, the fourth RepDSC_ASKA module, the fifth RepDSC_ASKA module, the sixth RepDSC_ASKA module, the seventh RepDSC_ASKA module, the eighth RepDSC_ASKA module, the ninth RepDSC_ASKA module, the fourth Aconv module and the fifth Aconv module;
[0111] The first AMF module, the fourth RepDSC_ASKA module, the fifth RepDSC_ASKA module, the fourth Aconv module, the sixth RepDSC_ASKA module, the fifth Aconv module and the seventh RepDSC_ASKA module are connected in sequence;
[0112] The second AMF module, the eighth RepDSC_ASKA module and the ninth RepDSC_ASKA module are connected in sequence.
[0113] In this embodiment, the existing Spatial Pyramid Ensemble with Lightweight Networks (SPPELAN) module, based on YOLOv9s, enhances feature representation capabilities through multi-level max pooling, aiming to extract global features at different scales. However, for the task of dry cell surface defect detection, due to the monotonous image background and low defect-background distinction, traditional pooling strategies have significant limitations in extracting and distinguishing multi-level defects in complex backgrounds. To address this, the present invention proposes an innovative AMF module to replace the original SPPELAN module. By combining multi-scale feature extraction with a lightweight attention mechanism, this module significantly improves the model's sensitivity to detailed features and overall detection performance.
[0114] S3 specifically:
[0115] The third defect feature is input into the first AMF module, the feature output by the first AMF module is upsampled and then fused with the second defect feature, the fused feature is input into the fourth RepDSC_ASKA module, the feature output by the fourth RepDSC_ASKA module is upsampled and then fused with the first defect feature, the fused feature is input into the fifth RepDSC_ASKA module to obtain a first detection feature, the first detection feature is input into the fourth Aconv module, the feature output by the fourth Aconv module is fused with the feature output by the fourth RepDSC_ASKA module, the fused feature is input into the sixth RepDSC_ASKA module to obtain a second detection feature, the second detection feature is input into the fifth Aconv module, the feature output by the fifth Aconv module is fused, and the fused feature is input into the seventh RepDSC_ASKA module to obtain a third detection feature;
[0116] The third defect feature is input into the second AMF module to obtain the sixth detection feature. The sixth detection feature is upsampled and fused with the second defect feature. The fused feature is input into the eighth RepDSC_ASKA module to obtain the fifth detection feature. The fifth detection feature is upsampled and fused with the first defect feature. The fused feature is input into the ninth RepDSC_ASKA module to obtain the fourth detection feature.
[0117] like Figure 7 As shown, the structure of the first AMF module and the second AMF module is the same, and the specific workflow of the structure is as follows:
[0118] B1. Input the input feature map of the structure into three parallel branches and one global branch respectively, fuse the output features of all branches, and input the fused features into the channel attention mechanism LSE module;
[0119] Three parallel branches are set up 、 and The convolution kernel of
[0120] In this embodiment, the AMF module contains three parallel branches, which respectively extract local features of different scales through three different sizes of convolution kernels: 1×1, 3×3 and 5×5. 、 and , thereby enhancing the diversity of features. Let the input feature map be X, these convolution operations can be expressed as:
[0121]
[0122]
[0123]
[0124] In addition, a global branch is designed to perform single-channel convolution using the global average of the input feature map to supplement the global context information. The multi-scale branch and the global branch together form a comprehensive multi-scale feature representation.
[0125]
[0126] in, represents the value of the cth channel at position (i, j), H and W are the height and width of the feature map respectively. Perform convolution operation to obtain global feature representation ;
[0127]
[0128] Features from different scales , , and global features Splice them together to get the final multi-scale feature representation y;
[0129]
[0130] The splicing operation here is performed along the channel dimension, that is, the number of channels of each feature map is merged.
[0131] B2. The channel attention mechanism LSE module outputs the attention weight of each channel in the input feature map, multiplies the attention weight of each channel with the input feature map channel by channel, and obtains the weighted feature map;
[0132] B3. Input the weighted feature map into the first Convolutional layer, obtain the output feature map of the structure.
[0133] In B2, the workflow of the channel attention mechanism LSE module is as follows:
[0134] The feature map input by the channel attention mechanism LSE module is sequentially input into the global average pooling layer, the second Convolution layer, ReLU activation function layer, third The convolution layer and the Sigmoid activation function layer generate channel weights, which are element-wise multiplied by the feature map input by the channel attention mechanism LSE module to obtain the attention weight of each channel.
[0135] In this embodiment, to further enhance the expression of key features, a lightweight channel attention mechanism LSE (Lightweight Squeeze-and-Excitation) is introduced. First, the input feature map is processed by global average pooling to extract the global statistical features of each channel and obtain a channel-level global feature vector z, namely:
[0136]
[0137] Where, is the eigenvalue of row i and column j;
[0138] Then, after two layers Convolution performs nonlinear mapping on the global feature vector z. The first layer Convolution increases the number of channels from down to , get a new vector s; s is activated by the ReLU function to get the intermediate representation ;
[0139]
[0140]
[0141] in, and are the weights and biases of the convolutional layer, , r is a hyperparameter;
[0142] Second floor Convolution restores the intermediate representation to the original number of channels , and get the output vector :
[0143]
[0144] in, is the weight of the convolution layer, is the bias value of the convolution layer.
[0145] Finally, the channel weight is generated by the Sigmoid activation function to obtain the attention weight of each channel , the attention weights are then combined with the input feature map Multiply channel by channel to get the attention weight of each channel :
[0146]
[0147] In this way, through channel-level weighting, the model can highlight the information of important channels while suppressing unimportant channels, thereby improving the ability to capture key features.
[0148] After the multi-scale features are concatenated in the channel dimension, they are weighted by the channel weights generated by the LSE attention mechanism. The weighted features are then processed through a Convolution performs dimensionality reduction to reduce computational burden and ensure efficient integration with subsequent network modules. In this way, the AMF module not only effectively integrates multi-scale features but also significantly reduces computational complexity through a lightweight design strategy. This module fully considers the diversity of feature expression and utilizes global contextual information, enhancing the model's ability to capture key features in complex environments.
[0149] S4 is specifically:
[0150] The first to sixth detection features are input into the decoding prediction end, and based on the preset Ciou loss function and LMFLoss loss function, a defect prediction result of each detection feature is generated to obtain the battery casing defect detection result;
[0151] In the dry cell battery industry, daily production is huge, while the number of defective products is small and the distribution of defect categories is uneven, which can lead to poor model performance when predicting rare categories. Therefore, this paper introduces the LMFLoss loss function to address the class imbalance problem, allowing the model to better learn the characteristics of rare categories.
[0152] The core idea of LMFLoss is to adjust the loss contribution of each category by marginalizing the category frequency, that is, it assigns a weight to each category that is inversely proportional to the frequency of the category. In this way, the loss of rare categories will account for a larger proportion of the total loss, prompting the model to pay more attention to these rare categories.
[0153] Large Margin-aware Focal (LMF) loss is a linear combination of Focal Loss and LDAM, weighted by two hyperparameters.
[0154] LMFLoss loss function The specific expression is:
[0155]
[0156] Where, is the first hyperparameter, is the second hyperparameter, is the LDAM loss, It is Focal Loss, and its expression is as follows:
[0157]
[0158]
[0159] Where, For battery shell defect detection category The predicted probability of is the adjustment factor, x is the sample, y is the label corresponding to x, It is a model composed of backbone network, bottleneck layer and prediction end. is the output of the model, is the index value after margin adjustment, where is the margin parameter, For a specific category, is the number of categories.
[0160] The present invention also provides the following experimental data to verify the effect of the solution of the present invention:
[0161] Step 1: Prepare the dataset:
[0162] The experiments of the present invention are mainly carried out on the self-made dry cell surface defect dataset Battery-Defects. Therefore, this section mainly introduces the self-made dataset. In addition, the present invention also uses the public steel plate surface defect dataset GC10-DET with defects similar to the self-made dataset to evaluate the proposed method, in order to test its performance more comprehensively and make a fairer comparison. GC10-DET is a surface defect dataset collected in real industry and released by Tianjin University. It contains ten types of surface defects, namely punching (Pu), weld (Wl), crescent gap (Cg), water spot (Water Spot), water spot (Ws), oil spot (Os), silk spot (Ss), inclusion (In), rolling pit (Rp), crease (Cr), waist crease (Wf). The collected defects are all on the surface of the steel plate. The dataset includes 2292 grayscale images with an image size of 2048 The 1000 dataset is arbitrarily divided into training and test sets in a ratio of 7:3.
[0163] The self-made dataset of this invention divides the surface defects of dry cell batteries into 6 categories: compression marks (CD), scratches (SH), pits (PT), U-shaped marks (UT), mouth wrinkles (PM), and mouth cracks (CM). The original self-made dry cell dataset Battery-Defects contains 1940 images. The number of samples is small and the distribution of each defect type shows significant imbalance. Figure 8 To overcome this limitation and increase the diversity of the metadata dataset to enhance the model's generalization performance, this paper augments the Battery-Defects dataset by a factor of three using image enhancement techniques such as flipping and contrast enhancement. Finally, the dataset was divided into a 7:3 ratio, with 4656 images used as the training set and 1164 images as the test set.
[0164] Step 2: Configure the experimental environment:
[0165] The experiment of the present invention is built on the deep learning framework Pytorch, and the relevant tests are carried out using the Ubuntu system. The specific experimental configuration is shown in Table 1.
[0166] Table 1 Experimental environment configuration
[0167]
[0168] The experiments presented in this paper used the YOLOv9s network model as a benchmark for improvement and training, and no pretrained weights were used during training. To ensure smooth convergence for both datasets and fully demonstrate the superiority of our method on different datasets, we used different training rounds for each dataset, while maintaining the same training hyperparameters. Because the image sizes of the two datasets differ, we set the batch size for training the Battery-Defects dataset to 8, with a training image resolution of 1280×1280 pixels; and the batch size for training the GC10-DET dataset to 16, with a training image resolution of 640×640 pixels. Other training hyperparameters are shown in Table 2.
[0169] Table 2 Model training parameters
[0170]
[0171] Step 3: Establish evaluation indicators:
[0172] To verify the performance of the model, this paper uses three evaluation metrics: precision, recall, and mean average precision (mAP). These metrics are calculated based on the confusion matrix. As shown in Table 3, TP indicates that the original data is a positive sample and is also a positive sample after the model prediction. FN indicates that the original data is a negative sample and is also a negative sample after the model prediction.
[0173] Table 3 Confusion matrix
[0174]
[0175] Precision (P) measures the accuracy of detection results, that is, the proportion of predicted positive samples that are actually positive. Higher precision values indicate fewer false positives, indicating higher detection accuracy. Recall (R) measures the model's coverage of positive samples, that is, the proportion of actual positive samples that are correctly detected. A higher recall value describes the model's effectiveness in capturing true instances, indicating greater sensitivity to the target object. The mean average precision (mAP) comprehensively considers the model's precision and recall for each category at different IoU thresholds, averaging the average accuracy (AP) across all categories (assuming there are C categories). A higher mAP value indicates superior overall performance in the object detection task, with improved precision and recall across all categories.
[0176] Step 4: Get the experimental results:
[0177] In order to verify the effectiveness and superiority of the proposed method, we conducted ablation experiments and comparative experiments on the self-made Battery-Defects dataset and the public GC10-DET dataset. By adding the RepDSC_ASKA module, AMF module and LMFLoss loss function one by one to conduct ablation experiments, the contribution of each module to the model performance was evaluated. The experimental results show that the RepDSC_ASKA module significantly enhances the model's ability to extract multi-scale features, can effectively deal with defects of different sizes and shapes, and improves the model's performance in complex backgrounds; the AMF module further enhances the model's sensitivity to detail features by combining multi-scale feature extraction with a lightweight attention mechanism, significantly improving the detection performance, especially in complex backgrounds. The performance is more robust; the LMFLoss loss function effectively alleviates the problem of category imbalance, making the model perform well in the detection of rare category defects.
[0178] Ultimately, the model combining all modules achieved significant improvements in detection accuracy, recall, and mean average precision (mAP), validating the effectiveness and synergy of each module. Specifically, in the task of dry cell surface defect detection, the proposed method not only surpassed existing methods in accuracy but also significantly improved the model's robustness, enabling it to adapt to changing industrial environments and ensuring efficient and reliable defect detection.
[0179] In comparative experiments, the proposed method was comprehensively compared with existing mainstream object detection models (such as YOLOv5s, YOLOv8s, YOLOv9s, YOLOv10s, and YOLOv11s). The experimental results show that the proposed method outperforms existing YOLO models in key metrics such as precision, recall, and mean average precision (mAP). In particular, the proposed method demonstrates greater robustness and improved generalization in complex background and multi-scale defect detection tasks, further demonstrating its potential for application in industrial surface defect detection.
[0180] Verified by ablation experiments and comparative experiments, the method proposed in this invention performs outstandingly in improving detection accuracy, adapting to complex backgrounds, and handling category imbalance problems. It not only enhances the detection capability of dry cell surface defects, but also provides a more efficient and reliable solution for the field of industrial defect detection.
[0181] In the description of the present invention, it should be understood that the terms "center", "thickness", "upper", "lower", "horizontal", "top", "bottom", "inner", "outer", "radial", etc., indicating the orientation or positional relationship, are based on the orientation or positional relationship shown in the accompanying drawings, and are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operate in a specific orientation, and therefore cannot be understood as limiting the present invention. In addition, the terms "first", "second", and "third" are used for descriptive purposes only and cannot be understood as indicating or implying the relative importance or the number of technical features implicitly specified. Therefore, the features defined by "first", "second", and "third" may explicitly or implicitly include one or more of such features.
Claims
1. A complex multi-scale adaptive battery casing defect detection method, characterized in that: The following steps are involved: S1. Obtain a dataset of surface defects of dry cell batteries; S2. Input the dry cell surface defect dataset into the backbone network to obtain the first to third defect features; S3, input the first to third defect features into the bottleneck layer to obtain the first to sixth detection features; S4. Input the first to sixth detection features into the decoding prediction end to obtain the battery shell defect detection result; In S2, the backbone network includes a first convolution module, a second convolution module, an ELAN1 module, a first Aconv module, a first RepDSC_ASKA module, a second Aconv module, a second RepDSC_ASKA module, a third Aconv module, and a third RepDSC_ASKA module, which are connected in sequence; The dry cell surface defect dataset is input into the backbone network, and the first, second, and third defect features are output respectively through the first, second, and third RepDSC_ASKA modules; The structures of the first RepDSC_ASKA module, the second RepDSC_ASKA module and the third RepDSC_ASKA module are the same, and the specific workflow of the structure is as follows: S21. Perform convolution on the input feature map of the structure and divide the generated result into components along the channel dimension. and ; S22, will Enter the RepNCSP module through two Convolution gets the components and , the amount Pass it to the bottleneck layer for feature extraction to obtain components , and then the amount and Connect in the channel dimension and convolve the connected components to obtain components ; S23, the amount Input DSC_ASKA module for feature extraction and obtain components ; S24, the amount Input the RepNCSP module and DSC_ASKA module in sequence to obtain the components ; S25, the amount 、 、 and After connection, Conv operation is performed to obtain the output feature map of the structure; The DSC_ASKA module adjusts the convolution kernel through learnable offset parameters, which are: The convolution kernel K Expand on the grid, starting from the center grid position and moving away from the center grid position, and increase the offset of each grid position by a random number , ; The DSC_ASKA module includes a Conv submodule, a first DSConv submodule, a second DSConv submodule, an ASKA submodule, and a feature fusion submodule connected in sequence. The input of the ConvM submodule is also input into the first DSConv submodule and the second DSConv submodule. The output of the ConvM submodule and the first DSConv submodule is also input into the ASKA submodule. The specific workflow of the ASKA submodule is as follows: A1. Obtain the input feature map of the ASKA submodule, extract features through several convolution branches of different sizes, and obtain a fused feature map; A2. Perform global average pooling on the fused feature map to generate a global descriptor; A3. Input the global descriptor into two fully connected layers in sequence to generate the weights of each convolution branch; A4. Perform weighted summation on the outputs of each convolution branch according to the weights to obtain the output feature map of the ASKA submodule.
2. The complex multi-scale adaptive battery casing defect detection method according to claim 1 is characterized in that: In S1, the dry cell surface defect dataset divides the dry cell surface defects into: crush, scratch, pit, U-shaped, mouth wrinkle and mouth crack.
3. The complex multi-scale adaptive battery casing defect detection method according to claim 1, characterized in that: In S3, the bottleneck layer includes the first AMF module, the second AMF module, the fourth RepDSC_ASKA module, the fifth RepDSC_ASKA module, the sixth RepDSC_ASKA module, the seventh RepDSC_ASKA module, the eighth RepDSC_ASKA module, the ninth RepDSC_ASKA module, the fourth Aconv module and the fifth Aconv module; The first AMF module, the fourth RepDSC_ASKA module, the fifth RepDSC_ASKA module, the fourth Aconv module, the sixth RepDSC_ASKA module, the fifth Aconv module and the seventh RepDSC_ASKA module are connected in sequence; The second AMF module, the eighth RepDSC_ASKA module and the ninth RepDSC_ASKA module are connected in sequence.
4. The complex multi-scale adaptive battery casing defect detection method according to claim 3, characterized in that: S3 specifically: The third defect feature is input into the first AMF module, the feature output by the first AMF module is upsampled and then fused with the second defect feature, the fused feature is input into the fourth RepDSC_ASKA module, the feature output by the fourth RepDSC_ASKA module is upsampled and then fused with the first defect feature, the fused feature is input into the fifth RepDSC_ASKA module to obtain a first detection feature, the first detection feature is input into the fourth Aconv module, the feature output by the fourth Aconv module is fused with the feature output by the fourth RepDSC_ASKA module, the fused feature is input into the sixth RepDSC_ASKA module to obtain a second detection feature, the second detection feature is input into the fifth Aconv module, the feature output by the fifth Aconv module is fused, and the fused feature is input into the seventh RepDSC_ASKA module to obtain a third detection feature; The third defect feature is input into the second AMF module to obtain the sixth detection feature. The sixth detection feature is upsampled and fused with the second defect feature. The fused feature is input into the eighth RepDSC_ASKA module to obtain the fifth detection feature. The fifth detection feature is upsampled and fused with the first defect feature. The fused feature is input into the ninth RepDSC_ASKA module to obtain the fourth detection feature.
5. The complex multi-scale adaptive battery casing defect detection method according to claim 3, characterized in that: The structure of the first AMF module and the second AMF module is the same, and the specific workflow of the structure is as follows: B1. Input the input feature map of the structure into three parallel branches and one global branch respectively, fuse the output features of all branches, and input the fused features into the channel attention mechanism LSE module; Three parallel branches are set up 、 and The convolution kernel of B2. The channel attention mechanism LSE module outputs the attention weight of each channel in the input feature map, multiplies the attention weight of each channel with the input feature map channel by channel, and obtains the weighted feature map; B3. Input the weighted feature map into the first Convolutional layer, obtain the output feature map of the structure.
6. The complex multi-scale adaptive battery casing defect detection method according to claim 5, characterized in that: In B2, the workflow of the channel attention mechanism LSE module is as follows: The feature map input by the channel attention mechanism LSE module is sequentially input into the global average pooling layer, the second Convolution layer, ReLU activation function layer, third The convolution layer and the Sigmoid activation function layer generate channel weights, which are element-wise multiplied by the feature map input by the channel attention mechanism LSE module to obtain the attention weight of each channel.
7. The complex multi-scale adaptive battery casing defect detection method according to claim 1, characterized in that: S4 is specifically: The first to sixth detection features are input into the decoding prediction end, and based on the preset Ciou loss function and LMFLoss loss function, a defect prediction result of each detection feature is generated to obtain the battery casing defect detection result; LMFLoss loss function The specific expression is: Where, is the first hyperparameter, is the second hyperparameter, is the LDAM loss, It is Focal Loss, and its expression is as follows: Where, For battery shell defect detection category The predicted probability of is the regulating factor, x For the sample, y for x The corresponding label, It is a model composed of backbone network, bottleneck layer and prediction end. is the output of the model, is the index value after margin adjustment, where is the margin parameter, For a specific category, is the number of categories.
Citation Information
Patent Citations
Light-weight industrial product surface defect detection method
CN119313659A