Lithium battery defect detection method, system and device based on YOLOv5 and storage medium
By segmenting and stitching the surface image of the lithium battery into effective detection areas, the efficiency and accuracy issues of YOLOv5 in large-size image detection are solved, achieving more efficient lithium battery defect detection.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-30
- Publication Date
- 2026-03-27
AI Technical Summary
Existing YOLOv5-based lithium battery defect detection methods suffer from low detection efficiency and inaccurate detection of small scratches when processing large images. In particular, the high false detection and false negative rates are caused by image size mismatch and small target pixel ratio.
By acquiring images of the effective detection area on the surface of lithium batteries, scaling them to a uniform size and segmenting them into multiple small images for data annotation and model training, training the YOLOv5 model on a larger dataset, and then stitching the images together after detection to restore the detection results.
It improves the accuracy and efficiency of lithium battery defect detection, reduces the false detection rate and missed detection rate, and significantly improves the detection effect of fine scratches.
Smart Images

Figure CN116128826B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of industrial automation machine vision, and in particular to a lithium battery defect detection method, system and device based on YOLOv5 and a storage medium. BACKGROUND
[0002] In the production and processing process, due to process limitations or operation errors, scratches, pits and other defects will inevitably appear on the surface of lithium batteries. These defects not only reduce product quality, but also may cause safety hazards. Therefore, the surface of the lithium battery must be detected for defects. In the field of industrial automation machine vision, target detection algorithms have gradually replaced traditional machine vision in the field of defect detection. In recent years, YOLO and its improved algorithms have been favored by the market due to their strong generality and low background false detection rate. The YOLOv5 model is a detection algorithm with good detection speed and accuracy in the YOLO series algorithm. Many algorithms based on YOLOv5 on the market are to process the whole image. The disadvantages of this processing are as follows: first, the sample image size collected by the lithium battery surface defect detection industry as the model input is large, and the general open source model cannot be well adapted; second, on the input of large-scale images, the pixels occupied by scratches usually only account for a very small part of the pixels of the whole image, and some small scratches are not easy to detect or have low confidence. SUMMARY
[0003] The technical problem to be solved by the present application is to provide a lithium battery defect detection method, system, device and storage medium based on YOLOv5 in view of at least one defect in the prior art.
[0004] The technical scheme adopted by the present application to solve the technical problem is: a lithium battery defect detection method based on YOLOv5 is constructed, comprising the following steps:
[0005] S1: obtaining an original image, and framing an effective detection area of the original image to obtain an effective detection area image;
[0006] S2: scaling the effective detection area image to a uniform size, and segmenting the effective detection area image into a plurality of small images of a uniform size suitable for model input;
[0007] S3: data labeling is performed on the segmented plurality of small images, and a YOLOv5 model trained on a larger data set is applied and trained;
[0008] S4: after the training is completed, performing inference using the trained model to obtain a model inference result, and splicing the plurality of small images according to the model inference result to restore the plurality of small images to the size of the effective detection area image, so as to obtain a result of the lithium battery defect detection.
[0009] Preferably, the step S1 is further performed after the step S1, and the step S1 further comprises:
[0010] The effective detection area image is subjected to a smoothing and denoising process.
[0011] Preferably, the adjacent two small images form an overlapping area of 12%-18%.
[0012] Preferably, the step S4 is further performed before the step S4, and the step S4 further comprises:
[0013] After the training is completed, a model weight is obtained, and the accuracy of the model is tested using a test set.
[0014] Preferably, the step S2 of scaling the effective detection area image to a uniform size comprises: dividing the width and height of the effective detection area image, and setting the length dimension of the effective detection area image to be close to the input size of the YOLOv5 model.
[0015] Preferably, the step S4 is further performed after the step S4, and the step S4 further comprises:
[0016] The spliced effective detection area image is subjected to a non-maximum suppression process.
[0017] The application also provides a lithium battery defect detection system based on YOLOv5, which comprises:
[0018] An effective detection area image acquisition module is configured to acquire an original image, and frame an effective detection area of the original image to obtain an effective detection area image.
[0019] A segmentation module is configured to scale the effective detection area image to a uniform size, and segment the effective detection area image into a plurality of small images of a uniform size suitable for model input.
[0020] A model training module is configured to perform data labeling on the segmented plurality of small images, and apply a YOLOv5 model trained on a larger data set and complete the training.
[0021] A defect detection result acquisition module is configured to, after the training is completed, perform inference using the trained model to obtain a model inference result, and splice the plurality of small images according to the model inference result to restore the plurality of small images to the size of the effective detection area image, so as to obtain a result of the lithium battery defect detection.
[0022] The application also provides an electronic device, characterized in that comprising a processor and a memory storing computer readable instructions, the processor is configured to execute the computer readable instructions to execute the method according to any one of the above.
[0023] The application also provides a computer readable storage medium, which stores a computer program, the program is executed by a processor to implement the method according to any one of the above.
[0024] By implementing the application, the following beneficial effects are achieved:
[0025] The application can tailor the detection area of any position and any shape according to the detection requirements, and segment and splice the effective detection area image, so as to reduce the false detection rate and the missed detection rate of lithium battery defect detection, and effectively improve the detection efficiency. BRIEF DESCRIPTION OF DRAWINGS
[0026] The application will be further described below in combination with the drawings and embodiments, and the drawings are as follows:
[0027] Figure 1 The scratch defect on the surface of the sealing nail of the lithium battery needs to be detected in some embodiments of the application;
[0028] Figure 2 The processing flowchart of the lithium battery defect detection method based on YOLOv5 is provided;
[0029] Figure 3 The frame selection diagram of the effective detection area in the original image is provided;
[0030] Figure 4 The schematic diagram of the segmentation processing of the effective detection area image is provided;
[0031] Figure 5 The block diagram of the lithium battery defect detection system based on YOLOv5 is provided;
[0032] Figure 6a The verification result diagram without image cutting preprocessing is provided; Figure 6b The verification result diagram after image cutting preprocessing is provided;
[0033] Figure 7a The inference result diagram without image cutting preprocessing is provided; Figure 7b The inference result diagram after image cutting preprocessing is provided. DETAILED DESCRIPTION
[0034] In order to have a clearer understanding of the technical features, objects and effects of the application, the specific embodiments of the application will be described in detail with reference to the drawings.
[0035] It should be noted that the flowchart shown in the drawing is only an exemplary illustration, and does not necessarily include all contents and operations / steps, nor does it necessarily have to be executed in the order described. For example, some operations / steps can be further decomposed, and some operations / steps can be combined or partially combined, so the actual execution order can be changed according to the actual situation.
[0036] The block diagram shown in the drawing is only a functional entity, and does not necessarily correspond to a physically independent entity. That is, these functional entities can be implemented in software form, or in one or more hardware modules or integrated circuits, or in different network and / or processor devices and / or microcontroller devices.
[0037] In the field of industrial automation machine vision, the image size of the lithium battery surface defect detection returned on site is relatively large, and the scratch contrast is low. If only the general model of YOLOv5 is used for detection, it is far from enough. Therefore, it is necessary to consider the pre-processing of segmenting the original input image in advance. As shown in Figure 1 The defects in the product image of the common lithium battery sealing nail surface need to be detected. The general processing flow is to first label the image, then import the labeled image file and the original image into the model for model training, and finally obtain the model training result for defect prediction. In the detection stage, the input image is given for small target detection. Taking the input image 2048x2048 as an example, 5 times of down-sampling are performed in yolov5, and the final feature map sizes are 64x64, 128x128 and 256x256. Among the three, the largest 256x256 is responsible for detecting small targets, and corresponds to 2048x2048. The size of the receptive field of each feature map is 8x8.
[0038] Specifically, as shown in Figure 2 The present application discloses a lithium battery defect detection method based on YOLOv5, which comprises the following steps:
[0039] S1: obtaining an original image, and framing an effective detection area of the original image to obtain an effective detection area image;
[0040] S2: scaling the effective detection area image to a uniform size, and segmenting the effective detection area image into a plurality of small images of a uniform size suitable for model input;
[0041] S3: data labeling is performed on the segmented plurality of small images, and a YOLOv5 model trained on a larger data set is applied and trained;
[0042] S4: After the training is completed, the model inference result is obtained by using the trained model for inference, and the multiple small images are spliced according to the model inference result to restore the effective detection area image size, so as to obtain the result of lithium battery defect detection.
[0043] Specifically, as shown in Figure 3 Step S1: obtaining an original image, and obtaining an effective detection area image by framing the effective detection area of the original image; as can be seen from the image, the effective detection area of the original image is Figure 3 the middle white area, and the black area around it greatly reduces the proportion of the effective detection area in the original image and affects the detection accuracy of the surface scratch defect detection of the lithium battery, so the black area should be removed to obtain the effective detection area image when the image is processed.
[0044] After step S1 is performed, it further includes:
[0045] The effective detection area image is subjected to smoothing and denoising processing. Specifically, the effective detection area image is subjected to smoothing and denoising processing by using a median filtering method, which can effectively remove isolated noise points of the effective detection area image, better distinguish defects and background information, and also retain most of the edge information so that it is not blurred.
[0046] Step S2: scaling the effective detection area image to a uniform size, and dividing the effective detection area image into multiple small images of a uniform size suitable for model input.
[0047] The scaling of the effective detection area image to a uniform size includes dividing the width and height of the effective detection area image, and setting the long side size of the effective detection area image to be close to the input size of the YOLOv5 model. Specifically, in some embodiments, the long side size of the effective detection area image can be set to 2048px, and it can be understood that in other embodiments, the long side size of the effective detection area image can also be set differently according to needs.
[0048] Since there are some fine scratch defects on the surface of the lithium battery, the input high-resolution image detection method of the YOLT algorithm needs to be improved on the basis of the YOLOv5 detection network structure, as shown in Figure 4 The effective detection area image is divided into nine small images for detection. Further, the adjacent two small images have an overlapping area of 12%-18% to better detect the scratch defects of the edge area of the small image and improve the detection accuracy.
[0049] Step S3: data labeling is performed on the segmented multiple small images, and a YOLOv5 model trained on a larger data set is applied and trained.
[0050] Step S4: after training, the model inference result is obtained by using the trained model for inference, and the multiple small images are spliced according to the model inference result to restore them to the effective detection region image size, so as to obtain the result of lithium battery defect detection.
[0051] Specifically, the trained model is used to detect defects in the multiple small images, and then the multiple small images are spliced to restore them to the effective detection region image size, and finally the result of lithium battery defect detection is obtained. Before step S4 is performed, the model weight is obtained after training, and the accuracy of the model is tested using a test set.
[0052] After step S4 is performed, the following steps are further included:
[0053] The spliced effective detection region image is subjected to non-maximum suppression processing, which can eliminate redundant boxes and select target boxes to achieve selection of multiple prediction boxes of the same detection target, thereby improving the accuracy of lithium battery surface defect detection.
[0054] As shown in Figure 5 The present application discloses a lithium battery defect detection system based on YOLOv5, which comprises:
[0055] An effective detection region image acquisition module is configured to acquire an original image and frame an effective detection region of the original image to obtain an effective detection region image.
[0056] A segmentation module is configured to scale the effective detection region image to a uniform size and divide the effective detection region image into multiple small images of the uniform size suitable for model input.
[0057] A model training module is configured to perform data labeling on the segmented multiple small images and apply and train a YOLOv5 model trained on a larger data set.
[0058] A defect detection result acquisition module is configured to, after training, use the trained model for inference to obtain a model inference result, and splice the multiple small images according to the model inference result to restore them to the effective detection region image size, so as to obtain the result of lithium battery defect detection.
[0059] Specifically, as shown in Figure 3 , an effective detection area image acquisition module is configured to acquire an original image and frame an effective detection area of the original image to obtain an effective detection area image. As can be seen from the image, the effective detection area of the original image is Figure 3 the middle white area, and the surrounding black area greatly reduces the proportion of the effective detection area in the original image and hinders the detection accuracy of the surface scratch defect of the lithium battery. Therefore, the black area should be removed to obtain the effective detection area image when the image is processed.
[0060] Before the effective detection area image acquisition module is executed, the method further includes:
[0061] The effective detection area image is subjected to smoothing and denoising processing. Specifically, the median filtering method is used to perform smoothing and denoising processing on the effective detection area image, which can effectively remove isolated noise points of the effective detection area image, better distinguish defects and background information, and also retain most of the edge information so that it is not blurred.
[0062] A segmentation module is configured to scale the effective detection area image to a uniform size and segment the effective detection area image into a plurality of small images of the uniform size suitable for model input.
[0063] The scaling of the effective detection area image to the uniform size includes dividing the width and height of the effective detection area image and setting the long side size of the effective detection area image to be close to the input size of the YOLOv5 model. Specifically, in some embodiments, the long side size of the effective detection area image can be set to 2048px. Understandably, in other embodiments, the long side size of the effective detection area image can also be set differently according to needs.
[0064] Since the surface defects of the lithium battery exist in a certain fine scratch defect, the input high-resolution image detection method of the YOLT algorithm needs to be improved on the basis of the YOLOv5 detection network structure, as shown in Figure 4 , the effective detection area image is segmented into nine small images for detection. Further, the adjacent small images have an overlapping area of 12%-18% to better detect the scratch defects of the edge area of the small images and improve the detection accuracy.
[0065] The model training module is used for data labeling on the segmented small images, and a YOLOv5 model trained on a larger data set is applied and trained.
[0066] The defect detection result acquisition module is used for obtaining a model inference result by using the trained model to infer after the training is completed, and the small images are spliced according to the model inference result to restore the effective detection area image size, so as to obtain the result of the lithium battery defect detection.
[0067] Specifically, the trained model is used for defect detection on the small images, and the small images are spliced to restore the effective detection area image size, and finally the result of the lithium battery defect detection is obtained.
[0068] Before the defect detection result acquisition module is executed, the model weight is obtained after the training is completed, and the accuracy of the model is tested by using a test set.
[0069] After the defect detection result acquisition module is executed, the following steps are further included:
[0070] The non-maximum suppression processing is performed on the spliced effective detection area image, which can eliminate redundant frames, screen target frames, realize selection of multiple prediction frames of the same detection target, and further improve the accuracy of the lithium battery surface defect detection.
[0071] The present application also provides an electronic device, characterized by comprising a processor and a memory storing computer readable instructions, wherein the processor is configured to execute the computer readable instructions to execute the method of any one of the above.
[0072] The present application also provides a computer readable storage medium storing a computer program, wherein the program is executed by a processor to implement the method of any one of the above.
[0073] By implementing the present application, the following beneficial effects are achieved: the present application can tailor the detection area of any position and any shape according to the detection requirements, and the effective detection area image is segmented and spliced, which can reduce the false detection rate and the missed detection rate of the lithium battery defect detection, and effectively improve the detection efficiency.
[0074] Specifically, Figure 6a The verification result image without image cutting preprocessing; Figure 6bFor the verification result map after image cutting pretreatment, Table 1 below is the comparison of various data of image cutting pretreatment and non-cutting pretreatment. It can be seen that the detection accuracy of lithium battery defects after cutting is improved by 3.0%.
[0075]
[0076] Table 1
[0077] Figure 7a For the inference result map without image cutting pretreatment; Figure 7b For the inference result map after image cutting pretreatment. It can be seen that the model after cutting pretreatment can detect small target defects, and the average accuracy is improved by 12%.
[0078] It can be understood that the above embodiments only express the preferred embodiments of the present application, and the description is more specific and detailed, but it cannot be understood as a limitation on the scope of the patent of the present application; it should be pointed out that for ordinary skilled in the art, the above technical features can be freely combined without departing from the concept of the present application, and several modifications and improvements can be made, which belong to the protection scope of the present application; therefore, any equivalent transformation and modification within the scope of the claims of the present application shall belong to the scope of the claims of the present application.
Claims
1. A lithium battery defect detection method based on YOLOv5, characterized in that, Includes the following steps: S1: Obtain the original image, and select the effective detection area of the original image to obtain the effective detection area image; S2: Scale the effective detection region image to a uniform size, and divide the effective detection region image into multiple small images of a uniform size that adapt to the model input, with the adjacent edges of two small images forming an overlap area of 12%-18%. S3: Perform data annotation on the segmented multiple small images, and apply the YOLOv5 model trained on a larger dataset to complete the training; S4: After training, the trained model is used to perform inference to obtain the model inference result, and the multiple small images are stitched together according to the model inference result to restore it to the size of the effective detection area image, so as to obtain the result of lithium battery surface scratch defect detection.
2. The lithium battery defect detection method based on YOLOv5 according to claim 1, characterized in that, After performing step S1, the following is also included: The image of the effective detection area is then smoothed and denoised.
3. The lithium battery defect detection method based on YOLOv5 according to claim 1, characterized in that, Before performing step S4, the following is also included: After training, the model weights are obtained, and the accuracy of the model is tested using a test set.
4. The lithium battery defect detection method based on YOLOv5 according to claim 1, characterized in that, The step S2 of scaling the effective detection region image to a uniform size includes: dividing the width and height of the effective detection region image into equal parts, and setting the long side size of the effective detection region image to match the input size of the YOLOv5 model.
5. The lithium battery defect detection method based on YOLOv5 according to claim 1, characterized in that, After performing step S4, the process further includes: Non-maximum suppression processing is applied to the stitched image of the effective detection region.
6. A lithium battery defect detection system based on YOLOv5, characterized in that, The system includes: The effective detection region image acquisition module is used to acquire the original image and select the effective detection region of the original image to obtain the effective detection region image. The segmentation module is used to scale the effective detection region image to a uniform size and segment the effective detection region image into multiple small images of a uniform size adapted to the model input, wherein the adjacent edges of two small images form an overlap area of 12%-18%. The model training module is used to annotate the segmented multiple small images and apply the YOLOv5 model trained on a larger dataset to complete the training. The defect detection result acquisition module is used to perform inference using the trained model after training to obtain the model inference result, and to stitch together the multiple small images according to the model inference result to restore them to the size of the effective detection area image, so as to obtain the result of lithium battery surface scratch defect detection.
7. An electronic device, characterized in that, It includes a processor and a memory storing computer-readable instructions, the processor being configured to perform the method as described in any one of claims 1-5 when executing the computer-readable instructions.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1-5.
Citation Information
Patent Citations
Lithium battery defect detection method based on Tiny-yoxov3 network embedded with grouping attention module
CN111612751A