Traditional Chinese medicinal material identification method based on dual-channel dynamic convolution
By combining global-local dual-path dynamic convolution and multi-granularity coordinate attention modules, a lightweight Chinese medicinal herb recognition model is constructed, which solves the problems of multi-scale feature fusion, morphological diversity and spatial sensitivity in Chinese medicinal herb recognition, and achieves high-precision and low-cost Chinese medicinal herb recognition.
Patent Information
- Application Number
- CN202511031623.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-25
- Publication Date
- 2025-11-14
AI Technical Summary
Existing Chinese medicinal herb identification technologies have shortcomings in terms of multi-scale feature fusion, morphological diversity, spatial sensitivity, real-time performance, and deployment cost, making it difficult to achieve high-precision and robust detection results.
A method for identifying Chinese medicinal materials based on dual-path dynamic convolution is adopted. By combining a global-local dual-path dynamic convolution module and a multi-granularity coordinate attention module with dynamic feature extraction and spatial perception optimization, a lightweight medicinal material identification model is constructed and iteratively trained and deployed.
It achieves high-precision and robust recognition of Chinese medicinal materials, improves the detection accuracy of small and large targets, reduces computational complexity and hardware costs, and adapts to the needs of Chinese medicinal material recognition in complex scenarios.
Smart Images

Figure CN120953970A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a method for identifying medicinal materials, and more particularly to a method for identifying Chinese medicinal materials based on dual-path dynamic convolution, belonging to the field of computer vision and deep learning technology. Background Technology
[0002] As a core resource of traditional medicine, the accurate identification of Chinese medicinal herbs is crucial for ensuring medication safety and promoting the modernization of traditional Chinese medicine. However, the identification of Chinese medicinal herbs currently faces severe challenges: more than 12,000 kinds of Chinese medicinal herbs circulate globally, of which 30% are closely related species with highly similar morphologies. Traditional manual identification relies on experience, resulting in low efficiency, high error rates, and difficulty in meeting the needs of large-scale industrial testing.
[0003] While automated recognition technology has made some progress and can assist in classification, it still has significant limitations in complex scenarios, mainly as follows: I. Insufficient multi-scale feature fusion: Current methods for identifying Chinese medicinal herbs mainly rely on single-modal feature analysis. However, medicinal herbs may exist in images at extremely small or large scales. Traditional single-scale detection or simple feature fusion methods struggle to balance the detection accuracy of targets at different scales, often resulting in missed detections of small targets or inaccurate localization of large targets. For example, while traditional 5×5 convolutional kernels can cover a larger receptive field, they can blur fine structures such as surface textures of medicinal herbs; while 3×3 convolutional kernels may ignore global morphological information. Existing optimization methods such as CondConv only support weight adjustment of a single-dimensional channel and cannot simultaneously fuse multi-scale, multi-dimensional features. This leads to a detection accuracy of less than 70% for small targets such as seeds and a decreased ability to extract texture details for large targets such as roots and rhizomes.
[0004] II. Issues of morphological diversity: Traditional Chinese medicinal materials include targets with significant morphological differences, such as rhizomes, plants, and seeds. Traditional convolution operations with fixed receptive fields are difficult to adaptively capture features of different scales and complexities, resulting in insufficient feature extraction.
[0005] III. Insufficient spatial sensitivity: In practical applications, images of Chinese medicinal herbs may suffer from uneven lighting, varying shooting angles, and complex backgrounds. The identification of some herbs relies on subtle features such as leaf vein density, epidermal pubescence distribution, and cross-sectional texture. Existing methods struggle to accurately locate the main body of the herb, leading to the weakening of crucial information. For example, the SE attention mechanism only focuses on channel dimension weight allocation, ignoring spatial positional differences; while the CBAM attention mechanism combines channel and spatial attention, its spatial attention uses global pooling, failing to distinguish the importance of features in the horizontal and vertical directions. Experiments show that when the herb image is occluded or rotated, the false detection rate can rise to over 25%.
[0006] IV. The conflict between real-time requirements and deployment costs: Multimodal fusion technology offers a new approach to the identification of Chinese medicinal herbs; for example, combining images with terahertz spectral data can improve identification accuracy. However, existing multimodal spectral fusion models have high computational complexity, with inference latency exceeding 300ms when deployed on mobile devices, failing to meet the needs of production-level detection. Furthermore, the model parameters typically exceed 200MB, limiting their widespread application in small and medium-sized pharmaceutical companies due to hardware costs.
[0007] These limitations make it difficult for existing models to achieve high-precision and robust detection results in the context of Chinese medicinal materials. There is an urgent need to provide a Chinese medicinal material recognition method based on dual-path dynamic convolution that combines dynamic feature extraction, spatial perception optimization, and efficient multi-scale fusion. Summary of the Invention
[0008] To address the shortcomings of the aforementioned technologies, this invention provides a method for identifying Chinese medicinal materials based on dual-path dynamic convolution.
[0009] To solve the above technical problems, the technical solution adopted by this invention is: a method for identifying Chinese medicinal materials based on dual-path dynamic convolution, comprising the following steps: Step 1: Construct a database for identifying Chinese medicinal herbs; Step 2: Construct a lightweight medicinal herb recognition model; This lightweight medicinal herb recognition model is based on the YOLOv11 model and introduces a global-local dual-path dynamic convolution module and a granular coordinate attention module; A global-local dual-path dynamic convolution module is embedded in the backbone network, which has a dual-path feature extraction and adaptive fusion mechanism; the granular coordinate attention module maintains the basic CA core architecture and introduces a multi-granularity pooling mechanism. Step 3: Iteratively train the constructed lightweight medicinal herb identification model until the optimal model parameters are obtained; Step 4: Validate the performance of the optimized lightweight medicinal herb identification model; Step 5: Deploy the lightweight medicinal herb recognition model that has passed performance verification to GPUs and edge devices; Step 6: Call the lightweight medicinal herb recognition model to recognize the input Chinese medicinal herb image.
[0010] Preferably, the data in the Chinese medicinal herb identification database comes from images of Chinese medicinal herbs; the images of Chinese medicinal herbs undergo data enhancement processing, including: geometric transformation, color space enhancement processing, and special enhancement processing for Chinese medicinal herb images; The geometric transformation method is as follows: random rotation ±15°, scaling 0.8-1.2 times, and translation ±10% pixels to simulate different shooting angles; The color space enhancement processing method is to adjust brightness ±20%, contrast ±15%, and saturation ±15% to adapt to uneven lighting scenes. The special enhancement method for Chinese medicinal materials is to add Gaussian blur and sharpen to the image of powdered medicinal materials to enhance texture and simulate the noise of microscope images; Occlusion simulation is performed on the occluded image. 1-3 rectangular occlusion regions are randomly generated with an area ≤ 30% of the entire image. The occluded targets are then used to train the model.
[0011] Preferably, in step 2, the design strategy of the global-local dual-path dynamic convolution module is as follows: After inputting the feature map, firstly, dual-path parallel feature extraction is performed on the global feature path and the local feature path. Global average pooling is used to compress and extract global information of the channel dimension, and 1×1 convolution is used to extract local information. Secondly, the parallel features of the global feature path and the local feature path are fused through the attention mechanism; Subsequently, a dynamic weight matrix is generated through a fully connected layer, where the spatial sensitivity of the 3×3 convolution kernel is adjusted in the front part, and the weights of the 5×5 convolution kernel are expanded by bilinear interpolation in the back part. Finally, the two convolutional kernels are computed in parallel and then fused channel by channel according to dynamic weights.
[0012] As a preferred embodiment, the specific design method of the global-local dual-path dynamic convolution module is as follows: 1) Input feature map: Set input feature map Where R represents the real number field, X represents the input feature map, and the dimensions are, in order, the number of channels C, the height H, and the width W; 2) Dual parallel processing, including global feature paths and local feature paths; Global feature pathways: ; Local characteristic pathways: ; in, This indicates the output feature vector; This indicates the output of global channel features; Represents the linear rectification activation function; Indicates a fully connected layer; Indicates global average pooling; Indicates the input feature map; This indicates that a 1×1 convolution kernel is used to convolve the input feature map X; 3) Establish a dual-pathway system: ; in, This indicates that the two channels, global feature path and local feature path, are blocked and spliced together. Indicates the use of convolution kernel Perform local convolution on the input feature map X; This indicates that the outputs of the global feature path and the local feature path are added element by element, channel by channel; 4) Dynamically learn the optimal feature combination weights through dynamic weight generation and multi-scale fusion: ), in, Indicates use The activation function maps the weights of the fully connected output to channel attention weights; This indicates a channel-by-channel weighted average. This represents the residual connection, and the final output is the enhanced feature map. It is consistent with the input feature map X in dimension; 5) Generate dynamic convolution weights based on fused features: , in, and It is a fully connected network of Layer 1 and Layer 2. Enhance feature maps Flatten it into a one-dimensional vector to obtain high-level abstract features; By mapping to S×K×K dimensions through a fully connected layer, S K×K matrices are obtained, generating dynamic weight parameters; S represents the number of dynamic branches; finally, using... The activation function normalizes the weights; 6) Perform multi-scale feature fusion: Enhanced feature maps are achieved by dynamically generating S convolutional kernels. Parallel execution of multi-scale convolutions adaptively extracts multi-scale features from Chinese medicinal materials, and through... The branch weights balance the contributions of each branch, and finally, the S branches are weighted and summed. , in, s This represents the branch weight, which indicates the contribution of the S-th branch to the identification of Chinese medicinal materials. Y represents the dynamic convolution of the S-th branch, with multiple branches adapting to the needs of large-scale, medium-scale, and small-scale feature extraction respectively; Y represents the weighted fusion result of the features from the multiple branches.
[0013] The weights for each scale are calculated by a lightweight attention module: , Where MLP represents branch weight extraction; Softmax represents normalization of the results of MLP. Finally, the weights for each scale are calculated from the input feature map using a lightweight attention module.
[0014] Preferably, in step 2, the Feature Pyramid Network (FPN) is optimized: A three-level feature pyramid was constructed, namely shallow features P3 that preserve high-resolution details, mid-level features P4 that balance details and semantics, and deep features P5 that extract global semantics. The strategy for fusing cross-layer features is as follows: Top-down fusion: P5 is upsampled to the size of P4 by bilinear interpolation and then stitched together to supplement the detailed information of the large target; Bottom-up fusion: P3 is downsampled to the size of P4 by a 3×3 convolution with a stride of 2 and then stitched together to enhance the semantic expression of small targets; After fusion, the number of channels is adjusted by 1×1 convolution to make the feature dimensions consistent.
[0015] Preferably, in step 2, the design strategy for the multi-granularity pooling coordinate attention module is as follows: After inputting the feature map, decompose the multi-granularity coordinate features: perform three-granularity adaptive average pooling along the width W and height H directions respectively; then transpose the width W and height H to the same dimension and stack them to concatenate the three-level features to obtain the feature layer: [C,1,H+W], which is compressed by 1×1 convolution. Next, the two parallel stages are merged, and the width W and height H are transposed to the same dimension and stacked to merge the width and height features together. The feature layer obtained at this time is: [C,1,H+W]. After merging, spatial correlation features are extracted. The process is then split into two parallel stages, with the width and height further separated into [C,1,H] and [C,1,W], which are then transposed to obtain two feature layers [C,H,1] and [C,1,W]. A 1x1 convolution is then used to adjust the number of channels, followed by a sigmoid function to obtain the attention parameters in the width and height dimensions. Finally, the original feature output structure is multiplied to suppress the weight of the background region to below 0.2, while enhancing the response of the main medicinal material region.
[0016] Preferably, the design method of the multi-granularity pooling coordinate attention module includes the following steps: 1) Decompose multi-granularity coordinate features: Input feature map Three-granularity adaptive average pooling is performed along the height H and width W directions respectively, followed by three-level grid pooling processing; The single-level feature maps for height and width are as follows: ; ; in, , ; Indicates aggregation in the width direction; Indicates aggregation in the height direction; This represents the sum of the values of each channel of the input feature map X. Feature maps, calculate respectively and H represents height, and W represents width.
[0017] Therefore, the output feature dimension is represented as: ; Where s∈{1,2,4} represents the granularity level: s=1 represents a 1×1 grid, corresponding to a large-scale target; s=2 represents a 2×2 grid, corresponding to a medium-scale target; s=4 represents a 4×4 grid, corresponding to a small-scale target; 2) Perform multi-scale feature fusion and generate spatial attention weights; After concatenating the three-level features, dimensionality reduction is achieved by compressing the channels using a 1×1 convolution: the channel compression ratio r=16 is set; spatial attention weights are decomposed through row and column feature decoupling and dynamic attention generation. , , , in, This indicates that features are concatenated on rows and columns, and the spatial dimensions are merged to (H + W) after concatenation. This means that the concatenated features are processed using a 1×1 convolution kernel, compressing the number of channels from C to C / r, thus completing channel dimensionality reduction, where r is the compression ratio; It is the ReLU activation function; for function; 3) Recalibrate multi-granularity coordinate features;
[0018] By multiplying element-wise, the row attention weight gh and column attention weight gw are jointly applied to the input feature map. The output feature map is obtained. .
[0019] Preferably, in step 2, a differentiated attention mechanism is designed for feature maps of different scales, and then multi-scale feature fusion is performed on the global-local dual-path dynamic convolution module and the multi-granularity coordinate attention module, including: (1) Input feature map First, it passes through a global-local dual-path dynamic convolution module to generate multi-scale dynamically weighted features: , in, For dynamically generated convolutional kernel weights, Attention weights for each scale; (2) Coordinate attention weighting: The feature map output by the global-local dual-path dynamic convolution module is weighted. Then, input the MG-CA module, which performs global pooling, channel compression, and normalization on rows and columns to generate spatial attention weights for the row and column feature distribution of Chinese medicinal materials. , , in, Indicates global pooling; (3) The final weighted feature is: the global-local dual-path dynamic convolution module and the multi-granularity coordinate attention module are alternately cascaded.
[0020] Preferably, in step 2, based on the target scale distribution of Chinese medicinal materials, a three-level detection head is configured for the lightweight medicinal material identification model, and a bidirectional feature transfer mechanism is designed to generate fused features: ; The bidirectional feature transfer mechanism is as follows: Top-down propagation: Large-scale features are upsampled to mesoscale through bilinear interpolation and concatenated with mesoscale features to enhance the global semantic information of medium-sized targets; Bottom-up propagation: Small-scale features are downsampled to medium scale through 3×3 convolution, and then concatenated with medium-scale features to supplement the contextual information of small targets; Ultimately, the fused features Through residual connection and original features Add them together to obtain the final fusion result. + .
[0021] Preferably, the loss function for model optimization and training is a multi-task joint loss function: , Among them, L cls L represents the classification loss. loc L represents the localization loss. attn This represents the attention regularization loss; Empirical coefficient of classification loss Positioning loss L loc empirical coefficient Attention regularization loss L attn empirical coefficient Set them to 0.8, 0.5, and 0.1 respectively.
[0022] This invention discloses a method for identifying Chinese medicinal materials based on dual-path dynamic convolution. It introduces global-local dual-path dynamic convolution (GL-DualPathODConv) and multi-granularity coordinate attention (MG-CA) to form a collaborative optimization mechanism. The GL-DualPathODConv module adjusts the convolution kernel parameters through multi-branch dynamic weights to achieve dynamic feature extraction and improve the ability to model complex morphologies. The MG-CA module is inserted after feature concatenation, guiding attention to enhance key spatial regions and optimize the multi-scale feature fusion effect. Through upsampling / downsampling and cross-layer concatenation, combined with a three-level detection head, end-to-end multi-scale detection with full coverage from fine-grained to high-level semantic features is achieved, accurately adapting to the diverse sizes and shapes of Chinese medicinal materials. Attached Figure Description
[0023] Figure 1 This is a flowchart of the global-local dual-path dynamic convolution (GL-DualPathODConv) of the present invention.
[0024] Figure 2 This is a structural diagram of the multi-granularity coordinate attention (MG-CA) of the present invention.
[0025] Figure 3 This is a diagram showing the overall structure of the lightweight medicinal herb identification algorithm of the present invention.
[0026] Figure 4 This is a comparison chart of ablation experiments.
[0027] Figure 5 This is a diagram showing the actual test results.
[0028] Figure 6 This is a flowchart illustrating the computational process of the lightweight medicinal herb identification algorithm of the present invention. Detailed Implementation
[0029] The present invention will now be described in further detail with reference to the accompanying drawings and specific embodiments.
[0030] This invention proposes a method for identifying Chinese medicinal materials based on dual-path dynamic convolution. It is an intelligent identification method for Chinese medicinal materials based on YOLOv11. By designing global-local dual-path dynamic convolution (GL-DualPathODConv) and multi-granularity coordinate attention (MG-CA), and by dynamically adjusting the convolution kernel size, enhancing spatial location sensitivity, and optimizing small sample data augmentation strategies, it solves the shortcomings of traditional models in terms of feature capture flexibility, key information expression, and multi-scale detection balance, providing a more efficient and accurate technical solution for intelligent identification of Chinese medicinal materials.
[0031] The method for identifying Chinese medicinal materials based on dual-path dynamic convolution disclosed in this invention includes the following specific steps: Step 1: Construct a database for identifying Chinese medicinal herbs; First, data collection was conducted, collecting images of 100 kinds of Chinese medicinal materials, covering categories such as roots, stems, leaves, flowers, fruits, and seeds, including natural and laboratory scene images, totaling 50,000 labeled images.
[0032] Secondly, the data is enhanced and optimized. Based on conventional enhancement methods, specific parameters are designed to address the image characteristics of Chinese medicinal materials. 1.1 Geometry and Color Enhancement
[0033] Geometric transformations: random rotation (±15°), scaling (0.8-1.2x), and translation (±10% pixels) to simulate different shooting angles.
[0034] Color space: Adjust brightness (±20%), contrast (±15%), and saturation (±15%) to adapt to uneven lighting scenes.
[0035] 1.2 Special Enhancement for Traditional Chinese Medicine Materials
[0036] Texture enhancement: Gaussian blurring and sharpening are added to powdered medicinal materials such as Fritillaria cirrhosa powder to simulate noise in microscope images.
[0037] Occlusion simulation: Randomly generate 1-3 rectangular occlusion regions with an area ≤ 30% of the entire image, and train the model to recognize partially occluded targets, simulating the ability to identify stacked medicinal materials.
[0038] Finally, after data optimization, a database for identifying Chinese medicinal materials was constructed, which consists of the following components: Training set: 35,000 images, including 30% with complex backgrounds; Validation set: 7500 images, used to balance the category distribution; Test set: 7,500 images, including 20% unlabeled new perspective images.
[0039] Step 2: Construct a lightweight medicinal herb identification model; This lightweight medicinal herb recognition model is based on the YOLOv11 model and introduces a global-local dual-path dynamic convolution (GL-DualPathODConv) module and a granular coordinate attention (MG-CA) module. The global-local dual-path dynamic convolution module is embedded in the backbone network, which has a dual-path feature extraction and adaptive fusion mechanism. The granular coordinate attention module maintains the basic CA core architecture and introduces a multi-granularity pooling mechanism.
[0040] The architecture design process for the Global-Local Dual-Path Dynamic Convolution (GL-DualPathODConv) module and the Granular Coordinate Attention (MG-CA) module is as follows: (2.1) Design a multi-scale feature extraction architecture; 2.11 Based on Global-Local Dual-Path Dynamic Convolution (GL-DualPathODConv). To address the challenge of feature capture posed by the morphological diversity of Chinese medicinal herbs, a global-local dual-path dynamic convolution (GL-DualPathODConv) is embedded in the backbone network. Its core innovation lies in the dual-path feature extraction and adaptive fusion mechanism, thereby achieving dynamic receptive field enhancement. Then, dynamic weight generation and multi-scale fusion are performed to accurately capture diverse morphologies; furthermore, based on dual-path feature extraction, both global channel information and spatial local details are captured simultaneously.
[0041] (1) Input feature map
[0042] Define feature map , where R represents the real number field, X represents the input feature map, and the dimensions are, in order, the number of channels C, the height H, and the width W.
[0043] (2) Dual parallel structure processing, including global feature path and local feature path.
[0044] Global feature pathways: ; in, This indicates the output feature vector; Represents the linear rectification activation function; Indicates a fully connected layer; Indicates global average pooling; This represents the input feature map.
[0045] Local characteristic pathways: ; in, This indicates the output of global channel features; Represents the linear rectification activation function; Indicates a fully connected layer; Indicates global average pooling; This indicates that a 1×1 convolution kernel is used to convolve the input feature map X, and the dual-path structure expands the effective receptive field.
[0046] 2.12 Fusing parallel features from both global and local feature paths via an attention mechanism;
[0047] (1) Dual-pathway construction: , in, This indicates that the two channels, global feature path and local feature path, are blocked and spliced together. Indicates the use of convolution kernel Perform local convolution on the input feature map X; This means that the outputs of the global feature path and the local feature path are added element by element according to each channel, thus fusing the features of both.
[0048] Furthermore, by dynamically generating weights and fusing them across multiple scales, the optimal feature combination weights are learned dynamically. ), in, Indicates use The activation function maps the weights of the fully connected output to channel attention weights; This indicates channel-wise weighting, which means multiplying the channel attention weights by the input feature map X channel-wise and pixel-wise. This indicates a residual connection, where the weighted input feature map X is added element-wise to the initial feature map, and the final output is an enhanced feature map. It is consistent with the input feature map X in dimension.
[0049] (2) Generate dynamic convolution weights based on fused features: , in, and It is a fully connected network of Layer 1 and Layer 2. Enhance feature maps Flattening it into a one-dimensional vector reduces computational cost and allows for the acquisition of high-level abstract features; By mapping to S×K×K dimensions through a fully connected layer, S K×K matrices are obtained, generating dynamic weight parameters; S represents the number of dynamic branches; finally, using... The activation function normalizes the weights to avoid weight explosion and improve stability.
[0050] (3) Perform multi-scale feature fusion: Enhanced feature maps are achieved by dynamically generating S convolutional kernels. Parallel execution of multi-scale convolutions adaptively extracts multi-scale features from Chinese medicinal materials, and through... The branch weights balance the contributions of each branch, and finally, the S branches are weighted and summed.
[0051] By using weighted fusion of multi-branch dynamic convolution, we can both adapt dynamic kernels to morphological diversity and strengthen fine-grained differentiation through weight learning, thereby achieving adaptive extraction and balancing of multi-scale features of Chinese medicinal materials.
[0052] , in, s The branch weight represents the contribution of the S-th branch to the identification of Chinese medicinal materials. This represents the dynamic convolution of the S-th branch. Multiple branches can adapt to feature extraction needs at large scale (overall shape), medium scale (texture), and small scale (details) respectively. Y represents the weighted fusion result of the multi-branch features, i.e., the output feature map of the global-local dual-path dynamic convolution (GL-DualPathODConv) module, with feature dimensions and enhanced feature maps. It is consistent and includes multi-scale features and dynamic adaptation capabilities, providing more comprehensive feature support for subsequent detection heads.
[0053] The weights for each scale are calculated by a lightweight attention module: , Here, MLP stands for Branch Weight Extraction, which extracts the non-linear correlation between features of different branches by first compressing and then expanding the dimension; Softmax represents the normalization of the results of MLP to avoid weight explosion and improve stability.
[0054] (4) Finally, the weights of each scale are calculated from the input feature map through a lightweight attention module.
[0055] Traditional dynamic convolution, with its fixed sampling points, struggles to cover continuous curved structures, and its global pooling dilutes features of small targets. While maintaining the advantages of traditional dynamic convolution kernels, this invention designs a Global-Local Dual Path (GL-DualPath) mechanism. By adding local paths, it enhances spatial continuity perception, allowing dynamic offset points to be distributed along curves, thus satisfying the recognition of slender and curly features. Simultaneously, each 1×1 convolutional path independently captures discrete local features, and channel attention strengthens key regions. This significantly enhances the ability to characterize the complex morphology of Chinese medicinal materials, making it particularly suitable for the accurate recognition of slender, curved structures and small, scattered targets.
[0056] Furthermore, combined Figure 1The flowchart of Global-Local Dual-Path Dynamic Convolution (GL-DualPathODConv) shown provides a more detailed explanation of the design of the Global-Local Dual-Path Dynamic Convolution (GL-DualPathODConv) module of this invention.
[0057] like Figure 1 As shown in the figure: Left branch (feature preprocessing): Input (In): Feature map output by the previous layer of the network.
[0058] GAP (Global Average Pooling): Calculates the average value of the feature map for each channel, compresses the spatial dimension, preserves channel information, and highlights global features.
[0059] FC (Fully Connected): Performs dimensionality reduction transformation on the output of GAP to reduce computational load.
[0060] ReLU: Introduces non-linear activation to enhance feature representation capabilities.
[0061] 1×1Conv (1×1 convolution): Does not change the spatial dimension, only adjusts the number of channels, and fuses local information.
[0062] FC+ReLU: Performs dimensionality transformation and non-linear activation on the convolutional features.
[0063] concat (concatenation): concatenates the outputs of the two branches along the channel dimension, fusing global statistical features (GAP branch) and local detailed features (1×1 convolutional branch).
[0064] Right-hand branch (multi-dimensional attention weighting): Four fully connected (FC) layers: further process the concat features and output four attention weights, corresponding to spatial, channel, frequency, and weight.
[0065] Sigmoid activation: Maps the FC output to the [0,1] interval as an attention coefficient. The larger the value, the more important the corresponding position.
[0066] Attention parameters are defined as follows: (Position Attention): The spatial position of the feature map is weighted to highlight the shape and position information of the medicinal material.
[0067] (Channel Attention): Weights the channel dimensions of features to highlight the channels corresponding to color and texture.
[0068] (Frequency Attention): Weights the frequency components to highlight the frequency features of the texture.
[0069] (Weighted Attention): The original weights w1, w2, and w3 are weighted to optimize the importance of parameters and suppress redundant weights.
[0070] Original weights (w1, w2, w3): weights of three different branches.
[0071] ⊙ (element-by-element multiplication): Multiply the attention coefficients ( , , , The weights are multiplied by the corresponding original weights (w1, w2, w3) to achieve weighted enhancement of important features and suppression of irrelevant features.
[0072] * (Fusion Operation): The four weighted results (spatial, channel, frequency, and weight dimension) are added or cascaded and fused to output the final feature (Out), which is used by the subsequent YOLO detection head.
[0073] Therefore, after inputting the feature map, the system first performs parallel feature extraction via both global and local feature paths. Global average pooling (GAP) is used to compress and extract global information from the channel dimensions, while 1×1 Conv extracts local information. The two parallel feature paths are then concatenated, and the dimensions are adjusted using a fully connected layer. Subsequently, a dynamic weight matrix is generated through a fully connected layer, where the first part adjusts the spatial sensitivity of the 3×3 convolutional kernel, and the latter part is expanded to a 5×5 convolutional kernel weight using bilinear interpolation. After parallel computation of the two convolutional kernels, the weights are fused channel-by-channel according to the dynamic weights. This module significantly improves the model's adaptability to multi-scale targets, such as simultaneously capturing the global morphology of the entire medicinal plant and slice details. The functions of each part are as follows: GAP (Global Average Pooling): Performs global average pooling on the input features to generate a global feature vector. This operation reduces spatial dimensionality while preserving the global statistical features of channel information.
[0074] Fully connected (FC) layers combined with ReLU achieve non-linear feature transformation. FC: Fully connected layers perform a linear transformation on the pooled global feature vectors, projecting them into a new feature space and enhancing feature expressiveness. ReLU activation function: The ReLU activation function is applied to the output of the fully connected layer, increasing the model's non-linear representation capability.
[0075] Multi-branch attention module: Independent branches generate different channel / spatial attention weights, and the weight coefficients α of each branch are dynamically adjusted through a fully connected layer activated by Sigmoid.
[0076] w1 to w3 weight generation: Each branch generates a set of channel weights, which are learned by studying different weight matrices w. i Each weight matrix corresponds to a different channel or spatial feature subset.
[0077] α-weight coefficients: Through multiple sigmoid-activated fully connected layers, weight coefficients α are generated for each branch. These coefficients are used to control the feature importance of each branch. , ... are the weights generated for the first branch. , ... represents the weight for the second branch, and so on.
[0078] Feature weighting: The weight coefficient α of each branch is applied to the corresponding feature through element-wise multiplication. This allows for different weighting of the input features in each branch, highlighting different important features.
[0079] Weighted feature fusion stage: After Softmax normalization of weights, the weighted sum is calculated to output the fused features.
[0080] Softmax weight allocation: In the final weighting stage, the Softmax function is used to normalize the final branch weights to ensure that the contributions of all branches are relatively balanced.
[0081] Softmax ensures that the weighted sum of weights is 1, avoiding over-reliance on a particular branch.
[0082] Addition operation: All weighted features are combined by adding them element by element to generate the final output y.
[0083] This module can adaptively adjust the shape of the convolution kernel and the receptive field to adapt to complex shapes such as curved and multi-branched Chinese medicinal materials. The multi-branch mechanism realizes multi-dimensional dynamic weighting of features, enhancing the expressive power of key local features.
[0084] (2.2) Optimize the design of the Feature Pyramid Network (FPN): Construct a three-level feature pyramid and perform cross-layer feature fusion; The three-level feature pyramid enables hierarchical extraction and fusion of multi-scale features, as detailed below: P3 (64×160×160): Shallow features that preserve high-resolution details, such as leaf hairs and seed epidermal texture, and are responsible for small target detection.
[0085] P4 (128×80×80): Mid-level features, balancing details and semantics, such as leaf outlines and root structure, for handling medium-level targets.
[0086] P5 (256×40×40): Deep features, extracting global semantics, such as the overall plant morphology and the color distribution of medicinal slices, for large target detection.
[0087] The cross-layer feature fusion strategy is as follows: Top-down fusion: P5 is upsampled to the size of P4 via bilinear interpolation and then stitched together to supplement the detailed information of the large target, such as the local texture of the whole medicinal plant.
[0088] Bottom-up fusion: P3 is downsampled to the size of P4 by a 3×3 convolution with a stride of 2 and then spliced to enhance the semantic expression of small targets, such as the global association of granular medicinal materials.
[0089] After fusion, the number of channels is adjusted by 1×1 convolution to ensure consistent feature dimensions.
[0090] (2.3) Design a multi-granularity pooling coordinate attention (MG-CA) module; While maintaining the core architecture of basic CA, the MG-CA module significantly enhances multi-scale feature perception capabilities through an innovative multi-granularity pooling mechanism, addressing the issues of morphological diversity and scale differences in Chinese medicinal materials. This module is specifically designed to solve the scale diversity problem in Chinese medicinal material recognition, and its core structure is as follows: 2.31 Decomposition of multi-granularity coordinate features: Input feature map Three-granularity adaptive average pooling is performed along both the height (H) and width (W) directions, followed by three levels of grid pooling to generate multi-scale orientation-sensitive feature maps. Two formulas aggregate the width and height along the row and column directions respectively, resulting in single-level feature maps for height and width, as shown below: ; ; in, , .
[0091] Indicates aggregation in the width direction; Indicates aggregation in the height direction; This represents the sum of the values of each channel of the input feature map X. Feature maps, calculate respectively and H represents height, and W represents width.
[0092] Therefore, the output feature dimension can be expressed as: ; Where s∈{1,2,4} represents the granularity level: s=1 represents a 1×1 grid, corresponding to global granularity, capturing the morphological features of the whole medicinal material, targeting large-scale targets such as ginseng and astragalus; s=2 represents a 2×2 grid, corresponding to medium-scale granularity, extracting slice texture features, targeting texture targets such as angelica and atractylodes; s=4 represents a 4×4 grid, corresponding to local granularity, locating particle details, targeting small targets such as wolfberry and cordyceps.
[0093] 2.32 Multi-scale feature fusion is performed on the multi-granularity coordinate features obtained from the decomposition, and spatial attention weights are generated; First, the three-level features in the horizontal and vertical directions are concatenated and then compressed through a 1×1 convolution channel for dimensionality reduction: the channel compression ratio r=16 is set to control the number of parameters while maintaining the expressive power of the features; then, the spatial attention weights are decomposed into horizontal and vertical weights; this part achieves precise enhancement of the row and column spatial morphology of Chinese medicinal materials through row and column feature decoupling and dynamic attention generation, while suppressing background interference.
[0094] , , , in, This indicates that features are concatenated from rows and columns, and the spatial dimensions are merged to (H + W). This means that the concatenated features are processed using a 1×1 convolution kernel, compressing the number of channels from C to C / r, thus completing channel dimensionality reduction. r is the compression ratio, which is set to 16 in this invention. The ReLU activation function is used to suppress negative values and enhance the expression of nonlinear features. for The function is used for normalization and to generate spatial attention weights.
[0095] 2.33 Recalibrate multi-granularity coordinate features: By multiplying element-wise, the row attention weight gh and column attention weight gw are jointly applied to the input feature map. The output feature map is obtained. This enables the enhancement of key spatial regions and suppression of irrelevant backgrounds, thereby enhancing key features and achieving precise enhancement of key spatial regions of Chinese medicinal materials.
[0096] , Multi-granularity pooling coordinate attention innovatively extends the feature perception capability of the traditional coordinate attention mechanism through three-level multi-granularity pooling (1×1 / 2×2 / 4×4), capturing spatial information at different scales separately. With only a slight increase in computation, it significantly improves the detection accuracy of multi-scale targets in Chinese medicinal materials, especially the recall rate of small targets, providing an efficient solution for complex Chinese medicinal material recognition scenarios.
[0097] Furthermore, combined Figure 2 The diagram of the multi-granularity coordinate attention (MG-CA) structure shown provides a further detailed explanation of the multi-granularity pooling coordinate attention (MG-CA) module designed in this invention.
[0098] like Figure 2 As shown, by using multi-scale pooling and row / column separation attention, we can capture the multi-scale features of Chinese medicinal materials in the DE space dimension of row and column directions, enhance the expression of key areas such as texture direction and shape edges, and suppress background interference.
[0099] In the picture: Input: In(C×H×W) Parameter meanings: C = number of channel dimensions, representing different feature types such as color and texture; H = height; W = width.
[0100] The multi-scale pooling branches (1×1, 2×2, 4×4 AvgPooling) perform 1×1, 2×2, and 4×4 average pooling on the input, respectively, and each pooling branch outputs two tensors: C×H×1: Pooling in the width (W) direction while preserving global features in the height (H) direction.
[0101] C×1×W: Pooling in the height (H) direction while preserving global features in the width (W) direction.
[0102] 1×1 pooling: capturing fine-grained features of texture details in Chinese medicinal materials; 4×4 pooling: capturing the overall coarse-grained characteristics of Chinese medicinal materials; Concat (splicing): Concatenates the C×H×1 values of the three pooling branches along the channel dimension to obtain 3C×H×1. Similarly, concatenates the C×1×W values of the three pooling branches along the channel dimension to obtain 3C×1×W. This integrates global row (H) and column (W) features at multiple scales, allowing spatial information at different scales to complement each other.
[0103] 1×1Conv (Compressed Channels): The 3C channels are compressed back to C using 1×1 convolution, resulting in C×H×1 (row features) and C×1×W (column features). This reduces computational cost while maintaining the same number of channels for row and column features as the input, facilitating subsequent processing.
[0104] ReLU (Nonlinear Activation): ReLU activation is applied to C×H×1 and C×1×W respectively; nonlinearity is introduced to enhance the feature representation ability.
[0105] Separate row (H) and column (W) features: The tensor is split into row features (C×H×1) and column features (C×1×W). The shape and texture of Chinese medicinal materials can be accurately captured through row / column features.
[0106] 1×1 Conv+Sigmoid (generates attention weights): 1×1Conv: Perform 1×1 convolutions on row and column features respectively, adjust channels, and maintain dimensionality; Sigmoid: Maps the convolution output to [0,1], generating row and column attention. The higher the attention value, the more important the features of the corresponding row / column.
[0107] Feature recalibration: This operation involves fusing row and column attention weights with the original feature map or using a weighted approach to enhance the features of key rows / columns and suppress irrelevant regions. This improves the distinguishability of small targets or similar medicinal materials.
[0108] Output: Attention-weighted feature maps are input into the YOLOv11 detector head to predict the category and location of Chinese medicinal materials.
[0109] Therefore, it can be seen that the multi-granularity coordinate attention (MG-CA) of this invention innovatively designs a multi-level pooling mechanism, the implementation process of which is as follows: After inputting the feature map (C×H×W), 1×1 average pooling, 2×2 grid partition pooling, and 4×4 grid partition pooling are performed in parallel along the width W and height H directions. In the width W and height H directions, the width W and height H are transposed to the same dimension and then stacked to concatenate the three-level features. The resulting feature layer is [C,1,H+W]. Then, 1×1 convolution is used to compress the channels, Batch Normalization (BN) is used to improve the efficiency of model learning and training, and ReLU nonlinear activation is used to enhance the model's nonlinear fitting and expression capabilities.
[0110] The two parallel stages are merged, the width and height are transposed to the same dimension, and then stacked to merge the width and height features together. The resulting feature layer is [C,1,H+W]. After merging, spatial correlation features are extracted through 1×1 convolution + BN + ReLU.
[0111] The process is then split into two parallel stages, further separating the width and height into [C,1,H] and [C,1,W] layers, which are then transposed. This yields two feature layers: [C,H,1] and [C,1,W]. A 1x1 convolution is then used to adjust the number of channels, followed by a sigmoid function to obtain the attention parameters in the width and height dimensions. Finally, the output is multiplied by the original feature structure, suppressing the weights of background regions (such as container edges or lighting interference) to below 0.2 while enhancing the response of the main medicinal material region.
[0112] This module can explicitly model spatial coordinate information, solving the problem of irregular spatial distribution of Chinese medicinal materials. It enhances the model's ability to locate elongated rhizome-type or densely distributed seed-type targets.
[0113] (2.4) Design differentiated attention mechanisms for feature maps of different scales to achieve multi-path attention allocation; The strategies for differentiated attention mechanisms are as follows: Large target enhancement path: Apply MG-CA to the fused features (F4) of P5 after upsampling with P4, focusing on global structural features such as stem thickness and leaf outline, and weighting coefficients. global Enhance contour detection related channels.
[0114] Small target enhancement path: Apply MG-CA to the upsampled P4 and fused features with P3 (F3), focusing on local details such as seed surface texture and fuzz distribution, and weighting coefficients. global Strengthen channels related to high-frequency details.
[0115] Medium-target enhancement path: Apply MG-CA to the fused features (F4') of F3 downsampled and F4, balancing global and local features, and weighting coefficients. mid Enhance the medium-scale identification features of cross-sectional texture of medicinal slices.
[0116] (2.5) Perform multi-scale feature fusion on the Global-Local Dual-Path Dynamic Convolution (GL-DualPathODConv) module and the Multi-Granularity Coordinate Attention (MG-CA) module; (1) Input feature map First, the GL-DualPathODConv module generates multi-scale dynamically weighted features: , in, For dynamically generated convolutional kernel weights, The attention weights are for each scale.
[0117] (2) Coordinate attention weighting: The feature map output by the GL-DualPathODConv module is weighted. Then input the MG-CA module, which generates spatial attention weights for the row and column directional feature distribution of Chinese medicinal materials by performing global pooling, channel compression and normalization on rows and columns.
[0118] , , in, This indicates global pooling.
[0119] (3) The final weighted features are: In the model backbone, the GL-DualPathODConv module and the MG-CA module are alternately cascaded. Through this cascaded design, the model gradually integrates multi-scale features and enhances spatial sensitivity.
[0120] (2.6) Configure a three-stage detection head and design a bidirectional feature transfer mechanism: (1) Based on the target scale distribution of Chinese medicinal materials, a three-level detection head was designed and matched with different feature map sizes, as shown in the table below:
[0121] (2) Perform cross-scale feature fusion: To address the imbalance in multi-scale detection, this invention designs a bidirectional feature transmission mechanism to generate fused features: .
[0122] Top-down propagation: Large-scale (20×20) features are upsampled to 40×40 via bilinear interpolation and concatenated with medium-scale (40×40) features to enhance the global semantic information of medium-scale targets (such as the positional association of leaves within the whole plant).
[0123] Bottom-up propagation: Small-scale (80×80) features are downsampled to 40×40 by a 3×3 convolution with a stride of 2, and then concatenated with medium-scale features to supplement the contextual information of small targets (such as the aggregation pattern of granular medicinal materials).
[0124] Residual connection optimization: The fused features are added to the original features through residual connections. + This avoids gradient vanishing and preserves the independence between low-level details and high-level semantics.
[0125] Step 3: Iteratively train the multiple lightweight medicinal herb recognition models until the optimal model parameters are obtained; The specific strategies for model optimization and training are as follows: First, we design a loss function and construct a multi-task joint loss function to balance the optimization of classification, localization, and attention.
[0126] Among them, the classification loss L cls To address the imbalance between positive and negative samples, the classification loss method resolves the imbalance issue and enhances the learning weights for cases such as overlapping leaves.
[0127] Positioning loss L loc Considering the overlapping area of the bounding boxes, the distance between center points, and the aspect ratio, the localization loss can significantly improve the localization accuracy of curved roots and irregular targets.
[0128] Attention regularization loss L attn Constraining channel weight distribution enhances feature sparsity and avoids overfitting. Attention regularization loss forces attention weights to focus on a few key channels, further enhancing feature sparsity.
[0129] Finally, the weight allocation strategy for integrating the joint loss function is as follows: , Among them, three empirical coefficients , Set them to 0.8, 0.5, and 0.1 respectively.
[0130] Secondly, the model training parameters were sampled using a GPU (NVIDIA RTX 3060) and trained for 140 epochs.
[0131] Step 4: Validate the performance of the optimized lightweight medicinal herb identification model; The performance of the model was verified and analyzed using ablation experiments. The experimental results are as follows: Figure 4 As shown, Figure 4 The ablation experiment comparison graph shows how mAP@.5 (mean precision, the value at an IoU threshold of 0.5) changes with Epoch (training rounds) for four different algorithms during training.
[0132] By comparing the model's performance on mAP@0.5 (mean accuracy when IOU≥0.5), the contribution of each module to the detection accuracy of Chinese medicinal materials is verified.
[0133] The horizontal axis (Epoch) represents the number of training epochs, reflecting the model's progress from "non-converged" to "stable convergence." It indicates the number of training epochs, ranging from 0 to 140, reflecting the training progress.
[0134] The ordinate (mAP@0.5) is a core metric for object detection. A higher value indicates higher average accuracy, meaning the bounding box of the medicinal material overlaps with the ground truth box by ≥50%. Larger values, ranging from 0 to 1.2, indicate higher average accuracy when the algorithm detects the target at an IoU of 0.5.
[0135] Furthermore, the four curves are specifically represented as follows: Series 1 (blue): Represents the YOLOv11 algorithm. It has a low initial mAP@.5, which rises rapidly with each epoch and then stabilizes after a certain number of epochs. Its performance is slightly lower than other algorithms with improved modules.
[0136] Series 2 (orange): Corresponds to the YOLOv11+GL-DualPathODConv algorithm. It shows a faster performance improvement at the beginning, and the upward trend is similar to other curves. In the stable phase, its performance is better than YOLOv11.
[0137] Series 3 (Gray): This is the YOLOv11+MG-CA algorithm. It shows a significant increase in mAP@.5 in the early stage of training, and then stabilizes in the later stage. Its performance varies with other improved algorithms at different stages.
[0138] Series 4 (yellow): This refers to the YOLOv11+GL-DualPathODConv+MG-CA algorithm. It shows a significant performance improvement in the early stages of training, and the overall curve is at a relatively high position in most epochs. This indicates that combining the GL-DualPathODConv and MG-CA modules has a significant effect on improving the algorithm's performance. Finally, mAP@.5 is relatively high among the four curves.
[0139] The ablation experiment comparison charts show that, after training, the lightweight medicinal herb recognition model of this invention (YOLOv11+GL-DualPathODConv+MG-CA algorithm) achieves an mAP@0.5 value of 89.7%, significantly higher than the 77.4% of the YOLOv11 model, the 80.1% of the YOLOv11+GL-DualPathODConv model, and the 83.3% of the YOLOv11+MG-CA model. This indicates that adding either the GL-DualPathODConv or MG-CA modules individually can improve model performance, and their combination can achieve even better detection accuracy, demonstrating a synergistic effect in improving model performance.
[0140] Therefore, analysis of the ablation experiment results shows that: 1) Necessity of GL-DualPathODConv: After removal, the accuracy of small target recognition decreased by 6.4%, indicating that the dynamic receptive field is crucial for the detection of trivial targets.
[0141] 2) Effect of MG-CA: After removal, the feature differentiation between channels decreased, and the misclassification rate of closely related varieties such as Coptis chinensis and Picrorhiza scrophulariiflora increased by 9.7%.
[0142] 3) Multi-path fusion advantage: Compared with traditional YOLOv11 detection, this design improves the accuracy of full-scale target detection by 12.3%.
[0143] Furthermore, actual tests were conducted. As Figure 5 can be seen from the actual test effect diagram of Figure 5 : The category annotation indicates whether the model can accurately classify; the confidence level indicates whether the prediction result is reliable; the display of the traditional Chinese medicine image recognition function of this design can accurately classify and recognize traditional Chinese medicines such as Asarum heterotropoides, Schizonepeta tenuifolia, and Germinated Barley Seeds in scenarios such as stacked medicinal material recognition, uneven illumination, and subtle features. By inputting the traditional Chinese medicine image, the corresponding medicinal material name and recognition confidence level are output.
[0144] From the perspective of the recognition confidence level, the recognition results for the three traditional Chinese medicines are all above 0.95, 0.964 for Asarum heterotropoides, 0.957 for Schizonepeta tenuifolia, and 0.976 for Germinated Barley Seeds, indicating that the algorithm is relatively accurate in feature extraction and classification judgment and has high reliability.
[0145] This algorithm can recognize traditional Chinese medicines in various different forms, whether it is the rhizome form of Asarum heterotropoides, the plant form of Schizonepeta tenuifolia, or the seed form of Germinated Barley Seeds, indicating that the algorithm has good adaptability and can process different types of traditional Chinese medicine image data.
[0146] The actual test effect diagram shows the recognition results of the three traditional Chinese medicines. From left to right, they are Asarum heterotropoides (Xixin) with a recognition confidence level of 0.964, Schizonepeta tenuifolia (Jingjiesui) with a recognition confidence level of 0.957, and Germinated Barley Seeds (Daoya) with a recognition confidence level of 0.976. The name and the corresponding recognition confidence level value are marked above each medicinal material picture, indicating that the recognition model has high credibility for the recognition of these traditional Chinese medicines, and the closer the value is to 1, the higher the recognition accuracy.
[0147] Step Five: Deploy the lightweight medicinal material recognition model that meets the performance verification to the GPU and edge devices; Quantization before deployment: Adopt 8-bit integer (INT8) quantization. Combining with a calibration dataset of 1000 pictures, on the premise of maintaining mAP@0.5≥88.5%, the model volume is compressed from the original FP32 model of 37.5MB to 9.4MB.
[0148] The hardware deployment strategy is as follows: GPU deployment: Through TensorRT optimization, to improve the model generalization ability, set Batch = 1, and the FPS is increased to 125, which can support the identification and detection of high-speed production lines on-site.
[0149] Edge device deployment: Deployed to the RK3588 chip (4-core ARM Cortex-A76) based on the NCNN framework, and the FPS reaches 38, meeting the real-time recognition requirements of handheld terminals such as inspection PDAs.
[0150] Step Six: Call the lightweight medicinal material recognition model to recognize the input traditional Chinese medicine image.
[0151] Specifically, it can be applied to the following technical scenarios: 1) Quality control in production and processing
[0152] For the planting and processing of Chinese medicinal herbs, a global-local dual-path dynamic convolution (GL-DualPathODConv) module is used to dynamically capture multi-morphological features such as seedling leaf texture and irregular edge formation of processed herbs. Combined with multi-granularity coordinate attention (MG-CA) to enhance key identification channels such as color and microstructure, it can distinguish easily confused varieties and detect quality defects such as mold and impurities, thereby improving the quality control of automated production lines.
[0153] 2) Intelligent inventory and sorting
[0154] In warehouse management, the lightweight model constructed by this invention can support real-time processing of multiple cameras, achieve high recall detection of densely stacked and partially obscured medicinal materials such as bagged goji berries and boxed poria cocos, automatically generate inventory lists, and use multi-granularity coordinate attention (MG-CA) to focus on subtle features such as cell structure and surface texture of medicinal powder in the module. Global-local dual-path dynamic convolution (GL-DualPathODConv) captures the morphological distortion of counterfeit products, providing reliable image data for product sorting and traceability, and curbing the circulation of counterfeit products.
[0155] 3) Intelligent detection and defect identification of medicinal materials
[0156] For drug sampling and standard setting, the lightweight model constructed in this invention can process mixed samples of multiple categories such as compound decoction pieces in batches. By using a multi-scale detection head to simultaneously locate large and small targets, the model system can suppress background interference and quickly screen suspicious categories. At the same time, it automatically extracts quantitative features of medicinal materials such as length, assists in building a visualized quality standard database, and promotes the intelligentization and standardization of the testing process.
[0157] 4) Promotion of Traditional Chinese Medicine Culture and Public Education
[0158] By integrating a lightweight model with a smart terminal, this invention can facilitate the dissemination of traditional Chinese medicine (TCM) culture and public education. For example, in TCM museums, visitors can scan medicinal specimens to obtain real-time information such as names and efficacy, enhancing the interactive experience. In field herb-gathering scenarios, the system can guide gatherers to quickly identify targets and avoid mistakenly picking poisonous plants. Combined with OCR technology to support the output of Chinese and English labels, it promotes the international dissemination of TCM knowledge in international TCM exhibitions.
[0159] Furthermore, combined Figure 3 and Figure 6 The present invention will provide a more detailed description of the lightweight medicinal herb identification model (YOLOv11+GL-DualPathODConv+MG-CA algorithm) proposed in this invention.
[0160] Figure 3 The diagram shows the overall structure of the algorithm. Input: 640×640×3, where 640 is the input resolution (width / height) and 3 is the number of RGB channels, adapted to the image size of common Chinese medicinal herbs.
[0161] Conv, k=3, s=2, where k=3 represents a 3×3 convolution kernel for extracting local features, and s=2 represents a stride of 2. This quickly reduces the feature map size and computational cost.
[0162] GL-DualPathODConv is used to enhance feature adaptability.
[0163] C3k2 is YOLO's classic 3-branch residual module with 2 residual blocks inside, which enhances feature fusion; it extracts complex features such as texture interweaving and color gradients, supporting subsequent multi-scale processing.
[0164] SPPF is a spatial pyramid pooling algorithm that uses multi-scale pooling kernels to capture multi-scale shape features and adapt to the size differences of Chinese medicinal materials.
[0165] C2PSA is a position-sensitive attention structure with a two-branch structure that enhances the spatial location features of medicinal materials and the semantic features of category attributes, respectively; it highlights the medicinal material region, suppresses the interference of leaves and soil background, and increases the proportion of main features.
[0166] Neck (middle column: feature fusion).
[0167] Upsample is used to upsample low-resolution feature maps to high resolution, fusing high-level semantic features with low-level fine textures and other detailed features.
[0168] Chinese medicinal herbs can be used to improve positioning accuracy.
[0169] Concat is used for concatenating feature maps of different levels along the channel dimension. It enriches the feature dimensions, allowing each feature location to simultaneously contain both "texture details" and "category information," thus enhancing the comprehensiveness of detection.
[0170] MG-CA uses multi-granularity precise weighting to enhance key channels by assigning different features to different channels.
[0171] The Head is the detection head structure, with three detection heads corresponding to feature maps of different scales: the deep layer corresponds to large medicinal materials, the middle layer to medium-sized medicinal materials, and the shallow layer to small medicinal materials. This covers the size differences of Chinese medicinal materials and improves multi-scale detection capabilities.
[0172] Depend on Figure 3As can be seen, the overall architecture of this method is based on the improved YOLOv11 framework. The backbone adopts the CSPDarknet53 structure, replacing the original four CSP modules with global-local dual-path dynamic convolution (GL-DualPathODConv) to enhance the feature extraction capability for the slender shape and complex texture of Chinese medicinal materials. Each GL-DualPathODConv module dynamically fuses 3×3 and 5×5 convolutional kernels, adjusting the contribution of multi-scale features through weighted adjustments. The neck adopts the PANet feature pyramid structure, inserting multi-granularity coordinate attention (MG-CA) at three points after feature fusion at each layer to suppress background noise and enhance the response of the target region. The head is decoupled into classification and regression branches. The classification branch outputs the softmax probability, and the regression branch uses CIoU loss to optimize the bounding box coordinates, with preset anchor sizes to adapt to targets of different scales. The final output includes class labels and confidence scores, realizing the identification of Chinese medicinal materials. Details are as follows: (a) Input stage: The input is image data with a size of 640×640 and 3 channels.
[0173] (II) Feature Extraction Stage
[0174] 1. Initial Convolution: The input image first passes through a convolutional layer (Conv) with a kernel size of k=3 and a stride of s=2, which performs preliminary feature extraction and reduces the spatial dimension of the image.
[0175] 2. Global-Local Dual-Path ODConv: Passing through multiple deformable convolution modules in sequence, GL-DualPathODConv can adaptively adjust the receptive field to capture image features more flexibly, with C3k2 residual structure modules interspersed in between.
[0176] 3. Spatial Pyramid Pooling Fast Layer (SPPF): After passing through a series of GL-DualPathODConv and C3k2 modules, the data enters the SPPF module, which can extract and fuse features at different scales, enhancing the model's ability to detect targets at multiple scales.
[0177] 4. C2PSA Module: The features are then further processed through the C2PSA module, which may involve operations on the channel and spatial dimensions to integrate the feature information.
[0178] (III) Feature Fusion and Processing Stage
[0179] 1. Upsampling and Concat: The features output from the feature extraction stage are upsampled through different paths. The low-resolution features are restored to their original size and then concatted with features from other paths to achieve the fusion of features at different levels.
[0180] 2. Multi-granularity coordinate attention (MG-CA) module: The fused features enter the MG-CA module. The MG-CA module enhances the features of important channels and suppresses the features of unimportant channels by learning the weight relationship between channels, thereby improving the feature representation ability.
[0181] 3. C3k2 module: The C3k2 module performs further feature processing and integration.
[0182] 4. Downsampling Convolution: Some paths will be downsampled through a convolutional layer (Conv, k=3, s=2) to reduce the feature map size and extract more abstract features. Then, the features are concatenated with those of other paths and processed by the C3k2 module.
[0183] (iv) Output stage
[0184] The features processed in the above series are finally input into the head part, which usually contains a detection-related prediction layer to output the prediction results such as the target's category and location, thus completing the target detection task.
[0185] Figure 6 The flowchart of the algorithm's computation is shown in the figure: I. Initial layer of the input domain; 1. Input image: 640×640×3, where 640 is the input resolution in the width / height direction and 3 is the number of RGB channels.
[0186] 2. Initial layer: 32×320×320. Parameter meaning: 32 is the number of output channels, which initially extracts basic features such as edges and colors, and expands the channels; 320 is the width / resolution, which performs downsampling through convolution with a stride of 2 to quickly reduce the size of the feature map and reduce the amount of subsequent computation.
[0187] II. Backbone Network: GL-DualPathODConv module; 3. Output characteristics: P3 (64×160×160), P4 (128×80×80), P5 (256×40×40); The number of channels doubled with each downsampling step, from 32 to 64 to 128 to 256, enhancing feature representation. The feature resolution was 320→160→80→40, with a downsampling step size of 2 each time, to construct a multi-scale feature pyramid that covers large / medium / small-sized medicinal materials respectively.
[0188] III. Neck: Pooling layer + multi-scale fusion (upsampling / downsampling + stitching + MG-CA). 4. Pooling layer: 512×20×20, capturing multi-scale shape features to provide deep semantic support for subsequent feature fusion. The number of channels is set to 512 for further amplification, extracting more abstract global features. The feature resolution is 20, and the feature parameters are compressed.
[0189] 5. Multi-scale feature fusion (upsampling / downsampling + concatenation + MG-CA), taking P5 upsampling → concatenation P4 → MG-CA → F4 (256×40×40) as an example: Upsampling: P5 (feature resolution 40×40) is enlarged to match the size of P4 (feature resolution 80×80) to preserve deep semantic features.
[0190] Concatenation: P5 (global semantics) and P4 (local details) are merged, and the number of channels is temporarily increased from 256 and 128 to 384.
[0191] MG-CA (Multi-granularity channel attention): Weights the spliced features, highlighting key channels and suppressing background channels; compresses the channels to 256, and outputs the fused feature F4.
[0192] Other fusion branch logics are similar, aligning features at different scales to achieve complementary fusion of "details + semantics".
[0193] IV. Detection Head: Multi-scale Classification and Regression; 6. Scale 1: F3 (128×80×80) → 4×80×80; F3: Shallow features (128 channels, 80×80 feature resolution), preserving fine-grained details; F4: Each grid predicts 4 anchor boxes, adapting to the diverse shapes of small targets and improving positioning accuracy; 80×80: Feature map size, corresponding to the high-resolution region of the input image.
[0194] 7. Scale 2: F4 (256×40×40) → 4×40×40; F4: Mid-level features (256 channels, 40×40 feature resolution), balancing details and semantics; 40×40: Feature map size, corresponding to the medium resolution region of the input image.
[0195] 8. Scale 3: F5 (512×20×20) → 4×20×20; F5: Deep features (512 channels, 20×20 feature resolution), strong semantic information; 20×20: Feature map size, corresponding to the low-resolution region of the input image.
[0196] 9. Output: Classification and regression results; Classification: Predict the category of Chinese medicinal materials, such as Asarum, Schizonepeta spike, and rice sprouts; Regression: Predict bounding box coordinates to accurately locate the medicinal materials.
[0197] Traditional Chinese medicinal materials (TCM) exhibit diverse morphologies (roots, stems, seeds, etc.), complex textures, and multi-scale distribution, resulting in insufficient feature extraction capabilities and poor multi-scale adaptability. This solution, based on the YOLOv11 framework, introduces Global-Local Dual-Path Dynamic Convolution (GL-DualPathODConv) and Multi-Granularity Coordinate Attention (MG-CA) to construct a multi-scale feature optimization network for TCM image recognition, achieving high-precision and robust detection results. The figure illustrates the complete computational flow of the algorithm from image input to multi-scale classification and regression, as follows: 1. Input and Preprocessing
[0198] Input: A 640×640×3 RGB image. After normalization, it is processed by a 3×3 convolutional layer (stride 2) for preliminary feature extraction and downsampling, and outputs a 320×320×32 feature map as the basis for subsequent processing.
[0199] 2. Multi-scale feature extraction
[0200] Global-Local Dual-Path Dynamic Convolution (GL-DualPathODConv): Replacing traditional convolution, it adaptively adjusts the convolution kernel parameters through multi-branch dynamic weight generation (global pooling → fully connected layer → Softmax normalization), enhancing the ability to capture features of complex morphologies of Chinese medicinal materials (such as curved roots and stems, and dense seeds).
[0201] Alternating stacking with C3k2 residual modules (repeated 4 times) to progressively generate multi-scale features: P3 (64×160×160): Fine-grained features used for small target detection.
[0202] P4 (128×80×80): Medium-scale features, covering common targets.
[0203] P5 (256×40×40): High-level semantic features, handling large targets and contextual information.
[0204] SPPF pyramid pooling: Integrates multi-scale receptive field features (5×5, 9×9, 13×13 pooling) to output high-dimensional abstract features of 512×20×20, enhancing the model's adaptability to size changes.
[0205] 3. Cross-scale feature fusion and optimization
[0206] C2PSA module: Combines channel and spatial attention to initially optimize high-level feature weights.
[0207] The core function of the Multi-Granularity Coordinate Attention (MG-CA) module is to model spatial attention along the width and height directions respectively, thereby enhancing the ability to locate elongated targets (such as roots and stems). Multi-path interaction and multi-granularity coordinate attention (MG-CA) attention: Upsampling path: Upsample P5 and concatenate it with P4. Enhance the features of key channels and spatial positions through the MG-CA module to generate F4 (256×40×40).
[0208] Downsampling path: The mid-level features are downsampled and concatenated with the high-level features, and then optimized by MG-CA to generate F4' (256×40×40).
[0209] Cross-layer fusion: The low-level features (P3) are concatenated with the optimized mid-level features (F4), and F3 (128×80×80) is generated through the MG-CA module, preserving detailed information.
[0210] Then, the feature response is dynamically adjusted by Sigmoid weights to suppress background noise and highlight the edges and texture areas of the medicinal materials.
[0211] 4. Multi-scale detection and output
[0212] Level 3 detection head: Scale 1 (F3: 128×80×80): Detects small targets such as rice sprouts and grains, and outputs prediction results at a resolution of 80×80.
[0213] Scale 2 (F4': 256×40×40): Identifies medium-sized targets such as catnip spikes and outputs results at a resolution of 40×40.
[0214] Scale 3 (F5: 512×20×20): Locate large targets such as Asarum rhizome bundles and output 20×20 resolution results.
[0215] Loss function: Combining FocalLoss (classification), CIoULoss (regression) and binary cross-entropy (confidence) to optimize training stability and detection accuracy.
[0216] In summary, this invention introduces GL-DualPathODConv for the first time to solve the challenges of detecting irregular shapes and small targets, improving the recall rate of small targets; designs a multi-path MG-CA module to enhance different target features, improving the accuracy of identifying closely related species; optimizes YOLOv11 to achieve a balance between accuracy and speed, meeting industrial-grade real-time requirements; and customizes domain-specific training strategies to improve robustness in complex scenarios. Through systematic design and experimental verification, an efficient solution for Chinese medicinal herb image recognition has been constructed, providing a replicable technical paradigm for the intelligentization of the traditional Chinese medicine industry.
[0217] The method for identifying Chinese medicinal materials based on dual-path dynamic convolution proposed in this invention solves the following technical problems: 1) The challenge of capturing characteristics due to the morphological diversity of Chinese medicinal materials: Chinese medicinal materials are diverse and have significant morphological differences (such as rhizomes, flowers and leaves, and seeds). For example, the curved outline of rhizomes (such as Asarum), the branching structure of plants (such as catnip spikes), and the dense granular features of seeds (such as rice sprouts) make it difficult for traditional convolution operations with fixed receptive fields to adaptively capture complex features of different scales and textures, which can easily lead to missed detection of small targets or loss of detailed features.
[0218] 2) Insufficient ability to express key features: The surface of Chinese medicinal herbs often exhibits complex textures such as wrinkles and spots, and these texture features are key characteristics for identifying these herbs. When these textures are mixed with background elements such as soil and leaves, the false detection rate increases. The traditional YOLOv11 model has limited ability to distinguish the importance of features between channels, making it difficult to focus on key discriminative features such as leaf vein patterns and epidermal texture, thus limiting classification accuracy.
[0219] 3) Imbalance between efficiency and accuracy in multi-scale target detection: In real-world scenarios, it is often necessary to detect both large-scale root bundles (such as Asarum) and small-scale seed particles (such as rice sprouts) simultaneously. Traditional single-scale detection is difficult to take into account that Chinese medicinal materials may exist at different scales in the image. Simple feature fusion methods are difficult to balance the detection accuracy of targets at different scales, and problems such as large target localization deviation or small target recognition ambiguity may occur.
[0220] Compared with the prior art, the solution of the present invention has the following technical advantages: This scheme introduces global-local dual-path dynamic convolution (GL-DualPathODConv) and multi-granularity coordinate attention (MG-CA) to form a collaborative optimization mechanism, which significantly improves the performance of Chinese medicinal material image recognition. The specific advantages are as follows: 1) Multi-scale feature adaptive extraction capability
[0221] Global-Local Dual-Path ODConv: Unlike traditional fixed convolution kernels, GL-DualPathODConv adaptively adjusts the sampling point position by learning the offset, which can flexibly capture key regions of different shapes of targets in Chinese medicinal materials images (such as slender roots and small seeds), and is especially accurate in feature extraction of irregular shapes or small-scale targets.
[0222] Multi-scale feature map generation: Three different scale feature maps (P3, P4, P5) are generated by downsampling using GL-DualPathODConv, corresponding to the image's detail texture (small scale), structural contour (medium scale), and global semantics (large scale), respectively, providing rich feature input for subsequent multi-scale detection.
[0223] 2) Key feature enhancement and redundancy suppression
[0224] The channel attention mechanism focuses on core information: The multi-granularity coordinate attention (MG-CA) module calculates the dependencies between channels and generates weight coefficients for each channel. This enhances channels that are strongly related to the identification of Chinese medicinal materials (such as color and texture feature channels), suppresses background noise or irrelevant channels, and makes the model pay more attention to key identification features such as leaf veins and epidermal hairs, thereby improving classification accuracy.
[0225] Experimental verification results: In actual tests, the confidence level for identifying Chinese medicinal materials such as Asarum, Schizonepeta tenuifolia spike, and rice sprouts all exceeded 95%, which is significantly higher than that of the traditional YOLOv11 model, demonstrating a significant improvement in the ability to extract and express key features.
[0226] 3) Collaborative optimization of multi-scale detection
[0227] Cross-scale feature fusion strategy: Through upsampling / downsampling and splicing operations, feature maps of different scales (such as P5 upsampling and fusion with P4) are fused across layers. Combined with the MG-CA module to optimize feature weights, each detection scale (large / medium / small) can retain its own scale feature advantages and fuse complementary information from other scales, avoiding the limitations of single-scale detection.
[0228] Balancing detection accuracy across different scales: Scale 1 (80×80) provides fine-grained localization for large targets, Scale 3 (20×20) captures semantic features of small targets, and the intermediate scale (40×40) balances structure and semantics. Through feature fusion and attention optimization, these three scales achieve accurate detection of Chinese medicinal materials targets across all scales. In the ablation experiment, the complete model (GL-DualPathODConv+MG-CA) achieved an mAP@0.5 improvement of more than 12% compared to the baseline model.
[0229] 4) Balancing algorithm efficiency and practicality
[0230] Lightweight design: The introduction of GL-DualPathODConv and MG-CA modules does not significantly increase computational complexity. Through reasonable network structure design (such as C3k2 module and SPPF layer), accuracy is improved while maintaining real-time detection speed, making it suitable for practical scenarios such as automated sorting and quality inspection of Chinese medicinal materials.
[0231] Enhanced generalization ability: It exhibits strong robustness to images of Chinese medicinal materials under different shooting angles, lighting conditions, and background interference, reducing manual annotation costs and enabling rapid adaptation to recognition tasks of multiple categories of Chinese medicinal materials.
[0232] This solution addresses issues such as inflexible feature capture, insufficient expression of key information, and imbalance in multi-scale detection in the recognition of Chinese medicinal materials by using GL-DualPathODCon for multi-scale adaptive feature extraction and MG-CA attention module for channel attention optimization. It achieves high-precision recognition while maintaining efficient computation, providing advanced technical support for intelligent detection in the field of traditional Chinese medicine.
[0233] The above embodiments are not intended to limit the present invention, and the present invention is not limited to the examples given above. Any changes, modifications, additions or substitutions made by those skilled in the art within the scope of the technical solution of the present invention are also within the protection scope of the present invention.
Claims
1. A method for identifying Chinese medicinal materials based on dual-path dynamic convolution, characterized in that: Includes the following steps: Step 1: Construct a database for identifying Chinese medicinal herbs; Step 2: Construct a lightweight medicinal herb recognition model; This lightweight medicinal herb recognition model is based on the YOLOv11 model and introduces a global-local dual-path dynamic convolution module and a granular coordinate attention module; A global-local dual-path dynamic convolution module is embedded in the backbone network, which has a dual-path feature extraction and adaptive fusion mechanism; the granular coordinate attention module maintains the basic CA core architecture and introduces a multi-granularity pooling mechanism. Step 3: Iteratively train the constructed lightweight medicinal herb identification model until the optimal model parameters are obtained; Step 4: Validate the performance of the optimized lightweight medicinal herb identification model; Step 5: Deploy the lightweight medicinal herb recognition model that has passed performance verification to GPUs and edge devices; Step 6: Call the lightweight medicinal herb recognition model to recognize the input Chinese medicinal herb image.
2. The method for identifying Chinese medicinal materials based on dual-path dynamic convolution according to claim 1, characterized in that: The data in the Chinese medicinal herb identification database comes from images of Chinese medicinal herbs; The images of Chinese medicinal materials undergo data augmentation processing, including: geometric and transformation processing, color space enhancement processing, and special enhancement processing for Chinese medicinal material images; The geometric transformation method is as follows: random rotation ±15°, scaling 0.8-1.2 times, and translation ±10% pixels to simulate different shooting angles; The color space enhancement processing method is to adjust brightness ±20%, contrast ±15%, and saturation ±15% to adapt to uneven lighting scenes. The special enhancement method for Chinese medicinal materials is to add Gaussian blur and sharpen to the image of powdered medicinal materials to enhance texture and simulate the noise of microscope images; Occlusion simulation is performed on the occluded image. 1-3 rectangular occlusion regions are randomly generated with an area ≤ 30% of the entire image. The occluded targets are then used to train the model.
3. The method for identifying Chinese medicinal materials based on dual-path dynamic convolution according to claim 1, characterized in that: In step 2, the design strategy of the global-local dual-path dynamic convolution module is as follows: After inputting the feature map, firstly, dual-path parallel feature extraction is performed on the global feature path and the local feature path. Global average pooling is used to compress and extract global information of the channel dimension, and 1×1 convolution is used to extract local information. Secondly, the parallel features of the global feature path and the local feature path are fused through the attention mechanism; Subsequently, a dynamic weight matrix is generated through a fully connected layer, where the spatial sensitivity of the 3×3 convolution kernel is adjusted in the front part, and the weights of the 5×5 convolution kernel are expanded by bilinear interpolation in the back part. Finally, the two convolutional kernels are computed in parallel and then fused channel by channel according to dynamic weights.
4. The method for identifying Chinese medicinal materials based on dual-path dynamic convolution according to claim 3, characterized in that: The specific design method of the global-local dual-path dynamic convolution module is as follows: 1) Input feature map: Set input feature map Where R represents the real number field, X represents the input feature map, and the dimensions are, in order, the number of channels C, the height H, and the width W; 2) Dual parallel processing, including global feature paths and local feature paths; Global feature pathways: ; Local characteristic pathways: ; in, This indicates the output feature vector; This indicates the output of global channel features; Represents the linear rectification activation function; Indicates a fully connected layer; Indicates global average pooling; Indicates the input feature map; This indicates that a 1×1 convolution kernel is used to convolve the input feature map X; 3) Establish a dual-pathway system: ; in, This indicates that the two channels, global feature path and local feature path, are blocked and spliced together. Indicates the use of convolution kernel Perform local convolution on the input feature map X; This indicates that the outputs of the global feature path and the local feature path are added element by element, channel by channel; 4) Dynamically learn the optimal feature combination weights through dynamic weight generation and multi-scale fusion: ) in, Indicates use The activation function maps the weights of the fully connected output to channel attention weights; This indicates a channel-by-channel weighted average. This represents the residual connection, and the final output is the enhanced feature map. It is consistent with the input feature map X in dimension; 5) Generate dynamic convolution weights based on fused features: in, and It is a fully connected network of Layer 1 and Layer 2. Enhance feature maps Flatten it into a one-dimensional vector to obtain high-level abstract features; By mapping to S×K×K dimensions through a fully connected layer, S K×K matrices are obtained, generating dynamic weight parameters; S represents the number of dynamic branches; finally, using... The activation function normalizes the weights; 6) Perform multi-scale feature fusion: By dynamically generating S convolutional kernels, the feature map is enhanced. Parallel execution of multi-scale convolutions adaptively extracts multi-scale features from Chinese medicinal materials, and through... The branch weights balance the contributions of each branch, and finally, the weighted sum of the S branches is calculated. in, s This represents the branch weight, which indicates the contribution of the S-th branch to the identification of Chinese medicinal materials. Y represents the dynamic convolution of the S-th branch, with multiple branches adapting to the needs of large-scale, medium-scale, and small-scale feature extraction respectively; Y represents the weighted fusion result of the features from the multiple branches. The weights for each scale are calculated by a lightweight attention module: Where MLP represents branch weight extraction; Softmax represents normalization of the results of MLP. Finally, the weights for each scale are calculated from the input feature map using a lightweight attention module.
5. The method for identifying Chinese medicinal materials based on dual-path dynamic convolution according to claim 3, characterized in that: In step 2, the Feature Pyramid Network (FPN) was optimized and designed: A three-level feature pyramid was constructed, namely shallow features P3 that preserve high-resolution details, mid-level features P4 that balance details and semantics, and deep features P5 that extract global semantics. The strategy for fusing cross-layer features is as follows: Top-down fusion: P5 is upsampled to the size of P4 by bilinear interpolation and then stitched together to supplement the detailed information of the large target; Bottom-up fusion: P3 is downsampled to the size of P4 by a 3×3 convolution with a stride of 2 and then stitched together to enhance the semantic expression of small targets; After fusion, the number of channels is adjusted by 1×1 convolution to make the feature dimensions consistent.
6. The method for identifying Chinese medicinal materials based on dual-path dynamic convolution according to claim 5, characterized in that: In step 2, the design strategy for the multi-granularity pooling coordinate attention module is as follows: After inputting the feature map, decompose the multi-granularity coordinate features: perform three-granularity adaptive average pooling along the width W and height H directions respectively; then transpose the width W and height H to the same dimension and stack them to concatenate the three-level features to obtain the feature layer: [C,1,H+W], which is compressed by 1×1 convolution. Next, the two parallel stages are merged, and the width W and height H are transposed to the same dimension and stacked to merge the width and height features together. The feature layer obtained at this time is: [C,1,H+W]. After merging, spatial correlation features are extracted. The process is then split into two parallel stages, with the width and height further separated into [C,1,H] and [C,1,W], which are then transposed to obtain two feature layers [C,H,1] and [C,1,W]. A 1x1 convolution is then used to adjust the number of channels, followed by a sigmoid function to obtain the attention parameters in the width and height dimensions. Finally, the original feature output structure is multiplied to suppress the weight of the background region to below 0.2, while enhancing the response of the main medicinal material region.
7. The method for identifying Chinese medicinal materials based on dual-path dynamic convolution according to claim 6, characterized in that: The design method for multi-granularity pooling coordinate attention modules includes the following steps: 1) Decompose multi-granularity coordinate features: Input feature map Three-granularity adaptive average pooling is performed along the height H and width W directions respectively, followed by three-level grid pooling processing; The single-level feature maps for height and width are as follows: ; ; in, , ; Indicates aggregation in the width direction; Indicates aggregation in the height direction; This represents the sum of the values of each channel of the input feature map X. Feature maps, calculate respectively and H represents height, and W represents width. Therefore, the output feature dimension is represented as: ; Where s∈{1,2,4} represents the granularity level: s=1 represents a 1×1 grid, corresponding to a large-scale target; s=2 represents a 2×2 grid, corresponding to a medium-scale target; s=4 represents a 4×4 grid, corresponding to a small-scale target; 2) Perform multi-scale feature fusion and generate spatial attention weights; After concatenating the three-level features, dimensionality reduction is achieved by compressing the channels using a 1×1 convolution: the channel compression ratio r=16 is set; spatial attention weights are decomposed through row and column feature decoupling and dynamic attention generation. in, This indicates that features are concatenated on rows and columns, and the spatial dimensions are merged to (H + W) after concatenation. This means that the concatenated features are processed using a 1×1 convolution kernel, compressing the number of channels from C to C / r, thus completing channel dimensionality reduction, where r is the compression ratio; It is the ReLU activation function; for function; 3) Recalibrate multi-granularity coordinate features; By multiplying element-wise, the row attention weight gh and column attention weight gw are jointly applied to the input feature map. The output feature map is obtained. .
8. The method for identifying Chinese medicinal materials based on dual-path dynamic convolution according to claim 6, characterized in that: In step 2, a differentiated attention mechanism is designed for feature maps of different scales. Then, multi-scale feature fusion is performed on the global-local dual-path dynamic convolution module and the multi-granularity coordinate attention module, including: (1) Input feature map First, it passes through a global-local dual-path dynamic convolution module to generate multi-scale dynamically weighted features: in, For dynamically generated convolutional kernel weights, Attention weights for each scale; (2) Coordinate attention weighting: The feature map output by the global-local dual-path dynamic convolution module is weighted. Then, input the MG-CA module, which performs global pooling, channel compression, and normalization on rows and columns to generate spatial attention weights for the row and column feature distribution of Chinese medicinal materials. in, Indicates global pooling; (3) The final weighted feature is: the global-local dual-path dynamic convolution module and the multi-granularity coordinate attention module are alternately cascaded.
9. The method for identifying Chinese medicinal materials based on dual-path dynamic convolution according to claim 6, characterized in that: In step 2, based on the target scale distribution of Chinese medicinal materials, a three-level detection head is configured for the lightweight medicinal material recognition model, and a bidirectional feature transfer mechanism is designed to generate fused features: ; The bidirectional feature transfer mechanism is as follows: Top-down propagation: Large-scale features are upsampled to mesoscale through bilinear interpolation and concatenated with mesoscale features to enhance the global semantic information of medium-sized targets; Bottom-up propagation: Small-scale features are downsampled to medium scale through 3×3 convolution, and then concatenated with medium-scale features to supplement the contextual information of small targets; Ultimately, the fused features Through residual connection and original features Add them together to obtain the final fusion result. + .
10. The method for identifying Chinese medicinal materials based on dual-path dynamic convolution according to claim 1, characterized in that: The loss function for model optimization and training is a multi-task joint loss function: Among them, L cls L represents the classification loss. loc L represents the localization loss. attn This represents the attention regularization loss; Empirical coefficient of classification loss Positioning loss L loc empirical coefficient Attention regularization loss L attn empirical coefficient Set them to 0.8, 0.5, and 0.1 respectively.
Citation Information
Cited By
Traditional Chinese medicine powder microscopic feature recognition and model training method and device
CN121789216A
AI authenticity identification method and system based on traditional Chinese medicine powder microscopic image
CN122336743A
