Method and system for detecting tiny flaws on surface of paper cup based on deep learning
By improving the TFAS feature extraction, SC shared convolution, and CSLDH detection head of the YOLOv11 model and optimizing the loss function, the problems of false detection and false negative detection in traditional paper cup detection methods under complex environments have been solved, achieving accurate detection of minor defects and improving product quality.
Patent Information
- Application Number
- CN202510949587.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-10
- Publication Date
- 2025-11-04
AI Technical Summary
Traditional paper cup defect detection methods are easily affected by changes in lighting, texture and pattern diversity in complex production environments, leading to false positives and false negatives, and making it difficult to accurately identify minor defects such as stains and minor damage.
An improved YOLOv11 model was adopted, and a small defect detection model for paper cup surface was constructed through the TFAS feature extraction module, SC shared convolution module and CSLDH detection head. The loss function was optimized to reduce false detections and false negatives and improve detection accuracy.
In complex environments, it reduces false positives and false negatives, enables accurate identification and location of minor defects, and improves product quality.
Smart Images

Figure CN120894291A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer vision, in particular to a paper cup surface micro defect detection method and system based on deep learning. BACKGROUND
[0002] With the continuous improvement of industrial automation, the paper cup production industry improves production efficiency while the requirement for product quality is increasingly strict. Especially in large-scale production process, the surface defects of paper cups directly affect product quality and consumer experience. Therefore, ensuring that the quality of paper cups in each production link meets the standards is a crucial task. As a core link in quality control, defect detection determines whether the product can successfully enter the market.
[0003] Currently, traditional paper cup defect detection mostly relies on manual methods, which not only has low detection efficiency and is difficult to meet the needs of modern high-speed production lines, but also is easily affected by subjective judgment differences of different detection personnel. Long-time work often leads to fatigue, thereby increasing the risk of misjudgment and omission, seriously affecting the overall quality of products.
[0004] However, the traditional paper cup defect detection method based on artificial intelligence is often disturbed by factors such as illumination changes, diversity of paper cup surface textures and patterns in complex production environments, resulting in false detection and omission.
[0005] In addition, the traditional paper cup defect detection method based on artificial intelligence cannot accurately identify and locate some small stains, slight damage or difficult-to-detect cup mouth deformation, thereby affecting the further improvement of product quality. SUMMARY
[0006] In view of the above deficiencies of the prior art, the purpose of the embodiments of the present application is to provide a paper cup surface micro defect detection method based on deep learning, which can solve the technical problems that the traditional paper cup defect detection method based on artificial intelligence is often disturbed by factors such as illumination changes, diversity of paper cup surface textures and patterns in complex production environments, resulting in false detection and omission, and cannot accurately identify and locate some small stains, slight damage or difficult-to-detect cup mouth deformation, thereby affecting the further improvement of product quality.
[0007] The first aspect of the embodiments of the present application provides a paper cup surface micro defect detection method based on deep learning, comprising:
[0008] S1: obtaining a surface image of a paper cup to be detected;
[0009] S2: a paper cup surface micro defect detection model based on a deep learning model is constructed, wherein the deep learning model is an improved YOLOv11 model, the improved YOLOv11 model comprises a TFAS feature extraction module located at a position of a part C3k2 module in the YOLOv11 model, a SC shared convolution module located at a position of an SPPF module in the YOLOv11 model, and a CSLDH detection head located at a position of a detect detection head in the YOLOv11 model;
[0010] S3: a loss function of the paper cup surface micro defect detection model is constructed.
[0011] S4: taking minimizing a function value of the loss function as an objective, the paper cup surface micro defect detection model is optimized through an optimization algorithm.
[0012] S5: a surface image is input into the optimized paper cup surface micro defect detection model for detection, and a surface micro defect detection result of a paper cup to be detected is output.
[0013] In a second aspect of the embodiment of the present application, a paper cup surface micro defect detection system based on deep learning is provided, comprising a processor and a memory.
[0014] The memory stores programs or instructions executable on the processor, and the programs or instructions are executed by the processor to implement the steps of the paper cup surface micro defect detection method based on deep learning as described in the first aspect.
[0015] In a third aspect of the embodiment of the present application, a readable storage medium is provided, and the readable storage medium stores programs or instructions, and the programs or instructions are executed by a processor to implement the steps of the paper cup surface micro defect detection method based on deep learning as described in the first aspect.
[0016] The technical scheme provided by the embodiment of the present application has at least the following beneficial effects:
[0017] In the embodiment of the present application, the loss function of the paper cup surface micro defect detection model is constructed, and taking minimizing the function value of the loss function as an objective, the paper cup surface micro defect detection model is optimized through an optimization algorithm, thereby avoiding the interference of factors such as light changes, diversity of paper cup surface textures and patterns in complex production environments on the detection algorithm, reducing the occurrence of false detection and missed detection, and through inputting the surface image into the optimized paper cup surface micro defect detection model for detection, outputting the surface micro defect detection result of the paper cup to be detected, and accurately identifying and positioning some small stains, slight damage or difficult-to-detect cup mouth deformation, thereby promoting the further improvement of product quality. BRIEF DESCRIPTION OF DRAWINGS
[0018] The accompanying drawings are included to provide a further understanding of the embodiments of the application, and are incorporated in and constitute a part of this specification, illustrate embodiments of the application and, together with the description, serve to explain the principles of the application. In the drawings:
[0019] Figure 1 is a flowchart of a paper cup surface micro defect detection method based on deep learning provided by an embodiment of the application;
[0020] Figure 2 is a structural diagram of an improved YOLOv11 model provided by an embodiment of the application;
[0021] Figure 3 is a structural diagram of a TFAS feature extraction module provided by an embodiment of the application;
[0022] Figure 4 is a structural diagram of a SC shared convolution module provided by an embodiment of the application;
[0023] Figure 5 is a working flowchart of a CSLDH detection head provided by an embodiment of the application;
[0024] Figure 6 is a working flowchart of another CSLDH detection head provided by an embodiment of the application;
[0025] Figure 7 is a structural diagram of a paper cup surface micro defect detection system based on deep learning provided by an embodiment of the application. DETAILED DESCRIPTION
[0026] In order for those skilled in the art to better understand the technical solutions in the embodiments of the application, the technical solutions of the application will be described clearly and completely below with reference to the drawings. Obviously, the described embodiments are only some of the embodiments of the application, rather than all the embodiments. It should be understood that these descriptions are only exemplary, and are not intended to limit the scope of the application. Based on the embodiments of the application, all other embodiments obtained by those skilled in the art without creative labor should fall within the scope of protection of the application.
[0027] The paper cup surface micro defect detection method based on deep learning provided by the embodiments of the application will be described in detail below with reference to the drawings and specific embodiments and their application scenarios.
[0028] Reference is made to the accompanying drawings in the description of the specification Figure 1Fig. 1 shows a flowchart of a paper cup surface micro flaw detection method based on deep learning according to an embodiment of the present application.
[0029] The paper cup surface micro flaw detection method based on deep learning according to an embodiment of the present application can comprise the following steps:
[0030] S1: Obtain a surface image of a paper cup to be detected.
[0031] Optionally, a camera is used to obtain the surface image of the paper cup to be detected.
[0032] Reference is made to the accompanying drawings Figure 2 Fig. 2 shows a structure diagram of an improved YOLOv11 model according to an embodiment of the present application.
[0033] Reference is made to the accompanying drawings Figure 3 Fig. 3 shows a structure diagram of a TFAS feature extraction module according to an embodiment of the present application.
[0034] Reference is made to the accompanying drawings Figure 4 Fig. 4 shows a structure diagram of an SC shared convolution module according to an embodiment of the present application.
[0035] Reference is made to the accompanying drawings Figure 5 Fig. 5 shows a working flowchart of a CSLDH detection head according to an embodiment of the present application.
[0036] Reference is made to the accompanying drawings Figure 6 Fig. 6 shows another working flowchart of a CSLDH detection head according to an embodiment of the present application.
[0037] In the figure, s represents a step size, for example, s = 2 represents a step size of 2.
[0038] S2: Construct a paper cup surface micro flaw detection model based on a deep learning model, wherein the deep learning model is an improved YOLOv11 model, the improved YOLOv11 model comprises a TFAS feature extraction module located at the position of a part C3k2 module in the YOLOv11 model, an SC shared convolution module located at the position of an SPPF module in the YOLOv11 model, and a CSLDH detection head located at the position of a detect detection head in the YOLOv11 model.
[0039] Specifically, the improved YOLOv11 model replaces part of the C3k2 module in the original YOLOv11 model with a TFAS feature extraction module, replaces the SPPF module in the original YOLOv11 model with a SC shared convolution module, and replaces the detect detection head in the original YOLOv11 model with a CSLDH detection head. Based on the improved YOLOv11 model, a paper cup surface micro defect detection model is constructed.
[0040] In the embodiments of the present application, through these improvements of the YOLOv11 model, especially in the design of feature extraction, convolution sharing and detection head, the precision and efficiency of paper cup surface micro defect detection can be significantly improved. These improvements make the model not only more accurate in precision, but also have advantages in computational efficiency, resource consumption and real-time performance, especially suitable for fast and accurate defect detection tasks on industrial production lines.
[0041] Further, the paper cup surface micro defect detection model comprises a first convolution layer, a second convolution layer, a first TFAS feature extraction module, a third convolution layer, a second TFAS feature extraction module, a fourth convolution layer, a third TFAS feature extraction module, a fifth convolution layer, a fourth TFAS feature extraction module, a SC shared convolution module, a C2PSA module, a first upsampling layer, a first feature splicing layer, a first C3k2 module, a second upsampling layer, a second feature splicing layer, a second C3k2 module, a sixth convolution layer, a third feature splicing layer, a third C3k2 module, a seventh convolution layer, a fourth feature splicing layer, a fourth C3k2 module, a first CSLDH detection head, a second CSLDH detection head and a third CSLDH detection head.
[0042] In the embodiments of the present application, through the design of multiple convolution layers, TFAS feature extraction modules, shared convolution, upsampling and splicing modules, the present application constructs a multi-level and multi-scale micro defect detection model. This model can extract detailed information from multiple scales, enhancing the detection capability of paper cup surface micro defects. At the same time, using the innovative design of CSLDH detection head and attention mechanism, the computational efficiency is optimized, and the stability and reliability of the model in practical application are improved.
[0043] The TFAS feature extraction module comprises a Scharr convolution layer, a fifth feature splicing layer, a first 3x3 convolution layer, a sixth feature splicing layer, a first 1x1 convolution layer, an FFT feature conversion layer, a second 1x1 convolution layer, an IFFT feature conversion layer, a second 3x3 convolution layer, a feature fusion layer and a third 1x1 convolution layer.
[0044] In the embodiment of the present application, the TFAS feature extraction module significantly enhances the detection capability of the model for the tiny defects on the surface of the paper cup by combining various technical means such as time domain and frequency domain feature extraction, dilated convolution, Scharr convolution, FFT / IFFT conversion, etc. At the same time, the design of the module focuses on computational efficiency and robustness, making the method suitable for complex industrial application scenarios.
[0045] In a possible implementation, the TFAS feature extraction module is specifically used for:
[0046] In the Scharr convolution layer, the input feature map is subjected to feature extraction by a Scharr operator to obtain a horizontal gradient map and a vertical gradient map.
[0047] The Scharr operator includes a convolution kernel G x for detecting horizontal edges in an image and a convolution kernel G y for detecting vertical edges in an image.
[0048]
[0049] Specifically, the input feature map is subjected to feature extraction by the convolution kernel G x to obtain the horizontal gradient map. The input feature map is subjected to feature extraction by the convolution kernel G y to obtain the vertical gradient map.
[0050] In the fifth feature splicing layer, the horizontal gradient map and the vertical gradient map are subjected to a splicing operation to obtain a fifth spliced feature map.
[0051] In the first 3x3 convolution layer, the fifth spliced feature map is subjected to feature extraction to obtain an eighth feature map.
[0052] Specifically, in the first 3x3 convolution layer, a dilated convolution with a dilation rate of 2 is introduced to expand the receptive field of the first 3x3 convolution layer from 3x3 to 7x7, so as to extract features from the fifth spliced feature map to obtain the eighth feature map.
[0053] In the sixth feature splicing layer, the input feature map and the eighth feature map are subjected to a splicing operation to obtain a sixth spliced feature map.
[0054] In the first 1x1 convolution layer, the sixth spliced feature map is subjected to feature extraction to obtain a time domain feature map.
[0055] In the FFT feature conversion layer, the input feature map is converted into a frequency domain feature map by an FFT algorithm.
[0056] Specifically, in the FFT feature conversion layer, the input feature map is subjected to two-dimensional real fast Fourier transform to obtain a frequency domain feature map.
[0057] In the second 1x1 convolutional layer, feature extraction is performed on the frequency domain feature map to obtain a ninth feature map.
[0058] Specifically, first, the real part and the imaginary part in the frequency domain feature map are extracted respectively. Second, the real part and the imaginary part are spliced to obtain a new frequency domain feature map. Finally, feature extraction is performed on the new frequency domain feature map in the second 1x1 convolutional layer to obtain the ninth feature map.
[0059] In the IFFT feature conversion layer, the ninth feature map is converted into a spatial domain feature map through an IFFT algorithm.
[0060] Specifically, first, the ninth feature map is reconstructed into a complex tensor, and second, two-dimensional inverse fast Fourier transform is performed on the complex tensor to obtain the spatial domain feature map.
[0061] In the second 3x3 convolutional layer, feature extraction is performed on the spatial domain feature map to obtain a frequency domain feature map.
[0062] In the feature fusion layer, the time domain feature map and the frequency domain feature map are element-wise added to obtain a preliminary fusion feature map.
[0063] Optionally, the time domain feature map and the frequency domain feature map are element-wise added according to the following formula to obtain the preliminary fusion feature map:
[0064]
[0065] Wherein, F fused represents the preliminary fusion feature map, F spatial represents the time domain feature map, represents element-wise addition, F freq represents the frequency domain feature map.
[0066] In the third 1x1 convolutional layer, feature extraction is performed on the preliminary fusion feature map to obtain a fusion feature map.
[0067] In the embodiment of the present application, the Scharr convolutional layer effectively enhances the capture ability of edge features by extracting the horizontal and vertical gradient information of the image, and is particularly suitable for the detection of small defects. The dilated convolution expands the receptive field of the first 3x3 convolutional layer, so that the model can better capture details and context information. The frequency domain feature extraction of FFT and IFFT further enhances the perception of periodic textures and global patterns, which helps to suppress low-frequency noise and improve the detection accuracy of details. By fusing the time domain features and the frequency domain features, the model can utilize spatial information and global texture information at the same time, thereby improving the robustness of small defects in complex backgrounds.
[0068] The SC shared convolution module comprises a fourth 1*1 convolution layer, a first feature extraction branch, a second feature extraction branch, a third feature extraction branch, a third 3*3 convolution layer, a seventh feature splicing layer and a fifth 1*1 convolution layer, wherein the first feature extraction branch, the second feature extraction branch and the third feature extraction branch share the third 3*3 convolution layer.
[0069] In the embodiment of the application, the SC shared convolution module effectively reduces the calculation and memory overhead of the model through the design of shared convolution layers and feature splicing, while maintaining efficient feature extraction capability. This design not only improves the calculation efficiency of the model and reduces redundant calculation, but also enhances the generalization ability and feature integration ability of the model, making the model more suitable for complex detection tasks. In addition, the modular design improves the flexibility and scalability of the model, enabling the model to be adjusted and optimized according to actual needs, further improving its applicability and real-time performance in industrial environments.
[0070] In a possible implementation, the SC shared convolution module is specifically used for:
[0071] In the fourth 1*1 convolution layer, the input feature map is subjected to feature extraction to obtain a tenth feature map.
[0072] In the first feature extraction branch, the tenth feature map is subjected to 1 layer of zero padding to obtain a first padded feature map.
[0073] In the second feature extraction branch, the tenth feature map is subjected to 3 layers of zero padding to obtain a second padded feature map.
[0074] In the third feature extraction branch, the tenth feature map is subjected to 5 layers of zero padding to obtain a third padded feature map.
[0075] Optionally, the padding amount of the feature map is calculated according to the following formula:
[0076]
[0077] wherein paddind represents the padding amount of the feature map, d i represents the i-th layer of zero padding, and C represents the size of the convolution kernel.
[0078] In the third 3*3 convolution layer, the first padded feature map, the second padded feature map and the third padded feature map are subjected to feature extraction respectively to obtain an eleventh feature map, a twelfth feature map and a thirteenth feature map.
[0079] Optionally, the first padded feature map, the second padded feature map and the third padded feature map are subjected to feature extraction respectively to obtain the eleventh feature map, the twelfth feature map and the thirteenth feature map according to the following formula:
[0080]
[0081] wherein, represents the eleventh feature map, represents the twelfth feature map, represents the thirteenth feature map, b k represents the kth feature extraction branch, RELU represents a RELU activation function, Conv 3×3 represents a 3x3 convolution kernel, represents a zero padding operation of the kth feature extraction branch, X c represents an input feature map.
[0082] In the seventh feature concatenation layer, the eleventh feature map, the twelfth feature map and the thirteenth feature map are subjected to a concatenation operation to obtain a seventh concatenated feature map.
[0083] Optionally, the eleventh feature map, the twelfth feature map and the thirteenth feature map are subjected to a concatenation operation according to the following formula to obtain the seventh concatenated feature map:
[0084]
[0085] wherein, X concat represents the seventh concatenated feature map, and Concat represents a concatenation operation.
[0086] In the fifth 1x1 convolution layer, the seventh concatenated feature map is subjected to feature extraction in combination with a BN algorithm and a ReLU activation function to obtain a shared feature map.
[0087] Optionally, the seventh concatenated feature map is subjected to feature extraction according to the following formula to obtain the shared feature map:
[0088] X fused = RELU (BN (Conv 1×1 (X concat )))
[0089] wherein, X fused represents the shared feature map, BN represents a BN algorithm, and Conv 1×1 represents a 1x1 convolution kernel.
[0090] In the embodiment of the present application, the plurality of feature extraction branches share the third 3x3 convolutional layer, reducing redundant calculation and parameter quantity, thereby reducing memory and calculation consumption and improving inference speed. Through zero padding at different levels, the model can extract features at multiple scales, enhancing the ability to capture tiny defects. In addition, the feature concatenation layer fuses the feature maps of different branches, enriching the feature expression and helping to improve the detection accuracy of complex defects. By combining the ReLU activation function and Batch Normalization (BN), the model is more stable during training and can speed up convergence.
[0091] The CSLDH detection head comprises a sixth 1x1 convolutional layer, a shared convolutional layer, a regression branch, a classification branch, and an eighth feature concatenation layer, wherein the first CSLDH detection head, the second CSLDH detection head, and the third CSLDH detection head share the shared convolutional layer.
[0092] In a possible implementation, the CSLDH detection head is specifically used for:
[0093] In the sixth 1x1 convolutional layer, the input feature map is subjected to feature extraction to obtain a fourteenth feature map.
[0094] The fourteenth feature map is subjected to standardization processing.
[0095] In the shared convolutional layer, the fourteenth feature map subjected to standardization processing is subjected to feature extraction to obtain a fifteenth feature map.
[0096] Specifically, first, the spatial local features are extracted by using 3x3 grouped convolution, and then the channel information is fused by using 1x1 convolution, thereby completing the feature extraction of the fourteenth feature map subjected to standardization processing to obtain the fifteenth feature map.
[0097] In the regression branch, the fifteenth feature map is subjected to 3x3 convolution operation, nonlinear scaling operation, and discrete probability distribution modeling operation in sequence, and the boundary box position probability distribution is output.
[0098] Optionally, the nonlinear scaling operation is performed according to the following formula:
[0099]
[0100] γ=α·Sigmoid(β)
[0101] wherein F' represents the fifteenth feature map after the nonlinear scaling operation, γ represents the nonlinear scaling factor, F represents the fifteenth feature map after the 3x3 convolution operation, and α and β both represent learnable parameters.
[0102] In the classification branch, the fifteenth feature map is subjected to 3x3 convolution operation and ReLU activation operation in sequence, and the class confidence is output.
[0103] In the eighth feature splicing layer, the bounding box position probability distribution and the category confidence are spliced to obtain an eighth spliced feature map.
[0104] According to the eighth spliced feature map, a detection result is output through a Sigmoid activation function, wherein the detection result includes a bounding box position of a surface micro defect of the paper cup to be detected and a category.
[0105] Specifically, first, the data dimension is reconstructed to separate the parameters of the regression and classification tasks, and then an anchor grid matching the resolution of the eighth spliced feature map is dynamically generated. On this basis, the integral operation is performed on the bounding box position probability distribution output by the regression branch to obtain the predicted position of the bounding box. Then, combined with the preset linear transformation strategy, the offset of the regression branch is mapped to the original image coordinate system by calculating center point coordinate (dx) × 2-0.5+grid and width-height ratio (dw×2) 2 ×anchor (dx represents the center point offset predicted by the regression branch, grid represents the grid coordinates on the feature map, w represents the width offset predicted by the regression branch, and anchor represents the predefined anchor width). In this process, the Sigmoid activation function is used to process the category confidence output by the classification branch at the same time. Finally, by fusing the decoded physical coordinates and the category scores, the complete detection result is output.
[0106] In the embodiment of the present application, the CSLDH detection head realizes efficient and accurate detection of the surface micro defects of the paper cup through the design of the shared convolutional layer, the regression branch and the classification branch. The sixth 1×1 convolutional layer extracts features and reduces the calculation overhead through the shared convolutional layer, while enhancing the feature extraction capability of the model. The regression branch optimizes the position prediction of the bounding box through the nonlinear scaling operation, improving the positioning accuracy. The classification branch outputs accurate category confidence through the 3×3 convolution and the RELU activation function, ensuring the reliability of the detection result. By splicing the bounding box position and the category confidence and processing them through the Sigmoid activation function, the model can comprehensively judge the type and position of the defects on the surface of the paper cup, thereby realizing efficient and accurate defect detection, especially suitable for automatic detection tasks in industrial production.
[0107] S3: constructing a loss function of the paper cup surface micro defect detection model.
[0108] In a possible implementation, S3 specifically includes sub-steps S301 to S304:
[0109] S301: constructing a classification loss function of the paper cup surface micro defect detection model:
[0110]
[0111] Among them, L cls Let represent the classification loss function, y represent the true label, where when y = 1, it is determined that the surface of the paper cup to be detected has defects, and when y = 0, it is determined that the surface of the paper cup to be detected does not have defects, log represents the natural logarithm, and p represents the predicted defect probability.
[0112] S302: Constructing the confidence loss function for a paper cup surface minor defect detection model:
[0113]
[0114] Among them, L obj Let y represent the confidence loss function. ′ Represents the true confidence level, where when y ′ When y = 1, it is determined that the surface of the paper cup to be tested has defects. ′ When p = 0, it is determined that the surface of the paper cup to be tested is free of defects. ′ This represents the probability of predicting confidence.
[0115] S303: Localization loss function for constructing a model for detecting minor defects on the surface of paper cups:
[0116]
[0117] Among them, L CIoU Let IoU represent the intersection-over-union ratio (IoU) between the predicted and ground truth bounding boxes, c represent the diagonal length of the minimum bounding box, ρ represent the distance between the center of the predicted and ground truth bounding boxes, and b represent the center point of the predicted bounding box. gt Let α represent the center point of the ground truth bounding box, α represent the aspect ratio consistency weight coefficient, v represent the aspect ratio consistency metric, A represent the region of the predicted bounding box, B represent the region of the ground truth bounding box, π represent pi, arctan represent the arctangent function, and h represent the center point of the ground truth bounding box. gt w represents the height of the actual bounding box gt h represents the width of the ground truth bounding box, h represents the height of the predicted bounding box, and w represents the width of the predicted bounding box.
[0118] S304: The loss function for the paper cup surface minor defect detection model is constructed by weighted summing of the classification loss function, confidence loss function, and localization loss function:
[0119] LOSS=λ1L cls +λ2L obj +λ3L CIoU .
[0120] Where LOSS represents the loss function, λ1 represents the weight coefficient of the classification loss function, λ2 represents the weight coefficient of the confidence loss function, and λ3 represents the weight coefficient of the localization loss function.
[0121] In the embodiments of the present application, the classification loss function adopts cross-entropy loss, which ensures the accuracy of the model in judging whether there is a defect on the surface of the paper cup. The confidence loss function improves the confidence of the model in the detection result by optimizing the confidence prediction. The positioning loss function adopts CIoU loss, which not only optimizes the overlap of the frame, but also considers the center point, aspect ratio and diagonal length of the frame, thereby improving the positioning accuracy of the tiny defects. By weighting and summing these loss functions and combining the weight coefficients of different tasks, the model can flexibly adjust the training focus, thereby realizing the comprehensive optimization of multiple tasks and improving the detection accuracy, confidence estimation and target positioning accuracy.
[0122] S4: optimizing the paper cup surface tiny defect detection model by minimizing the function value of the loss function.
[0123] S5: inputting the surface image into the optimized paper cup surface tiny defect detection model for detection, and outputting the surface tiny defect detection result of the to-be-detected paper cup.
[0124] In one possible implementation, S5 specifically includes sub-steps S501 to S529:
[0125] S501: in the first convolutional layer, performing feature extraction on the surface image to obtain a first feature map.
[0126] S502: in the second convolutional layer, performing feature extraction on the first feature map to obtain a second feature map.
[0127] S503: in the first TFAS feature extraction module, performing feature extraction on the second feature map to obtain a first fusion feature map.
[0128] S504: in the third convolutional layer, performing feature extraction on the first fusion feature map to obtain a third feature map.
[0129] S505: in the second TFAS feature extraction module, performing feature extraction on the third feature map to obtain a second fusion feature map.
[0130] S506: in the fourth convolutional layer, performing feature extraction on the second fusion feature map to obtain a fourth feature map.
[0131] S507: in the third TFAS feature extraction module, performing feature extraction on the fourth feature map to obtain a third fusion feature map.
[0132] S508: in the fifth convolutional layer, performing feature extraction on the third fusion feature map to obtain a fifth feature map.
[0133] S509: In the fourth TFAS feature extraction module, the fifth feature map is subjected to feature extraction to obtain a fourth fusion feature map.
[0134] S510: In the SC shared convolution module, the fourth fusion feature map is subjected to feature extraction to obtain a shared feature map.
[0135] S511: In the C2PSA module, the shared feature map is subjected to enhancement processing through a spatial attention mechanism to obtain an enhanced feature map.
[0136] S512: In the first upsampling layer, the enhanced feature map is subjected to upsampling operation to obtain a first upsampling feature map.
[0137] S513: In the first feature splicing layer, the third fusion feature map and the first upsampling feature map are subjected to splicing operation to obtain a first splicing feature map.
[0138] S514: In the first C3k2 module, the first splicing feature map is subjected to feature extraction to obtain a first multi-scale feature map.
[0139] S515: In the second upsampling layer, the first multi-scale feature map is subjected to upsampling operation to obtain a second upsampling feature map.
[0140] S516: In the second feature splicing layer, the second fusion feature map and the second upsampling feature map are subjected to splicing operation to obtain a second splicing feature map.
[0141] S517: In the second C3k2 module, the second splicing feature map is subjected to feature extraction to obtain a second multi-scale feature map.
[0142] S518: In the sixth convolution layer, the second multi-scale feature map is subjected to feature extraction to obtain a sixth feature map.
[0143] S519: In the third feature splicing layer, the first multi-scale feature map and the sixth feature map are subjected to splicing operation to obtain a third splicing feature map.
[0144] S520: In the third C3k2 module, the third splicing feature map is subjected to feature extraction to obtain a third multi-scale feature map.
[0145] S521: In the seventh convolution layer, the third multi-scale feature map is subjected to feature extraction to obtain a seventh feature map.
[0146] S522: In the fourth feature splicing layer, the enhanced feature map and the seventh feature map are subjected to splicing operation to obtain a fourth splicing feature map.
[0147] S523: In the fourth C3k2 module, the fourth splicing feature map is subjected to feature extraction to obtain a fourth multi-scale feature map.
[0148] S524: detecting the second multi-scale feature map in the first CSLDH detection head to obtain a first detection result.
[0149] S525: detecting the third multi-scale feature map in the second CSLDH detection head to obtain a second detection result.
[0150] S526: detecting the fourth multi-scale feature map in the third CSLDH detection head to obtain a third detection result.
[0151] S527: outputting the first detection result, the second detection result, and the third detection result as the surface minor defect detection result of the to-be-detected paper cup.
[0152] In the embodiment of the present application, the paper cup surface minor defect detection model can capture low-level detail information and high-level global information at the same time through multi-scale feature extraction and fusion, thereby improving the detection capability of minor defects. In addition, the use of SC shared convolution modules reduces the amount of calculation and optimizes the calculation efficiency, while the C2PSA module enhances the attention of the model to key areas through a spatial attention mechanism, further improving the detection accuracy. Under the cooperation of multiple CSLDH detection heads, the model can accurately detect defects at different scales, and finally output more reliable detection results by synthesizing multiple detection results, thereby ensuring high precision and high robustness of the detection.
[0153] Further, the output surface minor defect detection result of the to-be-detected paper cup is displayed on the human-computer interaction interface.
[0154] In a possible implementation, the training process of the paper cup surface minor defect detection model specifically includes:
[0155] Obtain the original images of a plurality of paper cup samples with minor defects.
[0156] Optionally, the original images of a plurality of paper cup samples with minor defects are obtained using a camera.
[0157] Label each original image.
[0158] Specifically, the minor defects in each original image are labeled using online labeling software Make Sense, and the labeling process includes specifying the category (such as spots, stains, etc.) of each minor defect and drawing a rectangular box representing the location of the defect. After completing the labeling, the software will generate the label files required by the YOLO model, which are saved in TXT format, and the content includes the category of each minor defect, the center coordinates of the rectangular box, and the width and height of the rectangular box.
[0159] Convert each original image after labeling into a mask image.
[0160] According to a preset ratio, each mask image is divided into a training set and a test set.
[0161] It should be noted that the size of the preset ratio can be set by the person skilled in the art according to actual needs, and the present application does not limit it.
[0162] Optionally, the preset ratio is 8:2.
[0163] The training set is used to train the paper cup surface tiny defect detection model.
[0164] The test set is used to test the trained paper cup surface tiny defect detection model.
[0165] In the embodiment of the present application, the model learns how to accurately detect the tiny defects on the surface of the paper cup through the training set, and the test set is used to evaluate the performance of the model to ensure that it can maintain high accuracy and robustness on unseen data. Through this process, the model can learn from the diversified data in the real world and effectively reduce human error, improve detection accuracy, and enhance the generalization ability of the model in complex production environments.
[0166] The technical scheme provided by the embodiment of the present application has at least the following beneficial effects:
[0167] In the embodiment of the present application, the loss function of the paper cup surface tiny defect detection model is constructed, and the function value of the loss function is minimized as the target, and the paper cup surface tiny defect detection model is optimized through the optimization algorithm, avoiding the interference of factors such as light changes, surface texture and pattern diversity of the paper cup in complex production environments on the detection algorithm, reducing the occurrence of false detection and missed detection, and by inputting the surface image into the optimized paper cup surface tiny defect detection model for detection, the surface tiny defect detection result of the paper cup to be detected is output. For some tiny stains, slight damage or difficult-to-detect cup mouth deformation, accurate recognition and positioning can also be achieved, thereby promoting the further improvement of product quality.
[0168] Referring to the accompanying drawings Figure 7 , a structure schematic diagram of a paper cup surface tiny defect detection system based on deep learning provided by an embodiment of the present application is shown.
[0169] The embodiment of the present application provides a paper cup surface tiny defect detection system 20 based on deep learning, which comprises a processor 201 and a memory 202.
[0170] The memory 202 stores programs or instructions executable on the processor 201, which, when executed by the processor 201, implement the steps of the above-described deep learning-based paper cup surface tiny defect detection method and achieve the same technical effects. To avoid repetition, the present application will not be described again.
[0171] It should be understood that the processor 201 in the embodiments of the present application can be a central processing unit (CPU), and can also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field programmable gate arrays (FPGAs) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or can also be any conventional processor.
[0172] It should also be understood that the memory 202 in the embodiments of the present application can be a volatile memory or a non-volatile memory, or can include both volatile and non-volatile memories. Among them, the non-volatile memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically EPROM (EEPROM) or a flash memory. The volatile memory can be a random access memory (RAM) used as an external cache. By way of example but not limitation, many forms of random access memory (RAM) are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced SDRAM (ESDRAM), synchlink DRAM (SLDRAM) and direct rambus RAM (DR RAM).
[0173] The above-described embodiments can be implemented in part or in whole through software, hardware (e.g., circuitry), firmware, or any combination thereof. When implemented in software, the above-described embodiments can be implemented in the form of a computer program product. The computer program product includes one or more computer instructions or computer programs. When loaded and executed by a computer, the computer instructions or computer programs cause the computer to perform the processes or functions described above according to the embodiments of the present application. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable apparatus. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium, such as from a website, a computer, a server, or a data center to another website, computer, server, or data center through a wired (e.g., infrared, wireless, microwave, or the like) manner. The computer-readable storage medium can be any available medium or a collection of medium accessible by a computer or a data storage device such as a server, data center, or the like, which includes one or more medium. The medium can be a magnetic medium (e.g., a floppy diskette, a hard disk, a magnetic tape), an optical medium (e.g., a DVD), or a semiconductor medium. The semiconductor medium can be a solid-state hard disk.
[0174] It should be understood that the size of the sequence number of each process described above does not mean the order of execution, and the execution order of each process should be determined according to its function and inherent logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0175] Those skilled in the art can realize that the units and algorithm steps of the examples described in combination with the embodiments disclosed herein can be realized by electronic hardware or a combination of computer software and electronic hardware. Whether the functions are realized in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.
[0176] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described devices, apparatuses, and units can refer to the corresponding processes in the foregoing method embodiments, which will not be described here.
[0177] In several embodiments provided by the present application, it should be understood that the disclosed devices, apparatuses and methods can be implemented in other manners. For example, the embodiments of the apparatus described above are merely schematic. For example, the division of the units is only a logical function division. There can be another division manner for the actual implementation. For example, a plurality of units or components can be combined or integrated into another device, or some features can be ignored or not executed. In addition, the displayed or discussed mutual couplings or direct couplings or communication connections can be indirect couplings or communication connections through some interfaces, devices or units, and can be in electrical, mechanical or other forms.
[0178] The units described as separate components can or can not be physically separate, and the components shown as units can or can not be physical units, that is, can be located in one place, or can be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the embodiment.
[0179] In addition, each functional unit in the various embodiments of the present application can be integrated into a processing unit, or each unit can exist physically, or two or more units can be integrated into one unit.
[0180] If the functions are realized in the form of software function units and sold or used as independent products, they can be stored in a computer readable storage medium. Based on this understanding, the technical solutions of the present application or the part of the technical solutions that essentially contribute to the prior art can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in the various embodiments of the present application. The aforementioned storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and various media that can store program codes.
[0181] The embodiment of the present application provides a readable storage medium, which includes: a program or instruction stored on the readable storage medium, the program or instruction is executed by a processor to realize the steps of the above-mentioned paper cup surface micro defect detection method based on deep learning, and the same technical effect can be achieved. To avoid repetition, the present application will not be described again.
[0182] It should be pointed out finally that the above embodiments are only used to illustrate the technical solutions of the embodiments of the present application, but not to limit them. Although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those skilled in the art that the technical solutions recorded in the foregoing embodiments can be modified, or some technical features can be replaced equivalently; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application. Any changes or replacements that can be easily thought of by those skilled in the art within the technical scope disclosed by the present application should be covered within the protection scope of the present application.
Claims
1. A deep learning-based method for detecting tiny surface defects of paper cups, characterized in that, The method comprises the following steps: S1: obtaining a surface image of a paper cup to be detected; S2: constructing a paper cup surface micro defect detection model based on a deep learning model, wherein the deep learning model is an improved YOLOv11 model, the improved YOLOv11 model comprises a TFAS feature extraction module located at a position of a part C3k2 module in the YOLOv11 model, a SC shared convolution module located at a position of an SPPF module in the YOLOv11 model, and a CSLDH detection head located at a position of a detect detection head in the YOLOv11 model; S3: constructing a loss function of the paper cup surface micro defect detection model; S4: optimizing the paper cup surface micro defect detection model by minimizing the function value of the loss function; S5: inputting the surface image into the optimized paper cup surface micro defect detection model for detection, and outputting a surface micro defect detection result of the paper cup to be detected. 2.The deep learning-based paper cup surface tiny flaw detection method according to claim 1, characterized in that, The S3 specifically comprises: S301: constructing a classification loss function of the paper cup surface micro defect detection model; wherein, L cls represents a classification loss function, y represents a true label, wherein when y=1, it is determined that the surface of the paper cup to be detected has a defect, when y=0, it is determined that the surface of the paper cup to be detected has no defect, log represents a natural logarithm, and p represents a predicted defect probability; S302: constructing a confidence loss function of the paper cup surface micro defect detection model; Wherein, L obj represents a confidence loss function, y ′ represents a real confidence, wherein, when y ′ =1, it is determined that the surface of the paper cup to be detected has defects, when y ′ =0, it is determined that the surface of the paper cup to be detected has no defects, p ′ represents a predicted confidence probability; S303: constructing a positioning loss function of the paper cup surface micro defect detection model; wherein, L CIoU represents a positioning loss function, IoU represents an intersection over union of the prediction box and the real box, c represents a diagonal length of a minimum bounding box, p represents a distance between a center of the prediction box and a center of the real box, b represents a center point of the prediction box, b gt represents a center point of the real box, a represents a length-width ratio consistency weight coefficient, v represents a length-width ratio consistency measure, A represents an area of the prediction box, B represents an area of the real box, p represents a circular constant, arctan represents an inverse tangent function, h gt represents a height of the real box, w gt represents a width of the real box, h represents a height of the prediction box, and w represents a width of the prediction box. S304: weighting and summing the classification loss function, the confidence loss function, and the positioning loss function to construct a loss function of the paper cup surface micro defect detection model: LOSS = λ1L cls + λ2L obj + λ3L CIoU ; wherein LOSS represents the loss function, λ1 represents a weight coefficient of the classification loss function, λ2 represents a weight coefficient of the confidence loss function, and λ3 represents a weight coefficient of the positioning loss function. 3.The deep learning-based paper cup surface micro flaw detection method of claim 1, wherein, The paper cup surface micro defect detection model comprises a first convolution layer, a second convolution layer, a first TFAS feature extraction module, a third convolution layer, a second TFAS feature extraction module, a fourth convolution layer, a third TFAS feature extraction module, a fifth convolution layer, a fourth TFAS feature extraction module, a SC shared convolution module, a C2PSA module, a first up-sampling layer, a first feature splicing layer, a first C3k2 module, a second up-sampling layer, a second feature splicing layer, a second C3k2 module, a sixth convolution layer, a third feature splicing layer, a third C3k2 module, a seventh convolution layer, a fourth feature splicing layer, a fourth C3k2 module, a first CSLDH detection head, a second CSLDH detection head, and a third CSLDH detection head; The TFAS feature extraction module comprises a Scharr convolution layer, a fifth feature splicing layer, a first 3x3 convolution layer, a sixth feature splicing layer, a first 1x1 convolution layer, an FFT feature conversion layer, a second 1x1 convolution layer, an IFFT feature conversion layer, a second 3x3 convolution layer, a feature fusion layer, and a third 1x1 convolution layer; The SC shared convolution module comprises a fourth 1*1 convolution layer, a first feature extraction branch, a second feature extraction branch, a third feature extraction branch, a third 3*3 convolution layer, a seventh feature splicing layer and a fifth 1*1 convolution layer, wherein the first feature extraction branch, the second feature extraction branch and the third feature extraction branch share the third 3*3 convolution layer; The CSLDH detection head comprises a sixth 1*1 convolution layer, a shared convolution layer, a regression branch, a classification branch and an eighth feature splicing layer, wherein the first CSLDH detection head, the second CSLDH detection head and the third CSLDH detection head share the shared convolution layer.
4. The deep learning-based paper cup surface tiny defect detection method according to claim 3, characterized in that, The S5 specifically comprises: S501: performing feature extraction on the surface image in the first convolution layer to obtain a first feature map; S502: performing feature extraction on the first feature map in the second convolution layer to obtain a second feature map; S503: performing feature extraction on the second feature map in the first TFAS feature extraction module to obtain a first fusion feature map; S504: performing feature extraction on the first fusion feature map in the third convolution layer to obtain a third feature map; S505: performing feature extraction on the third feature map in the second TFAS feature extraction module to obtain a second fusion feature map; S506: performing feature extraction on the second fusion feature map in the fourth convolution layer to obtain a fourth feature map; S507: performing feature extraction on the fourth feature map in the third TFAS feature extraction module to obtain a third fusion feature map; S508: performing feature extraction on the third fusion feature map in the fifth convolution layer to obtain a fifth feature map; S509: performing feature extraction on the fifth feature map in the fourth TFAS feature extraction module to obtain a fourth fusion feature map; S510: performing feature extraction on the fourth fusion feature map in the SC shared convolution module to obtain a shared feature map; S511: performing enhancement processing on the shared feature map through a spatial attention mechanism in the C2PSA module to obtain an enhanced feature map; S512: performing up-sampling operation on the enhanced feature map in the first up-sampling layer to obtain a first up-sampling feature map; S513: performing splicing operation on the third fusion feature map and the first up-sampling feature map in the first feature splicing layer to obtain a first splicing feature map; S514: performing feature extraction on the first splicing feature map in the first C3k2 module to obtain a first multi-scale feature map; S515: performing up-sampling operation on the first multi-scale feature map in the second up-sampling layer to obtain a second up-sampling feature map; S516: performing splicing operation on the second fusion feature map and the second up-sampling feature map in the second feature splicing layer to obtain a second splicing feature map; S517: performing feature extraction on the second splicing feature map in the second C3k2 module to obtain a second multi-scale feature map; S518: feature extraction is performed on the second multi-scale feature map in the sixth convolutional layer to obtain a sixth feature map; S519: a splicing operation is performed on the first multi-scale feature map and the sixth feature map in the third feature splicing layer to obtain a third spliced feature map; S520: feature extraction is performed on the third spliced feature map in the third C3k2 module to obtain a third multi-scale feature map; S521: feature extraction is performed on the third multi-scale feature map in the seventh convolutional layer to obtain a seventh feature map; S522: a splicing operation is performed on the enhanced feature map and the seventh feature map in the fourth feature splicing layer to obtain a fourth spliced feature map; S523: feature extraction is performed on the fourth spliced feature map in the fourth C3k2 module to obtain a fourth multi-scale feature map; S524: detection is performed on the second multi-scale feature map in the first CSLDH detection head to obtain a first detection result; S525: detection is performed on the third multi-scale feature map in the second CSLDH detection head to obtain a second detection result; S526: detection is performed on the fourth multi-scale feature map in the third CSLDH detection head to obtain a third detection result; S527: the first detection result, the second detection result and the third detection result are output as the surface minor flaw detection result of the paper cup to be detected. 5.The deep learning-based paper cup surface tiny flaw detection method according to claim 3, characterized in that, The TFAS feature extraction module is specifically used for: in the Scharr convolutional layer, feature extraction is performed on the input feature map by a Scharr operator to obtain a horizontal gradient map and a vertical gradient map; in the fifth feature splicing layer, a splicing operation is performed on the horizontal gradient map and the vertical gradient map to obtain a fifth spliced feature map; in the first 3x3 convolutional layer, feature extraction is performed on the fifth spliced feature map to obtain an eighth feature map; in the sixth feature splicing layer, a splicing operation is performed on the input feature map and the eighth feature map to obtain a sixth spliced feature map; in the first 1x1 convolutional layer, feature extraction is performed on the sixth spliced feature map to obtain a time domain feature map; in the FFT feature conversion layer, the input feature map is converted into a frequency domain feature map by an FFT algorithm; in the second 1x1 convolutional layer, feature extraction is performed on the frequency domain feature map to obtain a ninth feature map; in the IFFT feature conversion layer, the ninth feature map is converted into a spatial domain feature map by an IFFT algorithm; in the second 3x3 convolutional layer, feature extraction is performed on the spatial domain feature map to obtain a frequency domain feature map; in the feature fusion layer, the time domain feature map and the frequency domain feature map are added element by element to obtain a preliminary fusion feature map; in the third 1x1 convolutional layer, feature extraction is performed on the preliminary fusion feature map to obtain a fusion feature map. 6.The deep learning-based paper cup surface tiny flaw detection method according to claim 3, characterized in that, The SC shared convolution module is specifically used for: in the fourth 1x1 convolutional layer, feature extraction is performed on the input feature map to obtain a tenth feature map; In the first feature extraction branch, the tenth feature map is zero-padded with one layer to obtain the first filled feature map; In the second feature extraction branch, the tenth feature map is zero-padded with three layers to obtain the second filled feature map; In the third feature extraction branch, the tenth feature map is zero-padded with 5 layers to obtain the third filled feature map; In the third 3×3 convolutional layer, features are extracted from the first filled feature map, the second filled feature map, and the third filled feature map to obtain the eleventh feature map, the twelfth feature map, and the thirteenth feature map. In the seventh feature stitching layer, the eleventh feature map, the twelfth feature map, and the thirteenth feature map are stitched together to obtain the seventh stitched feature map; In the fifth 1×1 convolutional layer, the BN algorithm and ReLU activation function are combined to extract features from the seventh concatenated feature map to obtain a shared feature map.
7. The deep learning-based paper cup surface tiny flaw detection method according to claim 3, characterized in that, The CSLDH detection head is specifically used for: In the sixth 1×1 convolutional layer, features are extracted from the input feature map to obtain the fourteenth feature map; The fourteenth feature map is standardized. In the shared convolutional layer, feature extraction is performed on the standardized fourteenth feature map to obtain the fifteenth feature map; In the regression branch, the fifteenth feature map is sequentially subjected to 3×3 convolution, nonlinear scaling, and discrete probability distribution modeling to output the bounding box position probability distribution. In the classification branch, the fifteenth feature map is sequentially subjected to a 3×3 convolution operation and a ReLU activation operation to output the class confidence score; In the eighth feature stitching layer, the probability distribution of the bounding box position and the class confidence are stitched together to obtain the eighth stitched feature map; Based on the eighth stitched feature map, the detection result is output through the Sigmoid activation function, wherein the detection result includes the bounding box position and category of the surface micro-defects of the paper cup to be detected. 8.The deep learning-based paper cup surface tiny flaw detection method according to claim 1, characterized in that, The training process of the paper cup surface micro-defect detection model specifically includes: Obtain raw images of multiple paper cup samples with minor defects; Each of the original images is labeled; Convert the labeled original images into masked images; According to a preset ratio, each of the mask images is divided into a training set and a test set; The training set was used to train the paper cup surface minute defect detection model; The trained paper cup surface minor defect detection model was tested using the test set.
9. A deep learning-based paper cup surface tiny defect detection system, characterized in that, include: Processor and memory; The memory stores programs or instructions that can run on the processor, which, when executed by the processor, implement the steps of the deep learning-based method for detecting minute defects on the surface of paper cups as described in any one of claims 1 to 8.
10. A readable storage medium, characterized by, The readable storage medium stores a program or instructions that, when executed by a processor, implement the steps of the deep learning-based method for detecting minute defects on the surface of paper cups as described in any one of claims 1 to 8.
Citation Information
Cited By
Fabric hyperspectral flaw reconstruction method and system based on frequency domain dynamic convolution
CN121661264A