Blister tablet defect detection method and system
By combining the attention mechanism and the improved GFL function, the blister tablet defect detection is optimized, and the problem of inconsistent classification and positioning in the existing technology is solved, and efficient multi-category and multi-defect detection is achieved.
Patent Information
- Application Number
- CN202411797668.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-09
- Publication Date
- 2025-03-25
AI Technical Summary
The prior art has problems with inconsistency between classification and positioning tasks in the detection of blister tablet defects, resulting in inefficient detection and difficulty in multi-defect detection.
Using a yolov8 network model combining attention mechanism and improved GFL function, optimize bounding box and feature importance to build an efficient defect detection model. The model enhances detail capture capabilities through the fusion of high-resolution and low-resolution features, and adjusts balance accuracy and speed through dynamic weighting.
It significantly improves the model's detailed capture ability in complex scenarios, solves the problems of defect missed detection and missed detection, and realizes synchronous detection of multiple types and multiple defect targets, which is suitable for application requirements in actual scenarios.
Smart Images

Figure CN119693338A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of tablet defect detection, and in particular to a defect detection method and system for blister tablets. Background Art
[0002] With the rapid development of the pharmaceutical manufacturing industry, automated testing technology has been widely used in various fields. At present, there are two main methods for defect detection of pharmaceutical blister tablets: traditional manual testing: relying on specialized technicians for manual inspection, but due to the low accuracy, low efficiency and long time consumption of the test, it is difficult to meet the needs of large-scale production. Laser measurement technology: This technology can accurately detect and analyze the appearance of blister tablets, but the equipment cost is high and is not suitable for low-cost detection of large-volume products.
[0003] With the continuous advancement of artificial intelligence and deep learning technologies, the field of machine vision has also undergone tremendous changes. In recent years, a large number of deep learning algorithms (such as convolutional neural networks and recurrent neural networks) have been widely used in object detection. Compared with traditional machine vision methods, algorithms based on deep learning show significant advantages in accuracy, computing speed, and generalization capabilities. In the future, with the further development of deep learning and artificial intelligence technologies, machine vision technology will achieve larger-scale innovations and breakthroughs.
[0004] In the defect detection of Yunnan Baiyao blister tablets, since a single product may have multiple defects, the complexity of the detection algorithm is significantly increased. Traditional detection algorithms can usually only deal with a single defect. For the detection of multiple defects, a combination of multiple methods is often required, but it is still difficult to completely solve this problem. In addition, as the number of defects increases, the difficulty of detection gradually increases. At present, when performing defect detection on blister tablets, we are faced with the problem of low detection efficiency of traditional detection methods and inconsistency between classification and positioning tasks in target detection. Summary of the invention
[0005] The purpose of the present invention is to overcome the deficiencies in the prior art and to provide a defect detection method and system for blister tablets, which can solve the inconsistency problem between classification and positioning tasks in traditional target detection.
[0006] To achieve the above object, the present invention is implemented by adopting the following technical solutions:
[0007] In one aspect, the present invention provides a method for defect detection of blister tablets, comprising:
[0008] Acquire blister tablet images;
[0009] Inputting the blister tablet image into a pre-built defect detection model, and outputting a defect detection result of the blister tablet;
[0010] The construction of the defect model includes:
[0011] Get the yolov8 network model;
[0012] The bounding box of the yolov8 network model is optimized by using the loss defined by the improved GFL function to obtain the optimized yolov8 network model; the improved GFL function is obtained by adding a nonlinear dynamic weight function to the GFL function;
[0013] An attention mechanism is added to the neck network of the optimized yolov8 network model to obtain a constructed defect detection model; the attention mechanism is an attention mechanism that fuses high-resolution features and low-resolution features.
[0014] Optionally, the training of the defect detection model includes:
[0015] Obtain historical blister tablet images and a public dataset; the public dataset is a coco dataset;
[0016] The historical blister tablet image is subjected to angle rotation, horizontal flipping, brightness adjustment, HSV adjustment, and image cropping by using data enhancement technology to obtain an expanded historical blister tablet image;
[0017] Using the public data set to train the defect detection model to obtain a pre-trained defect detection model;
[0018] The pre-trained defect detection model is trained using the expanded historical blister tablet images to obtain a trained defect detection model.
[0019] Optionally, the defect detection results of the blister tablets include tablet breakage, tablet cracks, missing tablets, tablet foreign matter, and tablet color mismatch.
[0020] Optionally, the loss defined by the improved GFL function is expressed as:
[0021] ;
[0022] ;
[0023] ;
[0024] ;
[0025] In the formula, represents the loss of improving the GFL function definition; represents the number of positive samples; Indicates the index of the sample; represents the improved GFL loss; Represents the first weight hyperparameter of the loss defined by the improved GFL function; The second weight hyperparameter representing the loss defined by the improved GFL function; represents the auxiliary regression loss; Indicates the number of negative samples; represents the negative sample suppression loss; represents the predicted value; represents the true label; represents a nonlinear dynamic weight function; Represents the predicted value of the yolov8 network model; represents the focus adjustment factor; represents the evaluation factor; represents the generalized intersection-combination loss; represents the predicted bounding box; represents the ground-truth bounding box; represents the auxiliary regression loss weight; represents the uncertainty parameter of the prediction; represents the true uncertainty parameter; represents the indicator function; Indicates the threshold value.
[0026] Optionally, the attention mechanism is expressed as:
[0027] ;
[0028] ;
[0029] In the formula, represents the attention mechanism; represents the linear attention mechanism; Represents features of cross-scale fusion; Represents the fusion weight coefficient; Represents feature concatenation operation; Represents an upsampling operation; Represents low-resolution features; Represents high-resolution features.
[0030] Optionally, local enhancement terms, dynamic normalization terms, and feature interaction terms are added to the calculation formula of the attention mechanism.
[0031] Optionally, the calculation formula of the attention mechanism is expressed as:
[0032] ;
[0033] ;
[0034] ;
[0035] ;
[0036] ;
[0037] ;
[0038] ;
[0039] In the formula, Indicates The output of the position attention mechanism; Indicates the first feature points; Indicates The index vector of the positions; Represents the total number of vectors; Indicates the first feature points; Indicates the value vector feature points; Represents the weight parameter, which is used to control the impact of the cross term on the result; represents the displayed Q, K, and V interaction terms; represents the dynamic normalization term; represents the linear transformation of the query vector Q; Represents the input of the attention mechanism; Represents the linear transformation weight matrix of the query vector; represents a nonlinear activation function; represents the third hyperparameter; represents the fourth hyperparameter; represents a local enhancement term; represents the linear transformation of the key vector K; Represents the weight matrix of the linear transformation of the key vector; represents the linear transformation of the value vector V; Represents the weight matrix of the linear transformation of the value vector; Indicates The neighborhood feature set of each location; express No. The feature vector of the neighboring points; Indicates how the offset value is calculated; represents the norm; Represents an element-wise multiplication operation.
[0040] Optionally, the processing steps of the defect detection model include:
[0041] performing feature extraction, feature fusion, and feature splicing on the blister tablet image in sequence to obtain spliced features;
[0042] According to a preset size, upsampling is performed on the spliced features to obtain a high-resolution feature map; the high-resolution feature map is sequentially spliced in the feature channel direction and convolutionally fused to obtain a convolutionally fused feature map; the convolutionally fused feature map includes multi-scale fusion features of semantic information and spatial information;
[0043] The feature map after the convolution fusion is sequentially subjected to two-dimensional convolution and normalization to obtain the defect detection result of the blister tablet.
[0044] In a second aspect, the present invention provides a defect detection system for blister tablets, comprising:
[0045] A data acquisition module is used to: acquire a blister tablet image;
[0046] A defect detection module, used to: input the blister tablet image into a pre-built defect detection model, and output a defect detection result of the blister tablet;
[0047] The construction of the defect model includes:
[0048] Get the yolov8 network model;
[0049] The bounding box of the yolov8 network model is optimized by using the loss defined by the improved GFL function to obtain the optimized yolov8 network model; the improved GFL function is obtained by adding a nonlinear dynamic weight function to the GFL function;
[0050] An attention mechanism is added to the neck network of the optimized yolov8 network model to obtain a constructed defect detection model; the attention mechanism is an attention mechanism that fuses high-resolution features and low-resolution features.
[0051] In a third aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the defect detection method for blister tablets described in the first aspect.
[0052] Compared with the prior art, the present invention has the following beneficial effects:
[0053] The present invention combines the attention mechanism with the yolov8 network model to construct a defect detection model, and the principle of the attention mechanism is to integrate cross-scale feature enhancement and dynamic normalization mechanism. By constructing local enhancement items and cross-feature interactions, the model's ability to capture details in complex scenes is significantly improved, thereby improving the performance of the model. The introduction of the attention mechanism effectively solves the two thorny problems of defect omission and defect misdetection, and can simultaneously realize the synchronous detection of multiple types of multi-defect targets without bringing too much burden to network training; an improved GFL function is also designed to optimize the bounding box of the yolov8 network model for dynamically adjusting the importance of different features, that is, a feature selection mechanism based on adaptive gating is introduced in the GFL function, and the feature learning process is divided into two parts: "enhanced feature path" and "suppressed noise path", which can solve the inconsistency problem between classification and positioning tasks in traditional target detection; the combination of the attention mechanism and the improved GFL function can effectively balance accuracy and speed when processing target detection tasks, and is more suitable for application requirements in actual scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] Figure 1 FIG. 1 is a schematic flow chart of a defect detection method for blister tablets according to an embodiment of the present invention;
[0055] Figure 2 Shown is a schematic structural diagram of a defect detection model of the present invention in one embodiment;
[0056] Figure 3 Shown is a schematic diagram of the structure of the attention mechanism of the present invention in one embodiment;
[0057] Figure 4 Shown is a schematic diagram of defect detection results of a blister tablet of the present invention in one embodiment;
[0058] Figure 5 FIG. 1 is a schematic diagram showing the defect detection result of a blister tablet of the present invention in another embodiment. DETAILED DESCRIPTION
[0059] The technical solution of the present invention is described in detail below through the accompanying drawings and specific embodiments. It should be understood that the embodiments of the present invention and the specific features in the embodiments are detailed descriptions of the technical solution of the present invention, rather than limitations on the technical solution of the present invention. The embodiments of the present invention and the technical features in the embodiments may be combined with each other unless there is a conflict.
[0060] The term "and / or" is only a description of the association relationship between related objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " generally indicates that the related objects are in an "or" relationship.
[0061] Example 1
[0062] like Figure 1 As shown, this embodiment introduces a defect detection method for blister tablets, which specifically includes the following steps:
[0063] Step 1: Get the blister tablet image.
[0064] Step 2: Input the blister tablet image into a pre-built defect detection model, and output the defect detection results of the blister tablet, which include tablet damage, tablet cracks, tablet missing, tablet foreign matter, and tablet color mismatch. The defect conditions of tablet damage, tablet cracks, and tablet missing are as follows: Figure 4 As shown, the defects of foreign matter in the tablets and mismatched tablet colors are as follows Figure 5 shown.
[0065] Wherein, the construction of the defect detection model includes:
[0066] Get the yolov8 network model;
[0067] In order to further improve the performance of the model, the present invention also designs an improved GFL (AGFL, Adaptive Gated Feature Learning) function for dynamically adjusting the importance of different features. The core of the AGFL function is to introduce a feature selection mechanism based on adaptive gating, that is, by adding a nonlinear dynamic weight function to the GFL function, the AGFL function is obtained. The AGFL function divides the feature learning process into two parts: "enhanced feature path" and "noise suppression path". The implementation of the AGFL function is as follows:
[0068] Enhanced path: Strengthen the response to the target feature through a dynamically generated weight matrix.
[0069] Suppression path: Reduce sensitivity to noise through feature compression and normalization.
[0070] Gating unit: combines the enhancement and suppression results into the final feature output.
[0071] The AGFL function also combines position encoding (such as rotation position encoding) technology to maintain the spatial information of the feature and improve the accuracy of feature selection during fast reasoning. The bounding box of the yolov8 network model is optimized using the loss defined by the improved GFL function to obtain the optimized yolov8 network model;
[0072] Although the original Quality Focal Loss (QFL) and Generalized Focal Loss (GFL) introduce weights to balance positive and negative samples, their weights are fixed or linearly adjusted and cannot dynamically respond to changes in the ratio of positive and negative samples under different tasks and data distributions.
[0073] In practical applications, positive samples are usually far less than negative samples, and the existing fixed weights may lead to insufficient learning of positive samples or excessive impact of negative samples on the overall loss.
[0074] Nonlinear dynamic adjustment weights are added to the AGFL function, and the loss contribution of positive and negative samples is adaptively adjusted through the nonlinear function, especially to enhance the influence of rare positive samples.
[0075] The AGFL function is expressed as:
[0076] ;
[0077] It is a nonlinear dynamic weight function of positive and negative samples, which is adaptively adjusted according to the sample category ratio; is an evaluation factor used to balance classification loss and regression loss; Used to emphasize the model's approximation to positive samples; is the focus adjustment factor, which is used to control the loss contribution of easy-to-classify samples; is the predicted value of the yolov8 network model, for positive samples , when negative sample .
[0078] The loss defined by the improved GFL function is expressed as:
[0079] ;
[0080] The auxiliary regression loss is:
[0081]
[0082] Evaluate the predicted bounding boxes of the yolov8 network model using the Generalized Intersection over Union (IoU) loss and the Improved Generalized Intersection over Union (GIoU) loss and the ground-truth bounding box The overlap of Auxiliary regression loss weight used to constrain the scale parameter.
[0083] Negative sample suppression loss:
[0084] ;
[0085] When the predicted value Greater than a threshold , suppressing the impact of negative samples on the overall loss. At this time, is the preset threshold.
[0086] In the formula, represents the number of positive samples; Indicates the index of the sample; Represents the first weight hyperparameter of the loss defined by the improved GFL function; The second weight hyperparameter representing the loss defined by the improved GFL function; Indicates the number of negative samples; represents the predicted value; represents the true label; represents the generalized intersection-combination loss; represents the uncertainty parameter of the prediction; represents the true uncertainty parameter; Represents the indicator function.
[0087] An attention mechanism is added to the neck network of the optimized yolov8 network model to obtain a constructed defect detection model; the attention mechanism is an attention mechanism that fuses high-resolution features and low-resolution features, and combines the attention mechanism (SCALA, Scalable Cross-Attention Linear Architecture) with the yolov8 network model, and directly integrates the target positioning quality (such as the overlap degree between the bounding box and the real object, such as the intersection over union (IoU) score) into the classification loss to form a joint representation, thereby optimizing the total loss function.
[0088] The structure of SCALA is as follows Figure 3As shown in Figure 1, the principle of SCALA is to further optimize the performance of the attention mechanism through cross-scale feature interaction and dynamic weight adaptation. Specifically, SCALA integrates the cross-scale feature enhancement module and the dynamic normalization mechanism. By constructing local enhancement items and cross-feature interactions, it significantly improves the model's ability to capture details in complex scenes. At the same time, on the basis of optimizing computational efficiency, SCALA enhances the robustness of the attention mechanism to changes in feature distribution by introducing a dynamically adjusted normalization factor. In addition, SCALA establishes effective connections between features of different resolutions through a cross-level feature fusion mechanism, thereby improving classification and detection accuracy.
[0089] The cross-scale attention mechanism combines the multi-layer information of the input features and uses the fusion mechanism of high-resolution features and low-resolution features, which can be expressed as:
[0090] ;
[0091] is a high-resolution feature, is a low-resolution feature, By upsampling to Consistent resolution. is an upsampling operation, such as nearest neighbor interpolation or deconvolution;
[0092] The attention mechanism The final expression is:
[0093] ;
[0094] In the formula, represents the linear attention mechanism;
[0095] Local enhancement terms, dynamic normalization terms and feature interaction terms are added to the calculation formula of the attention mechanism. That is, when calculating the query Q, key K and value V, the information of the local neighborhood is added to capture the detailed features and improve the traditional normalization method so that it is dynamically associated with the input feature distribution. By adding feature interaction terms, the modeling capability is improved.
[0096] Defining Inputs , Q, K, V are generated through learning, expressed as:
[0097] ;
[0098] ;
[0099] ;
[0100] Local Enhancement It is expressed as:
[0101] ;
[0102] Indicates The local enhancement term enhances the representation ability of Q through the local receptive field and captures fine-grained features.
[0103] No. The output of the position attention mechanism is expressed as:
[0104] ;
[0105] Dynamic Normalization Term It is expressed as:
[0106] ;
[0107] Add explicit Q, K, V interaction terms It is expressed as:
[0108] ;
[0109] In the formula, Indicates the first feature points; Indicates The index vector of the positions; Represents the total number of vectors; Indicates the first feature points; Indicates the value vector feature points; Represents the weight parameter, which is used to control the impact of the cross term on the result; Represents the linear transformation weight matrix of the query vector; represents a nonlinear activation function; represents the third hyperparameter; represents the fourth hyperparameter; represents the linear transformation of the key vector K; Represents the weight matrix of the linear transformation of the key vector; represents the linear transformation of the value vector V; Represents the weight matrix of the linear transformation of the value vector; express No. The feature vector of the neighboring points; Indicates how the offset value is calculated; represents the norm; Represents an element-wise (element-by-element) multiplication operation.
[0110] The SCALA+AGFL function can effectively balance accuracy and speed when processing target detection tasks, and is more suitable for application requirements in actual scenarios.
[0111] The training of the defect detection model includes:
[0112] Obtain historical blister tablet images and a public dataset; the public dataset is the coco dataset, and the number of early stop rounds is set to 20 in this embodiment;
[0113] The historical blister tablet image is subjected to angle rotation, horizontal flipping, brightness adjustment, HSV adjustment, and image cropping by using data enhancement technology to obtain an expanded historical blister tablet image;
[0114] in,
[0115] Rotation angle: By rotating the image at random angles, images in different directions are generated to improve the robustness of the model to various directional defects.
[0116] Horizontal flip: By mirror-flipping the image, the model can effectively identify defects in symmetry or different directions.
[0117] Random brightness adjustment: By randomly changing the brightness of the image, the model's defect detection ability under different lighting conditions is enhanced.
[0118] HSV adjustment: Generate diverse images by adjusting the hue, saturation, and brightness of the image to improve the model's generalization ability in various color environments.
[0119] Image cropping: Crop the image parts containing the target defects from the dataset, ensuring that each cropped image contains at least one defect, thereby increasing the data containing the target features and further expanding the dataset.
[0120] These data augmentation techniques aim to improve the accuracy and stability of defect detection by increasing the diversity of images and improving the generalization ability of the model.
[0121] Using the public data set to train the defect detection model to obtain a pre-trained defect detection model;
[0122] The pre-trained defect detection model is trained using the expanded historical blister tablet images to obtain a trained defect detection model.
[0123] The defect detection model includes a Backbone module, a Neck module and a Head module. The structure of the defect detection model is as follows: Figure 2 As shown;
[0124] in:
[0125] The Backbone module includes a first ConvModule (Conv) module, a second Conv module, a first CSPL_2 (C2f) module, a third Conv module, a second C2f module, a fourth Conv module, a third C2f module, a fifth Conv module, a fourth C2f module, and an SPPF module;
[0126] The Neck module includes a second Upsample module, a second Concat module, a sixth C2f module, a first Upsample module, a first Concat module, a fifth C2f module, a first SCALA module, a sixth Conv module, a third Concat module, a seventh C2f module, a seventh Conv module, a fourth Concat module, an eighth C2f module, and a second SCALA module;
[0127] The Head module includes three detection heads Detect, each of which includes an eighth Conv module, a ninth Conv module, a first Conv2d, a second Conv2d, and an AGFL module.
[0128] The blister tablet image is first input into the Backbone module, and feature extraction, feature fusion, and feature splicing are performed on the blister tablet image in sequence to obtain spliced features;
[0129] Then, the spliced features are upsampled according to a preset size through the Neck module to obtain a high-resolution feature map; the high-resolution feature map is sequentially spliced in the feature channel direction and convolutionally fused to obtain a convolutionally fused feature map; the convolutionally fused feature map includes multi-scale fusion features of semantic information and spatial information;
[0130] Finally, the Head module is used to perform two-dimensional convolution and normalization on the feature map after convolution fusion, and the defect detection result of the blister tablet is output.
[0131] In the Conv module, features are extracted to increase nonlinearity, help the network learn complex features, accelerate training and stabilize the network; in the C2f module, deep features are extracted through two or more convolutional layers, and the input feature map is directly added to the output feature through residual connection to alleviate the gradient vanishing problem, and the features extracted by multiple different branches are fused to adapt to features of different scales; in the SPPF module, pooling kernels of different sizes (such as 1x1, 3x3, 5x5) are used to pool the input feature map, extract local and global features, and splice the pooled multi-scale features together to form a richer feature representation.
[0132] In the Upsample module, the size of the low-resolution feature map (e.g., a feature map of size H×W×C, where H and W are height and width, and C is the number of channels) from the Backbone module is enlarged to the target size using an upsampling operation, for example, from H×W to 2H×2W, to generate a high-resolution feature map. The upsampling operation can be nearest neighbor interpolation: copying each pixel value directly to the surrounding area to enlarge the size of the feature map; or bilinear interpolation: calculating the weighted average of the surrounding pixels to fill in the new pixels; or deconvolution (Transposed Convolution): applying a learnable convolution kernel to generate a more refined high-resolution feature map based on the input feature map.
[0133] In the Concat module, two or more feature maps (usually feature maps from different branches or different scales, such as high-resolution shallow features and low-resolution deep features) are combined. The feature map sizes need to be consistent in the spatial dimension. If the sizes are different, they are usually adjusted to the same size through Upsample or Downsample, and spliced along the channel dimension to merge multiple feature maps into a larger feature map. For example, two feature maps F1 and F2 have C1 and C2 channels respectively, and the number of channels of the spliced feature map is C1+C2. The convolution operation is performed on the spliced feature map to fuse the information and compress the number of channels. Activation functions (such as ReLU) and normalization (such as BatchNorm) can also be used to enhance the feature expression ability and generate a fused feature map that contains both high-resolution spatial detail information and low-resolution semantic information.
[0134] In the Conv2d module, the fused feature map is used to extract features from the input feature map using a two-dimensional convolution kernel and further processed. The convolution kernel size is usually set to 1×1 or 3×3 for different tasks. 1×1 convolution: changes the number of channels (such as dimensionality reduction or adjustment to the number of categories or prediction dimensions); 3×3 convolution: further enhances local feature representation, and the stride is usually set to 1 to maintain the spatial resolution of the feature map; padding methods (such as SAME) are usually used to ensure that the output feature map size remains unchanged; activation functions (such as ReLU, Leaky ReLU or Sigmoid) are applied to introduce nonlinearity so that the network can learn complex feature relationships; in target detection tasks, the activation function may be adjusted according to the task, Sigmoid: used for confidence and category probability output (ranging from 0 to 1); no activation: used for direct regression prediction (such as bounding box coordinates); normalize the convolution output to reduce gradient vanishing or gradient explosion problems, accelerate network training and improve convergence stability; the output of the Conv2d module is a multi-scale feature map, each of which is used to predict the target detection result, including: the center point coordinates of the bounding box (x, y); the width and height of the bounding box (w, h); the confidence score of the target; the target category probability.
[0135] Example 2
[0136] This embodiment introduces a defect detection system for blister tablets, including:
[0137] A data acquisition module is used to: acquire a blister tablet image;
[0138] A defect detection module, used to: input the blister tablet image into a pre-built defect detection model, and output a defect detection result of the blister tablet;
[0139] The model building module is used for: the building of the defect model includes:
[0140] Get the yolov8 network model;
[0141] The bounding box of the yolov8 network model is optimized by using the loss defined by the improved GFL function to obtain the optimized yolov8 network model; the improved GFL function is obtained by adding a nonlinear dynamic weight function to the GFL function;
[0142] An attention mechanism is added to the neck network of the optimized yolov8 network model to obtain a constructed defect detection model; the attention mechanism is an attention mechanism that fuses high-resolution features and low-resolution features.
[0143] Example 3
[0144] This embodiment introduces a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of the defect detection method for blister tablets described in Embodiment 1 are implemented.
[0145] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0146] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0147] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0148] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable device. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0149] The embodiments of the present invention are described above in conjunction with the accompanying drawings, but the present invention is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the enlightenment of the present invention, ordinary technicians in this field can also make many forms without departing from the scope of protection of the purpose of the present invention and the claims, which all fall within the protection of the present invention.
Claims
1. A defect detection method for blister tablets, characterized in that: include: Obtaining a front image of a blister tablet; Inputting the blister tablet image into a pre-built defect detection model, and outputting a defect detection result of the blister tablet; The construction of the defect model includes: Get the yolov8 network model; The bounding box of the yolov8 network model is optimized by using the loss defined by the improved GFL function to obtain the optimized yolov8 network model; the improved GFL function is obtained by adding a nonlinear dynamic weight function to the GFL function; An attention mechanism is added to the neck network of the optimized yolov8 network model to obtain a constructed defect detection model; the attention mechanism is an attention mechanism that fuses high-resolution features and low-resolution features.
2. The defect detection method for blister tablets according to claim 1, characterized in that: The training of the defect detection model includes: Obtain historical blister tablet images and a public dataset; the public dataset is a coco dataset; The historical blister tablet image is subjected to angle rotation, horizontal flipping, brightness adjustment, HSV adjustment, and image cropping by using data enhancement technology to obtain an expanded historical blister tablet image; Using the public data set to train the defect detection model to obtain a pre-trained defect detection model; The pre-trained defect detection model is trained using the expanded historical blister tablet images to obtain a trained defect detection model.
3. The defect detection method for blister tablets according to claim 1, characterized in that: The defect detection results of the blister tablets include tablet breakage, tablet cracks, tablet missing, tablet foreign matter, and tablet color mismatch.
4. The defect detection method for blister tablets according to claim 1, characterized in that: The loss defined by the improved GFL function is expressed as: ; ; ; ; In the formula, represents the loss of improving the GFL function definition; represents the number of positive samples; Indicates the index of the sample; represents the improved GFL loss; Represents the first weight hyperparameter of the loss defined by the improved GFL function; The second weight hyperparameter representing the loss defined by the improved GFL function; represents the auxiliary regression loss; Indicates the number of negative samples; represents the negative sample suppression loss; represents the predicted value; represents the true label; represents a nonlinear dynamic weight function; Represents the predicted value of the yolov8 network model; represents the focus adjustment factor; represents the evaluation factor; represents the generalized intersection-combination loss; represents the predicted bounding box; represents the ground-truth bounding box; represents the auxiliary regression loss weight; represents the uncertainty parameter of the prediction; represents the true uncertainty parameter; represents the indicator function; Indicates the threshold value.
5. The defect detection method for blister tablets according to claim 1, characterized in that: The attention mechanism is expressed as: ; ; In the formula, represents the attention mechanism; represents the linear attention mechanism; Represents features of cross-scale fusion; Represents the fusion weight coefficient; Represents feature concatenation operation; Represents an upsampling operation; Represents low-resolution features; Represents high-resolution features.
6. The defect detection method for blister tablets according to claim 1, characterized in that: Add local enhancement terms, dynamic normalization terms, and feature interaction terms to the calculation formula of the attention mechanism.
7. The defect detection method for blister tablets according to claim 6, characterized in that: The calculation formula of the attention mechanism is expressed as: ; ; ; ; ; ; ; In the formula, Indicates The output of the position attention mechanism; Indicates the first feature points; Indicates The index vector of the positions; Represents the total number of vectors; Indicates the first feature points; Indicates the value vector feature points; Represents the weight parameter, which is used to control the impact of the cross term on the result; represents the displayed Q, K, and V interaction terms; represents the dynamic normalization term; represents the linear transformation of the query vector Q; Represents the input of the attention mechanism; Represents the linear transformation weight matrix of the query vector; represents a nonlinear activation function; represents the third hyperparameter; represents the fourth hyperparameter; represents a local enhancement term; represents the linear transformation of the key vector K; Represents the weight matrix of the linear transformation of the key vector; represents the linear transformation of the value vector V; Represents the weight matrix of the linear transformation of the value vector; Indicates The neighborhood feature set of each location; express No. The feature vector of the neighboring points; Indicates how the offset value is calculated; represents the norm; Represents an element-wise multiplication operation.
8. The defect detection method for blister tablets according to claim 1, characterized in that: The processing steps of the defect detection model include: performing feature extraction, feature fusion, and feature splicing on the blister tablet image in sequence to obtain spliced features; According to a preset size, upsampling is performed on the spliced features to obtain a high-resolution feature map; the high-resolution feature map is sequentially spliced in the feature channel direction and convolutionally fused to obtain a convolutionally fused feature map; the convolutionally fused feature map includes multi-scale fusion features of semantic information and spatial information; The feature map after the convolution fusion is sequentially subjected to two-dimensional convolution and normalization to obtain the defect detection result of the blister tablet.
9. A defect detection system for blister tablets, characterized in that: include: A data acquisition module is used to: acquire a blister tablet image; A defect detection module, used to: input the blister tablet image into a pre-built defect detection model, and output a defect detection result of the blister tablet; The model building module is used for: the building of the defect model includes: Get the yolov8 network model; The bounding box of the yolov8 network model is optimized by using the loss defined by the improved GFL function to obtain the optimized yolov8 network model; the improved GFL function is obtained by adding a nonlinear dynamic weight function to the GFL function; An attention mechanism is added to the neck network of the optimized yolov8 network model to obtain a constructed defect detection model; the attention mechanism is an attention mechanism that fuses high-resolution features and low-resolution features.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the defect detection method for blister tablets according to any one of claims 1 to 8 are implemented.
Citation Information
Cited By
Drug packaging defect detection method and device based on improved YOLOv11 model
CN121190437A