Methods, apparatus, equipment, storage media and procedures for the detection of Chinese herbal granules
By improving the YOLOv8 model and multi-core attention module, the problem of low detection accuracy of Chinese medicine powder particles was solved, and efficient and accurate particle detection and quality control were achieved, especially the detection effect was improved under the conditions of uneven particle size and overlap.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- JIANGSU KANION PHARMA CO LTD
- Filing Date
- 2025-05-27
- Publication Date
- 2026-06-30
Smart Images

Figure CN120656166B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of target detection technology, specifically to a method, apparatus, equipment, storage medium, and program product for detecting traditional Chinese medicine granules. Background Technology
[0002] Traditional Chinese medicine (TCM) powder is an important form of TCM usage, involving grinding medicinal materials into granules for convenient carrying and administration by patients. The particle size of TCM powder affects the specific surface area of the drug particles, thus influencing the solubility and bioavailability of the TCM, and also impacting production efficiency, product quality, and medication safety. Due to the irregularity and non-uniformity of TCM powder particles, measuring their weight is complex, and methods such as sieving, sedimentation, and laser measurement have low efficiency and limited online application.
[0003] In recent years, image granularity detection technology based on deep neural networks has attracted widespread attention. With its excellent feature extraction and nonlinear mapping capabilities, deep learning methods have demonstrated significant accuracy advantages in granularity detection. Among them, the YOLO (You Only Look Once) algorithm, due to its outstanding performance in speed, global vision, and generalization ability, has become the preferred model in many industrial applications, meeting the high requirements for real-time performance and accuracy in production processes. YOLOv8, as the 8th generation object detection model in the YOLO series, has innovated in its backbone network and neck structure, effectively improving the model's performance and flexibility.
[0004] However, despite YOLOv8's excellent performance in target detection, the uneven particle size distribution of traditional Chinese medicine powder and the tendency for particles to overlap can still lead to missed detections and decreased accuracy, severely interfering with the detection process and reducing detection precision. Summary of the Invention
[0005] In view of this, the present invention provides a method, apparatus, equipment, storage medium and program product for detecting Chinese medicine granules, so as to solve the problem of low detection accuracy of Chinese medicine powder granules in the prior art.
[0006] In a first aspect, the present invention provides a method for detecting traditional Chinese medicine granules, the method comprising:
[0007] Acquire images of the Chinese herbal medicine granules to be detected;
[0008] The image of the Chinese medicine granules to be detected is input into the pre-constructed improved YOLOv8 Chinese medicine granule detection model to obtain the detection results. The improved YOLOv8 Chinese medicine granule detection model is obtained by replacing all strided convolutional layers in the backbone network and neck network of the original YOLOv8 model with cross-block multi-core attention spatial depth modules.
[0009] The method for detecting Chinese medicine particles proposed in this invention enhances the model's ability to learn features of small-diameter particles by combining the YOLOv8 model with a cross-sub-block multi-core attention spatial depth module, significantly improving the overall detection accuracy of particles. In particular, it improves the detection effect in cases of uneven particle size and particle overlap, effectively realizing the rapid detection and accurate positioning of Chinese medicine particles.
[0010] In one optional implementation, the cross-sub-block multi-core attention spatial depth module includes: a cross-sub-block spatial attention layer and a multi-core channel attention layer connected in sequence; wherein, the cross-sub-block spatial attention layer is used to output the input sub-feature map as a spatial attention feature map; and the multi-core channel attention layer is used to output the input spatial attention feature map after channel attention adjustment.
[0011] This embodiment combines cross-sub-block spatial attention and multi-core channel attention. Through effective feature extraction and channel importance modeling, it effectively enhances the model's ability to capture fine-grained information, thereby exhibiting higher accuracy and robustness in small target detection tasks. The cross-sub-block multi-core attention spatial depth module proposed in this invention can effectively improve the performance of small target detection.
[0012] In one alternative implementation, the cross-sub-block spatial attention layer includes:
[0013] Receive the input sub-feature map;
[0014] Perform average pooling and max pooling operations on the sub-feature maps respectively to obtain the average pooling results and max pooling results;
[0015] The results of average pooling and max pooling are combined and then fed into the convolutional layer.
[0016] Activation operations are performed on the convolution results of the convolutional layer to obtain the spatial attention map corresponding to the sub-feature map;
[0017] The spatial attention map is applied to the sub-feature map, and the applied sub-feature map is placed sequentially into the channel dimension according to the index order to generate the spatial attention feature map.
[0018] In one alternative implementation, the multi-core channel attention layer includes:
[0019] Spatial information compression is performed on the input spatial attention feature map to obtain the global features of each channel;
[0020] Perform convolution operations of different sizes on the global features of each channel to obtain convolution feature maps of different sizes;
[0021] We obtain channel attention features by weighted fusion of convolutional feature maps of different sizes that correspond one-to-one.
[0022] The channel attention features are activated and recalibrated to obtain the adjusted feature map.
[0023] In this embodiment, by combining cross-sub-block spatial attention and multi-core channel attention, and through effective feature extraction and channel importance modeling, the model's ability to capture fine-grained information can be effectively enhanced, thereby exhibiting higher accuracy and robustness in small target detection tasks.
[0024] In one optional implementation, after obtaining the test results of the traditional Chinese medicine granules, the method further includes:
[0025] Obtain a pre-built particle weight percentage prediction model;
[0026] Based on the test results of Chinese herbal medicine granules, the total number of granules and the total projected area of the granules were determined.
[0027] Input the total number of particles and the total projected area of the particles into the particle weight percentage prediction model to obtain the particle weight percentage result.
[0028] This implementation combines target detection technology with regression modeling, proposing a two-stage prediction framework that integrates an improved YOLOv8 model and multiple linear regression to predict particle weight percentage, thereby providing quantitative information such as particle weight percentage. By predicting the particle weight percentage, quality in the production process can be effectively controlled, ensuring the consistency of quality in each batch of products; it can also help analyze non-uniformity or anomalies in the production process, thereby optimizing the production process and improving efficiency.
[0029] In one alternative implementation, the weight percentage prediction model is established through the following steps:
[0030] Obtain a set of images of Chinese herbal medicine granule samples;
[0031] Determine the total number of granules, the total projected area of the granules, and the weight percentage of each granule in the image set of Chinese medicine granules.
[0032] A multiple linear regression model was constructed by using the total number of particle samples and the total projected area of particle samples as independent variables and the weight ratio of particle samples as dependent variable.
[0033] The constructed multiple linear regression model was used as the weight proportion prediction model.
[0034] In this embodiment, after particle detection, a particle weight ratio prediction model is further constructed using linear regression to improve the measurement of particle weight characteristics. This not only successfully detects particles but also effectively overcomes the challenge of detecting small particles, significantly improving the model's robustness. Furthermore, it provides an innovative technology for particle size detection in traditional Chinese medicine, offering efficient and reliable technical support for quality control in traditional Chinese medicine production.
[0035] Secondly, the present invention provides a device for detecting traditional Chinese medicine granules, the device comprising:
[0036] The acquisition module is used to acquire images of the Chinese herbal medicine granules to be detected;
[0037] The detection module is used to input the image of the Chinese medicine granules to be detected into a pre-constructed improved YOLOv8 Chinese medicine granule detection model to obtain the detection results. The improved YOLOv8 Chinese medicine granule detection model is obtained by replacing all strided convolutional layers in the backbone network and neck network of the original YOLOv8 model with cross-sub-block multi-core attention spatial depth modules.
[0038] Thirdly, the present invention provides a computer device, comprising: a memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the computer instructions to perform the traditional Chinese medicine granule detection method of the first aspect or any corresponding embodiment described above.
[0039] Fourthly, the present invention provides a computer-readable storage medium storing computer instructions for causing a computer to execute the method for detecting traditional Chinese medicine granules described in the first aspect or any corresponding embodiment.
[0040] Fifthly, the present invention provides a computer program product, including computer instructions, which are used to cause a computer to execute the method for detecting traditional Chinese medicine granules described in the first aspect or any corresponding embodiment.
[0041] It should be noted that the traditional Chinese medicine granule detection device, computer equipment, computer-readable storage medium, and computer program product provided by this invention correspond to the aforementioned traditional Chinese medicine granule detection method. Therefore, regarding the beneficial effects of the traditional Chinese medicine granule detection device, computer equipment, computer-readable storage medium, and computer program product, please refer to the description of the corresponding beneficial effects of the traditional Chinese medicine granule detection method above, and will not be repeated here. Attached Figure Description
[0042] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0043] Figure 1 This is a schematic flowchart of a method for detecting traditional Chinese medicine granules according to an embodiment of the present invention;
[0044] Figure 2 This is a schematic diagram of the original YOLOv8 model structure according to an embodiment of the present invention;
[0045] Figure 3 This is a schematic diagram of the detection results of traditional Chinese medicine granules according to an embodiment of the present invention;
[0046] Figure 4 This is a schematic diagram of manually labeled Chinese herbal medicine granules according to an embodiment of the present invention;
[0047] Figure 5 This is a schematic diagram of the cross-sub-block multi-core attention space depth module structure according to an embodiment of the present invention;
[0048] Figure 6 This is a schematic diagram of the weight percentage prediction results according to an embodiment of the present invention;
[0049] Figure 7 This is a structural block diagram of a traditional Chinese medicine granule detection device according to an embodiment of the present invention;
[0050] Figure 8 This is a schematic diagram of the structure of a traditional Chinese medicine granule detection system according to an embodiment of the present invention;
[0051] Figure 9 This is a schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. Detailed Implementation
[0052] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0053] According to an embodiment of the present invention, a method for detecting traditional Chinese medicine granules is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0054] This embodiment provides a method for detecting traditional Chinese medicine granules, which can be executed by devices such as servers, terminals, and mobile terminals. Figure 1 This is a flowchart of a method for detecting traditional Chinese medicine granules according to an embodiment of the present invention, such as... Figure 1 As shown, the process includes the following steps:
[0055] Step S101: Obtain an image of the Chinese herbal medicine granules to be detected. The image of the Chinese herbal medicine granules to be detected can be a picture of Chinese herbal medicine powder granules acquired by an image acquisition device.
[0056] Step S102: Input the image of the Chinese medicine granules to be detected into the pre-constructed improved YOLOv8 Chinese medicine granule detection model to obtain the detection result of the Chinese medicine granules; wherein, the improved YOLOv8 Chinese medicine granule detection model is obtained by replacing all the strided convolutional layers in the backbone network and neck network of the original YOLOv8 model except for the first strided convolutional layer of the backbone network with cross-sub-block multi-core attention spatial depth modules.
[0057] The YOLO (You Only Look Once) model family is a real-time object detection algorithm based on deep learning. Its principle is to use a single neural network to simultaneously classify and regress the location of objects during a single forward propagation, thus achieving efficient object detection. Unlike traditional object detection methods, the YOLO model directly divides the image into a grid and predicts the category and location of objects within each grid, significantly improving the algorithm's real-time performance. Due to its efficient detection process and fast inference speed, YOLO is widely used in real-time scenarios. YOLOv8, as the eighth generation of the YOLO series, further optimizes the original architecture, resulting in significant improvements in object detection performance in several aspects. Its main innovations are reflected in several aspects: 1. The YOLOv8 model introduces an anchor-free strategy, avoiding the limitations of traditional methods that rely on fixed anchor boxes, thereby improving the detection accuracy for small objects and targets of different scales; 2. The YOLOv8 model adopts a more efficient network structure for feature extraction and combines various novel modules (such as SPPF and C2f) to enhance the ability to capture multi-scale features; 3. The YOLOv8 model design emphasizes a balance between speed and accuracy, making it not only perform well in routine tasks but also maintain high efficiency in applications with high real-time requirements. These improvements make YOLOv8 more accurate and robust in target detection in complex backgrounds, especially in the task of detecting Chinese medicine powder particles, where it can accurately identify Chinese medicine powders of different particle sizes and quickly process large-scale image data, meeting the needs of efficient detection.
[0058] The YOLOv8 network structure used in this embodiment consists of four parts, as shown in the figure. Figure 2 As shown, the network consists of the input layer, backbone, neck, and head. The application of each part is as follows:
[0059] The primary task of the input layer is to receive the input image and enhance the diversity of the training data through online data augmentation. In the task of detecting Chinese herbal medicine particles, the input layer can simulate different shooting angles, lighting changes, and particle size variations by performing data augmentation techniques such as image rotation, cropping, and scaling. This improves the model's adaptability to different situations, thereby enhancing its robustness. Especially when faced with variations in the morphology of different Chinese herbal medicine particles, data augmentation helps the model better identify particles of different shapes and sizes.
[0060] The backbone network is mainly responsible for extracting features from the image. YOLOv8 adopts a network architecture based on DarkNet53, combined with SPPF (Spatial Pyramid Pooling Fast) and C2f (CSP Bottleneck) modules to improve the accuracy and efficiency of feature extraction.
[0061] The SPPF module captures features at different scales in an image through multi-scale pooling operations. This is particularly important for the detection of Chinese medicine particles, as the size of the particles may vary greatly. The SPPF module can effectively handle particles of different sizes and enhance the recognition of small particles.
[0062] The C2f module optimizes the network's deep feature extraction by introducing multiple Bottleneck units, convolutional layers, and skip connections. Traditional Chinese medicine granules often exhibit complex textures and shapes due to powder or impurities. The C2f module can establish better connections between deeper features and shallower details through these skip connections, helping the model better identify the subtle features of the granules.
[0063] The neck network is primarily responsible for fusing feature information from different levels to generate the final detection result. YOLOv8 combines a Feature Pyramid Network (FPN) and a Path Aggregation Network (PAN) in its neck network.
[0064] FPN fuses features from different levels in a top-down manner, effectively combining high-level semantic features with low-level detail features. For the detection of Chinese medicine particles, FPN can effectively fuse macroscopic information and microscopic details of particles in an image, ensuring that even small and complex particles can be accurately detected.
[0065] PAN (Polymerase Interaction) aggregates low-level detailed information in a bottom-up manner, enhancing the expressive power of features. This is particularly important in the detection of Chinese medicine granules, because the morphology of powder particles is usually quite complex, and PAN helps to further extract detailed information about the particles, improving the detection accuracy of small or obscured particles.
[0066] The output layer employs an anchor-free strategy, directly predicting the center position, size, and category of the target without relying on traditional anchor box designs. This design offers significant advantages in detecting traditional Chinese medicine granules, as the shapes and sizes of granules vary considerably, and traditional anchor boxes often fail to cover all variations. The anchor-free strategy enables YOLOv8 to adaptively predict the precise position and size of each granule, improving detection efficiency and accuracy. Through decoupling, the output layer not only enhances prediction speed but also strengthens the model's ability to detect granules of different sizes and shapes.
[0067] In the YOLOv8 architecture, the strided convolutional layer (Conv) extracts features by skipping some pixels, which effectively captures relatively obvious features in most tasks. However, when dealing with small targets such as powder particles, strided convolutions may lose some key details due to the limited fine-grained information, thus weakening the model's representational ability. Especially when processing small particles in powder, subtle morphological changes and local features are crucial for accurate identification. Therefore, to address this issue, this invention involves the operation of strided convolutional layers (Conv) in the Backbone and Neck parts of YOLOv8. Except for the first strided convolutional layer after the input layer, the remaining strided convolutional layers are replaced with cross-sub-block multi-kernel attention spatial depth modules, thereby preserving more fine-grained feature information. Furthermore, the model's sensitivity to small targets is enhanced through cross-sub-block spatial attention and multi-kernel channel attention mechanisms, thereby improving the model's performance and robustness in powder particle detection tasks.
[0068] The improved YOLOv8 traditional Chinese medicine granule detection model constructed in this embodiment uses sample images collected from the production site, covering three different types of traditional Chinese medicine granules: Xingbei Zhike Granules, Sanhan Huashi Granules, and Yinqiao Jiedu Granules. The granule detection dataset contains a total of 582 images, each with a resolution of 4000 pixels × 3000 pixels. After expert annotation, the granule images were randomly divided into a training set of 465 images and a test set of 116 images at an 8:2 ratio. The granule weight ratio prediction part used 660 samples, all from the same variety, and did not overlap with the dataset of the target detection part. After weighing the granules and powder in the laboratory, the true proportion was calculated by mixing them, and then randomly divided into a training set of 528 samples and a test set of 132 samples at an 8:2 ratio.
[0069] Model training consists of two parts. The first part is the training of a traditional Chinese medicine particle detection model based on cross-sub-block multi-core attention space depth and YOLOv8. Sample image data is input into the model, and the training epochs are set to 200. In each training epoch, precision (P), recall (R), and mean average precision (mAP50) are used as evaluation metrics to assess the model's performance in the particle size detection task.
[0070] To comprehensively evaluate the performance of the improved model, multiple control groups were set up in this experiment, including the original YOLOv8 model and a version of YOLOv8 combined with a traditional spatial depth module. By comparing the improved YOLOv8 model with these two control models on a particle detection task, the significant improvements in accuracy and robustness were verified. The comparison results are shown in Table 1.
[0071] Table 1
[0072] Model P / % R / % mAP@0.5 / % YOLOv8 73.6 63.9 70.2 YOLOv8 combines traditional spatial depth modules 74.7 66.5 72.7 YOLOv8 combined with multi-core attention space depth across sub-blocks 75.5 67.0 73.5
[0073] As shown in Table 1, the baseline YOLOv8 has an mAP@0.5 of 70.2%. Introducing the traditional spatial depth module improves detection accuracy, increasing mAP@0.5 by 3.6%. Using the module proposed in this invention, mAP@0.5 is improved by 4.7% compared to the baseline model, with significant improvements in precision (P) and recall (R), demonstrating excellent detection performance. Furthermore, compared to the model with the traditional spatial depth module, the proposed model improves mAP@0.5 by 1.1%, confirming the superior accuracy of this invention in small particle detection. The detection results using the proposed model are shown in the table below. Figure 3 As shown, Figure 4 These are manually labeled results.
[0074] The proposed method for detecting Chinese medicine particles in this embodiment enhances the model's ability to learn features of small-diameter particles by combining the YOLOv8 model with a multi-core attention spatial depth module across sub-blocks. This significantly improves the overall detection accuracy of particles, especially in cases of uneven particle size and particle overlap, thereby enhancing the detection effect and effectively achieving rapid detection and precise positioning of Chinese medicine particles.
[0075] In some optional implementations, the cross-sub-block multi-core attention spatial depth module includes: a cross-sub-block spatial attention layer and a multi-core channel attention layer connected in sequence; wherein, the cross-sub-block spatial attention layer is used to output the input sub-feature map as a spatial attention feature map; and the multi-core channel attention layer is used to output the input spatial attention feature map after channel attention adjustment.
[0076] This embodiment combines cross-sub-block spatial attention and multi-core channel attention. Through effective feature extraction and channel importance modeling, it effectively enhances the model's ability to capture fine-grained information, thereby exhibiting higher accuracy and robustness in small target detection tasks. The cross-sub-block multi-core attention spatial depth module proposed in this invention can effectively improve the performance of small target detection.
[0077] In some alternative implementations, the cross-subblock space attention layer includes:
[0078] Receive the input sub-feature map;
[0079] Perform average pooling and max pooling operations on the sub-feature maps respectively to obtain the average pooling results and max pooling results;
[0080] The results of average pooling and max pooling are combined and then fed into the convolutional layer.
[0081] Activation operations are performed on the convolution results of the convolutional layer to obtain the spatial attention map corresponding to the sub-feature map;
[0082] The spatial attention map is applied to the sub-feature map, and the applied sub-feature map is placed sequentially into the channel dimension according to the index order to generate the spatial attention feature map.
[0083] Specifically, refer to Figure 5 As shown, before data processing in the cross-block spatial attention layer, the S×S×C feature map X is first split according to the stride P of the original strided convolutional layer to obtain P. 2 Each sub-feature map. Its calculation expression is as follows:
[0084]
[0085] In the formula, n,m∈[0,P-1] are the slice indices of the sub-feature map.
[0086] In this embodiment, P = 2, therefore four sub-feature maps can be obtained, X 0,0 X 0,1 X 1,0 X 1,1 Each one has a size of (S / 2)×(S / 2)×C.
[0087] Spatial attention is applied to each sub-feature map to enhance important features within each sub-block. This process begins by performing average pooling and max pooling operations on each sub-feature map, yielding the average pooling result (AvgPool) and the max pooling result (MaxPool) for each sub-feature map. These two results are then combined and used as spatial information between channels, inputting them into a convolutional layer for processing. The spatial attention map of the sub-feature map is obtained through convolution. The formula is as follows:
[0088]
[0089] In the formula, σ represents the Sigmoid mapping function.
[0090] The spatial attention map of the sub-feature map is applied to each sub-feature map and placed sequentially into the channel dimension according to the index order, generating a new feature map X′(S / 2)×(S / 2)×4C, which is the spatial attention feature map. This successfully achieves downsampling of the feature map while preserving the fine-grained information in the original feature map to the maximum extent.
[0091] The formula for merging is: X′=concat(X 0,0 ·attn0,X 0,1 ·attn1,X 1,0 ·attn2,X 1,1 ·attn3).
[0092] In some alternative implementations, the multi-core channel attention layer includes:
[0093] Spatial information compression is performed on the input spatial attention feature map to obtain the global features of each channel;
[0094] Perform convolution operations of different sizes on the global features of each channel to obtain convolution feature maps of different sizes;
[0095] We obtain channel attention features by weighted fusion of convolutional feature maps of different sizes that correspond one-to-one.
[0096] The channel attention features are activated and recalibrated to obtain the adjusted feature map.
[0097] Reference Figure 5 As shown, in the multi-core channel attention module, the input feature map is first spatially compressed using a global average pooling (GAP) operation to obtain the global feature representation for each channel. The formula is as follows:
[0098]
[0099] Where H and W are the height and width of the spatial attention feature map, and X c (i,j) represents the value at position (i,j) in the spatial attention feature map, y c It is the global feature scalar of channel c.
[0100] The global features of each channel are processed using multiple 1D convolutional kernels of different sizes (3×3, 5×5, 7×7). Each convolutional kernel generates a feature map of a different size, which is then weighted and fused to obtain the final channel attention features, as shown in the following formula:
[0101]
[0102] In the formula, K is the number of different convolution kernels, and w k These are the weight coefficients corresponding to the convolution kernel, representing the importance of that kernel. These weights are directly defined through learnable parameters called Fusion Weights and are optimized during training. k This represents convolution operations with different kernel sizes.
[0103] To ensure that the weights of all convolutional kernels sum to 1, this embodiment also uses the Softmax function to normalize FusionWeights. Finally, the Sigmoid function is applied to the weighted fused features for activation, and then recalibrated to obtain the adjusted feature map.
[0104] In this embodiment, by combining cross-sub-block spatial attention and multi-core channel attention, and through effective feature extraction and channel importance modeling, the model's ability to capture fine-grained information can be effectively enhanced, thereby demonstrating higher accuracy and robustness in small target detection tasks.
[0105] In some optional embodiments, after obtaining the test results of the traditional Chinese medicine granules, the method further includes:
[0106] Obtain a pre-built particle weight percentage prediction model;
[0107] Based on the test results of Chinese herbal medicine granules, the total number of granules and the total projected area of the granules were determined.
[0108] Input the total number of particles and the total projected area of the particles into the particle weight percentage prediction model to obtain the particle weight percentage result.
[0109] The detection results of Chinese herbal medicine granules obtained using the improved YOLOv8 model include the coordinate information of all detection boxes. The projected area of the granules corresponding to each detection box can be calculated based on pixel analysis, and the total number of granules (N) and the total projected area (Stotal) in the entire image can be statistically analyzed to construct two key morphological feature variables.
[0110] Then, the total number of particles N and the total projected area Stotal extracted during the detection phase can be used as independent variables and input into the particle weight percentage prediction model, which adopts a multiple linear regression model, namely:
[0111] W pred =β0 + β1 × N + β2 × S total +ε
[0112] Among them, W pred This represents the particle weight percentage, where N is the total number of particles, and S... total ε represents the total projected area of the particles, β0 is the intercept term, β1 and β2 are the regression coefficients, and ε is the error term.
[0113] This model can accurately predict the weight percentage of powder based on the number and total area of particles in an image.
[0114] This embodiment combines target detection technology with regression modeling, proposing a two-stage prediction framework that integrates an improved YOLOv8 model and multiple linear regression to predict particle weight percentage, thereby providing quantitative information such as particle weight percentage. By predicting the particle weight percentage, quality in the production process can be effectively controlled, ensuring the consistency of quality in each batch of products; it can also help analyze non-uniformity or anomalies in the production process, thereby optimizing the production process and improving efficiency.
[0115] In some alternative implementations, the weight percentage prediction model is established through the following steps:
[0116] Obtain a set of images of Chinese herbal medicine granule samples;
[0117] Determine the total number of granules, the total projected area of the granules, and the weight percentage of each granule in the image set of Chinese medicine granules.
[0118] A multiple linear regression model was constructed by using the total number of particle samples and the total projected area of particle samples as independent variables and the weight ratio of particle samples as dependent variable.
[0119] The constructed multiple linear regression model was used as the weight proportion prediction model.
[0120] In this embodiment, after particle detection, a particle weight ratio prediction model is further constructed using a linear regression method to improve the measurement of particle weight characteristics. This embodiment collects images of traditional Chinese medicine particles from actual industrial production, which are then annotated by experts to construct a dataset. Based on this, a YOLOv8 detection model and a particle weight ratio prediction model embedding a cross-sub-block multi-core attention spatial depth module are developed, and detection experiments are conducted on new production images. Experimental results show that the model not only successfully detects particles but also effectively overcomes the challenge of detecting small particles, significantly improving the model's robustness. Furthermore, it provides an innovative technology for the particle size detection of traditional Chinese medicine, offering efficient and reliable technical support for quality control in traditional Chinese medicine production.
[0121] The multiple linear regression model trained in this embodiment can predict the mapping relationship between particle characteristics and weight percentage. The accuracy of the prediction results is evaluated by calculating the mean relative error (MRE). For the predicted weight percentage, the actual weight and predicted weight of all validation samples are plotted on the same coordinate graph, with reference to... Figure 6 As shown, the R of the model 2 The mean relative error (MRE) was 0.9063, and the mean relative error (MRE) was 12.8%, which is within the acceptable deviation range for production operation, demonstrating the stability and reliability of the model in practical applications.
[0122] This embodiment also provides a traditional Chinese medicine granule detection device, which is used to implement the above embodiments and preferred embodiments; details already described will not be repeated. As used below, the term "module" can refer to a combination of software and / or hardware that performs a predetermined function. Although the device described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.
[0123] This embodiment provides a device for detecting traditional Chinese medicine granules, such as... Figure 7 As shown, the device includes:
[0124] The acquisition module 201 is used to acquire images of the Chinese herbal medicine granules to be detected;
[0125] The detection module 202 is used to input the image of the Chinese herbal medicine granules to be detected into a pre-constructed improved YOLOv8 Chinese herbal medicine granule detection model to obtain the detection results. The improved YOLOv8 Chinese herbal medicine granule detection model is obtained by replacing all strided convolutional layers in the backbone network and neck network of the original YOLOv8 model (except for the first strided convolutional layer of the backbone network) with a cross-sub-block multi-kernel attention spatial depth module. The cross-sub-block multi-kernel attention spatial depth module includes a cross-sub-block spatial attention layer and a multi-kernel channel attention layer connected in sequence. The cross-sub-block spatial attention layer outputs the input sub-feature map as a spatial attention feature map; the multi-kernel channel attention layer outputs the input spatial attention feature map after channel attention adjustment.
[0126] In some alternative embodiments, the apparatus further includes:
[0127] The particle weight percentage prediction module is used to obtain a pre-built particle weight percentage prediction model; based on the detection results of Chinese medicine particles, it determines the total number of particles and the total projected area of particles; and inputs the total number of particles and the total projected area of particles into the particle weight percentage prediction model to obtain the particle weight percentage result.
[0128] The weight percentage prediction model construction unit is used to acquire a set of Chinese herbal medicine granule sample images; determine the total number of granule samples, the total projected area of the granule samples, and the weight percentage of the granule samples corresponding to each Chinese herbal medicine granule sample image in the set of Chinese herbal medicine granule sample images; construct a multiple linear regression model with the total number of granule samples and the total projected area of the granule samples as independent variables and the weight percentage of the granule samples as dependent variables; and use the constructed multiple linear regression model as the weight percentage prediction model.
[0129] The herbal granule detection device in this embodiment is presented in the form of a functional unit. Here, a unit refers to an ASIC circuit, a processor and memory that execute one or more software or fixed programs, and / or other devices that can provide the above functions.
[0130] Further functional descriptions of the above modules and units are the same as those in the corresponding embodiments described above, and will not be repeated here.
[0131] Reference Figure 8The diagram shows a schematic of a traditional Chinese medicine (TCM) granule detection system provided according to an embodiment of the present invention. The system includes an acquisition module composed of actual cameras, a detection module, and a host computer display module. The cameras are used to acquire images of the TCM granules to be detected and input the images into the detection module. The detection module is equipped with the improved YOLOv8 detection model described in this embodiment, which can accurately detect and identify the TCM granules in the images. After detection, the results are transmitted to the host computer for display and further data processing, such as calculating the total number of granules, the total projected area, and predicting the granule weight percentage. This system structure embodies a complete closed-loop process from image acquisition and model detection to result display, ensuring the real-time nature and effectiveness of TCM granule quality control.
[0132] This invention also provides a computer device having the above-described features. Figure 7 The device shown is for detecting Chinese herbal medicine granules.
[0133] Please see Figure 9 , Figure 9 This is a schematic diagram of the structure of a computer device provided in an optional embodiment of the present invention, such as... Figure 9 As shown, the computer device includes one or more processors 10, memory 20, and interfaces for connecting the components, including high-speed interfaces and low-speed interfaces. The components communicate with each other via different buses and can be mounted on a common motherboard or otherwise installed as needed. The processors can process instructions executed within the computer device, including instructions stored in or on memory to display graphical information of a GUI on external input / output devices (such as display devices coupled to the interfaces). In some alternative implementations, multiple processors and / or multiple buses can be used with multiple memories and multiple memory modules, if desired. Similarly, multiple computer devices can be connected, each providing some of the necessary operations (e.g., as a server array, a group of blade servers, or a multiprocessor system). Figure 9 Take a processor 10 as an example.
[0134] Processor 10 may be a central processing unit, a network processor, or a combination thereof. Processor 10 may further include a hardware chip. The hardware chip may be an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof. The programmable logic device may be a complex programmable logic device (CAMP), a field-programmable gate array (FPGA), a general-purpose array logic (GDA), or any combination thereof.
[0135] The memory 20 stores instructions executable by at least one processor 10 to cause the at least one processor 10 to perform the method shown in the above embodiments.
[0136] The memory 20 may include a program storage area and a data storage area. The program storage area may store the operating system and applications required for at least one function; the data storage area may store data created based on the use of the computer device. Furthermore, the memory 20 may include high-speed random access memory and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some alternative embodiments, the memory 20 may optionally include memory remotely located relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.
[0137] The memory 20 may include volatile memory, such as random access memory; the memory may also include non-volatile memory, such as flash memory, hard disk or solid-state drive; the memory 20 may also include a combination of the above types of memory.
[0138] The computer device also includes a communication interface 30 for communicating with other devices or communication networks.
[0139] This invention also provides a computer-readable storage medium. The methods described above according to embodiments of the invention can be implemented in hardware or firmware, or implemented as computer code that can be recorded on a storage medium, or implemented as computer code downloaded via a network and originally stored on a remote storage medium or a non-transitory machine-readable storage medium and then stored on a local storage medium. Thus, the methods described herein can be processed by software stored on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. The storage medium can be a magnetic disk, optical disk, read-only memory, random access memory, flash memory, hard disk, or solid-state drive, etc.; further, the storage medium can also include combinations of the above types of memory. It is understood that computers, processors, microprocessor controllers, or programmable hardware include storage components capable of storing or receiving software or computer code, which, when accessed and executed by the computer, processor, or hardware, implements the methods shown in the above embodiments.
[0140] A portion of this invention can be applied as a computer program product, such as computer program instructions, which, when executed by a computer, can invoke or provide the methods and / or technical solutions according to the invention through the operation of the computer. Those skilled in the art will understand that the forms in which computer program instructions exist in a computer-readable medium include, but are not limited to, source files, executable files, installation package files, etc. Correspondingly, the ways in which computer program instructions are executed by a computer include, but are not limited to: the computer directly executing the instructions, or the computer compiling the instructions and then executing the corresponding compiled program, or the computer reading and executing the instructions, or the computer reading and installing the instructions and then executing the corresponding installed program. Here, the computer-readable medium can be any available computer-readable storage medium or communication medium accessible to a computer.
[0141] Although embodiments of the invention have been described in conjunction with the accompanying drawings, those skilled in the art can make various modifications and variations without departing from the spirit and scope of the invention, and such modifications and variations all fall within the scope defined by the appended claims.
Claims
1. A method for detecting traditional Chinese medicine granules, characterized in that, The method includes: Acquire images of the Chinese herbal medicine granules to be detected; The image of the Chinese herbal medicine granules to be detected is input into a pre-constructed improved YOLOv8 Chinese herbal medicine granule detection model to obtain the detection results; wherein, the improved YOLOv8 Chinese herbal medicine granule detection model is obtained by replacing all strided convolutional layers in the backbone network and neck network of the original YOLOv8 model except for the first strided convolutional layer of the backbone network with cross-sub-block multi-core attention spatial depth modules after training; The cross-sub-block multi-core attention spatial depth module includes: a cross-sub-block spatial attention layer and a multi-core channel attention layer connected in sequence; wherein, the cross-sub-block spatial attention layer is used to output the input sub-feature map as a spatial attention feature map; the multi-core channel attention layer is used to output the input spatial attention feature map after channel attention adjustment; The cross-sub-block spatial attention layer includes: The input sub-feature map is received; wherein, before data processing is performed in the cross-sub-block spatial attention layer, the feature map is first split according to the stride of the original strided convolutional layer to obtain the sub-feature map; Average pooling and max pooling operations are performed on the sub-feature maps respectively to obtain average pooling results and max pooling results; The average pooling and max pooling results are combined and then input into the convolutional layer. An activation operation is performed on the convolution result of the convolutional layer to obtain the spatial attention map corresponding to the sub-feature map; The spatial attention map is applied to the sub-feature map, and the applied sub-feature map is placed sequentially into the channel dimension according to the index order to generate a spatial attention feature map. The multi-core channel attention layer includes: Spatial information compression is performed on the input spatial attention feature map to obtain the global features of each channel; Perform convolution operations of different sizes on the global features of each channel to obtain convolution feature maps of different sizes; The convolutional feature maps of different sizes are weighted and fused to obtain channel attention features. The channel attention features are activated and recalibrated to obtain an adjusted feature map.
2. The method according to claim 1, characterized in that, After obtaining the test results of the traditional Chinese medicine granules, the method further includes: Obtain a pre-built particle weight percentage prediction model; Based on the test results of the Chinese herbal medicine granules, the total number of granules and the total projected area of the granules were determined. The total number of particles and the total projected area of the particles are input into the particle weight ratio prediction model to obtain the particle weight ratio result.
3. The method according to claim 2, characterized in that, The weight percentage prediction model is established through the following steps: Obtain a set of images of Chinese herbal medicine granule samples; Determine the total number of granules, the total projected area of the granules, and the weight percentage of the granules corresponding to each granule sample image in the Chinese herbal medicine granule sample image set. A multiple linear regression model is constructed by taking the total number of particle samples and the total projected area of the particle samples as independent variables and the weight ratio of the particle samples as dependent variables. The constructed multiple linear regression model is used as the weight proportion prediction model.
4. A device for detecting traditional Chinese medicine granules, characterized in that, The device includes: The acquisition module is used to acquire images of the Chinese herbal medicine granules to be detected; The detection module is used to input the image of the Chinese herbal medicine granules to be detected into a pre-constructed improved YOLOv8 Chinese herbal medicine granule detection model to obtain the detection result of the Chinese herbal medicine granules; wherein, the improved YOLOv8 Chinese herbal medicine granule detection model is obtained by replacing all the strided convolutional layers in the backbone network and the neck network of the original YOLOv8 model with a cross-sub-block multi-core attention spatial depth module after training; The cross-sub-block multi-core attention spatial depth module includes: a cross-sub-block spatial attention layer and a multi-core channel attention layer connected in sequence; wherein, the cross-sub-block spatial attention layer is used to output the input sub-feature map as a spatial attention feature map; the multi-core channel attention layer is used to output the input spatial attention feature map after channel attention adjustment; The cross-sub-block spatial attention layer includes: The input sub-feature map is received; wherein, before data processing is performed in the cross-sub-block spatial attention layer, the feature map is first split according to the stride of the original strided convolutional layer to obtain the sub-feature map; Average pooling and max pooling operations are performed on the sub-feature maps respectively to obtain average pooling results and max pooling results; The average pooling and max pooling results are combined and then input into the convolutional layer. An activation operation is performed on the convolution result of the convolutional layer to obtain the spatial attention map corresponding to the sub-feature map; The spatial attention map is applied to the sub-feature map, and the applied sub-feature map is placed sequentially into the channel dimension according to the index order to generate a spatial attention feature map. The multi-core channel attention layer includes: Spatial information compression is performed on the input spatial attention feature map to obtain the global features of each channel; Perform convolution operations of different sizes on the global features of each channel to obtain convolution feature maps of different sizes; The convolutional feature maps of different sizes are weighted and fused to obtain channel attention features. The channel attention features are activated and recalibrated to obtain an adjusted feature map.
5. A computer device, characterized in that, include: The device includes a memory and a processor, which are interconnected. The memory stores computer instructions, and the processor executes the computer instructions to perform the traditional Chinese medicine granule detection method according to any one of claims 1-3.
6. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions for causing the computer to perform the traditional Chinese medicine granule detection method according to any one of claims 1-3.
7. A computer program product, characterized in that, It includes computer instructions for causing a computer to perform the traditional Chinese medicine granule detection method according to any one of claims 1-3.