Methods, equipment, and media for identifying traditional Chinese medicine decoction pieces based on dynamic serpentine convolution.
By dynamically adjusting the sampling points of the convolution kernel through serpentine convolution, the problem of feature mismatch in the image recognition of Chinese herbal medicine pieces is solved, and efficient and accurate recognition of Chinese herbal medicine pieces is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SHANTOU UNIV
- Filing Date
- 2026-01-16
- Publication Date
- 2026-05-26
AI Technical Summary
The fixed geometry of existing standard convolution kernels is difficult to adapt to the complex and meandering geometric contours of Chinese herbal medicine slices, resulting in insufficient feature extraction capabilities and poor recognition accuracy.
Dynamic serpentine convolution is employed, which adaptively adjusts the sampling points of the convolution kernel to align with the meandering geometric contours of the Chinese herbal medicine slice image for feature extraction. The method is further improved by combining multi-scale feature fusion and deformation-aware loss function for training.
It significantly improves the accuracy and efficiency of Chinese herbal medicine slice identification, enabling more precise capture of the unique characteristics of the slices and enhancing the identification accuracy and robustness in complex scenarios.
Smart Images

Figure CN122090124A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of neural network technology, specifically to a method, device, and medium for identifying traditional Chinese medicine decoction pieces based on dynamic serpentine convolution. Background Technology
[0002] In the field of quality inspection and variety identification of traditional Chinese medicine (TCM) decoction pieces, computer vision technology has gradually replaced traditional manual visual inspection, with convolutional neural networks (CNNs) becoming the mainstream method due to their powerful feature learning capabilities. Existing research is mostly based on standard architectures such as ResNet and DenseNet, extracting texture, color, and morphological features of decoction pieces through deep networks, achieving certain results on specific datasets. However, TCM decoction piece images exhibit significant irregularities and fine-grained characteristics: firstly, the morphology of decoction pieces is affected by processing techniques, exhibiting complex topological structures such as bending, fragmentation, and curling; similar decoction pieces show large size differences and non-rigid edges; secondly, visual differences between different varieties are subtle, relying on subtle discrimination of local textures; thirdly, strong background interference exists in the images, and decoction pieces are subject to occlusion and deformation when stacked. Standard convolutional kernels use fixed rectangular grids and regular geometric structures for sampling, and their inductive bias assumptions that the input features are uniformly distributed and isotropic, when faced with curved edges, gradually changing directions, and irregular regions of interest in decoction piece images, the sampling points are prone to deviating from the effective feature region, leading to blurred edges and loss of fine-grained texture information. While data augmentation, multi-scale feature fusion, or attention mechanisms can be used to compensate for these issues, the rigid geometric constraints of the convolution operator itself remain unresolved. The network needs to stack more layers to expand the receptive field to capture morphological variations, which exacerbates computational redundancy and the difficulty of gradient optimization. This fundamental mismatch between fixed geometric structures and irregular fine-grained features restricts the model's ability to discriminate in complex scenarios with small differences between different types of medicinal herbs and large variations within each type. This makes it difficult to meet the actual needs of high-precision and high-efficiency identification in the production and distribution of traditional Chinese medicine. Therefore, it is urgent to explore novel convolutional mechanisms that can adapt to the topological geometry of medicinal herbs, achieving accurate feature capture and efficient representation while maintaining network lightweightness. Summary of the Invention
[0003] This invention provides a method, device, and medium for identifying Chinese herbal medicine slices based on dynamic serpentine convolution, which can effectively solve the problem of mismatch between the fixed geometric structure of the standard convolution kernel and the image features of the slices, thereby significantly improving the recognition accuracy and efficiency of Chinese herbal medicine slices.
[0004] This invention provides a method for identifying traditional Chinese medicine decoction pieces based on dynamic serpentine convolution, the method comprising: Images of Chinese medicinal herbs are acquired and input into a preset feature extraction network, which includes multiple convolutional kernels. By adjusting the target convolution kernel among the plurality of convolution kernels, the sampling points of the target convolution kernel are adaptively aligned along the meandering geometric contours in the image of the Chinese herbal medicine slices; The target features are obtained by extracting features from the adaptively aligned meandering geometric contour. The target features are classified and identified using a preset classifier, and the identification results of the Chinese herbal medicine slice type are output.
[0005] Optionally, adjusting the target convolution kernel among the plurality of convolution kernels to adaptively align the sampling points of the target convolution kernel along the meandering geometric contours in the image of the traditional Chinese medicine decoction pieces includes: Based on the feature map corresponding to the Chinese herbal medicine slice image in the feature extraction network, determine the spatial offset of each sampling point in the target convolutional kernel; Based on the spatial offset, the spatial position of each sampling point is adjusted to transform the multiple sampling points from a regular grid distribution to an irregular distribution that matches the meandering geometric contour.
[0006] Optionally, adjusting the spatial position of each sampling point based on the spatial offset includes: Each sampling point of the target convolution kernel is arranged along a preset direction to obtain a sampling point sequence; When adjusting the spatial position of each sampling point in the sampling point sequence, the adjusted spatial position of the current sampling point is determined by superimposing the relative offset of the current sampling point on the adjusted spatial position of the previous sampling point in the sampling point sequence. After determining the adjusted spatial position of each sampling point in sequence, a deformation path matching the meandering geometric contour is formed.
[0007] Optionally, the method for identifying traditional Chinese medicine decoction pieces based on dynamic serpentine convolution further includes: Obtain the adjusted spatial position of each sampling point in the target convolutional kernel, wherein the adjusted spatial position includes non-integer coordinate values; For each sampling point with non-integer coordinate values, based on the non-integer coordinate values, multiple pixels with integer coordinate values are determined within a preset range of the sampling point with non-integer coordinate values in the feature map corresponding to the feature extraction network. Based on the relative positional relationship between the non-integer coordinate values and the integer coordinate values, the feature values of the pixels with the plurality of integer coordinate values are weighted and summed to obtain the feature values corresponding to the sampling points of the non-integer coordinate values.
[0008] Optionally, the step of extracting target features from the adaptively aligned meandering geometric contour includes: Multi-scale feature extraction is performed on the images of the Chinese herbal medicine slices to obtain shallow feature maps, medium feature maps, and deep feature maps; Feature extraction is performed on the shallow feature map to obtain shallow features of minute textures and edge details in the image of the Chinese herbal medicine slices; Feature extraction is performed on the mid-layer feature map to obtain mid-layer features from the adaptively aligned meandering geometric contour; Feature extraction is performed on the deep feature map to obtain deep features containing high semantic information and overall topological structure; The shallow features, the middle features, and the deep features are fused to obtain the target features.
[0009] Optionally, the mid-level features are obtained by extracting features from the adaptively aligned meandering geometric contour using at least one feature enhancement unit with a bottleneck structure. The processing steps of the feature enhancement unit include: A first convolution operation is performed on the feature map input to the feature enhancement unit to reduce the feature dimension; Feature extraction is performed on the feature map after reducing the feature dimension, so as to obtain the mid-level features by extracting features from the adaptively aligned meandering geometric contour; The feature map containing the mid-level features is added element-wise to the feature map after the feature dimension is reduced to obtain the residual enhanced feature map. After performing a second convolution operation on the residual enhanced feature map, a feature map that restores the feature dimensions is output.
[0010] Optionally, the feature extraction network is trained using a deformation-aware loss function, and the target convolutional kernel in the feature extraction network is adjusted using the trained feature extraction network. The process of training the feature extraction network includes: Construct the deformation-sensing loss function, which includes at least a localization loss term, a classification loss term, and a deformation constraint loss term; The regression accuracy of the bounding box of the irregular shape of the Chinese herbal medicine slices is calculated by the localization loss term, the error value of the recognition result is calculated by the classification loss term, and the smoothness constraint of the offset of the sampling point of the target convolution kernel is applied by the deformation constraint loss term. During the iterative training of the feature extraction network using the deformation-aware loss function, the network parameters of the feature extraction network are updated using a stochastic gradient descent algorithm or an adaptive moment estimation optimizer, and the learning rate for each update is adjusted using a cosine annealing strategy and a warm-up mechanism.
[0011] Optionally, the method for identifying traditional Chinese medicine decoction pieces based on dynamic serpentine convolution further includes: Acquire training images for training the feature extraction network; Based on the preset implementation probability of each enhancement operation, the training image is enhanced using any one or more enhancement operation methods. The enhancement operation methods include adjusting the illumination and color parameters of the image, injecting noise or applying a blur effect to the image, performing geometric affine transformation on the image, or combining and enhancing multiple images by cropping and splicing.
[0012] The present invention also provides an electronic device, the electronic device including a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the method for identifying traditional Chinese medicine decoction pieces based on dynamic snake convolution as described in any of the preceding claims.
[0013] The present invention also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the method for identifying traditional Chinese medicine decoction pieces based on dynamic snake convolution as described in any of the preceding claims.
[0014] The present invention has at least the following beneficial effects: This technical solution effectively solves the problem of mismatch between the fixed geometry of standard convolution kernels and the features of traditional Chinese medicine (TCM) decoction pieces images through dynamic serpentine convolution. Traditional convolution kernels have a fixed shape, making it difficult to adapt to the complex, meandering geometric contours of TCM decoction pieces. Dynamic serpentine convolution, however, adjusts the sampling points of the target convolution kernel, adaptively aligning it along the meandering contours of the decoction piece, accurately capturing its unique features. This adaptive adjustment capability makes feature extraction more closely match the actual shape of the decoction piece, avoiding information omissions or erroneous extractions caused by the mismatch between the convolution kernel and image features. Furthermore, accurate feature extraction provides higher-quality input for subsequent classifiers, significantly improving the accuracy and efficiency of classification and recognition, achieving efficient and accurate recognition in complex TCM decoction piece image recognition scenarios. Attached Figure Description
[0015] The accompanying drawings are provided to further understand the technical solutions of the present invention and constitute a part of the specification. They are used together with the embodiments of the present invention to explain the technical solutions of the present invention, and do not constitute a limitation on the technical solutions of the present invention.
[0016] Figure 1 This is a flowchart illustrating the steps of a method for recognizing Chinese herbal medicine slices based on dynamic serpentine convolution. Figure 2 This is a schematic diagram of the receptive field of a standard convolutional kernel in existing technology; Figure 3 This is a schematic diagram of the adaptive deformation receptive field of the convolution kernel in the method for recognizing Chinese herbal medicine pieces based on dynamic serpentine convolution of this application; Figure 4This is a flowchart of step S102 in a method for recognizing Chinese herbal medicine slices based on dynamic serpentine convolution. Figure 5 This is a flowchart illustrating the steps involved in implementing a differentiable sampling mechanism in a method for recognizing traditional Chinese medicine decoction pieces based on dynamic serpentine convolution. Figure 6 This is an improved YOLOv5 network topology diagram of the integrated C3_DySnakeConv module used to implement the technical solution of this application; Figure 7 This is a flowchart illustrating the steps of the internal computation of the feature enhancement unit in a method for recognizing Chinese herbal medicine slices based on dynamic serpentine convolution. Figure 8 This is a schematic diagram of the internal operations of the C3_DySnakeConv module; Figure 9 It is a schematic diagram illustrating the principle of using various enhancement methods to enhance training images; Figure 10 This is a schematic diagram of the structure of an electronic device. Detailed Implementation
[0017] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.
[0018] The researchers of this application discovered that traditional Chinese medicine (TCM) decoction pieces have wide applications in the prevention and treatment of diseases in TCM clinical practice. However, TCM decoction pieces are diverse and complex in nature (e.g., irregular shapes, complex textures, and surface features). Traditional TCM decoction piece identification mainly relies on human experience, which suffers from low efficiency, strong subjectivity, and susceptibility to errors. Ordinary users often find it difficult to distinguish between them, easily leading to misuse. With the development of deep learning technology, object detection algorithms (such as the YOLO series) have been widely used in image recognition. However, unlike rigid objects, TCM decoction pieces (such as Atractylodes lancea, Gastrodia elata, and fibrous herbs) exhibit high morphological heterogeneity and textural complexity. Their surface features often include slender, curled tubular structures or irregular topological morphologies (such as "cinnabar dots" or "brocade patterns"). The standard YOLO algorithm still has insufficient feature extraction capabilities when processing TCM decoction pieces with slender, curved, or extremely irregular texture features, resulting in poor accuracy in TCM decoction piece identification. Therefore, it is necessary to design a targeted intelligent recognition algorithm that takes into account the unique characteristics of Chinese medicinal herbs in terms of morphology, color, and texture, so as to achieve high accuracy and high efficiency in the automated recognition of Chinese medicinal herbs. This would overcome the problems of strong subjectivity and poor consistency caused by relying on human experience in the traditional method, and provide reliable technical support for the quality control, intelligent formulation, popular science education and digital management of Chinese medicinal herbs.
[0019] The closest existing technology is the standard YOLO series of object detection algorithms. Standard YOLO mainly consists of Input, Backbone, Neck, and Head. Its core feature extraction module, C3, uses standard 2D convolutional kernels (usually a 3x3 rectangular grid) for feature extraction. The processing flow is as follows: Input image, Backbone (CSPDarknet53) extracts features, Neck (FPN+PAN) performs multi-scale feature fusion, Head outputs predicted bounding boxes and categories.
[0020] Currently, mainstream object detection algorithms (such as the standard YOLOv5) primarily rely on standard 2D convolutional kernels for feature extraction. However, standard convolutional kernels have the following problems: The receptive field mismatch problem. Standard convolutional kernels are usually distributed in a fixed 3×3 or 5×5 rectangular grid, which is difficult to adapt to the slender, curved, and topologically varied geometric structures commonly found in traditional Chinese medicine decoction pieces. When convolutional kernels extract such irregular features, they often introduce a large amount of irrelevant background noise, leading to the dilution of effective feature information. Fine-grained feature loss problem. For targets with high-frequency texture information (such as micro-wrinkles, cross-sectional textures, and overlapping shapes), convolutional kernels with fixed shapes cannot achieve pixel-level alignment of feature edges. This leads to the degradation of key discriminative features during the feature fusion process of deep networks, thereby reducing the confidence and robustness of the model in complex scenes.
[0021] To address the aforementioned technical problems, this application provides a method, device, and medium for identifying traditional Chinese medicine (TCM) decoction pieces based on dynamic serpentine convolution. This aims to solve the problem that traditional convolutional neural networks lack sufficient feature extraction capabilities when processing TCM decoction pieces with complex topologies and elongated shapes, resulting in poor recognition accuracy. The following are various embodiments of the technical solution of this application.
[0022] Please refer to Figure 1 , Figure 1 This is a flowchart illustrating the steps of a method for recognizing traditional Chinese medicine decoction pieces based on dynamic serpentine convolution.
[0023] This embodiment provides a method for identifying traditional Chinese medicine decoction pieces based on dynamic serpentine convolution, including: S101. Obtain images of Chinese herbal medicine slices and input them into a preset feature extraction network, which includes multiple convolutional kernels.
[0024] S102. By adjusting the target convolution kernel among multiple convolution kernels, the sampling points of the target convolution kernel are adaptively aligned along the meandering geometric contour in the image of Chinese herbal medicine slices.
[0025] S103. Extract the target features from the adaptively aligned meandering geometric contour.
[0026] S104. Classify and identify the target features using a preset classifier, and output the identification results of the Chinese herbal medicine slice type.
[0027] Please see Figure 2 and Figure 3 The principle of the method for identifying traditional Chinese medicine (TCM) decoction pieces based on dynamic serpentine convolution is as follows: An adaptive feature extraction network based on dynamic serpentine convolution (DSConv) is constructed, granting the convolution kernel a degree of deformation freedom in the spatial dimension. This allows it to adaptively focus on the meandering geometric features of the target, thereby significantly improving the representation ability and recognition accuracy of fine-grained features of TCM decoction pieces while maintaining a lightweight architecture. (Comparison...) Figure 2 and Figure 3 , Figure 2 Standard convolutional kernels have a fixed rectangular receptive field, making it difficult to fit irregular targets. Figure 3 The dynamic serpentine convolution (DSConv) kernel learns the offset, and its mesh deforms to adaptively cover the curved texture features of Chinese herbal medicine slices.
[0028] Understandably, this technical solution effectively solves the problem of mismatch between the fixed geometry of standard convolution kernels and the features of traditional Chinese medicine (TCM) decoction pieces images through dynamic serpentine convolution. Traditional convolution kernels have a fixed shape, making it difficult to adapt to the complex, meandering geometric contours of TCM decoction pieces. Dynamic serpentine convolution, however, can adjust the sampling points of the target convolution kernel, adaptively aligning it along the meandering contours of the decoction piece, accurately capturing its unique features. This adaptive adjustment capability makes feature extraction more closely match the actual shape of the decoction piece, avoiding information omissions or erroneous extractions caused by the mismatch between the convolution kernel and image features. Furthermore, accurate feature extraction provides higher-quality input for subsequent classifiers, significantly improving the accuracy and efficiency of classification and recognition, achieving efficient and accurate recognition in complex TCM decoction piece image recognition scenarios.
[0029] Please refer to Figure 4 , Figure 4 This is a flowchart of step S102 in a method for recognizing Chinese herbal medicine slices based on dynamic serpentine convolution.
[0030] In some embodiments, step S102 includes: S201. Based on the feature map corresponding to the image of Chinese herbal medicine slices in the feature extraction network, determine the spatial offset of each sampling point in the target convolutional kernel.
[0031] S202. Based on the spatial offset, the spatial position of each sampling point is adjusted to transform multiple sampling points from a regular grid distribution to an irregular distribution that matches the meandering geometric contour.
[0032] Specifically, assuming the standard 2D convolutional kernel coordinates are K, and the center coordinates are Ki = (xi, yi), this invention introduces a learnable deformation offset field Δ, enabling the convolutional kernel mesh to undergo non-rigid deformation based on the local gradient information of the input feature map. By introducing the learnable offset parameter Δ, a non-rigid convolutional kernel with topological continuity is constructed. An iterative accumulation strategy is used to constrain the shape of the convolutional kernel in the x-axis and y-axis directions, allowing it to adaptively fit the irregular texture features of traditional Chinese medicine decoction pieces, such as their slenderness and curvature.
[0033] Understandably, this embodiment determines the spatial offset of sampling points based on the feature map and accordingly transforms the sampling points from a regular grid distribution to an irregular distribution that matches the meandering geometric contours, achieving more accurate adaptive alignment. This improvement allows the convolutional kernel to better fit the complex geometry of Chinese herbal medicine slices, thereby extracting features more effectively. This not only improves the accuracy and specificity of feature extraction but also further enhances the adaptability and robustness to the features of herbal medicine slice images, significantly improving the recognition accuracy and efficiency of Chinese herbal medicine slices.
[0034] In some embodiments, step S202 includes: Each sampling point of the target convolution kernel is arranged along a preset direction to obtain a sampling point sequence. When adjusting the spatial position of each sampling point in the sampling point sequence, the adjusted spatial position of the previous sampling point in the sampling point sequence is used as the basis, and the relative offset of the current sampling point is superimposed to determine the adjusted spatial position of the current sampling point. After determining the adjusted spatial position of each sampling point in sequence, a deformation path matching the meandering geometric contour is formed.
[0035] It should be noted that if only the sampling points of the convolution kernel are freely deformed, the sampling points may become excessively divergent, which may destroy the inherent continuity characteristics of the texture of Chinese herbal medicine slices (such as leaf veins and vascular bundles).
[0036] In this embodiment, an iterative strategy is used to constrain the shape of the convolution kernel, ensuring its connectivity during expansion and resulting in a serpentine distribution structure. The coordinate calculation of the deformation convolution is not independent but depends on the cumulative offset of the previous position, thus guaranteeing the topological continuity of the overall structure. Taking deformation convolution along the x-axis as an example, the coordinate calculation formula for the i±c-th grid is defined as:
[0037] Where c represents the horizontal distance between the grid point and the center of the convolution kernel; Δy is the offset automatically learned by the network through backpropagation, used to fit the curvature of the target.
[0038] Understandably, this embodiment arranges sampling points along a preset direction to form a sequence, and then uses the adjusted position of the previous sampling point in the sequence as a basis to superimpose the relative offset of the current point, gradually determining the final position of each sampling point to form a deformation path that matches the meandering geometric contour. This sequence-based stepwise adjustment method enhances the coherence and accuracy of sampling point position adjustment, enabling the convolution kernel to more accurately fit the complex contour of the Chinese herbal medicine slices. This not only improves the precision and adaptability of feature extraction but also further enhances recognition accuracy and efficiency, strengthening the robustness of the technical solution in complex image feature extraction.
[0039] Please refer to Figure 5 , Figure 5 This is a flowchart illustrating the steps involved in implementing a differentiable sampling mechanism in a method for identifying traditional Chinese medicine decoction pieces based on dynamic serpentine convolution.
[0040] In some embodiments, the method for identifying traditional Chinese medicine decoction pieces based on dynamic serpentine convolution further includes: S301. Obtain the adjusted spatial position of each sampling point in the target convolution kernel, wherein the adjusted spatial position includes non-integer coordinate values.
[0041] S302. For each sampling point with non-integer coordinate values, based on the non-integer coordinate values, determine multiple pixels with integer coordinate values within a preset range in the feature map corresponding to the sampling point with non-integer coordinate values.
[0042] S303. Based on the relative positional relationship between non-integer coordinate values and integer coordinate values, the feature values of multiple integer coordinate values are weighted and summed to obtain the feature values corresponding to the sampling points with non-integer coordinate values.
[0043] It should be noted that since the calculated coordinate offsets are usually floating-point numbers, they cannot be directly mapped to discrete pixel grids.
[0044] In this embodiment, to achieve end-to-end backpropagation training, the present invention employs a bilinear interpolation mechanism to map the feature values of non-integer coordinates back to the pixel space, ensuring that gradient information can be effectively transmitted to the offset learning branch.
[0045] Where B(·) is the bilinear interpolation kernel, and X(q) is the pixel value of the feature map at integer position q.
[0046] It is understood that this embodiment allows sampling points to have non-integer coordinate values, finds multiple pixels with integer coordinate values within a preset range of non-integer coordinate values in the feature map, and then performs a weighted summation of the feature values of these pixels according to their relative positions to obtain the feature values of the sampling points with non-integer coordinate values. This improvement enables feature extraction to process the spatial position of sampling points more precisely, avoiding feature loss or distortion caused by fixed sampling point positions. Ultimately, this technique significantly improves the accuracy and robustness of feature extraction, further enhancing the precision and efficiency of traditional Chinese medicine decoction piece recognition and strengthening its adaptability to complex image features.
[0047] In some embodiments, step S103 includes: Multi-scale feature extraction is performed on images of Chinese herbal medicine slices to obtain shallow, mid-level, and deep feature maps. Features are extracted from the shallow feature maps to obtain shallow features of minute textures and edge details in the images. Features are extracted from the mid-level feature maps to extract features from the adaptively aligned meandering geometric contours. Features are extracted from the deep feature maps to obtain deep features containing high semantic information and overall topological structure. The shallow, mid-level, and deep features are then fused to obtain the target features.
[0048] Understandably, this embodiment extracts minute textures and edge details from the shallow feature map, extracts meandering geometric contour features from the mid-level feature map, and extracts high-level semantic information and overall topological structure features from the deep feature map. By fusing these three layers of features, a more comprehensive and richer target feature is obtained. This multi-scale feature extraction and fusion method can more accurately capture the multi-dimensional features of Chinese herbal medicine images, further improving the completeness and accuracy of feature extraction. Ultimately, it significantly enhances the accuracy and robustness of Chinese herbal medicine recognition, making it perform better in complex image recognition scenarios and improving recognition efficiency and reliability.
[0049] It should be noted that traditional standard convolution kernels sample in Euclidean space, and their fixed geometry (such as a regular 3×3 grid) is difficult to effectively adapt to the non-rigid, meandering texture features of the surface of Chinese herbal medicine slices. To overcome this geometric constraint, this embodiment introduces DSConv to replace the traditional convolution at key locations.
[0050] Please see Figure 6 To realize the above-mentioned method for identifying Chinese herbal medicine slices based on dynamic snake convolution, the feature extraction network in this embodiment adopts an improved YOLOv5 network topology structure that integrates the C3_DySnakeConv module. The C3_DySnakeConv module is deployed on feature fusion nodes at different scales to enhance the ability to extract irregular features at multiple scales.
[0051] Specifically, based on the lightweight YOLOv5s model, the focus was on reconstructing its feature extraction and fusion network (Neck, i.e., FPN+PAN structure) to build a multi-scale adaptive receptive field. This improved YOLOv5 network topology includes a multi-scale deployment framework.
[0052] The scale of key identification features varies greatly among different types of Chinese medicinal herbs. For example, identifying Schisandra chinensis may rely on its overall morphology (large scale), while identifying Atractylodes lancea may rely on the "cinnabar dots" on its surface (small scale). Therefore, a cross-scale deployment strategy is adopted to achieve a multi-scale deployment framework. Specifically, the C3_DySnakeConv module is deployed on different levels of nodes in the feature fusion network (Neck): Deploy this module in the P3 / 8-small layer (shallow layer) to enhance the capture of minute textures and edge details.
[0053] Deploy this module in the P4 / 16-medium layer (middle layer) to accommodate shape variations in medium-sized medicinal slices.
[0054] In the P5 / 32-large layer (deep layer), this module is deployed to extract features with high semantic information and overall topological structure.
[0055] Please refer to Figure 7 , Figure 7 This is a flowchart illustrating the steps of the internal computation of the feature enhancement unit in a method for recognizing Chinese herbal medicine slices based on dynamic serpentine convolution.
[0056] In some embodiments, mid-level features are obtained by extracting features from the adaptively aligned meandering geometric contour using at least one feature enhancement unit with a bottleneck structure. The processing steps of the feature enhancement unit include: S401. Perform a first convolution operation on the feature map input to the feature enhancement unit to reduce the feature dimension.
[0057] S402. Perform feature extraction on the feature map after reducing the feature dimension, so as to obtain the mid-level features by extracting features from the adaptively aligned meandering geometric contour.
[0058] S403. Add the feature map containing the mid-level features to the feature map after reducing the feature dimension element by element to obtain the residual enhanced feature map.
[0059] S404. After performing the second convolution operation on the residual enhanced feature map, output the feature map that restores the feature dimension.
[0060] Please see Figure 8In the bottleneck structure of the C3_DySnakeConv module, the standard 3x3 convolution is replaced by the Dynamic Snake Convolution (DSConv) operator. This operator dynamically adjusts the shape of the convolution kernel using learnable offsets and adds it to the residual of the input features, thereby effectively capturing fine-grained features.
[0061] Regarding the construction of the C3_DySnakeConv module, the original C3 module in YOLOv5 was the core component for feature extraction. This embodiment designs a completely new C3_DySnakeConv module to replace the original C3 module. Its core improvement lies in replacing the standard 3×3 convolutional layer, originally responsible for feature dimensionality reduction and refinement, in the Bottleneck residual structure with the aforementioned dynamic snake-shaped convolution operator (DSConv Operator). This design allows the network to dynamically adjust the region of interest according to the shape of the target during deep feature propagation, greatly enhancing its ability to capture irregular edges and subtle textures.
[0062] Understandably, this embodiment first reduces the feature dimension through a first convolution operation, thereby reducing computational complexity. Then, it extracts features from the reduced feature map, enhancing the capture of features related to meandering geometric contours. Next, it adds the extracted feature map element-wise to the reduced feature map, forming a residual-enhanced feature map, using residual connections to retain more detailed information. Finally, it restores the feature dimension through a second convolution operation and outputs the result. This process not only improves the efficiency of feature extraction but also preserves more detailed features through the residual enhancement mechanism, further enhancing the expressive power and robustness of mid-level features, and significantly improving the accuracy and reliability of traditional Chinese medicine decoction piece recognition.
[0063] In some embodiments, the feature extraction network is trained using a deformation-aware loss function, and the target convolutional kernel in the feature extraction network is adjusted using the trained feature extraction network. The process of training the feature extraction network includes: A deformation-aware loss function is constructed, which includes at least a localization loss term, a classification loss term, and a deformation constraint loss term. The localization loss term is used to calculate the regression accuracy of the bounding box of the irregular shape of the Chinese herbal medicine slices, the classification loss term is used to calculate the error value of the recognition result, and the deformation constraint loss term is used to impose a smoothness constraint on the offset of the sampling points of the target convolutional kernel. During the iterative training of the feature extraction network using the deformation-aware loss function, the network parameters of the feature extraction network are updated using a stochastic gradient descent algorithm or an adaptive moment estimation optimizer, and the learning rate of each update is adjusted using a cosine annealing strategy and a preheating mechanism.
[0064] In this embodiment, to fully unleash the performance of the improved architecture, the present invention employs a targeted training strategy, specifically including: A composite loss function guides network optimization. In the localization loss, CIoU (Complete IoU) loss is used instead of the traditional IoU loss. CIoU comprehensively considers the overlap area between the predicted and ground truth bounding boxes, the distance between their center points, and the consistency of their aspect ratios, significantly improving the regression accuracy for irregularly shaped food scraps. The classification loss and confidence loss employ binary cross-entropy loss (BCE with Logits Loss) to ensure the accuracy of class prediction.
[0065] Parameter updates are performed using either the SGD optimizer with momentum or the AdamW optimizer. A cosine annealing learning rate scheduling strategy is introduced, and a warm-up mechanism is used in the early stages of training to prevent gradient explosion and help the model converge quickly to a better solution space.
[0066] Understandably, this embodiment further enhances the training performance of the feature extraction network through a deformation-aware loss function and optimization strategies. The deformation-aware loss function combines localization, classification, and deformation constraint loss terms to optimize bounding box regression accuracy, recognition error, and the smoothness of convolutional kernel sampling points, respectively, making the network more robust when handling complex shapes. During training, stochastic gradient descent or adaptive moment estimation optimizers are employed, combined with cosine annealing and a warm-up mechanism to adjust the learning rate, effectively accelerating network convergence and avoiding overfitting. This allows the feature extraction network to more accurately adjust the target convolutional kernel, further improving the accuracy and efficiency of traditional Chinese medicine decoction piece recognition and enhancing the model's generalization ability.
[0067] In some embodiments, the method for identifying traditional Chinese medicine decoction pieces based on dynamic serpentine convolution further includes: Acquire training images for training the feature extraction network; according to the preset implementation probability of each enhancement operation, perform enhancement operations on the training images using any one or more enhancement operation methods, wherein the enhancement operation methods are adjusting the illumination and color parameters of the image, injecting noise or applying a blur effect to the image, performing geometric affine transformation on the image, or combining and enhancing multiple images by cropping and stitching.
[0068] Please see Figure 9In this embodiment, given that traditional Chinese medicine decoction pieces are a typical fine-grained classification task, and that some categories exhibit "high inter-class similarity and large intra-class differences," a single traditional data augmentation method (such as simple rotation or flipping) is insufficient to simulate the complex changes in the real world. This embodiment proposes a randomized combined data augmentation pipeline that introduces a random process to generate highly diverse training samples, significantly expanding the boundaries of the sample space. This strategy includes the following parallel or serial processing modules, each activated with a certain probability threshold: (1) Illumination and color space perturbation: Simulates the color changes of medicinal slices caused by different storage times or shooting light differences. This includes random brightness adjustment (±30%), contrast enhancement, and hue fine-tuning in the HSV color space; (2) Noise injection and blurring: Simulate low-quality imaging equipment or environmental interference. This includes randomly adding Gaussian noise, salt-and-pepper noise, and applying Gaussian blur to simulate inaccurate focusing. (3) Geometric affine transformation: Simulate different shooting postures. In addition to the usual random rotation and horizontal / vertical mirror flip, random translation and shearing transformations are also introduced to enhance the model's tolerance to target position and deformation.
[0069] (4) Mosaic data augmentation: During the training phase, four images are dynamically scaled, cropped and arranged to be stitched together, which greatly enriches the background of the detected target and improves the model's ability to perceive small targets.
[0070] By employing the above strategies, the original dataset was effectively expanded to more than six times its original size, thus effectively alleviating the problem of model overfitting under small sample conditions.
[0071] In some embodiments, to ensure the robustness of the model in real-world application scenarios, environmental diversity was fully considered during the original image acquisition process. Acquisition equipment included high-resolution industrial cameras and mainstream smartphone cameras. The shooting environment covered natural and artificial light sources of varying intensities, with backgrounds ranging from solid-color lab benches to complex pharmacy backdrops. Shooting angles included eye-level, overhead, and multi-angle side views.
[0072] Understandably, this embodiment increases the diversity and complexity of training data by performing enhancement operations on the training images according to preset probabilities, such as adjusting illumination and color, injecting noise, applying blurring effects, geometric affine transformations, or cropping and splicing. This allows the feature extraction network to learn a wider range of image features during training, thus exhibiting stronger adaptability and stability when faced with changes in illumination, noise interference, blurring, or geometric deformation in actual Chinese herbal medicine images. Ultimately, data augmentation significantly improves the generalization ability and recognition accuracy of the Chinese herbal medicine identification method, enhancing the model's application effect in complex real-world scenarios.
[0073] This application also provides an electronic device, which includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement any of the above-mentioned methods for recognizing Chinese herbal medicine slices based on dynamic snake convolution.
[0074] refer to Figure 10 , Figure 10 The hardware structure of an electronic device according to another embodiment is illustrated. The electronic device includes: The processor 501 can be implemented using a general-purpose CPU (Central Processing Unit), microprocessor, application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this application. The memory 502 can be implemented as a read-only memory (ROM), static storage device, dynamic storage device, or random access memory (RAM). The memory 502 can store operating devices and other application programs. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 502 and is called and executed by the processor 501 to execute the method for identifying traditional Chinese medicine decoction pieces based on dynamic serpentine convolution according to the embodiments of this application. The input / output interface 503 is used to implement information input and output; The communication interface 504 is used to enable communication and interaction between this device and other devices. Communication can be achieved through wired means (such as USB, network cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.). Bus 505 transmits information between various components of the device (e.g., processor 501, memory 502, input / output interface 503, and communication interface 504); The processor 501, memory 502, input / output interface 503, and communication interface 504 are connected to each other within the device via bus 505.
[0075] It is understood that the content of the above method embodiments is applicable to the embodiments of this electronic device. The specific functions implemented by the embodiments of this electronic device are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.
[0076] This application also provides a computer-readable storage medium storing a processor-executable program, which, when executed by a processor, is used to implement the method for identifying traditional Chinese medicine decoction pieces based on dynamic serpentine convolution as described in any of the above specific embodiments.
[0077] This application also discloses a computer program product, including a computer program or computer instructions, which are stored in a computer-readable storage medium. The processor of the computer device reads the computer program or computer instructions from the computer-readable storage medium and executes the computer program or computer instructions, causing the computer device to perform the method for identifying Chinese herbal medicine slices based on dynamic snake convolution as described in any of the preceding embodiments.
[0078] It is understood that the content of the above method embodiments is applicable to this storage medium embodiment. The specific functions implemented in this storage medium embodiment are the same as those in the above method embodiments, and the beneficial effects achieved are also the same as those achieved in the above method embodiments.
[0079] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented, for example, in orders other than those illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, apparatus, product, or device that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or devices. It should be understood that in this application, “at least one” means one or more, and “more than one” means two or more.
[0080] In the several embodiments provided in this application, it should be understood that the disclosed apparatus, devices, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another device, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be indirect coupling or communication connection through some interfaces, devices, or units, and may be electrical, mechanical, or other forms.
[0081] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0082] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0083] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0084] Although the description of this application has been quite detailed and particularly focused on several of the described embodiments, it is not intended to limit itself to any of these details or embodiments or any particular embodiment. Rather, it should be considered as effectively covering the intended scope of this application by referring to the appended claims and taking into account the prior art, which provides for a broad possible interpretation of these claims. Furthermore, the foregoing description of this application with respect to embodiments foreseeable by the inventors is intended to provide a useful description, and non-substantial modifications to this application that have not yet been foreseen may still represent equivalent modifications.
Claims
1. A method for recognizing traditional Chinese medicine decoction pieces based on dynamic serpentine convolution, characterized in that, The method includes: Images of Chinese medicinal herbs are acquired and input into a preset feature extraction network, which includes multiple convolutional kernels. By adjusting the target convolution kernel among the plurality of convolution kernels, the sampling points of the target convolution kernel are adaptively aligned along the meandering geometric contours in the image of the Chinese herbal medicine slices; The target features are obtained by extracting features from the adaptively aligned meandering geometric contour. The target features are classified and identified using a preset classifier, and the identification results of the Chinese herbal medicine slice type are output.
2. The method according to claim 1, characterized in that, The step of adjusting the target convolution kernel among the plurality of convolution kernels to adaptively align the sampling points of the target convolution kernel along the meandering geometric contours in the image of the traditional Chinese medicine decoction pieces includes: Based on the feature map corresponding to the Chinese herbal medicine slice image in the feature extraction network, determine the spatial offset of each sampling point in the target convolutional kernel; Based on the spatial offset, the spatial position of each sampling point is adjusted to transform the multiple sampling points from a regular grid distribution to an irregular distribution that matches the meandering geometric contour.
3. The method according to claim 2, characterized in that, The adjustment of the spatial position of each sampling point based on the spatial offset includes: Each sampling point of the target convolution kernel is arranged along a preset direction to obtain a sampling point sequence; When adjusting the spatial position of each sampling point in the sampling point sequence, the adjusted spatial position of the current sampling point is determined by superimposing the relative offset of the current sampling point on the adjusted spatial position of the previous sampling point in the sampling point sequence. After determining the adjusted spatial position of each sampling point in sequence, a deformation path matching the meandering geometric contour is formed.
4. The method according to claim 3, characterized in that, The method further includes: Obtain the adjusted spatial position of each sampling point in the target convolutional kernel, wherein the adjusted spatial position includes non-integer coordinate values; For each sampling point with non-integer coordinate values, based on the non-integer coordinate values, multiple pixels with integer coordinate values are determined within a preset range of the sampling point with non-integer coordinate values in the feature map corresponding to the feature extraction network. Based on the relative positional relationship between the non-integer coordinate values and the integer coordinate values, the feature values of the pixels with the plurality of integer coordinate values are weighted and summed to obtain the feature values corresponding to the sampling points of the non-integer coordinate values.
5. The method according to claim 1, characterized in that, The step of extracting target features from the adaptively aligned meandering geometric contour includes: Multi-scale feature extraction is performed on the images of the Chinese herbal medicine slices to obtain shallow feature maps, medium feature maps, and deep feature maps; Feature extraction is performed on the shallow feature map to obtain shallow features of minute textures and edge details in the image of the Chinese herbal medicine slices; Feature extraction is performed on the mid-layer feature map to obtain mid-layer features from the adaptively aligned meandering geometric contour; Feature extraction is performed on the deep feature map to obtain deep features containing high semantic information and overall topological structure; The shallow features, the middle features, and the deep features are fused to obtain the target features.
6. The method according to claim 5, characterized in that, The mid-level features are obtained by extracting features from the adaptively aligned meandering geometric contour using at least one feature enhancement unit with a bottleneck structure. The processing steps of the feature enhancement unit include: A first convolution operation is performed on the feature map input to the feature enhancement unit to reduce the feature dimension; Feature extraction is performed on the feature map after reducing the feature dimension, so as to obtain the mid-level features by extracting features from the adaptively aligned meandering geometric contour; The feature map containing the mid-level features is added element-wise to the feature map after the feature dimension is reduced to obtain the residual enhanced feature map. After performing a second convolution operation on the residual enhanced feature map, a feature map that restores the feature dimensions is output.
7. The method according to claim 2, characterized in that, The feature extraction network is trained using a deformation-aware loss function, and the target convolutional kernels in the trained feature extraction network are adjusted using the trained feature extraction network. The training process of the feature extraction network includes: Construct the deformation-sensing loss function, which includes at least a localization loss term, a classification loss term, and a deformation constraint loss term; The regression accuracy of the bounding box of the irregular shape of the Chinese herbal medicine slices is calculated by the localization loss term, the error value of the recognition result is calculated by the classification loss term, and the smoothness constraint of the offset of the sampling point of the target convolution kernel is applied by the deformation constraint loss term. During the iterative training of the feature extraction network using the deformation-aware loss function, the network parameters of the feature extraction network are updated using a stochastic gradient descent algorithm or an adaptive moment estimation optimizer, and the learning rate for each update is adjusted using a cosine annealing strategy and a warm-up mechanism.
8. The method according to claim 7, characterized in that, The method further includes: Acquire training images for training the feature extraction network; Based on the preset implementation probability of each enhancement operation, the training image is enhanced using any one or more enhancement operation methods. The enhancement operation methods include adjusting the illumination and color parameters of the image, injecting noise or applying a blur effect to the image, performing geometric affine transformation on the image, or combining and enhancing multiple images by cropping and splicing.
9. An electronic device, characterized in that, The electronic device includes a memory and a processor. The memory stores a computer program, and when the processor executes the computer program, it implements the method for identifying traditional Chinese medicine decoction pieces based on dynamic snake convolution as described in any one of claims 1 to 8.
10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the method for identifying Chinese herbal medicine slices based on dynamic snake convolution as described in any one of claims 1 to 8.