Paper cup defect detection method and device
By improving the YOLO v5 network model, adding the CBAM attention mechanism and weighted two-way feature pyramid network, the problems of missed and missed detection in paper cup defect detection are solved, and the detection accuracy and robustness are improved.
Patent Information
- Application Number
- CN202310377132.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-10
- Publication Date
- 2025-08-12
- Estimated Expiration
- 2043-04-10
AI Technical Summary
The existing paper cup defect detection methods rely on manual screening efficiency and high subjective arbitraryness. The image processing-based methods are poorly robust in complex environments, and are prone to missed and missed defects with small sizes and no obvious characteristics.
The improved YOLO v5 network model is adopted, and the CBAM attention mechanism module and weighted bidirectional feature pyramid network are added to enhance feature extraction and fusion capabilities, and a fourth-scale detection layer is added to the output layer, combining data enhancement technology to improve the generalization capabilities of the model.
The accuracy of paper cup defect detection is improved, missed and missed detection is reduced, especially the detection ability of small targets and features is significantly improved.
Smart Images

Figure CN116309526B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of product detection, and in particular to a method and device for detecting defects in paper cups. Background Art
[0002] Paper cups have been used as dining containers for decades, and in recent years, they have also become widely used in food packaging. Due to their cleanliness, relatively simple production process, and flexible design, as well as their natural degradation, they are considered green packaging, making them popular with manufacturers and consumers. However, as a product, paper cups also require defect detection during the manufacturing process.
[0003] Currently, paper cup defect detection relies primarily on manual screening and image processing-based detection methods. Manual screening, however, suffers from shortcomings such as missed detections, low efficiency, and significant subjective arbitrariness, making it unable to meet modern production demands. Image processing-based detection methods require a series of cumbersome preprocessing operations, such as grayscale and binarization, during feature extraction. Furthermore, these methods, influenced by their principles, have high requirements for ambient lighting conditions and poor robustness. This can lead to missed and incorrect detections of small and less distinctive paper cup defects, making them difficult to meet actual production demands. Summary of the Invention
[0004] In view of the problems existing in the prior art, the present invention provides a paper cup defect detection method and device.
[0005] The present invention provides a paper cup defect detection method, comprising: obtaining a paper cup image to be detected; inputting the paper cup image into a trained detection model, and outputting a paper cup defect detection result; wherein the detection model is a YOLO v5 network model, adding a CBAM attention mechanism module after the last layer C3 module of the Backbone part, using a weighted bidirectional feature pyramid network for feature fusion in the Neck part, and adding a fourth-scale detection layer to the output layer, and the method is obtained after training based on paper cup image training samples marked with defect labels; wherein the scale of the fourth-scale detection layer is larger than the scales of the original three detection layers.
[0006] According to a paper cup defect detection method provided by the present invention, before inputting the paper cup image into the trained detection model, the method further includes: obtaining unqualified paper cup images of multiple defect types and constructing a data set; performing data augmentation operations on the data set, and adding labels of corresponding defect results to the paper cup images in the data set to obtain training samples; and using the training samples to train the constructed YOLO v5 network model to obtain the trained detection model; wherein the data augmentation operations include rotation, cropping, and brightness enhancement.
[0007] According to a paper cup defect detection method provided by the present invention, the last layer of the Backbone part of the detection model is the SPPF module, and a CBAM attention mechanism module is added between the last layer C3 module and the SPPF module.
[0008] According to a paper cup defect detection method provided by the present invention, inputting the paper cup image into a trained detection model comprises:
[0009] Input the paper cup image to be detected into the Backbone part, and obtain the first feature, second feature, third feature and fourth feature after processing by the first C3 module, the second C3 module, the third C3 module and the SPPF module in sequence according to the starting order of the input direction; perform tensor splicing based on the third feature and the fourth feature, and input the result into the fifth C3 module to obtain the fifth feature; perform tensor splicing based on the fifth feature and the second feature, and input the result into the sixth C3 module to obtain the sixth feature; perform tensor splicing based on the sixth feature and the first feature, and input the result into the seventh C3 module to obtain the seventh feature, and determine the The output of the fourth scale; tensor splicing is performed according to the sixth and seventh features, and the result is input into the eighth C3 module to obtain the eighth feature, and the output of the third scale is determined according to the eighth feature; feature fusion is performed based on the weighted bidirectional feature pyramid network according to the third feature, the fifth feature and the eighth feature, and the result is input into the ninth C3 module to obtain the ninth feature, and the output of the second scale is determined according to the ninth feature; tensor splicing is performed according to the ninth feature and the fourth feature, and the result is input into the tenth C3 module to obtain the tenth feature, and the output of the first scale is determined according to the tenth feature; wherein, the first scale to the fourth scale are arranged in descending order.
[0010] According to a paper cup defect detection method provided by the present invention, inputting the paper cup image into a trained detection model includes: upsampling features before the output layer of the third scale, fusing them with features before the output layer of the fourth scale, and determining an output result at the fourth scale based on the fused features.
[0011] The present invention also provides a paper cup defect detection device, comprising: an acquisition module for acquiring a paper cup image to be detected; a processing module for inputting the paper cup image into a trained detection model and outputting a paper cup defect detection result;
[0012] The detection model is a YOLO v5 network model. A CBAM attention mechanism module is added after the last C3 module in the Backbone part. A weighted bidirectional feature pyramid network is used for feature fusion in the Neck part. A fourth-scale detection layer is added to the output layer and trained based on paper cup image training samples marked with defect labels. The fourth-scale detection layer has a larger scale than the other three detection layers.
[0013] According to a paper cup defect detection device provided by the present invention, the processing module is specifically used for:
[0014] Input the paper cup image to be detected into the Backbone part, and obtain the first feature, second feature, third feature and fourth feature after processing by the first C3 module, the second C3 module, the third C3 module and the SPPF module in sequence according to the starting order of the input direction; perform tensor splicing based on the third feature and the fourth feature, and input the result into the fifth C3 module to obtain the fifth feature; perform tensor splicing based on the fifth feature and the second feature, and input the result into the sixth C3 module to obtain the sixth feature; perform tensor splicing based on the sixth feature and the first feature, and input the result into the seventh C3 module to obtain the seventh feature, and determine the The output of the fourth scale; tensor splicing is performed according to the sixth and seventh features, and the result is input into the eighth C3 module to obtain the eighth feature, and the output of the third scale is determined according to the eighth feature; feature fusion is performed based on the weighted bidirectional feature pyramid network according to the third feature, the fifth feature and the eighth feature, and the result is input into the ninth C3 module to obtain the ninth feature, and the output of the second scale is determined according to the ninth feature; tensor splicing is performed according to the ninth feature and the fourth feature, and the result is input into the tenth C3 module to obtain the tenth feature, and the output of the first scale is determined according to the tenth feature; wherein, the first scale to the fourth scale are arranged in descending order.
[0015] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, any of the above-described paper cup defect detection methods is implemented.
[0016] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the method for detecting paper cup defects as described above is implemented.
[0017] The present invention also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements any of the above-mentioned paper cup defect detection methods.
[0018] The paper cup defect detection method and device provided by the present invention incorporates a CBAM attention mechanism module to enhance the model's feature extraction capabilities. This module is added after the final C3 module. Unlike conventional applications of the CBAM attention mechanism, the output of the CBAM module after the final C3 module is sequentially combined with the feature processing of other network layers in the Backbone portion for operations such as tensor concatenation. This significantly enhances the feature extraction capabilities of the intermediate features and improves the ability to express defect features in complex environments. Combined with the fusion of a weighted bidirectional feature pyramid network in the Neck portion, the feature fusion capability is enhanced, allowing the extracted intermediate features to more significantly reflect the characteristic attributes of the detection target, resulting in more accurate detection results for small targets such as paper cup defects. Furthermore, combining the aforementioned intermediate features with high feature extraction capabilities and the fused features, a fourth detection layer, larger than the original three detection layers, is added to the output layer. This further mitigates the phenomenon of missed detections and false detections caused by the significant loss of detailed feature information as the model deepens, thereby improving the model's detection capabilities for small and less distinct defects and, consequently, the accuracy of paper cup defect detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the technical solutions in the present invention or the prior art, a brief introduction is given below to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0020] Figure 1 1 is a flow chart of a paper cup defect detection method provided by the present invention;
[0021] Figure 2 This is a diagram of the improved YOLOv5 network structure provided by the present invention;
[0022] Figure 3 This is a comparison chart of the mean average precision (mAP) curve before and after the improvement provided by the present invention;
[0023] Figure 4 This is a comparison chart of the accuracy curves before and after the improvement provided by the present invention;
[0024] Figure 5 is a comparison chart of the recall rate curves before and after the improvement provided by the present invention;
[0025] Figure 6a This is one of the comparison diagrams of the actual effect before and after the improvement provided by the present invention;
[0026] Figure 6bThis is the second comparison chart of the actual effect before and after the improvement provided by the present invention;
[0027] Figure 6c This is the third comparison chart of the actual effect detection before and after the improvement provided by the present invention;
[0028] Figure 7 1 is a schematic structural diagram of a paper cup defect detection device provided by the present invention;
[0029] Figure 8 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0030] To make the objectives, technical solutions, and advantages of the present invention more clear, the technical solutions of the present invention will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the embodiments described are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts shall fall within the scope of protection of the present invention.
[0031] The following combination Figures 1-8 The paper cup defect detection method and device of the present invention are described. Figure 1 FIG. 1 is a flow chart of the paper cup defect detection method provided by the present invention, as shown in FIG. Figure 1 As shown, the present invention provides a paper cup defect detection method, comprising:
[0032] 101. Acquire an image of a paper cup to be inspected;
[0033] Images of paper cups on the production line can be acquired through devices such as cameras. These paper cups are objects to be inspected, including some defective ones.
[0034] 102. Input the paper cup image into the trained detection model, and output a defect detection result of the paper cup.
[0035] The present invention inputs the aforementioned paper cup images into a detection model improved by the YOLO v5 network model, outputting the final defect detection results for the paper cups, such as the detection boxes corresponding to the defective areas. This process can be referenced from the existing YOLO v5 network model training and detection process. Furthermore, the detection model is pre-trained using images of paper cups labeled with defects.
[0036] Specifically, the above-mentioned detection model is a YOLO v5 network model. The CBAM attention mechanism module is added after the last layer C3 module in the Backbone part. The weighted bidirectional feature pyramid network is used for feature fusion in the Neck part. A fourth-scale detection layer is added to the output layer. It is constructed after training based on paper cup image training samples marked with defect labels. Among them, the scale of the fourth-scale detection layer is larger than the scales of the original three detection layers.
[0037] In the present invention, the improvements to the improved YOLO v5 paper cup defect detection model include three aspects: the CBAM attention mechanism module is introduced after the last layer C3 module of the Backbone part of the original YOLO v5 network model to enhance the feature extraction capability of the model; a larger-scale shallow detection layer is added to the output part of the model, and the three-scale detection is changed to four-scale detection. For example, the original three scales are 20×20, 40×40 and 80×80. In the present invention, a shallow detection layer with a scale of 160×160 can be added, thereby improving the model's detection capability for small targets and targets with unclear features. The weighted bidirectional feature pyramid network BiFPN is used in the Neck part of the model to partially improve the PANet in the model and enhance the feature fusion capability of the model. Among them, the last layer C3 module is the C3 module starting from the input direction to the last layer.
[0038] Among them, the CBAM attention mechanism module includes two parts: the channel attention module and the spatial attention module. The channel attention module focuses on the content information of the detection target, and the spatial attention module focuses on the location information of the detection target. By combining the two, the output feature information can be focused on the key feature information. The present invention places the CBAM attention mechanism module after the last layer C3 module in the feature extraction network (Backbone), which can solve the problem that the feature map in the feature extraction network gradually loses detailed feature information as the model depth increases, and improves the feature extraction network of the original model's ability to extract paper cup defect features and the ability to express paper cup defect features in insufficient light.
[0039] The Neck part uses BiFPN and introduces a weighted strategy and cross-scale connection method. It can fuse the feature information in the feature extraction network with the feature information in the shallow-to-deep transmission path and focus on adjusting the contribution of input feature information to the output feature map, thereby achieving better feature fusion.
[0040] Considering that some images in the paper cup defect dataset contain different types of defects and are relatively similar in feature expression, if such images are input into a model completely replaced by BiFPN for feature fusion, the different types of defects with similar feature expressions will be weighted by BiFPN at each scale, which will reduce the model feature fusion effect. Therefore, this paper chooses to improve the original feature fusion method by drawing on the weighting strategy and cross-scale connection method of BiFPN, thereby enhancing the feature fusion capability of the model.
[0041] The paper cup defect detection method of the present invention incorporates a CBAM attention mechanism module to enhance the model's feature extraction capabilities. This module is added after the final C3 module. Unlike conventional applications of the CBAM attention mechanism, the output of the CBAM module after the final C3 module is sequentially combined with the feature processing of other network layers in the Backbone portion for operations such as tensor concatenation. This significantly enhances the feature extraction capabilities of the intermediate features and improves the ability to express defect features in complex environments. Combined with the fusion of a weighted bidirectional feature pyramid network in the Neck portion, the feature fusion capability is further enhanced, allowing the extracted intermediate features to more significantly reflect the characteristic attributes of the detection target, resulting in more accurate detection results for small targets such as paper cup defects. Furthermore, by combining the aforementioned intermediate features with higher feature extraction capabilities and the fused features, a fourth detection layer, larger than the other three detection layers, is added to the output layer. This further mitigates the phenomenon of missed detections and false detections caused by the significant loss of detailed feature information as the model deepens, thereby improving the model's detection capabilities for small and less distinct defects and, consequently, the accuracy of paper cup defect detection.
[0042] In some embodiments, before inputting the paper cup image into the trained detection model, the process further includes: obtaining unqualified paper cup images of various defect types and constructing a data set; performing data augmentation on the data set, and adding corresponding defect status labels to the paper cup images in the data set to obtain training samples; and using the training samples to train the constructed YOLO v5 network model to obtain the trained detection model; wherein the data augmentation operations include rotation, cropping, and brightness enhancement.
[0043] Specifically, the model is trained before it is applied. A camera can be used to capture multiple images of unqualified paper cups on a conveyor belt to construct a dataset. The collected dataset of unqualified paper cup images is then augmented with operations such as rotation, cropping, and brightness enhancement to increase the diversity of the dataset and improve the generalization capabilities of model training. The augmented dataset is then standardized using annotation software, such as LabelImg, to annotate the dataset in VOC format. A Python script is then used to convert the dataset to YOLO format. The training dataset and test dataset can be split in an 8:2 ratio.
[0044] Finally, the constructed YOLOv5 network model is trained using a training dataset that includes images of unqualified paper cups and their corresponding labels, resulting in a YOLOv5 network model that meets the accuracy requirements, i.e., the trained detection model in step 102. Furthermore, the trained model is tested using a test dataset. If the test does not meet the accuracy requirements, a new dataset can be constructed for training.
[0045] In some embodiments, the last layer of the Backbone part of the detection model is the SPPF module, and a CBAM attention mechanism module is added between the last layer C3 module and the SPPF module.
[0046] Specifically, based on the addition of the CBAM attention mechanism after the last layer of the C3 module, the present invention realizes the fusion of local features and global features at the feature map (featherMap) level through the SPPF module.
[0047] In some embodiments, inputting the paper cup image into the trained detection model, and using the training sample to train the constructed YOLO v5 network model, includes:
[0048] Input the paper cup image to be detected into the Backbone part, and obtain the first feature, second feature, third feature and fourth feature after processing by the first C3 module, the second C3 module, the third C3 module and the SPPF module in sequence according to the starting order of the input direction; perform tensor splicing based on the third feature and the fourth feature, and input the result into the fifth C3 module to obtain the fifth feature; perform tensor splicing based on the fifth feature and the second feature, and input the result into the sixth C3 module to obtain the sixth feature; perform tensor splicing based on the sixth feature and the first feature, and input the result into the seventh C3 module to obtain the seventh feature, and determine the The output of the fourth scale; tensor splicing is performed according to the sixth and seventh features, and the result is input into the eighth C3 module to obtain the eighth feature, and the output of the third scale is determined according to the eighth feature; feature fusion is performed based on the weighted bidirectional feature pyramid network according to the third feature, the fifth feature and the eighth feature, and the result is input into the ninth C3 module to obtain the ninth feature, and the output of the second scale is determined according to the ninth feature; tensor splicing is performed according to the ninth feature and the fourth feature, and the result is input into the tenth C3 module to obtain the tenth feature, and the output of the first scale is determined according to the tenth feature; wherein, the first scale to the fourth scale are arranged in descending order.
[0049] like Figure 2 As shown in the figure, the backbone of the initial network includes modules 0 to 8 and 10, starting from the input. The present invention adds a CBAM attention mechanism module between the last layer of the backbone module, C3, and the SPPF module, that is, between modules 8 and 10. At this point, the features processed by modules 2, 4, 6, and 10 are recorded as the first feature, second feature, third feature, and fourth feature, respectively.
[0050] It should be noted that before performing tensor splicing according to the third feature and the fourth feature, those skilled in the art may perform pre-splicing processing operations, such as processing of feature dimensions, including Figure 2 The convolution and upsampling operations in . Similarly, the tensor splicing of other features mentioned later also includes the corresponding processing process, which will not be repeated here. You can refer to Figure 2 In addition, the model training process is the same as the above steps.
[0051] Among them, the Neck part also includes several C3 modules, such as Figure 2 As shown in , to distinguish the four C3 modules of Backbone, they are respectively recorded as the fifth C3 module, the fifth C3 module, and the tenth C3 module. Among them, Detect is the detection head (detector) of the network model, which is mainly responsible for multi-scale object detection on the feature maps extracted by the backbone network.
[0052] In the paper cup defect detection method of the present embodiment, the fourth feature, processed by the CBAM and SPPF modules, is directly or indirectly concatenated with the first to third features to generate new seventh to tenth features. These features are used to determine outputs at different scales, effectively improving the feature representation capabilities of paper cups, which are difficult to detect in complex environments. For the first and second small-scale detections, the ninth and tenth features, which effectively improve these feature representation capabilities, are utilized, combined with the fusion of multiple features from a weighted bidirectional feature pyramid network. This further mitigates the phenomenon of missed and false detections caused by the significant loss of detailed feature information with increasing model depth, thereby improving the model's detection capabilities for small and less distinct defects. Combined with the fourth-scale output determined by the seventh feature, this comprehensively improves the accuracy of paper cup defect detection.
[0053] Among them, the feature fusion does not replace the entire PANet feature fusion network of the Neck part with the weighted bidirectional feature pyramid network BiFPN. Instead, it draws on the weighting strategy and cross-scale connection method of BiFPN on the basis of PANet to integrate some of the key features mentioned above. It only introduces the original feature information of the sixth layer in Backbone into the deep of the feature fusion network ( Figure 2 The feature information at the BiFPN in the original model is weighted accordingly. This effectively addresses the original model's lack of original feature information deep within the feature fusion network and its failure to weight feature information at different feature layers, thereby improving the original model's feature fusion efficiency. Weighting feature information also takes into account the varying contributions of feature information at different layers to the fused output feature information.
[0054] In addition, paper cup defect forms contain different types of defect forms, and are relatively similar in feature expression. If this type of image is input into a conventional model replaced with BiFPN for feature fusion, the different types of defects with similar feature expressions will be subjected to the BiFPN weighted operation at each scale, which will reduce the model feature fusion effect. The present invention can effectively avoid this problem by only borrowing the BiFPN weighting strategy and cross-scale connection method for the PANet feature fusion network.
[0055] Figure 3 This is a comparison chart of the mean average precision (mAP) curve before and after the improvement provided by the present invention. Figure 4 This is a comparison chart of the accuracy curves before and after the improvement provided by the present invention. Figure 5The following is a comparison of the recall rate curves before and after the improvement provided by the present invention. As shown in the figures, after an experimental verification, the total number of iterations was set to 200, the iteration batch size was set to 16, and the image size was set to 640×640. Based on the improved model of the present invention, the detection accuracy P was 89.1%, the recall rate R was 90.4%, and the mean average precision (mAP) was 89.5%. Compared with the original model, the accuracy P increased by 1.5%, the recall rate R increased by 1.3%, and the mean average precision (mAP) increased by 1.2%. It can be seen that the present invention effectively improves the detection capability and robustness of the model, has better target resolution capabilities, and has a significant improvement in the detection effect of small-sized paper cup defects with unclear features.
[0056] Figures 6a to 6c This is a comparison chart of the actual effect detection before and after the improvement provided by the present invention. It can be seen that the improved model based on the present invention (right side) can detect defects that the conventional model (left side) cannot detect.
[0057] In some embodiments, inputting the paper cup image into the trained detection model includes: upsampling the features before the output layer of the third scale, fusing the features with the features before the output layer of the fourth scale, and determining the output result of the fourth scale based on the fused features.
[0058] Specifically, in this embodiment of the present invention, features are upsampled before being applied to the third-scale output layer (e.g., the 80×80 detection layer described above) and then fused with the features of the fourth-scale output layer (e.g., the 160×160 detection layer described above). If the fourth-scale output layer is 160×160, the third-scale output layer is upsampled by a factor of 2 before fusion. This improves the model's ability to detect small objects and objects with unclear features.
[0059] The paper cup defect detection device provided by the present invention is described below. The paper cup defect detection device described below and the paper cup defect detection method described above can be referenced to each other.
[0060] Figure 7 FIG. 1 is a schematic diagram of the structure of the paper cup defect detection device provided by the present invention. Figure 7 As shown, the paper cup defect detection device includes: an acquisition module 701 and a processing module 702. The acquisition module 701 is used to obtain the paper cup image to be detected; the processing module 702 is used to input the paper cup image into the trained detection model and output the paper cup defect detection result.
[0061] The detection model is a YOLO v5 network model. A CBAM attention mechanism module is added after the last C3 module in the Backbone part. A weighted bidirectional feature pyramid network is used for feature fusion in the Neck part. A fourth-scale detection layer is added to the output layer and trained based on paper cup image training samples marked with defect labels. The fourth-scale detection layer has a larger scale than the other three detection layers.
[0062] The device embodiments provided in the embodiments of the present invention are intended to implement the above-mentioned method embodiments. For specific processes and detailed contents, please refer to the above-mentioned method embodiments, which will not be repeated here.
[0063] The implementation principle and technical effects of the paper cup defect detection device provided in the embodiment of the present invention are the same as those of the aforementioned paper cup defect detection method embodiment. For the sake of brief description, any matters not mentioned in the embodiment of the paper cup defect detection device may be referred to the corresponding contents in the aforementioned paper cup defect detection method embodiment.
[0064] Figure 8 Schematic diagram of the structure of the electronic device provided by the present invention, such as Figure 8 As shown, the electronic device may include: a processor 801, a communications interface 802, a memory 803, and a communication bus 804, wherein the processor 801, the communications interface 802, and the memory 803 communicate with each other via the communication bus 804. The processor 801 may call logic instructions in the memory 803 to execute a paper cup defect detection method, which includes: obtaining a paper cup image to be inspected; inputting the paper cup image into a trained detection model, and outputting a paper cup defect detection result. The detection model is a YOLO v5 network model, which includes a CBAM attention mechanism module after the last C3 module in the Backbone portion, a weighted bidirectional feature pyramid network for feature fusion in the Neck portion, and a fourth-scale detection layer added to the output layer. The detection layer is trained based on defect-labeled paper cup image training samples. The fourth-scale detection layer has a larger scale than the other three detection layers.
[0065] In addition, the logic instructions in the above-mentioned memory 803 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. 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 other media that can store program code.
[0066] On the other hand, the present invention also provides a computer program product, which includes a computer program, which can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the paper cup defect detection method provided by the above methods, the method including: obtaining a paper cup image to be inspected; inputting the paper cup image into a trained detection model, and outputting a paper cup defect detection result; wherein, the detection model is a YOLO v5 network model, adding a CBAM attention mechanism module after the last layer C3 module of the Backbone part, using a weighted bidirectional feature pyramid network for feature fusion in the Neck part, and adding a fourth-scale detection layer to the output layer, and the fourth-scale detection layer is constructed after training based on paper cup image training samples marked with defect labels; wherein, the scale of the fourth-scale detection layer is larger than the scales of the original other three detection layers.
[0067] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to execute the paper cup defect detection method provided by the above-mentioned methods, the method comprising: obtaining a paper cup image to be detected; inputting the paper cup image into a trained detection model, and outputting a defect detection result of the paper cup; wherein the detection model is a YOLO v5 network model, adding a CBAM attention mechanism module after the last layer C3 module of the Backbone part, using a weighted bidirectional feature pyramid network for feature fusion in the Neck part, and adding a fourth-scale detection layer to the output layer, and the fourth-scale detection layer is constructed after training based on paper cup image training samples marked with defect labels; wherein the scale of the fourth-scale detection layer is larger than the scales of the original other three detection layers.
[0068] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, i.e., they may be located in one location or distributed across multiple network units. Some or all of the modules may be selected based on actual needs to achieve the objectives of the present embodiment. Persons of ordinary skill in the art will be able to understand and implement the present invention without inventive effort.
[0069] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a necessary general hardware platform, or of course, by hardware. Based on this understanding, the essence of the above technical solution or the part that contributes to the existing technology can be embodied in the form of a software product. The computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a magnetic disk, an optical disk, etc., and includes a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or certain parts of the embodiments.
[0070] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present invention.
Claims
1. A paper cup defect detection method, characterized in that: include: Obtain the paper cup image to be detected; Inputting the paper cup image into the trained detection model and outputting a defect detection result of the paper cup; The detection model is a YOLO v5 network model. It incorporates a CBAM attention mechanism module after the last C3 module in the Backbone layer. A weighted bidirectional feature pyramid network is used for feature fusion in the Neck layer. A fourth-scale detection layer is added to the output layer. This model is trained using images of paper cups labeled with defects. The fourth-scale detection layer is larger than the other three detection layers. Inputting the paper cup image into the trained detection model includes: Input the paper cup image to be detected into the Backbone part, and obtain the first feature, second feature, third feature and fourth feature after processing by the first C3 module, second C3 module, third C3 module and SPPF module in sequence according to the starting order of the input direction; Perform tensor splicing based on the third and fourth features, and input the result into the fifth C3 module to obtain the fifth feature; Perform tensor splicing based on the fifth feature and the second feature, and input the result into the sixth C3 module to obtain the sixth feature; Perform tensor splicing based on the sixth feature and the first feature, input the result into the seventh C3 module to obtain the seventh feature, and determine the output of the fourth scale based on the seventh feature; Perform tensor splicing based on the sixth and seventh features, input the result into the eighth C3 module to obtain the eighth feature, and determine the output of the third scale based on the eighth feature; Based on the third, fifth, and eighth features, feature fusion is performed based on a weighted bidirectional feature pyramid network, and the result is input into the ninth C3 module to obtain the ninth feature, and the output of the second scale is determined based on the ninth feature; Tensors are concatenated based on the ninth and fourth features, and the result is input into the tenth C3 module to obtain the tenth feature, and the output of the first scale is determined based on the tenth feature; wherein the first scale to the fourth scale are arranged in descending order.
2. The paper cup defect detection method according to claim 1, characterized in that: Before inputting the paper cup image into the trained detection model, the method further includes: Obtain images of unqualified paper cups with various defect types and construct a dataset; Performing data augmentation on the data set, and adding labels of corresponding defect results to paper cup images in the data set to obtain training samples; Using the training samples to train the constructed YOLO v5 network model to obtain the trained detection model; The data enhancement operations include rotation, cropping and brightness enhancement.
3. The paper cup defect detection method according to claim 2, characterized in that: The last layer of the Backbone part of the detection model is the SPPF module, and a CBAM attention mechanism module is added between the last layer C3 module and the SPPF module.
4. The paper cup defect detection method according to claim 1, characterized in that: Inputting the paper cup image into the trained detection model includes: The features before the output layer of the third scale are upsampled and fused with the features before the output layer of the fourth scale. The output result of the fourth scale is determined based on the fused features.
5. A paper cup defect detection device, characterized in that: include: An acquisition module, used to acquire an image of the paper cup to be inspected; a processing module, configured to input the paper cup image into a trained detection model and output a defect detection result of the paper cup; The detection model is a YOLO v5 network model. It incorporates a CBAM attention mechanism module after the last C3 module in the Backbone layer. A weighted bidirectional feature pyramid network is used for feature fusion in the Neck layer. A fourth-scale detection layer is added to the output layer. This model is trained using images of paper cups labeled with defects. The fourth-scale detection layer is larger than the other three detection layers. The processing module is specifically used to: Input the paper cup image to be detected into the Backbone part, and obtain the first feature, second feature, third feature and fourth feature after processing by the first C3 module, second C3 module, third C3 module and SPPF module in sequence according to the starting order of the input direction; Perform tensor splicing based on the third and fourth features, and input the result into the fifth C3 module to obtain the fifth feature; Perform tensor splicing based on the fifth feature and the second feature, and input the result into the sixth C3 module to obtain the sixth feature; Perform tensor splicing based on the sixth feature and the first feature, input the result into the seventh C3 module to obtain the seventh feature, and determine the output of the fourth scale based on the seventh feature; Perform tensor splicing based on the sixth and seventh features, input the result into the eighth C3 module to obtain the eighth feature, and determine the output of the third scale based on the eighth feature; Based on the third, fifth, and eighth features, feature fusion is performed based on a weighted bidirectional feature pyramid network, and the result is input into the ninth C3 module to obtain the ninth feature, and the output of the second scale is determined based on the ninth feature; Perform tensor splicing based on the ninth feature and the fourth feature, input the result into the tenth C3 module to obtain the tenth feature, and determine the output of the first scale based on the tenth feature; Among them, the first scale to the fourth scale are arranged from small to large.
6. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the paper cup defect detection method according to any one of claims 1 to 4 is implemented.
7. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the paper cup defect detection method according to any one of claims 1 to 4 is implemented.
8. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the paper cup defect detection method according to any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Surface defect real-time detection method based on deep learning
CN115249242A
Insulator defect image detection method based on improved YOLOv5 network
CN115861263A