X-ray-based Chinese herbal medicine slice sorting method and system
Through dual-view X-ray imaging and deep learning technology, combined with deformable convolutional networks and 3D convolutional attention modules, generative adversarial networks and array-based air nozzle control, the problem of insufficient recognition accuracy when stacking Chinese herbal medicines is solved, and efficient and accurate herbal medicine sorting is achieved.
Patent Information
- Application Number
- CN202510578450.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-07
- Publication Date
- 2025-09-16
- Estimated Expiration
- 2045-05-07
AI Technical Summary
In the existing technology, in the process of automated sorting of Chinese herbal medicine pieces, it is difficult to accurately identify and segment individual targets when the pieces are partially or completely stacked, resulting in insufficient recognition accuracy.
Dual-view X-ray imaging is used to obtain orthogonal projection images of the medicinal pieces to be sorted. The deformable convolutional network is combined to optimize image feature extraction. The 3D convolutional attention module and deep supervision mechanism are introduced to enhance the feature extraction capability. The generative adversarial network is used to generate occluded samples and combined with the Mixup strategy to improve the model generalization ability. The kinematic model and array-type air nozzle control are combined to achieve accurate sorting of medicinal pieces.
It effectively improves the recognition and sorting accuracy of medicinal pieces under high stacking rates, reduces the misjudgment and missed detection rates, and improves the overall efficiency and accuracy of the sorting system.
Smart Images

Figure CN120094869B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of decoction piece sorting, and in particular to an X-ray-based Chinese medicine decoction piece sorting method and system. Background Art
[0002] At present, in the process of automated sorting of Chinese herbal medicines, the sorting process is generally as follows: a conveyor belt is used to transport the pieces to be processed, and X-rays are first used on the conveyor belt to identify impurities and / or unqualified products in the pieces to be processed, and then an array of air blowing pipes is set at the end of the conveyor belt to blow the identified impurities and unqualified products out of the flow trajectory of the pieces to be sorted.
[0003] However, there may be a certain degree of stacking of the Chinese herbal medicine pieces to be sorted on the conveyor belt (for example, two Chinese herbal medicine pieces completely or partially overlap). At this time, the Chinese herbal medicine pieces with a certain degree of stacking will form overlapping projections in the X-ray image (for example, the edge texture of the bottom layer of the herbal medicine piece may be blocked by the upper object). The current algorithm cannot accurately segment a single target and is likely to misjudge this overlapping projection as impurity.
[0004] That is to say, the existing related technologies do not have sufficient recognition accuracy to meet the needs when the medicinal pieces to be sorted are partially or completely stacked. Summary of the Invention
[0005] In order to solve the technical problems in the related art, the present invention provides a method and system for sorting Chinese herbal medicine slices based on X-ray.
[0006] In order to achieve the above object, the technical solution adopted by the present invention includes:
[0007] According to a first aspect of the present invention, there is provided a method for sorting Chinese herbal medicine pieces based on X-rays, comprising:
[0008] Step S1: Obtain orthogonal projection images of the slices to be sorted through dual-view X-ray imaging, use a digital model to compensate for overlapping interference, and embed a deformable convolutional network to optimize image feature extraction;
[0009] Step S2: Based on the Neck structure of YOLOv5, a 3D convolutional attention module and a deep supervision mechanism are introduced to enhance the feature extraction capability of overlapping objects.
[0010] Step S3: Use the generative adversarial network to dynamically generate occlusion samples and combine it with the Mixup strategy to improve the generalization ability of the model;
[0011] Step S4: Combining the kinematic model and array-type air nozzle control to achieve the sorting of the medicinal pieces to be sorted.
[0012] Optionally, step S1 specifically includes:
[0013] Step S1-1: Arrange two X-ray sources at a 45° angle above the conveyor belt to obtain orthogonal projection images of the slices to be sorted;
[0014] Step S1-2: Establish the dynamic compensation formula of the attenuation coefficient:
[0015]
[0016] Where, is the X-ray projection intensity after compensation, 、 and is the position parameter in the three-dimensional coordinate system, and is a dynamic compensation factor, which is updated in real time through Kalman filtering to adapt to the attenuation differences of different materials. is the linear attenuation coefficient of the upper particles, is the linear attenuation coefficient of the lower layer particles;
[0017] Step S1-3: Embed the deformable convolutional network DCNv2 in the image preprocessing layer and dynamically adjust the convolution kernel sampling position of DCNv2 to adapt to the attenuation characteristics of different materials.
[0018] Optionally, step S2 specifically includes:
[0019] Step S2-1: Improve the Neck structure of YOLOv5 and construct a dual-path feature pyramid.
[0020] Among them, the main path uses the C3 module to extract global features;
[0021] The auxiliary path is embedded in the 3D convolution attention module, and its processing formula is:
[0022]
[0023] Where, is the activation function, is the first learnable weight matrix, is the average pooling operation, is the maximum pooling operation, is the input feature map, is the second learnable weight matrix, is element-wise multiplication, is the three-dimensional convolution kernel, is tensor multiplication;
[0024] Step S2-2: Introduce a deep supervision mechanism, set auxiliary detection heads at the P3-P5 feature layers respectively, and perform weighted fusion of the loss functions of each feature layer:
[0025]
[0026] Where, is the total loss function, is the learnable dynamic weight corresponding to the P3 feature layer, is the Complete IoU loss applied to the P3 feature layer, is the learnable dynamic weight corresponding to the P4 feature layer, is the Distribution Focal Loss applied to the P4 feature layer, is the learnable dynamic weight corresponding to the P5 feature layer, is the target presence loss applied to the P5 feature layer.
[0027] Optionally, step S3 specifically includes:
[0028] Step S3-1: Construct a generative adversarial network enhancement system, where the generator G is used to create particle overlapping interference samples:
[0029]
[0030] Where, is a random noise vector, is the hyperbolic tangent activation function, is the fully connected layer weight matrix of the generator, is the feature vector of the real medicinal material sample, Represents feature concatenation operation;
[0031] Step S3-2: Improve the Mixup strategy to dynamic adversarial mixing:
[0032]
[0033] Where, For dynamically generated mixed samples, is the dynamic mixing scale factor, and ;
[0034] Step S3-3: The discriminator D and the detector are optimized alternately, and their loss function is:
[0035]
[0036] Where, is an adversarial loss function used to jointly optimize the game process of the generator G and the discriminator D. Represents the discriminant output of the discriminator for the real medicinal material samples, Represents the discriminant output of the discriminator for the generated interference samples.
[0037] Optionally, step S4 specifically includes:
[0038] Step S4-1: Establish a kinematic model and dynamically adjust the air blowing delay time according to the conveyor belt speed:
[0039]
[0040] Where, is the delay time of air blowing, is the horizontal distance between the impurity position and the gas nozzle, is the real-time speed of the conveyor belt, is the speed fluctuation compensation coefficient and , is the air blowing response time;
[0041] Step S4-2: Construct an array-type air nozzle control system. The pressure equation corresponding to each air nozzle is:
[0042]
[0043] Where, For the The output pressure of each nozzle, is the base pressure coefficient, The target impurity and The vertical distance between the gas nozzles, is the pressure diffusion coefficient, is the confidence gain factor, To test confidence;
[0044] Step S4-3: Deploy a multi-target tracking algorithm to establish motion trajectory associations for suspected overlapping targets to reduce continuous false positives.
[0045] Optionally, the X-ray-based Chinese herbal medicine slice sorting method further comprises:
[0046] Step S5: realizing impurity removal optimization through secondary detection and dynamic threshold adjustment.
[0047] Optionally, step S5 specifically includes:
[0048] Step S5-1: Set up a secondary test in the air blowing blanking area and collect rejected samples for result verification;
[0049] Step S5-2: Establish an online learning mechanism, and error samples automatically trigger model fine-tuning:
[0050]
[0051] Where, is the model parameter update amount, is the learning rate, is the gradient operation function, is the air blowing error sample data set, is the validation set loss function, is the regularization coefficient, are the current model parameters, are the initial model parameters;
[0052] Step S5-2: Correct the detection sensitivity according to the environmental parameters:
[0053]
[0054] Where, is the adjusted detection sensitivity threshold, is the basic threshold, is the humidity change, is the temperature change.
[0055] According to a second aspect of the present invention, there is further provided an X-ray-based Chinese herbal medicine piece sorting system, which is applied to the X-ray-based Chinese herbal medicine piece sorting method described in any one of the technical solutions in the first aspect of the present invention, and the X-ray-based Chinese herbal medicine piece sorting system comprises:
[0056] A dual-view X-ray imaging unit, comprising a linear array detector and two X-ray sources arranged at a 45° angle above the conveyor belt, is used to capture orthogonal projection images of the slices to be sorted;
[0057] A YOLOv5 model unit, wherein a 3D convolutional attention module and a deep supervision mechanism are introduced into the Neck structure of the YOLOv5 model;
[0058] Generative adversarial network unit, used to generate occluded samples;
[0059] The air blowing execution unit includes an array-type air nozzle group, a kinematic controller and a pressure regulator. The array-type air nozzle group includes a plurality of air nozzles arranged at equal intervals at the end of the conveyor belt; the kinematic controller is used to calculate the air blowing delay time according to the real-time speed of the conveyor belt, and the pressure regulator is used to adjust the air blowing pressure of the air nozzle.
[0060] According to the third aspect of the present application, a computer device is also provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the X-ray-based method for sorting Chinese herbal medicines described in any one of the technical solutions in the first aspect of the present application can be implemented.
[0061] According to the fourth aspect of the present application, a computer-readable storage medium is also provided, on which a computer program is stored. When the computer program is executed by a processor, it can implement the steps of the X-ray-based Chinese herbal medicine sorting method described in any technical solution in the first aspect of the present application.
[0062] Beneficial effects:
[0063] 1. Through the above technical solution, first, in step S1 of the present invention, the dual-view X-ray imaging and dynamic compensation mechanism can not only break through the geometric limitations of single-view projection and improve the recognition rate of overlapping targets, but also improve the signal-to-noise ratio of foreign body recognition through dynamic attenuation compensation. In addition, the extraction accuracy of the features of medicinal materials with different morphologies can be improved through deformable convolution.
[0064] Second, in step S2 of the present invention, by introducing the 3D convolutional attention module and the deep supervision mechanism into the Neck structure of YOLOv5, not only can the mAP of overlapping target detection be improved through the 3D convolutional attention module, but also the small target missed detection rate can be reduced through the deep supervision mechanism.
[0065] Third, in step S3 of the present invention, through adversarial generation and dynamic Mixup strategies, it can be achieved that: the occluded samples generated by GAN can improve the F1-score of the model in overlapping scenes, and the dynamic mixing strategy can reduce the risk of overfitting and reduce the loss of the validation set.
[0066] Fourth, the coordinated control of the kinematic model and the array air nozzle can not only effectively improve the air blowing hit rate, but also effectively improve the air blowing energy utilization rate. In addition, it can also effectively reduce the false blowing rate.
[0067] In general, the method of the present invention forms a closed-loop control through multi-dimensional perception at the imaging end, adaptive learning at the algorithm end, and precise control at the execution end, which can effectively ensure a high sorting accuracy in application scenarios with a high stacking rate of medicinal pieces.
[0068] 2. Other beneficial effects or advantages of the present invention will be described in detail in the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0069] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for describing the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without paying any creative labor.
[0070] in:
[0071] Figure 11 is a schematic flow chart of the steps of a method for sorting Chinese herbal medicine pieces based on X-rays provided by an exemplary embodiment of the present invention;
[0072] Figure 2 It is a schematic diagram of the layout of an X-ray-based Chinese herbal medicine slice sorting system provided by an exemplary embodiment of the present invention.
[0073] Description of the reference numerals in the accompanying drawings:
[0074] 100-X-ray-based Chinese herbal medicine sorting system; 200-conveyor belt; 300-herbal medicine slices; 1-dual-view X-ray imaging unit; 2-YOLOv5 model unit; 3-generative adversarial network unit; 4-air blowing execution unit. DETAILED DESCRIPTION
[0075] The technical solution of the present invention is described in detail below with reference to the accompanying drawings.
[0076] According to the first aspect of the present invention, Figure 1 As shown, the present invention provides a method for sorting Chinese herbal medicine slices based on X-ray, comprising:
[0077] Step S1: Obtain 300 orthogonal projection images of the slices to be sorted by dual-view X-ray imaging, use a digital model to compensate for overlapping interference, and embed a deformable convolutional network to optimize image feature extraction;
[0078] Step S2: Based on the Neck structure of YOLOv5, a 3D convolutional attention module and a deep supervision mechanism are introduced to enhance the feature extraction capability of overlapping objects.
[0079] Step S3: Use the generative adversarial network to dynamically generate occlusion samples and combine it with the Mixup strategy to improve the generalization ability of the model;
[0080] Step S4: combining the kinematic model and array-type air nozzle control to achieve the sorting of the medicinal pieces 300 to be sorted.
[0081] Through the above technical solution, first, in step S1 of the present invention, dual-view X-ray imaging and dynamic compensation mechanism can not only break through the geometric limitations of single-view projection and improve the recognition rate of overlapping targets, but also improve the signal-to-noise ratio of foreign body recognition through dynamic attenuation compensation. In addition, the extraction accuracy of 300 features of medicinal slices with different forms can be improved through deformable convolution.
[0082] For dual-view X-ray imaging, dual-view orthogonal projections form the basis for 3D information reconstruction. When the medicinal slices 300 are stacked in the plane of the conveyor belt 200 (XY axis), two X-ray sources at a 45° angle project along the XZ and YZ planes, respectively, to reveal the overlapping structure along the Z axis. For example, the upper layer of medicinal slices 300 appears horizontally expanded in the XZ projection and vertically compressed in the YZ projection. The stacking hierarchy is then determined by the projection differences.
[0083] In addition, for deformable convolutional networks, DCNv2 uses deformable convolution kernel sampling position offset Adaptive adjustment of:
[0084]
[0085] Where, is the offset prediction quantity, is the input feature map.
[0086] In this way, the convolution kernel can dynamically fit the edge of the medicinal piece 300, especially adapting to the irregular hole characteristics of insect-eaten medicinal pieces.
[0087] Second, in step S2 of the present invention, by introducing the 3D convolutional attention module and the deep supervision mechanism into the Neck structure of YOLOv5, not only can the mAP (mean Average Precision) of overlapping target detection be improved through the 3D convolutional attention module, but also the small target missed detection rate can be reduced through the deep supervision mechanism.
[0088] Among them, for the 3D convolution attention module, it can calculate the attention weight in the channel-space-depth three-dimensional domain. , and its operation process is:
[0089]
[0090] Where, 、 and are the attention weight matrices of channel, space, and depth dimensions respectively. In this way, this structure can accurately capture the texture of the underlying medicinal material that is blocked by the upper layer.
[0091] Third, in step S3 of the present invention, through adversarial generation and dynamic Mixup strategies, it can be achieved that: the occluded samples generated by GAN can improve the F1-score of the model in overlapping scenes, and the dynamic mixing strategy can reduce the risk of overfitting and reduce the loss of the validation set.
[0092] Among them, the generative adversarial network can learn the physical stacking rules of real medicinal materials through adversarial training. Its latent space encoding can include parameters such as position offset, transparency, texture variation, etc., and can generate occluded samples that conform to the actual sorting situation.
[0093] Fourth, the coordinated control of the kinematic model and the array air nozzle can not only effectively improve the air blowing hit rate, but also effectively improve the air blowing energy utilization rate. In addition, it can also effectively reduce the false blowing rate.
[0094] In general, the method of the present invention forms a closed-loop control through multi-dimensional perception at the imaging end, adaptive learning at the algorithm end, and precise control at the execution end, which can effectively ensure a high sorting accuracy in application scenarios with a high stacking rate of 300 medicinal pieces.
[0095] In one embodiment of the present invention, step S1 of the present invention may specifically include:
[0096] Step S1-1: Arrange two X-ray sources above the conveyor belt 200 at an angle of 45° to obtain orthogonal projection images of the slices to be sorted 300;
[0097] Step S1-2: Establish the dynamic compensation formula of the attenuation coefficient:
[0098]
[0099] Where, is the X-ray projection intensity after compensation, 、 and is the position parameter in the three-dimensional coordinate system, and is a dynamic compensation factor, which is updated in real time through Kalman filtering to adapt to the attenuation differences of different materials. is the linear attenuation coefficient of the upper particles, is the linear attenuation coefficient of the lower layer particles;
[0100] Step S1-3: Embed the deformable convolutional network DCNv2 in the image preprocessing layer and dynamically adjust the convolution kernel sampling position of DCNv2 to adapt to the attenuation characteristics of different materials.
[0101] Thus, in this embodiment, first, for step S1-1, by arranging the two X-ray sources at a 45° angle, the spatial resolution can be effectively improved (for example, for thin slices of medicinal materials with a thickness of ≤3 mm, such as white peony slices, dual-view projection can resolve position differences of 0.2 mm in the Z-axis direction). At the same time, it can also effectively improve the overlap discrimination rate and provide more accurate spatial coordinate input for the subsequent kinematic model.
[0102] It should be noted that for projection geometry modeling, the plane of the conveyor belt 200 can be set as the XY axis, the X-ray source A is projected along the XZ plane at 45 degrees, and the X-ray source B is projected along the YZ plane at 45 degrees. When the slice P1 is stacked on the slice P2: in the view of the X-ray source A, the projection of the slice P1 is extended along the X axis. , is the stack height. In the view of X-ray source B, the projection of slice P1 extends along the Y axis. , calculate the stack height by the difference of two-view projection .
[0103] For example, in one application scenario, for example, angelica slices (impurities) are located above poria slices. In the existing related art, both the angelica slices (with finer textures) and the poria slices are considered impurities. However, in the dual-view projection of the present invention, in the view of X-ray source A, the angelica slices are extended 3.2mm along the X-axis, and in the view of X-ray source B, the angelica slices are extended 3.2mm along the Y-axis. The stacking height can be determined. There is an independent object at 3.2mm. Combined with the difference in attenuation coefficients of Angelica sinensis and Poria cocos in the material library, the two can be accurately distinguished.
[0104] Second, for step S2-1, the dynamic compensation factor is and It can be adapted to different types of medicinal slices 300 (for example, mineral medicinal slices or plant medicinal slices) respectively to meet the needs of sorting medicinal slices 300 of different materials. In this way, when an area with a high linear attenuation coefficient is detected, the weight of the corresponding layer can be automatically increased to reduce the influence of another layer of interference on the detection result. For example, in an exemplary embodiment, when mud blocks are mixed in the licorice slices and are transported on the conveyor belt 200, the mud blocks are located above or below the licorice slices. At this time, in the existing related technology, the attenuation difference between the licorice slices and the mud blocks will cause the X-ray image to be saturated, but it is impossible to accurately distinguish between the licorice slices and the mud blocks. In the method of the present invention, when the Kalman filter recognizes that the local linear attenuation coefficient is large, it will automatically adjust the weight of the corresponding layer. For example, when the mud block is above the licorice slice, at this time, the linear attenuation coefficient of the upper layer (i.e., the mud block) is large, and the weight of the upper layer (i.e., Corresponding dynamic compensation factor ) increases, the weight of the lower layer (i.e., Corresponding dynamic compensation factor ) is reduced, so that the edge sharpness of the mud block in the compensated image will be improved, so as to accurately distinguish the licorice slices and mud blocks and accurately mark the position of the mud blocks.
[0105] Third, in step S1-3 of the present invention, by embedding the deformable convolutional network DCNv2 in the image preprocessing layer and dynamically adjusting the convolution kernel sampling position of DCNv2, the feature extraction accuracy of the irregular edges of worm-eaten medicinal pieces (for example, wormholes in white pieces) can be improved.
[0106] For example, in one exemplary embodiment, when removing insect-infested portions of a Baibu piece and separating intact, uninfested pieces, the standard 3×3 convolution kernel in existing algorithms cannot fit snugly to the edges of the holes, resulting in blurred holes in the feature map and an inability to accurately distinguish between infested and uninfested Baibu pieces. In contrast, the offset is maximized at the edges of the holes, and the corrected sampling points closely surround the edges of the holes, resulting in more accurate identification of the holes and the ability to accurately identify defective products with holes greater than 5%.
[0107] Take the implementation method of mixed sorting of mineral and plant medicinal pieces as an example.
[0108] The flow of medicinal slices mixed with gypsum blocks (sorting targets) and Poria peels (sorting impurities) was sorted, with a stacking rate of 30%.
[0109] 1) Dual-view imaging.
[0110] X-ray source A detects abnormal expansion in the X-axis direction. ;
[0111] X-ray source B detects abnormal expansion in the Y-axis direction, ;
[0112] Calculated stack height It is 4.1mm.
[0113] 2) Identify the upper layer as having a low linear attenuation coefficient (Poria cocos peel, ), automatically adjust and , to strengthen the lower layer (gypsum blocks, ) of the projection contrast.
[0114] 3) Convolution kernel is generated at the edge of the gypsum block The pixel offset allows for precise identification of the edge position of the plaster block.
[0115] In this way, gypsum blocks and Poria peels can be accurately distinguished, thereby ensuring the accuracy of sorting.
[0116] In this embodiment, it should be noted that
[0117] First, in the dynamic compensation formula, the Kalman filter is updated in real time and , essentially building a state-space model:
[0118]
[0119] In the formula for The dynamic compensation factor at the moment, for The dynamic compensation factor at the moment, is the observation matrix, is the Kalman gain, is the actual measured linear attenuation coefficient, for The dynamic compensation factor at the moment, for Dynamic compensation factor at the moment.
[0120] In this way, the model can adjust the attenuation compensation coefficient of different materials (for example, mineral and plant pieces) online.
[0121] Second, the offset prediction network output is:
[0122]
[0123] The deformable convolution kernel is located at The sampling point at is corrected to:
[0124]
[0125] Where, is the original position, is the learned offset.
[0126] In one embodiment of the present invention, step S2 of the present invention may specifically include:
[0127] Step S2-1: Improve the Neck structure of YOLOv5 and construct a dual-path feature pyramid. The main path uses the C3 module to extract global features; the auxiliary path embeds the 3D convolution attention module. The processing formula is: Where, is the activation function, is the first learnable weight matrix, is the average pooling operation, is the maximum pooling operation, is the input feature map, is the second learnable weight matrix, is element-wise multiplication, is the three-dimensional convolution kernel, is tensor multiplication;
[0128] Step S2-2: Introduce a deep supervision mechanism, set auxiliary detection heads at the P3-P5 feature layers respectively, and perform weighted fusion of the loss functions of each feature layer: Where, is the total loss function, is the learnable dynamic weight corresponding to the P3 feature layer, is the Complete IoU loss applied to the P3 feature layer, is the learnable dynamic weight corresponding to the P4 feature layer, is the Distribution Focal Loss applied to the P4 feature layer, is the learnable dynamic weight corresponding to the P5 feature layer, is the target presence loss applied to the P5 feature layer.
[0129] This implementation focuses on improving the Neck structure of YOLOv5, significantly enhancing feature extraction capabilities in scenarios with 300 overlapping Chinese herbal medicine pieces through a three-dimensional attention mechanism and deep supervision. Specifically, the dual-path feature pyramid and 3D convolutional attention module not only effectively enhance overlapping object recognition but also effectively improve the fusion accuracy of the P3-P5 feature layers. Furthermore, computational efficiency is significantly improved (the dual-path design maintains a certain FPS real-time performance while minimizing the increase in model parameters).
[0130] Second, through the deep supervision mechanism and dynamic weighted loss, it can not only effectively achieve the recognition accuracy of small targets (for example, impurities ≤ 5mm), but also effectively strengthen the gradient propagation (through multi-level supervision, improve the efficiency of back propagation and accelerate the training convergence speed). In addition, through the learnable weights 、 and The model can be automatically adapted to different detection tasks (for example, the sorting of mineral and plant decoction pieces).
[0131] In this embodiment, it should be noted that, first, for the auxiliary path embedded 3D convolution attention module, it can accurately locate the edge texture of the obscured medicinal material 300 (for example, the wrinkled structure of Poria cocos). Second, for the weighted fusion formula of the loss function of each feature layer ( ), Optimize positioning accuracy, Enhance classification confidence, Reduce background misjudgment. For each learnable dynamic weight, the weight can be automatically adjusted according to the gradient contribution of each layer, that is, ,in, is 3 or 4 or 5, is the learning rate. For example, when processing high-density medicinal materials (e.g., calcined oysters), the learnable dynamic weights of the P5 layer Automatically enlarge to enhance deep semantic features.
[0132] Overall, this implementation method constructs a deep learning architecture that adapts to the complex stacking scenario of 300 Chinese herbal medicine pieces through multi-dimensional feature fusion and dynamic supervision mechanism, providing core technical support for high-precision sorting.
[0133] In one embodiment of the present invention, step S3 of the present invention may specifically include:
[0134] Step S3-1: Construct a generative adversarial network enhancement system, where the generator G is used to create particle overlapping interference samples: Where, is a random noise vector, is the hyperbolic tangent activation function, is the fully connected layer weight matrix of the generator, is the feature vector of the real medicinal material sample, Represents feature concatenation operation;
[0135] Step S3-2: Improve the Mixup strategy to dynamic adversarial mixing: Where, For dynamically generated mixed samples, is the dynamic mixing scale factor, and ;
[0136] Step S3-3: The discriminator D and the detector are optimized alternately, and their loss function is:
[0137]
[0138] Where, is an adversarial loss function used to jointly optimize the game process of the generator G and the discriminator D. Represents the discriminant output of the discriminator for the real medicinal material samples, Represents the discriminant output of the discriminator for the generated interference samples.
[0139] In this embodiment, by generating highly realistic overlapping samples and optimizing model adversarial training, the model's generalization and robustness in the scenario of 300 stacked Chinese herbal medicine slices are significantly improved. Specifically, first, for step S3-1, the constructed generative adversarial network enhancement system can achieve overlapping sample generation (generator G can synthesize overlapping samples of herbal medicine slices consistent with the real scene, for example, the projection of angelica slices covering licorice slices, thereby increasing the proportion of overlapping samples in the training data).
[0140] For example, when generating a projection of a gypsum block (high attenuation coefficient) covering a mulberry leaf (low attenuation coefficient), the generator adjusts Weighting, in the stitching feature, enhances the sharp edges of the plaster and the difference in the transmission texture of the mulberry leaf.
[0141] Second, the dynamic mixing ratio factor of the dynamic antagonistic mixing of the present invention , can dynamically control the weights of real samples and production samples, through random The dynamic mixing ratio factor of the present invention can simulate different degrees of occlusion (for example, complete occlusion and partial occlusion). Compared with the fixed-ratio mixing method of traditional Mixup, the dynamic mixing ratio factor of the present invention can make the model more adaptable to the random stacking scenario in the real production line.
[0142] Third, in step S3-3 of the present invention, alternate optimization of the discriminator and detector achieves defense against adversarial attacks (improving detection accuracy for adversarial examples with perturbed projection intensity). Specifically, the discriminator D and the generator G compete by minimizing the adversarial loss. The detector and the discriminator are trained alternately. The detector learns anti-interference features from generated samples, while the discriminator pushes the generator to approach the true data distribution, thereby improving detection accuracy.
[0143] In one embodiment of the present invention, step S4 of the present invention may specifically include:
[0144] Step S4-1: Establish a kinematic model and dynamically adjust the air blowing delay time according to the speed of the conveyor belt 200: Where, is the delay time of air blowing, is the horizontal distance between the impurity position and the gas nozzle, is the real-time speed of the conveyor belt 200, is the speed fluctuation compensation coefficient and , is the air blowing response time;
[0145] Step S4-2: Construct an array-type air nozzle control system. The pressure equation corresponding to each air nozzle is: Where, For the The output pressure of each nozzle, is the base pressure coefficient, The target impurity and The vertical distance between the gas nozzles, is the pressure diffusion coefficient, is the confidence gain factor, To test confidence;
[0146] Step S4-3: Deploy a multi-target tracking algorithm to establish motion trajectory associations for suspected overlapping targets to reduce continuous false positives.
[0147] In this embodiment, the focus is on dynamic kinematics prediction and adaptive air blowing control. By accurately modeling the motion trajectory of the slices 300 and the dynamic matching of the air blowing execution parameters, the problems of sorting execution lag and high misblowing rate in the stacking scenario are solved. Specifically, first, for step S4-1, the kinematic model and delay compensation can improve the sorting timing accuracy (in the case of certain fluctuations in the speed of the conveyor belt 200, the speed fluctuation compensation coefficient is used to compensate for the fluctuations). , it can still effectively ensure that the air blowing touch time error is within a smaller range).
[0148] Second, for step S4-2, the dynamic regulation of the array-type air nozzle control can effectively improve the air pressure adaptability (that is, different air blowing pressures can be set according to different impurities to ensure the success rate of blowing).
[0149] Third, in step S4-3 of the present invention, by establishing a motion trajectory association for the suspected overlapping targets, it is possible to avoid the array-type air nozzle from continuously blowing away two or more overlapping pieces of medicine 300, thereby reducing continuous misblowing.
[0150] Overall, the present invention can effectively solve the problem of precise control of the sorting actuator in the stacking scenario through kinematic-air blowing closed-loop optimization, and provides core technical support for high-speed, high-density 300-piece sorting of Chinese herbal medicine slices.
[0151] In this embodiment, it should be noted that, first, for the air blowing delay time formula, is the speed fluctuation compensation coefficient, which can be dynamically adjusted according to the historical speed variance. For example, when the speed of the conveyor belt 200 suddenly drops from 0.8m / s to 0.7m / s, the speed fluctuation compensation coefficient can be increased by , so that the air blowing delay time is increased, thereby ensuring the accurate air blowing timing.
[0152] Second, for the nozzle pressure equation, its physical meaning is: the closer the nozzle is to the target, the higher the output pressure, and the higher the detection confidence, the more overpressure injection is triggered.
[0153] In one embodiment of the present invention, the X-ray-based Chinese herbal medicine slice sorting method of the present invention may further include step S5: achieving impurity removal optimization through secondary detection and dynamic threshold adjustment.
[0154] Step S5 of the present invention may specifically include:
[0155] Step S5-1: Set up a secondary test in the air blowing blanking area and collect rejected samples for result verification;
[0156] Step S5-2: Establish an online learning mechanism, and error samples automatically trigger model fine-tuning:
[0157]
[0158] Where, is the model parameter update amount, is the learning rate, is the gradient operation function, is the air blowing error sample data set, is the validation set loss function, is the regularization coefficient, are the current model parameters, are the initial model parameters;
[0159] Step S5-2: Correct the detection sensitivity according to the environmental parameters:
[0160]
[0161] Where, is the adjusted detection sensitivity threshold, is the basic threshold, is the humidity change, is the temperature change.
[0162] In this embodiment, through the secondary inspection of the air-blowing blanking area, a closed-loop process of "initial inspection-execution-re-inspection" is formed, which can effectively reduce the false blow rate and missed detection rate. At the same time, the detection sensitivity is corrected by the environmental parameters ( ), which can be applied to various working conditions (for example, the texture conditions of different medicinal materials under different humidity and temperature conditions), and maintain relatively stable detection sensitivity to reduce the false positive rate. In addition, the online learning mechanism automatically triggers the model fine-tuning formula through error samples ( ) to achieve parameter fine-tuning to ensure that the average accuracy meets actual needs.
[0163] Among them, it should be noted that, first, for the error sample to automatically trigger the model fine-tuning formula, the regularization term ( ) uses the Elastic Weight Consolidation strategy, which allows the model to learn new features (such as new impurities) while avoiding catastrophic forgetting. Weight update direction Guided by KL divergence loss, it ensures compatibility between new and old knowledge.
[0164] Second, for the detection sensitivity correction formula, Compensate for the density change caused by the hygroscopic expansion of medicinal materials. The term corresponds to the detector temperature drift (for example, the photoelectric conversion efficiency decreases by about 4.8% for every 10°C increase in temperature, and signal stability is maintained through exponential compensation).
[0165] Overall, this implementation method builds an intelligent sorting system with self-diagnosis, self-learning and self-adaptation capabilities. Through the deep coupling of the physical detection layer and the digital twin layer, the open-loop process of the traditional sorting system is upgraded to a dynamic closed-loop system with continuous evolution capabilities.
[0166] According to the second aspect of the present invention, Figure 2 As shown, an X-ray-based Chinese herbal medicine piece sorting system 100 is also provided, which is applied to the X-ray-based Chinese herbal medicine piece sorting method of any technical solution in the first aspect of the present invention. The X-ray-based Chinese herbal medicine piece sorting system 100 includes:
[0167] A dual-view X-ray imaging unit 1 includes a linear array detector and two X-ray sources arranged at a 45° angle above the conveyor belt 200, for collecting orthogonal projection images of the slices to be sorted 300;
[0168] YOLOv5 model unit 2, the 3D convolutional attention module and deep supervision mechanism are introduced into the Neck structure of the YOLOv5 model;
[0169] Generative adversarial network unit 3, used to generate occlusion samples;
[0170] The air blowing execution unit 4 includes an array air nozzle group, a kinematic controller and a pressure regulator. The array air nozzle group includes a plurality of air nozzles arranged at equal intervals at the end of the conveyor belt 200; the kinematic controller is used to calculate the air blowing delay time according to the real-time speed of the conveyor belt 200, and the pressure regulator is used to adjust the air blowing pressure of the air nozzle.
[0171] In this way, through the X-ray-based Chinese herbal medicine sorting system 100 of the present invention, first, the dual-view X-ray imaging and dynamic compensation mechanism can not only break through the geometric limitations of single-view projection and improve the recognition rate of overlapping targets, but also improve the signal-to-noise ratio of foreign body recognition through dynamic attenuation compensation. In addition, the extraction accuracy of features of herbal medicines with different morphologies can be improved through deformable convolution.
[0172] Second, by introducing the 3D convolutional attention module and deep supervision mechanism into the Neck structure of YOLOv5, not only can the mAP of overlapping target detection be improved through the 3D convolutional attention module, but also the missed detection rate of small targets can be reduced through the deep supervision mechanism.
[0173] Third, through adversarial generation and dynamic Mixup strategies, it can be achieved that: the occluded samples generated by GAN can improve the model's F1-score in overlapping scenes, and the dynamic mixing strategy can reduce the risk of overfitting and reduce the loss of the validation set.
[0174] Fourth, the coordinated control of the kinematic model and the array air nozzle can not only effectively improve the air blowing hit rate, but also effectively improve the air blowing energy utilization rate. In addition, it can also effectively reduce the false blowing rate.
[0175] In general, the X-ray-based Chinese herbal medicine sorting system of the present invention forms a closed-loop control through multi-dimensional perception at the imaging end, adaptive learning at the algorithm end, and precise control at the execution end, which can effectively ensure a high sorting accuracy in application scenarios with a high stacking rate of herbal medicines.
[0176] According to the third aspect of the present application, a computer device is also provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the X-ray-based Chinese herbal medicine sorting method in any one of the technical solutions in the first aspect of the present application can be implemented.
[0177] It is understood that in this embodiment, the memory may include volatile memory, such as random access memory; the memory may also include non-volatile memory, such as read-only memory, flash memory, hard disk, or solid-state drive; and the memory may also include a combination of the aforementioned types of memory. This application does not impose specific limitations on this.
[0178] Similarly, a processor may implement or execute the various exemplary logical steps described in conjunction with the disclosure of this application. The processor may be a central processing unit, a general-purpose processor, a digital signal processor, an application-specific integrated circuit, a field programmable gate array or other programmable logic device, a transistor logic device, a hardware component, or any combination thereof. It may implement or execute the various exemplary logical steps described in conjunction with the disclosure of this application. The processor may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.
[0179] According to the fourth aspect of the present application, a computer-readable storage medium is also provided, on which a computer program is stored, characterized in that when the computer program is executed by a processor, it can implement the steps of the X-ray-based Chinese herbal medicine sorting method in any technical solution in the first aspect of the present application.
[0180] In this embodiment, the computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or component, or any combination thereof. More specific examples (non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a register, a hard disk, an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof, or any other form of computer-readable storage medium known in the art. An exemplary storage medium is coupled to a processor so that the processor can read information from the storage medium and write information to the storage medium. Of course, the storage medium may also be an integral part of the processor. The processor and the storage medium may be located in an application-specific integrated circuit (ASIC). In the embodiments of the present application, a computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.
[0181] The above are only specific embodiments of the present invention, but the scope of protection of the present invention is not limited thereto. Any changes or substitutions within the technical scope disclosed by the present invention should be covered by the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be based on the scope of protection of the claims.
Claims
1. A method for sorting Chinese herbal medicine slices based on X-ray, characterized in that: include: Step S1: Obtain orthogonal projection images of the slices to be sorted through dual-view X-ray imaging, use a digital model to compensate for overlapping interference, and embed a deformable convolutional network to optimize image feature extraction; Step S2: Based on the Neck structure of YOLOv5, a 3D convolutional attention module and a deep supervision mechanism are introduced to enhance the feature extraction capability of overlapping objects. Step S3: Use the generative adversarial network to dynamically generate occlusion samples and combine it with the Mixup strategy to improve the generalization ability of the model; Step S4: combining the kinematic model and array-type air nozzle control to achieve the sorting of the medicinal pieces to be sorted; Wherein, step S1 specifically includes: Step S1-1: Arrange two X-ray sources at a 45° angle above the conveyor belt to obtain orthogonal projection images of the slices to be sorted; Step S1-2: Establish the dynamic compensation formula of the attenuation coefficient: ; Where, is the X-ray projection intensity after compensation, 、 and is the position parameter in the three-dimensional coordinate system, and is a dynamic compensation factor, which is updated in real time through Kalman filtering to adapt to the attenuation differences of different materials. is the linear attenuation coefficient of the upper particles, is the linear attenuation coefficient of the lower layer particles; Step S1-3: Embed the deformable convolutional network DCNv2 in the image preprocessing layer and dynamically adjust the convolution kernel sampling position of DCNv2 to adapt to the attenuation characteristics of different materials.
2. The method for sorting Chinese herbal medicine slices based on X-ray according to claim 1, characterized in that: The step S2 specifically includes: Step S2-1: Improve the Neck structure of YOLOv5 and construct a dual-path feature pyramid. The main path uses the C3 module to extract global features; the auxiliary path embeds the 3D convolution attention module. The processing formula is: Where, is the activation function, is the first learnable weight matrix, is the average pooling operation, is the maximum pooling operation, is the input feature map, is the second learnable weight matrix, is element-wise multiplication, is the three-dimensional convolution kernel, is tensor multiplication; Step S2-2: Introduce a deep supervision mechanism, set auxiliary detection heads at the P3-P5 feature layers respectively, and perform weighted fusion of the loss functions of each feature layer: Where, is the total loss function, is the learnable dynamic weight corresponding to the P3 feature layer, is the Complete IoU loss applied to the P3 feature layer, is the learnable dynamic weight corresponding to the P4 feature layer, is the Distribution Focal Loss applied to the P4 feature layer, is the learnable dynamic weight corresponding to the P5 feature layer, is the target presence loss applied to the P5 feature layer.
3. The method for sorting Chinese herbal medicine slices based on X-ray according to claim 1, characterized in that: The step S3 specifically includes: Step S3-1: Construct a generative adversarial network enhancement system, where the generator G is used to create particle overlapping interference samples: Where, is a random noise vector, is the hyperbolic tangent activation function, is the fully connected layer weight matrix of the generator, is the feature vector of the real medicinal material sample, Represents feature concatenation operation; Step S3-2: Improve the Mixup strategy to dynamic adversarial mixing: Where, For dynamically generated mixed samples, is the dynamic mixing scale factor, and ; Step S3-3: The discriminator D and the detector are optimized alternately, and their loss function is: Where, is an adversarial loss function used to jointly optimize the game process of the generator G and the discriminator D. Represents the discriminant output of the discriminator for the real medicinal material samples, Represents the discriminant output of the discriminator for the generated interference samples.
4. The method for sorting Chinese herbal medicine slices based on X-ray according to claim 1, characterized in that: The step S4 specifically includes: Step S4-1: Establish a kinematic model and dynamically adjust the air blowing delay time according to the conveyor belt speed: Where, is the delay time of air blowing, is the horizontal distance between the impurity position and the gas nozzle, is the real-time speed of the conveyor belt, is the speed fluctuation compensation coefficient and , is the air blowing response time; Step S4-2: Construct an array-type air nozzle control system. The pressure equation corresponding to each air nozzle is: Where, For the The output pressure of each nozzle, is the base pressure coefficient, The target impurity and The vertical distance between the gas nozzles, is the pressure diffusion coefficient, is the confidence gain factor, To test confidence; Step S4-3: Deploy a multi-target tracking algorithm to establish motion trajectory associations for suspected overlapping targets to reduce continuous false positives.
5. The method for sorting Chinese herbal medicine slices based on X-ray according to claim 1, characterized in that: The X-ray-based Chinese herbal medicine slice sorting method further comprises: Step S5: realizing impurity removal optimization through secondary detection and dynamic threshold adjustment.
6. The method for sorting Chinese herbal medicine slices based on X-ray according to claim 5, characterized in that: The step S5 specifically includes: Step S5-1: Set up a secondary test in the air blowing blanking area and collect rejected samples for result verification; Step S5-2: Establish an online learning mechanism, and error samples automatically trigger model fine-tuning: Where, is the model parameter update amount, is the learning rate, is the gradient operation function, is the air blowing error sample data set, is the validation set loss function, is the regularization coefficient, are the current model parameters, are the initial model parameters; Step S5-2: Correct the detection sensitivity according to the environmental parameters: Where, is the adjusted detection sensitivity threshold, is the basic threshold, is the humidity change, is the temperature change.
7. A Chinese herbal medicine slice sorting system based on X-ray, characterized in that: The X-ray-based Chinese herbal medicine slice sorting method according to any one of claims 1 to 6, wherein the X-ray-based Chinese herbal medicine slice sorting system comprises: A dual-view X-ray imaging unit, comprising a linear array detector and two X-ray sources arranged at a 45° angle above the conveyor belt, is used to capture orthogonal projection images of the slices to be sorted; A YOLOv5 model unit, wherein a 3D convolutional attention module and a deep supervision mechanism are introduced into the Neck structure of the YOLOv5 model; Generative adversarial network unit, used to generate occluded samples; The air blowing execution unit includes an array-type air nozzle group, a kinematic controller and a pressure regulator. The array-type air nozzle group includes a plurality of air nozzles arranged at equal intervals at the end of the conveyor belt; the kinematic controller is used to calculate the air blowing delay time according to the real-time speed of the conveyor belt, and the pressure regulator is used to adjust the air blowing pressure of the air nozzle.
8. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the steps of the X-ray-based Chinese herbal medicine slice sorting method according to any one of claims 1 to 6 can be implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the X-ray-based Chinese herbal medicine slice sorting method according to any one of claims 1 to 6 can be implemented.
Citation Information
Patent Citations
Automatic traditional Chinese medicine screening device based on machine vision
CN109499919A
Security check contraband detection method based on multi-scale attention and data enhancement
CN116883933A
X-ray security check image dangerous goods detection algorithm based on YOLOv7
CN117274774A
Method, apparatus and system for determining if a piece of luggage contains a liquid product
US20120275646A1