Tablet defect detection and rejection system, method, medium, product, and terminal
By using a target detection model with a three-stage network structure (backbone-neck-head) combined with a lightweight RepVGG network, the problems of missed detection, false detection, and detection universality in the tablet defect detection system are solved. This achieves efficient and accurate identification and removal of tablet defects, adapts to the detection needs of various drugs, and reduces drug waste.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SHANGHAI YUBEN INTELLIGENT TECH CO LTD
- Filing Date
- 2026-04-09
- Publication Date
- 2026-05-29
Smart Images

Figure CN122098950A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of pharmaceutical production quality testing technology, and in particular to a tablet defect detection and rejection system, method, medium, product and terminal. Background Technology
[0002] Pharmaceutical manufacturing is a complex and strictly controlled industry that directly impacts patient medication safety and health. Therefore, the entire production process requires multiple quality inspections to ensure the safety, efficacy, and consistency of drug quality. Bottled packaging, as the final stage of pharmaceutical production, is the last crucial line of defense in ensuring patient medication safety.
[0003] Despite multiple quality checks throughout the tablet manufacturing process, defects such as cracked tablets, broken tablets, discoloration, or size discrepancies can still occur during tableting, coating, and conveying stages. These defects not only affect the appearance of the tablets but can also directly compromise the accuracy and stability of the drug's dosage, thereby affecting its efficacy and posing a potential risk to patient safety. Therefore, integrating a high-precision defect detection system into the automated tablet counting machine is crucial. This system can perform a final comprehensive inspection of each tablet before it is bottled and released to the market, identifying and rejecting substandard products in real time. This ensures that the final medication delivered to patients is safe, effective, and of consistent quality, providing a fundamental guarantee for avoiding major drug safety incidents, complying with strict regulatory requirements, and maintaining the company's reputation.
[0004] In recent years, with the rapid development of artificial intelligence technology, the technology for detecting defects in pharmaceutical tablets based on AI vision has developed rapidly. It integrates deep learning, machine vision and automated control, aiming to achieve efficient and high-precision quality control in the pharmaceutical production process.
[0005] Currently, existing AI vision-based tablet defect detection systems, when applied in the actual tablet counting process of pharmaceutical factories, still suffer from numerous technical shortcomings due to various practical factors, failing to meet the demands of large-scale, high-efficiency factory production. Specific shortcomings are as follows:
[0006] (1) During the counting process, the tablets flow rapidly along the vibration channel at a high speed. The recognition speed of the existing AI detection system cannot match the tablet flow rate, which can easily lead to missed detections and false detections, making it difficult to achieve accurate detection of each tablet.
[0007] (2) There are many types of drugs in pharmaceutical production. The appearance characteristics and size parameters of different types of tablets vary greatly. In addition, there are various types of tablet defects, including macroscopic defects such as breakage and contamination, as well as micro-cracks and other minor defects. The existing AI detection system has limited recognition capabilities and cannot fully cover all types of drugs and defects, resulting in poor detection versatility.
[0008] (3) The existing system’s rejection method is relatively crude, often resulting in qualified tablets being mistakenly rejected and unqualified tablets not being effectively rejected, leading to low rejection efficiency and drug waste. Summary of the Invention
[0009] In view of the shortcomings of the prior art described above, the purpose of this application is to provide a tablet defect detection and rejection system, method, medium, product and terminal to solve the technical problems of existing tablet defect identification schemes, such as easy missed detection and false detection, limited identification ability and poor detection versatility.
[0010] To achieve the above and other related objectives, a first aspect of this application provides a pill defect detection and rejection system, comprising: an image acquisition module for acquiring drug image data; wherein the drug image data includes multiple pills to be identified; a target recognition module for performing a decoupling operation based on the drug image data and a target detection model to generate a target detection box corresponding to each pill to be identified, coordinate data corresponding to the target detection box, and a target category corresponding to the target detection box; wherein the target category includes a normal category and multiple defect categories; and a rejection control module for real-time tracking of each pill to be identified based on the coordinate data corresponding to the target detection box, and locking the pill to be identified corresponding to the target detection box whose target category is defective as a defective pill when a preset channel area is reached, thereby performing a rejection operation on the defective pill.
[0011] In some embodiments of the first aspect of this application, the target detection model includes a backbone network layer, a neck network layer, a head network layer, and a post-processing layer; wherein, the method of generating a target detection box corresponding to each drug tablet to be identified, coordinate data corresponding to the target detection box, and target category corresponding to the target detection box, based on the drug image data and the target detection model, includes: the backbone network layer performing feature extraction based on the drug image data to generate a multi-scale initial feature map; the neck network layer performing feature fusion based on the multi-scale initial feature map to generate a multi-scale classification feature map and a multi-scale regression feature map; the head network layer performing decoupling based on the multi-scale classification feature map and the multi-scale regression feature map to generate category probability values and bounding box correction parameters corresponding to each prediction anchor point in each scale space; and the post-processing layer performing filtering based on the category probability values and bounding box correction parameters corresponding to each prediction anchor point in each scale space to generate a target detection box corresponding to each drug tablet to be identified, coordinate data corresponding to the target detection box, and target category corresponding to the target detection box.
[0012] In some embodiments of the first aspect of this application, the backbone network layer adopts a lightweight RepVGG network; the lightweight RepVGG network includes a reparameterized composite module; the reparameterized composite module is formed by multiple convolutional basic modules connected in series; wherein each convolutional basic module is a multi-branch parallel structure, which enhances feature extraction capability through multi-branch paths during the training phase, and is fused into a single convolutional layer through structural reparameterization during the inference phase.
[0013] In some embodiments of the first aspect of this application, the neck network layer includes a neck classification branch and a neck regression branch; the feature fusion operation includes an upsampling operation and a downsampling operation; wherein, the method of performing the feature fusion operation to generate a multi-scale classification feature map and a multi-scale regression feature map based on the multi-scale initial feature map includes: the neck classification branch performing an upsampling operation based on the multi-scale initial feature map to generate a multi-scale first intermediate fused feature map; performing a downsampling operation based on the multi-scale first intermediate fused feature map to generate a multi-scale classification feature map; the neck regression branch performing an upsampling operation based on the multi-scale initial feature map to generate a multi-scale second intermediate fused feature map; and performing a downsampling operation based on the multi-scale second intermediate fused feature map to generate a multi-scale regression feature map.
[0014] In some embodiments of the first aspect of this application, the head network layer includes a head classification branch and a head regression branch; the multi-scale classification feature map and the multi-scale regression feature map share the same set of prediction anchor points in the corresponding scale space; wherein, the method of performing decoupling operations based on the multi-scale classification feature map and the multi-scale regression feature map to generate the class probability value and bounding box correction parameters corresponding to each prediction anchor point in each scale space includes: the head classification branch is used to perform a classification prediction operation based on the multi-scale classification feature map to generate the class probability value corresponding to each prediction anchor point in each scale space; the head regression branch is used to perform a bounding box regression prediction operation based on the multi-scale regression feature map to generate the bounding box correction parameters corresponding to each prediction anchor point in each scale space.
[0015] In some embodiments of the first aspect of this application, the method of performing a filtering operation based on the category probability value corresponding to each prediction anchor point in each scale space and the bounding box correction parameters to generate a target detection box corresponding to each pill to be identified, the coordinate data corresponding to the target detection box, and the target category corresponding to the target detection box includes: performing a decoding operation based on the bounding box correction parameters corresponding to each prediction anchor point in each scale space to generate multiple prediction candidate boxes corresponding to each pill to be identified and the coordinate data corresponding to each prediction candidate box; and determining the target category corresponding to each prediction candidate box and the confidence score of the target category based on the category probability value corresponding to each prediction anchor point; and determining the target category corresponding to each prediction candidate box and the confidence score of the target category based on the category probability value corresponding to each prediction anchor point; and determining the target category corresponding to each prediction candidate box and the target category corresponding to ... The coordinate data corresponding to the selection box, the target category corresponding to each of the predicted candidate boxes, and the confidence score of the target category are used. Based on a preset confidence threshold, a filtering operation is performed to generate multiple preferred detection boxes, the coordinate data corresponding to each preferred detection box, and the target category corresponding to each preferred detection box for each tablet to be identified. Based on the multiple preferred detection boxes, the coordinate data corresponding to each preferred detection box, and the target category corresponding to each preferred detection box for each tablet to be identified, a filtering operation is performed based on a non-maximum suppression algorithm to generate target detection boxes, the coordinate data corresponding to each target detection box, and the target category corresponding to each target detection box for each tablet to be identified.
[0016] To achieve the above and other related objectives, a second aspect of this application provides a method for detecting and removing defective tablets, comprising: acquiring drug image data; wherein the drug image data includes multiple tablets to be identified; performing a decoupling operation based on the drug image data and a target detection model to generate a target detection box corresponding to each tablet to be identified, coordinate data corresponding to the target detection box, and a target category corresponding to the target detection box; wherein the target category includes a normal category and multiple defect categories; tracking each tablet to be identified in real time based on the coordinate data corresponding to the target detection box, and locking the tablet to be identified corresponding to the target detection box whose target category is defective as a defective tablet when it reaches a preset channel area, thereby performing a removal operation on the defective tablet.
[0017] To achieve the above and other related objectives, a third aspect of this application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the tablet defect detection and rejection method described above.
[0018] To achieve the above and other related objectives, a fourth aspect of this application provides a computer program product comprising computer program code that, when executed on a computer, causes the computer to implement the tablet defect detection and rejection method as described above.
[0019] To achieve the above and other related objectives, a fifth aspect of this application provides an electronic terminal, including a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the tablet defect detection and rejection method described above.
[0020] As described above, the tablet defect detection and rejection system, method, medium, product, and terminal of this application have the following beneficial effects:
[0021] (1) The target detection model adopts a three-stage network structure of backbone-neck-head. It proposes a neck network path that separates classification and regression tasks, and learns multi-scale fusion modes respectively. It works in conjunction with the head network layer to complete the deep decoupling of classification and regression tasks, thereby adapting to tablets of different sizes and appearance features. This solves the problem of decreased recognition accuracy caused by the coupling interference of the two tasks, effectively improving the accuracy of tablet defect recognition and avoiding misjudgment and missed judgment caused by task coupling. At the same time, the target detection model can identify normal categories and multiple defect categories without the need for large-scale model adjustments for different types of tablets, improving the detection versatility of the system, adapting to the detection needs of various drugs in pharmaceutical companies, and reducing model adaptation costs.
[0022] (2) The detection box is filtered through the post-processing layer and redundant detection boxes are deleted to ensure that one target detection box corresponds to one tablet to be identified, thereby realizing the identification and positioning of each tablet to be identified, improving the identification speed and identification ability, avoiding missed detection and false detection, and improving the accuracy and efficiency of detection.
[0023] (3) The rejection control module tracks each tablet to be identified in real time based on the coordinate data corresponding to the target detection box. When the tablet reaches the preset channel area, it locks the tablet to be identified corresponding to the target detection box of the defect category as a defective tablet and rejects it by blowing air. At the same time, the control logic of each vibration channel is independent and does not interfere with each other, avoiding false rejection caused by interference between channels. In addition, the air-blowing rejection method only applies to defective tablets, ensuring that normal tablets can fall smoothly into the counting slot to complete the boxing, effectively improving rejection efficiency, reducing false rejection of qualified drugs and drug waste, reducing drug loss rate, and improving production efficiency. Attached Figure Description
[0024] Figure 1 The diagram shown is a schematic representation of a tablet defect detection and rejection system in one embodiment of this application.
[0025] Figure 2 The diagram shown is a flowchart illustrating the process of generating a target detection box in one embodiment of this application.
[0026] Figure 3 The diagram shown is a structural schematic of a target detection model in one embodiment of this application.
[0027] Figure 4 The diagram shown is a structural schematic of the RepVGG Block, a basic convolutional module, in one embodiment of this application.
[0028] Figure 5 The diagram shown is a flowchart illustrating the classification and regression decoupling process in one embodiment of this application.
[0029] Figure 6 The diagram shown is a schematic of a hardware imaging system according to an embodiment of this application.
[0030] Figure 7 The diagram shown is a schematic representation of the overall software architecture in one embodiment of this application.
[0031] Figure 8 The diagram shown is a schematic diagram of a multi-threaded analysis and processing mechanism in one embodiment of this application.
[0032] Figure 9 The diagram shown is a flowchart of a method for detecting and removing defects in pharmaceutical tablets in one embodiment of this application.
[0033] Figure 10 The diagram shown is a structural schematic of an electronic terminal according to an embodiment of this application.
[0034] Component designation explanation:
[0035] 1 Vibration-following channel
[0036] 2 LED strip lights
[0037] 3. Shielding layer
[0038] 4. Polarizing lens
[0039] 5 Industrial Cameras Detailed Implementation
[0040] The following specific examples illustrate the implementation of this application. Those skilled in the art can easily understand other advantages and effects of this application from the content disclosed in this specification. This application can also be implemented or applied through other different specific embodiments, and various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of this application. It should be noted that, unless otherwise specified, the following embodiments and features in the embodiments can be combined with each other.
[0041] In the embodiments of this application, the terms "first" and "second" are used to distinguish identical or similar items with essentially the same function and effect. Those skilled in the art will understand that the terms "first" and "second" do not limit the quantity or execution order, and that the terms "first" and "second" do not necessarily imply that they are different.
[0042] It should be noted that, in the embodiments of this application, the words "exemplary" or "for example" indicate examples, illustrations, or descriptions. Any embodiment or design described as "exemplary" or "for example" in this application should not be construed as being more preferred or advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present the relevant concepts in a concrete manner.
[0043] Before providing a further detailed description of the present invention, the nouns and terms used in the embodiments of the present invention are explained, and the nouns and terms used in the embodiments of the present invention are subject to the following interpretations:
[0044] <1> Sigmoid: A sigmoid activation function, it is a commonly used non-linear activation function used to map features to the 0-1 interval.
[0045] <2> Mish: The Mish activation function is a smooth, non-linear activation function used to enhance the feature representation capabilities of a network.
[0046] <3> LED (Light Emitting Diode): A light-emitting diode used to provide illumination or indication.
[0047] <4> CCD (Charge-Coupled Device): refers to a charge-coupled device, which is a type of image sensor used to acquire image signals.
[0048] <5> Voice: refers to voice signals or audio signals used for audio-related data transmission and processing.
[0049] <6> Ne: Hardware control services, used to implement signal output functions such as device status indication and light prompts, and are uniformly scheduled and controlled by the main engine layer.
[0050] <7> GPIO (General-Purpose Input / Output): refers to a general-purpose input / output interface used to implement the input and output of hardware control signals.
[0051] <8> UDP (User Datagram Protocol): refers to the User Datagram Protocol, a connectionless transport layer communication protocol.
[0052] To facilitate understanding of the embodiments of this application, firstly, in conjunction with Figure 1 Detailed explanation. Figure 1 A schematic diagram of the structure of a tablet defect detection and rejection system according to an embodiment of the present invention is shown. The tablet defect detection and rejection system 100 in this embodiment includes:
[0053] The image acquisition module 101 is used to acquire drug image data; wherein, the drug image data includes multiple drug tablets to be identified.
[0054] The target recognition module 102 is used to perform a decoupling operation based on the drug image data and the target detection model to generate a target detection box corresponding to each drug tablet to be identified, coordinate data corresponding to the target detection box, and target category corresponding to the target detection box; wherein, the target category includes normal category and multiple defect categories.
[0055] The rejection control module 103 is used to track each of the tablets to be identified in real time according to the coordinate data corresponding to the target detection box. When the target detection box with the target category of defective category is reached, the tablet to be identified is locked as a defective tablet, and the defective tablet is rejected accordingly.
[0056] In this embodiment, the image acquisition module 101 acquires drug image data from each vibration-following channel in the vibration-following conveyor. The image acquisition module 101 can use multiple cameras for joint acquisition, covering all vibration-following channels in the vibration-following conveyor. The cameras used are industrial high-frame-rate CCD area array cameras, and the acquisition is performed using multiple high-frame-rate cameras in conjunction.
[0057] In this embodiment, the target category includes a normal category and multiple defect categories. The normal category indicates that the tablets are qualified, and the various defect categories correspond to different types of tablet defects, such as missing corners, cracks, chipped edges, stains, color differences, pitting, deformation, etc.
[0058] In this embodiment, as Figure 2 The diagram illustrates the process of generating a target detection box in an embodiment of the present invention. Figure 3 The diagram illustrates the structure of the target detection model in an embodiment of the present invention. The target detection model includes a backbone network layer, a neck network layer, a head network layer, and a post-processing layer. The method for generating a target detection box corresponding to each drug image, coordinate data corresponding to the target detection box, and the target category corresponding to the target detection box, based on the drug image data and the target detection model, includes:
[0059] S201: The backbone network layer is used to perform feature extraction operations based on the drug image data to generate a multi-scale initial feature map.
[0060] In this embodiment, the backbone network layer adopts a lightweight RepVGG network; the lightweight RepVGG network includes a reparameterized composite module (RepBlock); the reparameterized composite module (RepBlock) is formed by multiple convolutional basic modules (RepVGG Blocks) connected in series; wherein, each convolutional basic module (RepVGG Block) is a multi-branch parallel structure, which enhances feature extraction capability through multi-branch paths during the training phase, and is fused into a single convolutional layer through structural reparameterization during the inference phase.
[0061] In this embodiment, the target detection model adopts a three-stage network structure of backbone-neck-head. Its backbone network layer adopts a lightweight RepVGG network, which is a convolutional neural network. During the training phase, a multi-branch structure is used to help optimize the network, and during the inference / deployment phase, these branches are merged into a single convolutional layer through structural reparameterization.
[0062] In this embodiment, as Figure 4 The diagram illustrates the structure of the RepVGG Block, a convolutional basic module, in an embodiment of the present invention. The main component of the lightweight RepVGG network is the Reparameterized Composite Module (RepBlock), which is formed by cascading multiple RepVGG Blocks. Each RepVGG Block is a multi-branch parallel structure, including a 3x3 convolutional layer (main branch, i.e., 3x3 Conv), a 1x1 convolutional layer (identity mapping branch, i.e., 1x1 Conv), and a cross-mini-batch normalization layer (CmBN). The 3x3 Conv and 1x1 Conv are each connected to a cross-mini-batch normalization layer (CmBN). During training, the training data flows through these three branches simultaneously, and the outputs of the three branches are summed before being passed through an activation function (Mish). This multi-branch structure provides a rich gradient flow during training, enhancing feature representation and helping the model learn more powerful feature representations.
[0063] In this embodiment, after training, during the inference phase, the entire multi-branch convolutional base module (RepVGGBlock) is reparameterized and fused into a single 3x3 convolutional layer. Specifically, the 1x1 convolutional layer is zero-padded to a 3x3 convolutional layer; the parameters (such as mean, variance, scaling factor, and bias) of the cross-mini-batch normalization layer (CmBN) of each branch are absorbed into the weights and biases of the corresponding convolutional layer; and the convolutional layers of the three branches and the cross-mini-batch normalization layer (CmBN) are all fused into a single 3x3 convolutional layer and a bias term. Finally, the entire reparameterized composite module (RepBlock) becomes a series of consecutive 3x3 convolutional layers during inference. Therefore, only a series of efficient 3x3 convolutional operations need to be performed during inference, achieving lightweight and high-speed inference. This is used to extract multi-scale initial feature maps from pharmaceutical image data, thereby reducing computational overhead and increasing inference speed while ensuring detection accuracy, making it suitable for industrial vision scenarios such as real-time object detection.
[0064] In this embodiment, the multi-scale initial feature maps include a small-scale initial feature map C5, a medium-scale initial feature map C4, and a large-scale initial feature map C3. These three feature maps summarize target features at large, medium, and small scales, respectively, in their feature spaces. For example, the large-scale initial feature map C3 has a relatively large size (e.g., 52×52) and contains rich spatial details. The medium-scale initial feature map C4 has a medium size (e.g., 26×26) and combines semantics and details. The small-scale initial feature map C5 has the smallest size (e.g., 13×13) and the strongest semantics.
[0065] S202: The neck network layer is used to perform feature fusion operations based on the multi-scale initial feature map to generate multi-scale classification feature maps and multi-scale regression feature maps.
[0066] In this embodiment, as Figure 5 The diagram illustrates the classification and regression decoupling process in an embodiment of the present invention. Figure 5 In this context, U represents upsampling, C represents concatenation (cascading), Conv represents convolution, and RepBlock is a reparameterized composite module, whose principle is the same as that of the reparameterized composite module (RepBlock) in the backbone network layer, and will not be elaborated here. The neck network layer includes a neck classification branch and a neck regression branch; the feature fusion operation includes upsampling and downsampling operations; wherein, based on the multi-scale initial feature map, the feature fusion operation is performed to generate multi-scale classification feature maps and multi-scale regression feature maps in the following ways:
[0067] (1) The neck classification branch is used to perform an upsampling operation based on the multi-scale initial feature map to generate a multi-scale first intermediate fusion feature map; and to perform a downsampling operation based on the multi-scale first intermediate fusion feature map to generate a multi-scale classification feature map.
[0068] (2) The neck regression branch is used to perform an upsampling operation based on the multi-scale initial feature map to generate a multi-scale second intermediate fusion feature map; and to perform a downsampling operation based on the multi-scale second intermediate fusion feature map to generate a multi-scale regression feature map.
[0069] In this embodiment, the backbone network layer performs feature extraction operations on the drug image data to generate multi-scale initial feature maps (small-scale initial feature map C5, medium-scale initial feature map C4, and large-scale initial feature map C3).
[0070] In this embodiment, initial feature maps at each scale are input into the neck classification branch (PANetCLS) and the neck regression branch (PANetREG), respectively. At this stage, the model analyzes multi-scale fusion methods, establishes a fusion mode that separates classification and regression, and performs deep fusion of the initial feature maps at each scale through upsampling and downsampling. The classification and regression branches learn different fusion modes respectively. The neck classification branch (PANetCLS) sequentially performs upsampling and downsampling operations on the initial feature maps at each scale to generate multi-scale classification feature maps. The neck regression branch (PANetREG) sequentially performs upsampling and downsampling operations on the initial feature maps at each scale to generate multi-scale regression feature maps.
[0071] In this embodiment, the neck classification branch (PANetCLS) is used as an example to illustrate the upsampling operation process:
[0072] (1) Align the initial small-scale feature map C5 with the channel dimensions to obtain the first intermediate fusion feature map N5 at the small scale, and perform convolution processing (Conv) on the first intermediate fusion feature map N5 at the small scale.
[0073] (2) Perform an upsampling operation (U) on the low-resolution feature map N5 after convolution (Conv) to make its size consistent with the initial feature map C4 at the medium scale. Then, concatenate the features after the upsampling operation with the initial feature map C4 at the medium scale (C) and perform feature fusion through the reparameterized composite module (RepBlock) to obtain the first intermediate fused feature map N4 at the medium scale.
[0074] (3) After performing convolution processing (Conv) on the first intermediate fusion feature map N4 at the medium scale, an upsampling operation (U) is performed to make its size consistent with the initial feature map C3 at the large scale. The features after the upsampling operation are concatenated with the initial feature map C3 at the large scale (C), and then fused through the reparameterized composite module (RepBlock) to obtain the first intermediate fusion feature map N3 at the large scale.
[0075] In this embodiment, the upsampling operation typically employs nearest neighbor interpolation or bilinear interpolation. Nearest neighbor interpolation is an upsampling method that works by directly selecting the nearest original pixel value at the target location as the new pixel value when scaling up a low-resolution feature map to a high-resolution size, without performing any numerical calculations or weighting. This algorithm achieves size expansion by copying neighboring feature values, resulting in minimal computation, maximum speed, and preservation of the feature map's edge and structural information.
[0076] In this embodiment, the bilinear interpolation algorithm performs linear interpolation once in each of the two dimensions, and finally obtains the new feature value of the target position by weighted summation of the four nearest neighbor pixels. The principle is as follows: weights are assigned according to the distance between the target point and the four original pixels, with closer distances resulting in higher weights. Weighted fusion yields a smooth interpolation result. This algorithm can generate smooth, continuous, and jagged-free high-resolution feature maps, preserving more complete feature information, and is the most commonly used upsampling method in deep learning.
[0077] In this embodiment, the neck classification branch (PANetCLS) performs upsampling operations on the multi-scale initial feature maps (C5, C4, C3). This process proceeds layer by layer upwards (i.e., from bottom to top), starting with the deepest, most semantically informative small-scale feature map output from the backbone network layer. It first performs upsampling operations, then concatenates it with the shallow feature map of the same scale output from the backbone network layer, and finally fuses it through a reparameterized composite module (RepBlock). This injects high-level semantic information into the low-level features, enhancing the detection capability of small targets, to obtain the multi-scale first intermediate fused feature maps, namely, the small-scale first intermediate fused feature map N5, the medium-scale first intermediate fused feature map N4, and the large-scale first intermediate fused feature map N3.
[0078] In this embodiment, the process of upsampling the multi-scale initial feature maps (C5, C4, C3) in the neck regression branch (PANetREG) is the same as that in the neck classification branch (PANetCLS). Both adopt a bottom-up path, starting from the deepest and most semantically informative small-scale feature map output from the backbone network layer. First, an upsampling operation is performed, then it is concatenated with the shallow feature map of the same scale output from the backbone network layer, and finally fused through a reparameterized composite module (RepBlock) to generate multi-scale second intermediate fused feature maps, namely, small-scale second intermediate fused feature map N5', medium-scale second intermediate fused feature map N4', and large-scale second intermediate fused feature map N3'.
[0079] In this embodiment, the neck classification branch (PANetCLS) is used as an example to illustrate the downsampling operation process:
[0080] (1) Perform a downsampling operation on the large-scale first intermediate fusion feature map N3 so that its size is consistent with the medium-scale first intermediate fusion feature map N4, and obtain the large-scale classification feature map P3.
[0081] (2) After convolution processing (Conv) on the large-scale classification feature map P3, it is concatenated (C) with the first intermediate fusion feature map N4 of the medium scale, and then the feature is fused through the reparameterized composite module (RepBlock) to obtain the medium-scale classification feature map P4.
[0082] (3) After performing downsampling and convolution processing (Conv) on the medium-scale classification feature map P4, it is concatenated with the first intermediate fusion feature map N5 of the small scale (C), and then fused through the reparameterized composite module (RepBlock) to obtain the small-scale classification feature map P5.
[0083] In this embodiment, the downsampling operation is typically implemented using a 3×3 convolutional kernel with a stride of 2. When performing convolution calculations on the feature map, the stride of the convolutional kernel is set to 2 each time it slides across the feature map. That is, after each convolution operation, the kernel skips one pixel position in both the horizontal and vertical directions before performing the next operation. Simultaneously, a 3×3 convolutional kernel is used to extract features within the local receptive field. By controlling the stride, the size of the output feature map is reduced, making both the width and height of the output feature map half the size of the input feature map, thereby achieving a downsampling effect that reduces the feature map size.
[0084] In this embodiment, the neck classification branch (PANetCLS) performs downsampling operations on the multi-scale first intermediate fusion feature maps (N5, N4, N3) to obtain multi-scale classification feature maps, namely, large-scale classification feature map P3, medium-scale classification feature map P4, and small-scale classification feature map P5. A top-down approach is adopted, downsampling the results obtained from the upsampling operation, then concatenating them with the feature maps of the same scale from the previous stage, and finally fusing them through a reparameterized composite module (RepBlock). This process proceeds layer by layer downwards, injecting high-level semantic information into low-level features, enhancing the detection capability of small targets, and transferring precise localization information to high-level features, thus helping to improve localization accuracy.
[0085] In this embodiment, the process of the neck regression branch (PANetREG) performing downsampling on the multi-scale second intermediate fused feature map is the same as that of the neck classification branch (PANetCLS). Both adopt a top-down path, downsampling the result obtained from the upsampling operation, then concatenating it with the feature map of the same scale from the previous stage, and then fusing it through a reparameterized composite module (RepBlock) to generate multi-scale regression feature maps, namely large-scale regression feature map P3', medium-scale regression feature map P4', and small-scale regression feature map P5'.
[0086] S203: The head network layer is used to perform a decoupling operation based on the multi-scale classification feature map and the multi-scale regression feature map to generate the class probability value and bounding box correction parameters corresponding to each prediction anchor point in each scale space.
[0087] In this embodiment, the decoupled head includes a head classification branch and a head regression branch; the multi-scale classification feature map and the multi-scale regression feature map share the same set of prediction anchor points in their respective scale spaces; wherein, the method of performing decoupling operations based on the multi-scale classification feature map and the multi-scale regression feature map to generate the class probability values and bounding box correction parameters corresponding to each prediction anchor point in each scale space includes:
[0088] (1) The head classification branch is used to perform classification prediction operation based on the multi-scale classification feature map to generate the category probability value corresponding to each prediction anchor point in each scale space.
[0089] (2) The head regression branch is used to perform box regression prediction operation based on the multi-scale regression feature map to generate bounding box correction parameters corresponding to each prediction anchor point in each scale space.
[0090] In this embodiment, the head classification branch (CLS head) receives the multi-scale classification feature map output by the neck classification branch (PANetCLS), and the head regression branch (REG head) receives the multi-scale regression feature map output by the neck regression branch (PANetREG). A shared 1x1 convolutional layer (1x1 Conv) is used to reduce the number of feature map channels from the neck network layer. Then, the feature maps are fed into a 3x3 convolutional layer (3x3 Conv) and a 1x1 convolutional layer (1x1 Conv), respectively. The head classification branch outputs the class probability value corresponding to each prediction anchor point in each scale space. The head regression branch outputs the bounding box correction parameters corresponding to each prediction anchor point in each scale space.
[0091] In this embodiment, the neck network layer outputs three sets of feature maps at corresponding scales: a large-scale classification feature map P3, a medium-scale classification feature map P4, a small-scale classification feature map P5, and a feature map corresponding to the above classification features. Figure 1 There are corresponding large-scale regression feature maps P3', P4', and P5'. The multi-scale classification feature maps and multi-scale regression feature maps share the same set of prediction anchor points in their corresponding scale spaces. The large-scale classification feature map P3' and the large-scale regression feature map P3' share the same set of large-scale prediction anchor points; the medium-scale classification feature map P4' and the medium-scale regression feature map P4' share the same set of medium-scale prediction anchor points; and the small-scale classification feature map P5' and the small-scale regression feature map P5' share the same set of small-scale prediction anchor points. The position coordinates of the same set of prediction anchor points on the corresponding scale's classification and regression feature maps are the same.
[0092] In this embodiment, the head classification branch receives multi-scale classification feature maps (P3, P4, P5) output from the neck network layer. Through a shared 1x1 convolutional layer, a 3x3 convolutional layer, and a 1x1 convolutional layer, it sequentially performs classification prediction operations on each scale's feature map, extracting the class features corresponding to each prediction anchor point. This yields the class probability value for each position (i.e., each prediction anchor point) on the classification feature map at each scale. This class probability value is a C-dimensional vector representing the probability that the prediction anchor point belongs to each target class, where C is the number of target classes (i.e., num_classes). Subsequently, this C-dimensional vector is normalized using the Sigmoid function, normalizing each value in the vector to the range [0, 1]. The final output is a class probability matrix with dimensions (3, N*N, num_classes). It should be noted that "3" represents three scales (large scale, medium scale, and small scale), "N*N" represents the number of prediction anchors at each scale, and "num_classes" represents the number of target categories, which is the sum of the number of normal categories and the number of defective categories. Each normalized value in the matrix represents the probability value of the corresponding prediction anchor belonging to a certain target category at the corresponding scale. The larger the probability value, the higher the likelihood that the region corresponding to the prediction anchor belongs to that target category.
[0093] In this embodiment, the number of prediction anchor points at each scale is determined by the size of the corresponding scale feature map. For example, the large-scale classification feature map P3 has a size of 80×80 and the corresponding number of prediction anchor points is 80×80=6400; the medium-scale classification feature map P4 has a size of 40×40 and the corresponding number of prediction anchor points is 40×40=1600; and the small-scale classification feature map P5 has a size of 20×20 and the corresponding number of prediction anchor points is 20×20=400.
[0094] In this embodiment, the head regression branch receives multi-scale regression feature maps (P3', P4', P5') output from the neck network layer. Through a shared 1x1 convolutional layer, a 3x3 convolutional layer, and a 1x1 convolutional layer, it sequentially performs bounding box regression prediction operations on each set of scale regression feature maps, extracting the positional features corresponding to each prediction anchor point. This yields bounding box correction parameters for each position (i.e., each prediction anchor point) on the regression feature map at each scale. These bounding box correction parameters are 4-dimensional vectors representing the distances of the predicted bounding box relative to the four sides of the prediction anchor point, typically denoted as (l, t, r, b). Here, l represents the distance from the prediction anchor point to the left boundary of the predicted bounding box, t represents the distance from the prediction anchor point to the top boundary of the predicted bounding box, r represents the distance from the prediction anchor point to the right boundary of the predicted bounding box, and b represents the distance from the prediction anchor point to the bottom boundary of the predicted bounding box. The head regression branch ultimately outputs a bounding box correction parameter matrix of dimension (3, N*N, 4), which is used to subsequently correct the positions of the prediction anchor points to obtain the predicted bounding boxes, i.e., the prediction candidate boxes. It should be noted that "3" represents three scales (large scale, medium scale, and small scale), "N*N" represents the number of prediction anchor points at each scale, and 4 represents the number of bounding box correction parameters.
[0095] S204: The post-processing layer is used to perform a filtering operation based on the category probability value corresponding to each predicted anchor point in each scale space and the bounding box correction parameters, so as to generate a target detection box corresponding to each pill to be identified, the coordinate data corresponding to the target detection box, and the target category corresponding to the target detection box.
[0096] In this embodiment, the filtering operation is performed based on the category probability value corresponding to each predicted anchor point in each scale space and the bounding box correction parameters to generate the target detection box corresponding to each pill to be identified, the coordinate data corresponding to the target detection box, and the target category corresponding to the target detection box. The method includes:
[0097] (1) Based on the bounding box correction parameters corresponding to each prediction anchor point in each scale space, perform decoding operation to generate multiple prediction candidate boxes corresponding to each pill to be identified and the coordinate data corresponding to each prediction candidate box. Based on the category probability value corresponding to each prediction anchor point, determine the target category corresponding to each prediction candidate box and the confidence score of the target category.
[0098] (2) Based on the coordinate data corresponding to each of the predicted candidate boxes, the target category corresponding to each of the predicted candidate boxes and the confidence score of the target category, and based on the preset confidence threshold, a filtering operation is performed to generate multiple preferred detection boxes corresponding to each drug to be identified, the coordinate data corresponding to each preferred detection box and the target category corresponding to each preferred detection box.
[0099] (3) Based on the multiple preferred detection boxes corresponding to each of the tablets to be identified, the coordinate data corresponding to each preferred detection box, and the target category corresponding to each preferred detection box, and based on the non-maximum suppression algorithm, a filtering operation is performed to generate the target detection box corresponding to each tablet to be identified, the coordinate data corresponding to the target detection box, and the target category corresponding to the target detection box.
[0100] In this embodiment, each prediction anchor point corresponds to a pixel in the feature map, and the coordinates of this pixel are the center coordinates of the prediction anchor point. The prediction anchor point is the original candidate bounding box centered on the pixel in the feature map. Each prediction anchor point corresponds to a specific location in the drug image data, and its mapping relationship is determined by the stride of the feature map.
[0101] In this embodiment, taking the large-scale classification feature map P3 as an example, for the predicted anchor point on the large-scale classification feature map P3, the center coordinates of the predicted anchor point in the drug image data are calculated:
[0102] Formula (1)
[0103] Where i represents the row index of the predicted anchor point on the large-scale classification feature map; j represents the column index of the predicted anchor point on the large-scale classification feature map; stride represents the step size; x_center represents the horizontal center coordinate of the predicted anchor point in the drug image data; and y_center represents the vertical center coordinate of the predicted anchor point in the drug image data.
[0104] In this embodiment, the decoding operation involves correcting the bounding box parameters (l, t, r, b) corresponding to each predicted anchor point, and combining these parameters with the center coordinates (x_center, y_center) of the predicted anchor point in the drug image data to obtain multiple predicted candidate boxes for each drug tablet to be identified, as well as the coordinate data of each predicted candidate box in the drug image data. The method includes:
[0105] Formula (II)
[0106] Where x_center represents the horizontal center coordinate of the predicted anchor point in the drug image data; y_center represents the vertical center coordinate of the predicted anchor point in the drug image data; l represents the distance from the predicted anchor point to the left boundary of the predicted bounding box; t represents the distance from the predicted anchor point to the top boundary of the predicted bounding box; r represents the distance from the predicted anchor point to the right boundary of the predicted bounding box; b represents the distance from the predicted anchor point to the bottom boundary of the predicted bounding box; x_min represents the left boundary x-coordinate of the predicted candidate box in the drug image data; y_min represents the top boundary y-coordinate of the predicted candidate box in the drug image data; x_max represents the right boundary x-coordinate of the predicted candidate box in the drug image data; and y_max represents the bottom boundary y-coordinate of the predicted candidate box in the drug image data.
[0107] In this embodiment, (x_min, y_min) and (x_max, y_max) together constitute the diagonal vertex coordinates of the predicted candidate box, which are used to determine the position and range of the predicted candidate box in the original drug image.
[0108] In this embodiment, the predicted candidate box is the predicted bounding box corresponding to the predicted anchor point. Based on the category probability value corresponding to the predicted anchor point, the highest category probability value is used as the confidence score, and the corresponding target category is recorded to determine the target category corresponding to the predicted candidate box and the confidence score of that target category. For example, if the category probability value of the "normal category" corresponding to a certain predicted anchor point is 0.92, which is higher than the category probability values of other defect categories, then the target category of the predicted candidate box corresponding to that predicted anchor point is determined to be the normal category, and the confidence score is 0.92.
[0109] In this embodiment, to filter out invalid candidate boxes with low confidence and insufficient prediction accuracy, the confidence score of the target category corresponding to each predicted candidate box is compared with a preset confidence threshold (e.g., 0.5). Predicted candidate boxes with confidence scores greater than or equal to the preset confidence threshold are retained, while those with confidence scores less than the preset confidence threshold are discarded. The retained predicted candidate boxes are the preferred detection boxes, and their corresponding coordinate data and target categories remain unchanged. Finally, multiple preferred detection boxes and associated data (such as coordinate data, target category, and confidence score) corresponding to each pill to be identified are generated.
[0110] In this embodiment, a non-maximum suppression algorithm is used. For each of the multiple preferred detection boxes corresponding to the tablet to be identified, they are first sorted in descending order according to their confidence scores. The preferred detection box with the highest confidence score is selected as the initial target detection box. Then, the intersection-over-union (IoU) ratio between the initial target detection box and all the remaining preferred detection boxes is calculated. According to a preset IoU threshold (e.g., 0.3), if the IoU ratio between the remaining preferred detection boxes and the initial target detection box is greater than or equal to the preset IoU threshold, it indicates that the two detection boxes have too high overlap and belong to redundant predictions for the same tablet to be identified. The overlapping preferred detection boxes are then removed. If the IoU ratio between the remaining preferred detection boxes and the initial target detection box is less than the preset IoU threshold, it indicates that the two detection boxes correspond to different regions. The preferred detection box is then retained. The above steps are repeated until all redundant preferred detection boxes are removed. Each remaining preferred detection box is the target detection box corresponding to each tablet to be identified, so that one target detection box corresponds to one tablet to be identified. After screening using a non-maximum suppression algorithm, each remaining preferred detection box is the final detection result, which includes coordinate data, target category, and confidence score.
[0111] In this embodiment, the target detection model identifies the target detection box corresponding to each tablet to be identified, the coordinate data corresponding to the target detection box, and the target category corresponding to the target detection box. The rejection control module tracks the tablets to be identified in real time based on the coordinate data corresponding to the target detection box, comparing the coordinate data of each target detection box with the preset channel area (rectangular range) of the corresponding vibration-following channel in real time to determine the current position of the tablet to be identified. When the target detection box of a tablet to be identified is tracked into the preset channel area of the corresponding vibration-following channel, the target category corresponding to that target detection box is retrieved. If the target category is normal (the tablet is qualified), no operation is performed, and the tablet is conveyed normally with the conveyor belt. If the target category is defective (such as missing corners, stains, cracks, etc.), the tablet to be identified corresponding to that target detection box is immediately locked as a defective tablet, and its channel number and position are recorded.
[0112] In this embodiment, a multi-hole air-blowing device is installed on the vibration-following conveyor. The various vibration-following channels in the conveyor are arranged at intervals, with each air-blowing hole corresponding to a single channel. When normal tablets pass through a vibration-following channel, they naturally fall into the counting slot below for counting and boxing. When a defective tablet reaches the preset start line of its corresponding vibration-following channel, the air-blowing hole of that channel triggers an air-blowing signal. The defective tablet falls near the edge and is blown forward by the air-blowing hole during its fall, thus entering the waste tablet box.
[0113] In this embodiment, the locked defective tablet moves continuously along the conveyor belt in its respective vibration-following channel. When the rejection control module detects that the target detection frame of the defective tablet has reached the preset start line of its respective vibration-following channel, it sends a blowing signal to the corresponding blowing hole of the vibration-following channel to start the blowing device. The defective tablet continues to move along the conveying direction with the assistance of the blowing airflow. When the rejection control module detects that the target detection frame of the defective tablet has reached the preset stop line of its respective vibration-following channel, it sends a stop trigger signal to the corresponding blowing hole of the vibration-following channel to shut down the blowing device and stop the airflow output. At this point, the defective tablet, under the combined action of the airflow thrust and its own inertia, deviates from the normal conveying track and falls into the corresponding waste pill box, completing the real-time dynamic rejection operation. Because the control logic of each vibration-following channel is independent, this operation only affects the single vibration-following channel where the defective tablet is currently located, and will not interfere with the tablet conveying in other vibration-following channels, ensuring the stability and parallelism of the system operation.
[0114] It is worth noting that the tablet defect detection and rejection system of this application has the following advantages:
[0115] (1) The target detection model adopts a three-stage network structure of backbone-neck-head. It proposes a neck network path that separates classification and regression tasks, and learns multi-scale fusion modes respectively. It works in conjunction with the head network layer to complete the deep decoupling of classification and regression tasks, thereby adapting to tablets of different sizes and appearance features. This solves the problem of decreased recognition accuracy caused by the coupling interference of the two tasks, effectively improving the accuracy of tablet defect recognition and avoiding misjudgment and missed judgment caused by task coupling. At the same time, the target detection model can identify normal categories and multiple defect categories without the need for large-scale model adjustments for different types of tablets, improving the detection versatility of the system, adapting to the detection needs of various drugs in pharmaceutical companies, and reducing model adaptation costs.
[0116] (2) The detection box is filtered through the post-processing layer and redundant detection boxes are deleted to ensure that one target detection box corresponds to one tablet to be identified, thereby realizing the identification and positioning of each tablet to be identified, improving the identification speed and identification ability, avoiding missed detection and false detection, and improving the accuracy and efficiency of detection.
[0117] (3) The rejection control module tracks each tablet to be identified in real time based on the coordinate data corresponding to the target detection box. When the tablet reaches the preset channel area, it locks the tablet to be identified corresponding to the target detection box of the defect category as a defective tablet and rejects it by blowing air. At the same time, the control logic of each vibration channel is independent and does not interfere with each other, avoiding false rejection caused by interference between channels. In addition, the air-blowing rejection method only applies to defective tablets, ensuring that normal tablets can fall smoothly into the counting slot to complete the boxing, effectively improving rejection efficiency, reducing false rejection of qualified drugs and drug waste, reducing drug loss rate, and improving production efficiency.
[0118] The following describes the overall technical framework of a tablet defect detection and rejection system, using an example:
[0119] In this embodiment, as Figure 6 The diagram illustrates a hardware imaging system in an embodiment of the present invention. The image acquisition module 101 constitutes the hardware imaging system of this invention and is a prerequisite for accurate AI visual judgment, used to acquire high-quality, low-reflectivity drug image data. In the pharmaceutical counting and packaging process, the various follow-up channels of the vibration conveyor are made of smooth, glossy metal, which is highly reflective and causes visual interference. Therefore, in terms of light source design, this hardware imaging system adopts an inverted pyramid box structure, mounted above the follow-up channel 1, as shown... Figure 6 As shown, four sets of LED strip lights 2 form a ring-shaped light group on the upper part of the box. The light shines towards the center, and after reflection from the inner surface of the box and the sides, it is concentrated to form a multi-angle light source. Utilizing the principle of diffuse reflection, it avoids strong glare caused by direct light. In addition, a polarizing lens 4 is installed below the holes in the shielding layer 3 to reduce the impact of reflection. In terms of camera selection, this hardware imaging system uses multi-camera joint acquisition. Multiple industrial cameras 5 cover all vibration-following channels of the vibration-following conveyor. The industrial cameras 5 are high-frame-rate CCD area array cameras. Through high-frame-rate multi-camera joint acquisition, the software algorithm can analyze and eliminate defects in real time.
[0120] In this embodiment, as Figure 7 The diagram illustrates the overall software architecture in this embodiment of the invention. The target recognition module is implemented based on a software algorithm analysis system, employing a layered, multi-threaded parallel architecture to ensure the real-time performance of AI inference and system stability. The overall software architecture adopts a four-layer layered architecture, including:
[0121] (1) Main Engine Layer: This layer implements global scheduling through the component manager, configuration parser, command receiving service, and other services (Voice, Ne, GPIO, etc.). As the system initiator and lifecycle manager, it is used for overall scheduling of the lifecycle of each component, listening for UDP commands and distributing them to the corresponding components, initializing configuration parsing and logging systems, and starting services. Among them, the component manager realizes component lifecycle management and connection management by dynamically loading plugins, creating and initializing components, establishing data flow connections between components, and managing component start and stop.
[0122] (2) Component Layer: This layer includes a standard processing chain, a task processing component, and a scheduling component. The standard processing chain is a chained process of real-time image data acquisition, AI recognition, and data extraction, enabling image acquisition, image transmission, and AI recognition to determine whether the pills are defective. The task processing component is used for intrusion detection, signal analysis, and scene analysis. Based on the recognition results obtained from the standard recognition process, it performs specific scene analysis and distributes control tasks and network transmission tasks.
[0123] (3) Data Flow Layer: Data is transmitted in the form of message body data structure through thread-safe queues in each standard processing chain component. The thread-safe queue implements the producer-consumer pattern, controls each component to process data in real time and dynamically, and increases data security and liquidity.
[0124] (4) Hardware interface layer: integrates various hardware driver environments and controls hardware interface outputs such as camera acquisition, GPIO signal input and output, and audio playback.
[0125] Through the above software architecture design, a stable structure is formed that integrates engine management, hierarchical control, data standard circulation, and hardware integration. Compared with a single-structure software design, this structure can cope with various risks, further improves code robustness, and is the main guarantee for the effectiveness of the algorithm.
[0126] In this embodiment, as Figure 8 The diagram illustrates the multi-threaded analysis and processing mechanism in an embodiment of the present invention. To achieve real-time dynamic acquisition from multiple cameras, AI recognition, and real-time dynamic removal, this software architecture employs a multi-threaded analysis and processing mechanism, as shown below. Figure 8 As shown, a parallel structure is adopted, with the main thread controlling each sub-thread group. The main thread is the Engine thread, and the sub-thread groups include: an acquisition thread group, an identification thread group, a task analysis thread group, and a storage thread group. Each thread group processes its own task in parallel, and each thread group has independent task threads based on different functional elements. Specifically, the acquisition thread group has an independent acquisition thread for each individual camera. The identification thread group is divided into an AI inference thread, an image preprocessing thread, and a post-processing thread, achieving independent task parallelism and accelerating processing speed. The task thread group is divided into a scene analysis thread, an alarm processing thread, and a data upload thread (front end). The storage thread group includes an image saving thread, a video recording thread, and a data cleaning thread (storage monitoring). The multi-threaded analysis and processing mechanism ensures parallel task processing, and data distribution synchronization relies on thread-safe queues and a producer-consumer pattern, which maximizes the utilization of the controller's computing power and data resources, achieving millisecond-level identification and control response.
[0127] Existing AI detection systems are complex to deploy and configure, require highly skilled operators, and have long debugging cycles for adapting to different production lines and drug types, hindering rapid deployment in factories and making it difficult to meet flexible production needs. The hardware imaging system of this invention, acting as the producer of the detected materials, ensures real-time acquisition of high-definition images at high frame rates, a prerequisite for high-precision and high-speed detection. It employs diffuse reflection and polarization principles to avoid direct light irradiation on highly reflective materials. At the software architecture level, a layered architecture design ensures independent and orderly interaction between components. A multi-threaded analysis and processing mechanism facilitates tasks, and parallel computing among components improves resource utilization. It eliminates the need for complex manual configuration, reducing the technical requirements for operators. Furthermore, the layered architecture and component-based design allow the system to quickly adjust relevant parameters and component configurations according to different production line layouts and drug type detection needs without requiring system-wide reconstruction. This shortens the debugging cycle for adapting to different scenarios, reduces the professional technical requirements for on-site operators, and enables rapid system deployment, flexibly adapting to the detection needs of different types of tablets and different production scales.
[0128] Figure 9 This is a schematic flowchart of the tablet defect detection and rejection method provided in the embodiments of this application. Figure 9 As shown, the method for detecting and removing defects in the tablets includes:
[0129] S901: Acquire drug image data; wherein, the drug image data includes multiple tablets to be identified.
[0130] S902: Based on the drug image data and the target detection model, perform a decoupling operation to generate a target detection box corresponding to each drug tablet to be identified, coordinate data corresponding to the target detection box, and target category corresponding to the target detection box; wherein, the target category includes normal category and multiple defect categories.
[0131] S903: Based on the coordinate data corresponding to the target detection box, each of the tablets to be identified is tracked in real time. When the target reaches the preset channel area, the tablets to be identified corresponding to the target detection box with the target category of defect are locked as defective tablets, and the defective tablets are removed.
[0132] It should be understood that the specific process of each module performing the above-mentioned corresponding steps has been described in detail in the above system embodiments, and will not be repeated here for the sake of brevity.
[0133] It should also be understood that the module division in the embodiments of this application is illustrative and only represents a logical functional division; in actual implementation, there may be other division methods. Furthermore, the functional modules in the various embodiments of this application can be integrated into a single processor, exist as separate physical entities, or be integrated into a single module. The integrated modules described above can be implemented in hardware or as software functional modules.
[0134] Figure 10 This is a schematic block diagram of an electronic terminal provided in an embodiment of this application. The electronic terminal includes a memory, a processor, and a computer program stored in the memory. The processor executes the computer program to implement the tablet defect detection and rejection method described above. Figure 10 As shown, the electronic terminal 1000 includes at least one processor 1001, a memory 1002, at least one network interface 1003, and a user interface 1005. The various components in the electronic terminal 1000 are coupled together via a bus system 1004. It is understood that the bus system 1004 is used to implement communication between these components. In addition to a data bus, the bus system 1004 also includes a power bus, a control bus, and a status signal bus. However, for clarity, in… Figure 10 The general will label all buses as bus systems.
[0135] The user interface 1005 may include a monitor, keyboard, mouse, trackball, clicker, button, touchpad, or touch screen.
[0136] It is understood that memory 1002 can be volatile memory or non-volatile memory, or both. Non-volatile memory can be read-only memory (ROM) or programmable read-only memory (PROM), which serves as an external cache. By way of example, but not limitation, many forms of RAM are available, such as static random access memory (SRAM) and synchronous static random access memory (SSRAM). The memories described in the embodiments of this invention are intended to include, but are not limited to, these and any other suitable categories of memory.
[0137] In this embodiment of the invention, the memory 1002 is used to store various types of data to support the operation of the electronic terminal 1000. Examples of this data include: any executable program for operation on the electronic terminal 1000, such as the operating system 10021 and application program 10022; the operating system 10021 contains various system programs, such as the framework layer, core library layer, driver layer, etc., for implementing various basic services and handling hardware-based tasks. The application program 10022 may contain various applications, such as media players, browsers, etc., for implementing various application services. The method for detecting and removing defective tablets provided in this embodiment of the invention can be included in the application program 10022.
[0138] The methods disclosed in the above embodiments of the present invention can be applied to or implemented by the processor 1001. The processor 1001 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the integrated logic circuit of the hardware in the processor 1001 or by instructions in the form of software. The processor 1001 may be a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The processor 1001 can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of the present invention. The general-purpose processor 1001 may be a microprocessor or any conventional processor, etc. The steps of the accessory optimization method provided in the embodiments of the present invention can be directly reflected as being executed by a hardware decoding processor, or being executed by a combination of hardware and software modules in the decoding processor. The software module may be located in a storage medium, which is located in a memory. The processor reads the information in the memory and combines it with its hardware to complete the steps of the aforementioned method.
[0139] In an exemplary embodiment, the electronic terminal 1000 may be used by one or more application-specific integrated circuits (ASICs), DSPs, programmable logic devices (PLDs), or complex programmable logic devices (CPLDs) to execute the aforementioned method.
[0140] According to the method provided in the embodiments of this application, this application also provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the method of any of the embodiments described above.
[0141] According to the method provided in the embodiments of this application, this application also provides a computer program product, which includes computer program code. When the computer program code is run on a computer, it causes the computer to perform the method of any of the embodiments described above.
[0142] As used in this specification, the terms "component," "module," "system," etc., are used to refer to computer-related entities, hardware, firmware, combinations of hardware and software, software, or software in execution. For example, a component can be, but is not limited to, a process running on a processor, a processor, an object, an executable file, an execution thread, a program, and / or a computer. As illustrated, applications running on computing devices and computing devices can both be components. One or more components may reside in a process and / or an execution thread, and components may be located on a single computer and / or distributed among two or more computers. Furthermore, these components can be executed from various computer-readable media on which various data structures are stored. Components can communicate, for example, via local and / or remote processes based on signals having one or more data packets (e.g., data from two components interacting with another component between a local system, a distributed system, and / or a network, such as the Internet interacting with other systems via signals).
[0143] Those skilled in the art will recognize that the various illustrative logical blocks and steps described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this application.
[0144] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0145] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.
[0146] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0147] In addition, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0148] In the above embodiments, the functions of each functional unit can be implemented entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. A computer program product includes one or more computer instructions (programs). When the computer program instructions (programs) are loaded and executed on a computer, all or part of the flow or function according to the embodiments of this application is generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. Computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. Available media can be magnetic media (e.g., floppy disks, hard disks, magnetic tapes), optical media (e.g., high-density digital video discs (DVDs)), or semiconductor media (e.g., solid-state disks (SSDs)).
[0149] If a function is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0150] In summary, this application provides a tablet defect detection and rejection system, method, medium, product, and terminal. By adopting a three-stage network structure (backbone-neck-head) and designing a neck path that separates classification and regression tasks, as well as a decoupled head, it can identify tablets of different sizes and appearances, and various defect types, improving recognition accuracy and detection versatility while reducing model adaptation costs. A post-processing layer performs detection box filtering and removes redundant detection boxes, ensuring that one target detection box corresponds to one tablet to be identified, further improving recognition speed and positioning accuracy, and avoiding missed or false detections. Simultaneously, the rejection control module tracks the tablet in real time based on the target detection box coordinates, locks it in a preset channel area, and rejects defective tablets by blowing air. Each channel is independently controlled and does not interfere with each other, effectively reducing the false rejection of qualified tablets and drug waste, lowering the loss rate, and improving production efficiency. Therefore, this application effectively overcomes the various shortcomings of the prior art and has high industrial application value.
[0151] The above embodiments are merely illustrative of the principles and effects of this application and are not intended to limit this application. Any person skilled in the art can modify or alter the above embodiments without departing from the spirit and scope of this application. Therefore, all equivalent modifications or alterations made by those skilled in the art without departing from the spirit and technical concept disclosed in this application should still be covered by the claims of this application.
Claims
1. A pill defect detection and rejection system, characterized in that, include: An image acquisition module is used to acquire drug image data; wherein, the drug image data includes multiple drug tablets to be identified; The target recognition module is used to perform a decoupling operation based on the drug image data and the target detection model to generate a target detection box corresponding to each drug tablet to be identified, coordinate data corresponding to the target detection box, and target category corresponding to the target detection box; wherein, the target category includes a normal category and multiple defect categories; The rejection control module is used to track each of the tablets to be identified in real time according to the coordinate data corresponding to the target detection box. When the target detection box with the target category of defective is reached, the tablet to be identified is locked as a defective tablet, and the defective tablet is rejected accordingly.
2. The tablet defect detection and rejection system according to claim 1, characterized in that, The target detection model includes a backbone network layer, a neck network layer, a head network layer, and a post-processing layer. The method for generating a target detection box, its coordinate data, and the target category corresponding to each drug image based on the target detection model, through decoupling operations, includes: The backbone network layer is used to perform feature extraction operations based on the drug image data to generate multi-scale initial feature maps; The neck network layer is used to perform feature fusion operations based on the multi-scale initial feature map to generate multi-scale classification feature maps and multi-scale regression feature maps. The head network layer is used to perform decoupling operations based on the multi-scale classification feature map and the multi-scale regression feature map to generate the class probability value and bounding box correction parameters corresponding to each prediction anchor point in each scale space. The post-processing layer is used to perform a filtering operation based on the category probability value corresponding to each predicted anchor point in each scale space and the bounding box correction parameters, so as to generate a target detection box corresponding to each pill to be identified, the coordinate data corresponding to the target detection box, and the target category corresponding to the target detection box.
3. The tablet defect detection and rejection system according to claim 2, characterized in that, The backbone network layer adopts a lightweight RepVGG network; the lightweight RepVGG network includes a reparameterized composite module; the reparameterized composite module is formed by multiple convolutional basic modules connected in series; wherein, each convolutional basic module is a multi-branch parallel structure, which enhances feature extraction capability through multi-branch paths during the training phase, and is fused into a single convolutional layer through structural reparameterization during the inference phase.
4. The tablet defect detection and rejection system according to claim 2, characterized in that, The neck network layer includes a neck classification branch and a neck regression branch; the feature fusion operation includes an upsampling operation and a downsampling operation; wherein, based on the multi-scale initial feature map, the feature fusion operation is performed to generate multi-scale classification feature maps and multi-scale regression feature maps in the following ways: The neck classification branch is used to perform an upsampling operation based on the multi-scale initial feature map to generate a multi-scale first intermediate fusion feature map; and to perform a downsampling operation based on the multi-scale first intermediate fusion feature map to generate a multi-scale classification feature map. The neck regression branch is used to perform an upsampling operation based on the multi-scale initial feature map to generate a multi-scale second intermediate fusion feature map; and to perform a downsampling operation based on the multi-scale second intermediate fusion feature map to generate a multi-scale regression feature map.
5. The tablet defect detection and rejection system according to claim 2, characterized in that, The head network layer includes a head classification branch and a head regression branch; the multi-scale classification feature map and the multi-scale regression feature map share the same set of prediction anchor points in their respective scale spaces; wherein, the method of performing decoupling operations based on the multi-scale classification feature map and the multi-scale regression feature map to generate the class probability values and bounding box correction parameters corresponding to each prediction anchor point in each scale space includes: The head classification branch is used to perform classification prediction operations based on the multi-scale classification feature map to generate the category probability value corresponding to each prediction anchor point in each scale space. The head regression branch is used to perform box regression prediction operation based on the multi-scale regression feature map to generate bounding box correction parameters corresponding to each prediction anchor point in each scale space.
6. The tablet defect detection and rejection system according to claim 2, characterized in that, Based on the category probability values corresponding to each predicted anchor point in each scale space and the bounding box correction parameters, a filtering operation is performed to generate the target detection box corresponding to each pill to be identified, the coordinate data corresponding to the target detection box, and the target category corresponding to the target detection box. The methods include: Based on the bounding box correction parameters corresponding to each prediction anchor point in each scale space, a decoding operation is performed to generate multiple prediction candidate boxes corresponding to each pill to be identified and the coordinate data corresponding to each prediction candidate box. Based on the category probability value corresponding to each prediction anchor point, the target category corresponding to each prediction candidate box and the confidence score of the target category are determined. Based on the coordinate data corresponding to each predicted candidate box, the target category corresponding to each predicted candidate box, and the confidence score of the target category, and based on a preset confidence threshold, a filtering operation is performed to generate multiple preferred detection boxes corresponding to each pill to be identified, the coordinate data corresponding to each preferred detection box, and the target category corresponding to each preferred detection box. Based on the multiple preferred detection boxes corresponding to each of the tablets to be identified, the coordinate data corresponding to each preferred detection box, and the target category corresponding to each preferred detection box, a filtering operation is performed based on a non-maximum suppression algorithm to generate a target detection box corresponding to each tablet to be identified, the coordinate data corresponding to the target detection box, and the target category corresponding to the target detection box.
7. A method for detecting and rejecting defective tablets, characterized in that, include: Collect drug image data; wherein, the drug image data includes multiple tablets to be identified; Based on the drug image data and the target detection model, a decoupling operation is performed to generate a target detection box corresponding to each drug tablet to be identified, the coordinate data corresponding to the target detection box, and the target category corresponding to the target detection box; wherein, the target category includes a normal category and multiple defect categories; Based on the coordinate data corresponding to the target detection box, each of the tablets to be identified is tracked in real time. When the target reaches the preset channel area, the tablets to be identified corresponding to the target detection box with the target category of defect are locked as defective tablets, and the defective tablets are removed.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the tablet defect detection and rejection method as described in claim 7.
9. A computer program product, characterized in that, The computer program product includes computer program code, which, when run on a computer, enables the computer to implement the tablet defect detection and rejection method as described in claim 7.
10. An electronic terminal, comprising a memory, a processor, and a computer program stored in the memory, characterized in that, The processor executes the computer program to implement the tablet defect detection and rejection method as described in claim 7.