Packaging product defect detection method and system based on CDS-YOLO network
By improving the YOLOv5s network model, integrating attention mechanism and depth separable convolution, and using an improved SIOU loss function, the problem of identifying and positioning small defects in packaging defect detection is solved, and the detection effect is achieved with high accuracy and high efficiency .
Patent Information
- Application Number
- CN202410936172.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-12
- Publication Date
- 2024-11-15
AI Technical Summary
Existing deep learning methods are difficult to accurately identify and locate defects with extremely small or complex morphology in packaging defect detection, especially in complex backgrounds and production environments, and it is difficult to effectively distinguish actual defects from background noise.
Using a CDS-YOLO network-based method, the integrated attention mechanism module CBAM and depth-separable convolutional DSConv are used to improve the CDS-YOLO network model, and the integrated attention mechanism module CBAM and depth-separable convolutional DSConv are used to replace part of the convolutional layer, and the improved SIOU loss function is used to optimize the model to improve detection accuracy and speed.
While maintaining high accuracy, it can accurately identify and locate minor defects on packaging products in complex backgrounds and production environments, improving detection efficiency and accuracy, and is suitable for operation of resource-constrained equipment.
Smart Images

Figure CN118967568A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of deep learning technology, and in particular to a packaging product defect detection method and system based on a CDS-YOLO network. Background Art
[0002] Object detection is a core task in the field of computer vision, which aims to identify specific objects from images and determine their location and category. At present, the commonly used methods for traditional printed product defect detection include template matching, image difference and layered detection. With the advancement of deep learning technology, various models such as single-shot multi-box detector (SSD), Faster R-CNN and YOLO series have been widely used in various defect detection. Starting from the regional convolutional neural network (R-CNN) to its more advanced versions Fast R-CNN and Faster R-CNN, these algorithms have achieved a dual improvement in detection speed and accuracy by integrating the region proposal network (RPN). The YOLO series significantly improves the execution speed by simplifying the detection process to a single forward propagation, enabling it to shine in real-time application scenarios and become a key technology in fields such as robotics, autonomous driving and video surveillance.
[0003] In the field of packaged product defect detection, deep learning methods have significantly improved detection efficiency and accuracy compared to traditional machine learning techniques. However, these methods still face certain challenges for extremely small or complex defects. Modern inspection systems must be able to accurately identify and locate tiny defects on packaged products, such as scratches, indentations, or irregular seams, which are particularly difficult to detect in complex structural environments. Summary of the invention
[0004] In view of this, the present invention provides a packaging defect detection method and system based on the CDS-YOLO network, which is used to effectively distinguish actual defects from background noise in complex backgrounds and production environments while maintaining high accuracy, so as to accurately identify and locate tiny defects on the packaging.
[0005] In a first aspect, the present invention provides a packaging defect detection method based on a CDS-YOLO network, the method comprising:
[0006] Step 1: Select and preprocess the public packaging product defect dataset and the self-built packaging product defect dataset, divide the dataset, and obtain the training dataset and the test dataset;
[0007] Step 2: By improving the YOLOv5s network model, the CDS-YOLO network model is obtained;
[0008] Step 3: Deploy the CDS-YOLO network model in the configured model training environment, set the preset parameters, train the CDS-YOLO network model through the training data set, and obtain the trained CDS-YOLO network model;
[0009] Step 4: Call the weight file of the trained CDS-YOLO network model, conduct a comprehensive evaluation of the model through the test data set, and obtain the evaluation results.
[0010] Optionally, step 1 includes:
[0011] After obtaining public packaging defect images and self-built packaging defect images, preprocessing and annotating them, the processed image dataset is divided into a training dataset and a test dataset in a ratio of 8:2, stored in the specified path, and the first yaml configuration file and the second yaml configuration file corresponding to the training dataset and the test dataset are generated respectively.
[0012] Optionally, the step 2 includes:
[0013] Step 21, integrate the attention mechanism module CBAM into the backbone network of the YOLOv5s network model. The attention mechanism module CBAM is sequentially integrated by channel attention and spatial attention to enhance the model's ability to recognize key features;
[0014] Step 22: Replace some convolutional layers of the YOLOv5s network model with depthwise separable convolution (DSConv) to reduce the number of parameters and computational complexity of the model.
[0015] Step 23: Use SIOU as the loss function of the network model, and its expression is:
[0016]
[0017] Among them, B p represents the predicted bounding box, B g t represents the true bounding box, |B p ∩B g t| represents the intersection of the predicted box and the true box, |B p ∪B g t| represents the union of the predicted box and the true box; scale factor represents the factor adjusted according to the target size, which is used to compensate for the deviation of targets of different sizes in IOU calculation.
[0018] Optionally, the step 21 includes:
[0019] (a) Channel attention first uses global average pooling and global maximum pooling to obtain feature descriptions from different perspectives, and then fuses the feature descriptions from different perspectives through a shared network layer to generate the weight of each channel, which is expressed as:
[0020] M ca (F)=σ(MLP(AvgPool(F))+MLP(MaxPool(F)));
[0021] Where F represents the input feature map, AvgPool(F) and MaxPool(F) represent global average pooling and global maximum pooling operations respectively, MLP represents multi-layer perceptron, and σ represents the Sigmoid activation function, which is used to generate the weight of each channel.
[0022] (b) Spatial attention uses the channel aggregation information of the input feature map, applies average pooling and maximum pooling operations on the channel dimension, and passes the result through the convolution layer to generate a weight map of the spatial dimension, which is expressed as:
[0023] M sa (F) = σ(f 7×7 ([AvgPool(F);MaxPool(F)]));
[0024] Among them, f 7×7 Represents a convolutional layer with a 7×7 kernel, and [AvgPool(F); MaxPool(F)] means superimposing the results of average pooling and maximum pooling in the channel dimension.
[0025] Optionally, the step 22 includes:
[0026] The depth-separable convolution DSConv is performed in two parts. First, the depth convolution DC performs spatial convolution on the channels of each input feature map separately; for each channel, the convolution operation expression is:
[0027] D h (x,y)=∑ i,j I h (x+i,y+j)·K h (i,j);
[0028] Among them, D h (x, y) represents the value of channel h at position (x, y) in the output feature map; I h represents the hth channel in the input feature map; K h represents the convolution kernel applied to channel h; i and j represent the spatial position index of the convolution kernel;
[0029] After completing the depth convolution, the point-by-point convolution PC uses a 1×1 convolution kernel to merge the results of each channel to introduce interaction between channels. Its expression is:
[0030]
[0031] Among them, P(x,y) represents the value of the final output feature map at position (x,y); D h (x, y) represents the value of the hth channel at position (x, y) after depth convolution; W h Represents the weight of the 1×1 convolution kernel for channel h.
[0032] Optionally, the step 3 includes:
[0033] Configure the model training environment, read the training data set through the first yaml file, train the CDS-YOLO network model, and continuously optimize the loss function of the CDS-YOLO network model during the training process until the training converges.
[0034] Optionally, step 4 includes:
[0035] The test dataset is read through the second yaml file to comprehensively evaluate the CDS-YOLO network model. In terms of detection accuracy, the mean average precision (mAP) is used to evaluate the detection effect of the network model on the enhanced dataset. In terms of detection speed, the number of defect image frames detected per second (FPS) is used as the evaluation standard. In terms of network complexity, the number of network parameters (Params) is used to measure the lightweight of the network.
[0036] In a second aspect, the present invention provides a package defect detection system based on a CDS-YOLO network, wherein the system is implemented by a package defect detection method based on a CDS-YOLO network, and the system comprises:
[0037] Data acquisition module: selects and preprocesses public packaging defect data sets and self-built packaging defect data sets, divides the data sets, and obtains training data sets and test data sets;
[0038] Training environment configuration module: configure the model training environment;
[0039] Network model building module: By improving the YOLOv5s network model, the CDS-YOLO network model is obtained;
[0040] Training and verification module: deploy the CDS-YOLO network model in the configured model training environment, set preset parameters, train the CDS-YOLO network model through the training data set, and obtain the trained CDS-YOLO network model; call the weight file of the trained CDS-YOLO network model, and comprehensively evaluate the model through the test data set to obtain the evaluation results.
[0041] In the technical solution provided by the present invention, the method includes selecting and preprocessing a public packaging product defect data set and a self-built packaging product defect data set, and dividing the data set to obtain a training data set and a test data set; obtaining a CDS-YOLO network model by improving the YOLOv5s network model; deploying the CDS-YOLO network model in a configured model training environment, setting preset parameters, training the CDS-YOLO network model through the training data set, and obtaining a trained CDS-YOLO network model; calling the weight file of the trained CDS-YOLO network model, and comprehensively evaluating the model through the test data set to obtain an evaluation result. The method effectively distinguishes actual defects from background noise in a complex background and production environment while maintaining a high accuracy rate, and can accurately identify and locate minor defects on packaging products. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0043] Figure 1 A flowchart of a packaging product defect detection method provided by an embodiment of the present invention;
[0044] Figure 2 A schematic diagram of a CDS-YOLO network architecture provided by an embodiment of the present invention;
[0045] Figure 3a A schematic diagram of calculating the SIOU loss function provided by an embodiment of the present invention;
[0046] Figure 3b Another schematic diagram of calculating the SIOU loss function provided by an embodiment of the present invention;
[0047] Figure 4 A schematic diagram of an attention mechanism module CBAM provided in an embodiment of the present invention;
[0048] Figure 5 A schematic diagram of a depthwise separable convolution DSConv structure provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0049] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0050] It should be clear that the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0051] The terms used in the embodiments of the present invention are only for the purpose of describing specific embodiments, and are not intended to limit the present invention. The singular forms "a", "said" and "the" used in the embodiments of the present invention are also intended to include plural forms, unless the context clearly indicates other meanings.
[0052] It should be understood that the term "and / or" used in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.
[0053] The word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrases "if it is determined" or "if (stated condition or event) is detected" may be interpreted as "when it is determined" or "in response to determining" or "when detecting (stated condition or event)" or "in response to detecting (stated condition or event)", depending on the context.
[0054] Figure 1 A flowchart of a packaging product defect detection method provided by an embodiment of the present invention is shown in FIG. Figure 1 As shown, the method includes:
[0055] Step 1: Select and preprocess the public packaging product defect dataset and the self-built packaging product defect dataset, divide the dataset, and obtain the training dataset and the test dataset.
[0056] In an embodiment of the present invention, public packaging product defect images and self-built packaging product defect images are obtained, and after preprocessing and annotation, the processed image data set is divided into a training data set and a test data set in a ratio of 8:2, and the data sets are stored in a specified path, and a first yaml configuration file and a second yaml configuration file corresponding to the training data set and the test data set are generated respectively.
[0057] Use the script to convert the yaml configuration file into TXT format, which contains the defect category and location information. For example, the content of the TXT tag file is: 0, 0.7394260573942606, 0.43891221755648870.016998300169983, 0.7058588282343531, which means: the defect category ID is 0, the X coordinate of the center of the bounding box is approximately 73.94% of the image width, the Y coordinate of the center of the bounding box is approximately 43.89% of the image height, the width of the bounding box is approximately 1.70% of the image width, and the height of the bounding box is approximately 70.59% of the image height.
[0058] In the embodiment of the present invention, the public packaging defect images and the self-built packaging defect images include packaging cartons, cans, cigarette boxes, takeaway packaging, and packaging bags, etc. After the public packaging defect images and the self-built packaging defect images are unified into 640×640, they are pre-processed by translation, scaling, selection, binarization, etc., and are labeled using the LabelImg tool.
[0059] Step 2: By improving the YOLOv5s network model, the CDS-YOLO network model is obtained.
[0060] In the embodiment of the present invention, Figure 2 As shown in Figure 2, the CDS-YOLO network model is trained through the preprocessed and labeled package defect images. Figure 1As shown in the figure, the loss function of the CDS-YOLO network model is continuously optimized during the training process to improve the accuracy of package defect detection. The end-to-end CDS-YOLO network model created by the YOLO framework integrates multiple key modules: the Conv module is the basic convolution layer responsible for extracting primary features in the image; the C3 module is used to enhance the network's information flow and feature expression capabilities and improve detection accuracy; the DSConv module uses deep separable convolution technology to significantly reduce the number of model parameters and computational complexity, which is suitable for resource-constrained devices; the SPPF module processes inputs of different sizes through spatial pyramid pooling to extract multi-scale features; the CBAM module introduces an attention mechanism to highlight important features and suppress unimportant features, thereby enhancing the model's perception ability. The Upsample module is used to upsample low-resolution feature maps in the feature pyramid network so that they can be fused with high-resolution feature maps to improve the model's detection ability for small-sized objects. The integration of these modules makes the network structure streamlined, and can be efficiently deployed and run on detection equipment with limited computing power, realizing real-time monitoring and identification of package defects, thereby improving the accuracy and speed of defect detection.
[0061] In the embodiment of the present invention, step 2 includes:
[0062] Step 21, integrate the attention mechanism module CBAM into the backbone network of the YOLOv5s network model. The attention mechanism module CBAM is sequentially integrated by channel attention and spatial attention to enhance the model's ability to recognize key features;
[0063] Step 22: Replace some convolutional layers of the YOLOv5s network model with depthwise separable convolution (DSConv) to reduce the number of parameters and computational complexity of the model.
[0064] Step 23: Use SIOU as the loss function of the network model, and its expression is:
[0065]
[0066] Among them, B p represents the predicted bounding box, B g t represents the true bounding box, |B p ∩B g t| represents the intersection of the predicted box and the true box, such as Figure 3a The intersection A, |B p ∪B g t| represents the union of the predicted box and the true box, such as Figure 3b The scale factor represents the factor adjusted according to the target size, which is used to compensate for the deviation of targets of different sizes in IOU calculation. w and C hThey represent the height and width of the center points of the real box and the predicted box respectively; γ represents the distance between the center points of the real box and the predicted box; α represents the angle between the predicted box and a reference axis; β represents the supplementary angle, which is usually used when α exceeds a certain threshold θ. By adjusting α and β, the model can more accurately locate and identify the direction of the object.
[0067] In the embodiment of the present invention, Figure 4 As shown, step 21 includes:
[0068] (a) Channel attention first uses global average pooling and global maximum pooling to obtain feature descriptions from different perspectives, and then fuses the feature descriptions from different perspectives through a shared network layer to generate the weight of each channel, which is expressed as:
[0069] M ca (F)=σ(MLP(AvgPool(F))+MLP(MaxPool(F)));
[0070] Where F represents the input feature map, AvgPool(F) and MaxPool(F) represent global average pooling and global maximum pooling operations respectively, MLP represents multi-layer perceptron, and σ represents the Sigmoid activation function, which is used to generate the weight of each channel.
[0071] (b) Spatial attention uses the channel aggregation information of the input feature map, applies average pooling and maximum pooling operations on the channel dimension, and passes the result through the convolution layer to generate a weight map of the spatial dimension, which is expressed as:
[0072] M sa (F) = σ(f 7×7 ([AvgPool(F);MaxPool(F)]));
[0073] Among them, f 7×7 Represents a convolutional layer with a 7×7 kernel, and [AvgPool(F); MaxPool(F)] means superimposing the results of average pooling and maximum pooling in the channel dimension.
[0074] In the embodiment of the present invention, Figure 5 As shown in the figure, DSConv optimizes the convolutional network through quantization and distribution shift strategies. This technology is implemented through two key steps: depthwise convolution (DC) and pointwise convolution (PC), which correspond to the two core components of DSConv: variable quantization kernel (VQK) and distribution shift. For each layer, VQK is responsible for storing the quantized integer values and keeping the original convolution tensor (ch i ,k,k) of the same size, where ch iis the number of input layer channels, and k represents the convolution kernel size. These parameters are converted from floating point to integer and fixed, which speeds up the computation and reduces memory requirements. Distribution shift covers two main components: Kernel Distribution Shifter (KDS) and Channel Distribution Shifter (CDS). KDS is adjusted for each (blk,1,1) VQK slice, where blk is a hyperparameter of the block size and the tensor size is 2·(CEIL(ch i / blk),k,k). CDS is in each (ch i ,k,k) slices are adjusted to twice the number of output layer channels. These adjustments help the model more accurately simulate the behavior of the original convolution kernel, allowing VQK to effectively capture key features, thereby ensuring the classification performance of the network when processing different data sets, where CEIL(·) represents the upward rounding function, which returns an integer greater than or equal to the function parameter and closest to it.
[0075] In the embodiment of the present invention, step 22 includes:
[0076] The depth-separable convolution DSConv is performed in two parts. First, the depth convolution DC performs spatial convolution on the channels of each input feature map separately; for each channel, the convolution operation expression is:
[0077] D h (x,y)=∑ i,j I h (x+i,y+j)·K h (i,j);
[0078] Among them, D h (x, y) represents the value of channel h at position (x, y) in the output feature map; I h represents the hth channel in the input feature map; K h represents the convolution kernel applied to channel h; i and j represent the spatial position index of the convolution kernel;
[0079] After completing the depth convolution, the point-by-point convolution PC uses a 1×1 convolution kernel to merge the results of each channel to introduce interaction between channels. Its expression is:
[0080]
[0081] Among them, P(x,y) represents the value of the final output feature map at position (x,y); D h (x, y) represents the value of the hth channel at position (x, y) after depth convolution; W h Represents the weight of the 1×1 convolution kernel for channel h.
[0082] Step 3: Deploy the CDS-YOLO network model in the configured model training environment, set the preset parameters, train the CDS-YOLO network model through the training data set, and obtain the trained CDS-YOLO network model.
[0083] In an embodiment of the present invention, a model training environment is configured, a training data set is read through a first yaml file, and a CDS-YOLO network model is trained. During the training process, the loss function of the CDS-YOLO network model is continuously optimized until the training converges.
[0084] In the embodiment of the present invention, configuring the model training environment includes installing relevant software and libraries, setting hardware parameter configuration, and ensuring basic software and hardware configuration such as all dependencies. For example, torchvision is used for image operations and must be compatible with the PyTorch version; numpy is used for efficient numerical calculations; opencv-python is used for image processing; matplotlib is used for drawing charts and image display; Pillow is an image processing library, etc.
[0085] Step 4: Call the weight file of the trained CDS-YOLO network model, conduct a comprehensive evaluation of the model through the test data set, and obtain the evaluation results.
[0086] In the embodiment of the present invention, the evaluation includes visualization analysis, detection accuracy evaluation, network complexity evaluation and detection speed evaluation.
[0087] In the embodiment of the present invention, step 4 includes:
[0088] After setting up the data path configuration, preset parameters (training rounds, batches, and defect categories, etc.), logs and monitoring, backup and version control, security, and permissions, the test dataset is read through the second yaml file to conduct a comprehensive evaluation of the CDS-YOLO network model. In terms of detection accuracy, the mean average precision (mAP) is used to evaluate the detection effect of the network model on the enhanced dataset; in terms of detection speed, the number of defect image frames detected per second (FPS) is used as the evaluation standard; in terms of network complexity, the number of network parameters (Params) is used to measure the lightweightness of the network.
[0089] The present invention provides a package defect detection system based on a CDS-YOLO network. The system is implemented by a package defect detection method based on a CDS-YOLO network. The system includes:
[0090] Data acquisition module: select and preprocess public packaging defect data sets and self-built packaging defect data sets, divide the data sets, and obtain training data sets and test data sets; training environment configuration module: configure the model training environment; network model construction module: obtain the CDS-YOLO network model by improving the YOLOv5s network model; training and verification module: deploy the CDS-YOLO network model in the configured model training environment, set preset parameters, train the CDS-YOLO network model through the training data set, and obtain the trained CDS-YOLO network model; call the weight file of the trained CDS-YOLO network model, comprehensively evaluate the model through the test data set, and obtain the evaluation results.
[0091] In the embodiment of the present invention, the loss function of the CDS-YOLO network model is continuously optimized during the training process to improve the accuracy of packaged product defect detection; the end-to-end CDS-YOLO network model created by the YOLO framework has a streamlined network structure, so that it can be better deployed and run on detection equipment with limited computing power, thereby real-time and efficient monitoring and identification of packaged product defects, and improving the accuracy and speed of defect detection.
[0092] The present invention aims to improve the accuracy and efficiency of packaged product detection. In order to enhance the network's ability to recognize important features, the present invention introduces an attention mechanism module CBAM into the backbone network of the YOLOv5s network model; in order to improve computational efficiency and reduce the number of model parameters, the present invention replaces part of the traditional convolutional layer with a deep separable convolution DSConv module; finally, in order to optimize the accuracy of target positioning and regression loss, the present invention applies an improved SIOU loss function. The present invention can not only improve the accuracy of detection, but also reduce the computational burden, making the model suitable for running on resource-constrained devices. Compared with other algorithms, the present invention increases the accuracy of detection and optimizes the efficiency and accuracy of the entire detection process.
[0093] In the technical solution provided by the present invention, the method includes selecting and preprocessing a public packaging product defect data set and a self-built packaging product defect data set, and dividing the data set to obtain a training data set and a test data set; obtaining a CDS-YOLO network model by improving the YOLOv5s network model; deploying the CDS-YOLO network model in a configured model training environment, setting preset parameters, training the CDS-YOLO network model through the training data set, and obtaining a trained CDS-YOLO network model; calling the weight file of the trained CDS-YOLO network model, and comprehensively evaluating the model through the test data set to obtain an evaluation result. The method effectively distinguishes actual defects from background noise in a complex background and production environment while maintaining a high accuracy rate, and can accurately identify and locate minor defects on packaging products.
[0094] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0095] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A packaging defect detection method based on CDS-YOLO network, It is characterized in that The method comprises: Step 1: Select and preprocess the public packaging product defect dataset and the self-built packaging product defect dataset, divide the dataset, and obtain the training dataset and the test dataset; Step 2: By improving the YOLOv5s network model, the CDS-YOLO network model is obtained; Step 3: Deploy the CDS-YOLO network model in the configured model training environment, set the preset parameters, train the CDS-YOLO network model through the training data set, and obtain the trained CDS-YOLO network model; Step 4: Call the weight file of the trained CDS-YOLO network model, conduct a comprehensive evaluation of the model through the test data set, and obtain the evaluation results.
2. The method according to claim 1, It is characterized in that The step 1 comprises: After obtaining public packaging defect images and self-built packaging defect images, preprocessing and annotating them, the processed image dataset is divided into a training dataset and a test dataset in a ratio of 8:2, stored in the specified path, and the first yaml configuration file and the second yaml configuration file corresponding to the training dataset and the test dataset are generated respectively.
3. The method according to claim 1, It is characterized in that The step 2 comprises: Step 21, integrate the attention mechanism module CBAM into the backbone network of the YOLOv5s network model. The attention mechanism module CBAM is sequentially integrated by channel attention and spatial attention to enhance the model's ability to recognize key features; Step 22: Replace some convolutional layers of the YOLOv5s network model with depthwise separable convolution (DSConv) to reduce the number of parameters and computational complexity of the model. Step 23: Use SIOU as the loss function of the network model, and its expression is: Among them, B p represents the predicted bounding box, B g t represents the true bounding box, |B p ∩B g t| represents the intersection of the predicted box and the true box, |B p ∪B g t| represents the union of the predicted box and the true box; scale factor represents the factor adjusted according to the target size, which is used to compensate for the deviation of targets of different sizes in IOU calculation.
4. The method according to claim 3, It is characterized in that The step 21 comprises: (a) Channel attention first uses global average pooling and global maximum pooling to obtain feature descriptions from different perspectives, and then fuses the feature descriptions from different perspectives through a shared network layer to generate the weight of each channel, which is expressed as: M ca (F)=σ(MLP(AvgPool(F))+MLP(MaxPool(F))); Where F represents the input feature map, AvgPool(F) and MaxPool(F) represent global average pooling and global maximum pooling operations respectively, MLP represents multi-layer perceptron, and σ represents the Sigmoid activation function, which is used to generate the weight of each channel. (b) Spatial attention uses the channel aggregation information of the input feature map, applies average pooling and maximum pooling operations on the channel dimension, and passes the result through the convolution layer to generate a weight map of the spatial dimension, which is expressed as: M sa (F)=σ(f 7×7 ([AvgPool(F);MaxPool(F)])); Among them, f 7×7 Represents a convolutional layer with a 7×7 kernel, and [AvgPool(F); MaxPool(F)] means superimposing the results of average pooling and maximum pooling in the channel dimension.
5. The method according to claim 3, It is characterized in that The step 22 comprises: The depth-separable convolution DSConv is performed in two parts. First, the depth convolution DC performs spatial convolution on the channels of each input feature map separately; for each channel, the convolution operation expression is: D h (x,y)=∑ i,j I h (x+i,y+j)·K h (i,j); Among them, D h (x, y) represents the value of channel h at position (x, y) in the output feature map; I h represents the hth channel in the input feature map; K h represents the convolution kernel applied to channel h; i and j represent the spatial position index of the convolution kernel; After completing the depth convolution, the point-by-point convolution PC uses a 1×1 convolution kernel to merge the results of each channel to introduce interaction between channels. Its expression is: Among them, P(x,y) represents the value of the final output feature map at position (x,y); D h (x, y) represents the value of the hth channel at position (x, y) after depth convolution; W h Represents the weight of the 1×1 convolution kernel for channel h.
6. The method according to claim 1, It is characterized in that The step 3 comprises: Configure the model training environment, read the training data set through the first yaml file, train the CDS-YOLO network model, and continuously optimize the loss function of the CDS-YOLO network model during the training process until the training converges.
7. The method according to claim 1, It is characterized in that The step 4 comprises: The test dataset is read through the second yaml file to comprehensively evaluate the CDS-YOLO network model. In terms of detection accuracy, the mean average precision (mAP) is used to evaluate the detection effect of the network model on the enhanced dataset. In terms of detection speed, the number of defect image frames detected per second (FPS) is used as the evaluation standard. In terms of network complexity, the number of network parameters (Params) is used to measure the lightweight of the network.
8. A packaging defect detection system based on CDS-YOLO network, It is characterized in that The system is implemented by a package defect detection method based on a CDS-YOLO network, and the system includes: Data acquisition module: selects and preprocesses public packaging defect data sets and self-built packaging defect data sets, divides the data sets, and obtains training data sets and test data sets; Training environment configuration module: configure the model training environment; Network model building module: By improving the YOLOv5s network model, the CDS-YOLO network model is obtained; Training and verification module: deploy the CDS-YOLO network model in the configured model training environment, set preset parameters, train the CDS-YOLO network model through the training data set, and obtain the trained CDS-YOLO network model; call the weight file of the trained CDS-YOLO network model, and comprehensively evaluate the model through the test data set to obtain the evaluation results.
Citation Information
Patent Citations
Method and device for detecting illegal building objects in complex scene based on deep learning
CN115830438A
Edge end steel surface defect detection method based on YOLOv5s-CM
CN117934363A
Fan blade defect detection method and system based on improved SSD model
WO2023173598A1
