Chinese herbal medicine identification method and system based on YOLO-AMPMS
Through the YOLO-AMPMS method, the multi-scene image processing, composite attention mechanism CAM and multi-scale prototype pool MSPP are used to solve the problems of small target missed detection and inter-class misjudgment in Chinese herbal medicine detection, and high-precision Chinese herbal medicine recognition is achieved, which is suitable for edge computing devices.
Patent Information
- Application Number
- CN202510454486.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-11
- Publication Date
- 2025-07-25
AI Technical Summary
The prior art has problems such as small target miss detection, complex background noise interference, high inter-class misjudgment rate and uneven category distribution in traditional Chinese herbal medicine detection, which makes it difficult to take into account both detection accuracy and real-timeness, especially when the lightweight requirement is not met when deploying edge computing devices.
The YOLO-AMPMS method is adopted to generate data sets by acquiring herbal images of multiple scenes, implementing random rotation, brightness perturbation and occlusion strategies, and embed a composite attention mechanism CAM and multi-scale prototype pool MSPP in the YOLO11 model, combining the adaptive loss function optimization model training.
It improves the accuracy of Chinese herbal medicine identification, reduces the missed detection rate and false detection rate of small targets, enhances the distinction ability of similar medicinal materials, and meets the lightweight needs of edge computing devices.
Smart Images

Figure CN120375339A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of computer vision, and specifically to a Chinese herbal medicine recognition method and system based on YOLO-AMPMS. Background Art
[0002] As a treasure of traditional Chinese medicine of the Chinese nation, Chinese herbal medicines are diverse in variety and different in form. In the processes of medicinal material harvesting, processing and circulation, fast and accurate detection and recognition technologies are the key to ensuring the quality of medicinal materials and improving the level of industrial automation. Traditional identification of Chinese herbal medicines mainly relies on manual experience, and judgments are made by observing characteristics such as the color, texture, and shape of medicinal materials. However, this method is inefficient and easily affected by subjective factors, and it is difficult to meet the needs of large-scale industrial production. With the development of computer vision technology, methods based on image processing (such as threshold segmentation, morphological operations, color space analysis, etc.) have been introduced into the field of Chinese herbal medicine detection. However, these methods have high requirements for image quality and are not robust enough in the face of complex background interference, illumination changes, and significant differences in target scales, resulting in limited actual application effects.
[0003] In recent years, deep learning technologies, especially object detection algorithms (such as YOLO, Faster R-CNN, etc.), have demonstrated powerful performance in general object detection tasks. However, their migration and application in the scenario of Chinese herbal medicine detection still face multiple challenges: First, Chinese herbal medicines often have low image resolution due to shooting distance, equipment limitations, or environmental factors, and key details such as root hairs, fissures, and spots are blurred, resulting in prominent problems of missed detection of small targets; Second, medicinal materials are often mixed with soil, branches, leaves, and impurities in natural scenes, and complex background noise easily interferes with the model's focus on the main body area; Third, the shapes and textures of different types of Chinese herbal medicines (such as Angelica sinensis and Heracleum hemsleyanum, Astragalus membranaceus and Glycyrrhiza uralensis) are highly similar, and it is difficult to capture subtle differences based on global features alone, resulting in a high inter-class misjudgment rate; In addition, the class distribution of Chinese herbal medicine datasets is significantly unbalanced, the samples of rare medicinal materials are scarce, and the target poses and occlusion situations are variable, which exacerbates the difficulty of model training and the lack of generalization ability. Although existing research attempts to optimize the detection effect through multi-scale feature fusion, attention mechanisms, or data augmentation strategies, most methods solve single problems in isolation and fail to synergistically improve the feature expression ability of small targets, suppress complex background noise, and strengthen the perception of inter-class differences, resulting in the inability to balance detection accuracy and real-time performance, especially unable to meet the lightweight requirements for deployment on edge computing devices. Summary of the Invention
[0004] To solve the deficiencies mentioned in the above background art, the purpose of the present invention is to provide a Chinese herbal medicine recognition method and system based on YOLO-AMPMS.
[0005] In a first aspect, the object of the present invention can be achieved by the following technical solutions: A Chinese herbal medicine recognition method based on YOLO-AMPMS, the method comprising the following steps:
[0006] Obtain Chinese herbal medicine images in multiple scenarios, generate a Chinese herbal medicine data set by processing the Chinese herbal medicine images in multiple scenarios, and preprocess the Chinese herbal medicine data set to obtain a processed Chinese herbal medicine data set, wherein the multiple scenarios include: sunny noon scenario, cloudy scenario, multi-angle aerial photography scenario, and complex background scenario;
[0007] Input the processed Chinese herbal medicine data set into a pre-established YOLO11 model, and output a Chinese herbal medicine recognition result, wherein the Chinese herbal medicine recognition result includes the category, bounding box coordinates, and confidence of the Chinese herbal medicine target. The pre-established YOLO11 model is constructed by embedding a compound attention mechanism CAM in the backbone network and introducing a multi-scale prototype pool MSPP in the Neck network.
[0008] Combined with the first aspect, in certain implementation manners of the first aspect, the method further includes: the process of generating a Chinese herbal medicine data set by processing the Chinese herbal medicine images in multiple scenarios:
[0009] After implementing enhancement strategies such as random rotation, brightness perturbation Gaussian noise, and random occlusion, a Chinese herbal medicine data set is finally obtained.
[0010] Combined with the first aspect, in certain implementation manners of the first aspect, the method further includes: the process of the compound attention mechanism CAM of the pre-established YOLO11 model includes:
[0011] Channel attention branch, spatial attention branch, local-global attention branch, and dynamic fusion.
[0012] Combined with the first aspect, in certain implementation manners of the first aspect, the method further includes: the process of the channel attention branch is as follows:
[0013] Perform global average pooling GAP on the input feature map to obtain a channel description vector Generate channel weights through two fully connected layers The formula is:
[0014] w c =σ(w2·δ(w1·z))
[0015] where are the weights of the fully connected layer, δ is the ReLU activation, δ(x)=max(0,x); σ is the Sigmoid function, which maps the input to the interval (0,1);
[0016] The spatial attention branch is as follows:
[0017] Perform max pooling and average pooling on the input features along the channel dimension, and after concatenation, generate spatial weights through convolution The formula is:
[0018] w s =σ(Conv 7×7 ([MaxPool(F),AvgPool(F)]))
[0019] The local-global attention branch is as follows:
[0020] Use depthwise separable convolution and dilated convolution respectively to extract local details and global context features, and after concatenation, generate multi-scale weights through 1×1 convolution The formula is:
[0021] w lg =σ(Conv 1×1 ([Conv 3×3 (F),Conv 5×5 (F)]))
[0022] The dynamic fusion is as follows:
[0023] Weightedly fuse the channel, spatial, and multi-scale weights through learnable parameters α, β, γ. The formula is:
[0024]
[0025] Among them, α, β, γ are optimized through backpropagation.
[0026] Combined with the first aspect, in some implementation manners of the first aspect, the method further includes: The implementation process of the multi-scale prototype pool MSPP of the pre-established YOLO11 model includes:
[0027] Atrous spatial pyramid pooling ASPP
[0028] For the input feature map Use 3×3 dilated convolution for parallel processing, set two dilation rates to extract multi-scale features, and obtain two groups of multi-scale feature maps Concatenate the two groups of features with the original input feature F to form a multi-scale feature tensor Perform feature fusion;
[0029] Prototype library matching
[0030] First, initialize the prototype library, and pre-define K = 32 Chinese herbal medicine feature prototypes P = {p1, p2,..., p 32} All local feature blocks in the training set are clustered by K-means clustering, and the cluster centers are taken as the initial prototypes.
[0031] Subsequently, the feature-prototype similarity is calculated. For each spatial position (i, j) of the multi-scale F ASPP the cosine similarity between its feature vector and all prototypes is calculated, and the matching formula is:
[0032]
[0033] where τ = 0.1 is the temperature coefficient, which controls the sharpness of the matching weight distribution;
[0034] Finally, weight assignment is performed. Each position (i, j) generates a 32-dimensional weight vector indicating the matching degree of the feature at this position with each prototype; By weighted fusion of prototype features, the discriminative feature expression is enhanced:
[0035]
[0036] Prototype dynamic update
[0037] Every 1000 training iterations, the prototype library is updated based on the features extracted by the current model, and the formula is:
[0038]
[0039] where is to sample feature blocks from the current training batch, and use the K-means algorithm to re-partition them into 32 categories to obtain new cluster centers
[0040] Combined with the first aspect, in some implementation manners of the first aspect, the method further includes: The training process of the pre-established YOLO11 model is carried out by dynamically balancing the classification, localization, and confidence loss weights using an adaptive loss function.
[0041] Combined with the first aspect, in some implementation manners of the first aspect, the method further includes: The formula of the adaptive loss function is as follows:
[0042] L total = λ cls ·L cls + λ box ·L box + λ obj ·L obj
[0043] where λ cls ,λ box ,λ objis a learnable parameter that is dynamically adjusted through backpropagation, L cls is the dynamic class weight classification loss, L box is the scale-sensitive localization loss, L obj is the Top-K hard sample confidence loss.
[0044] Combined with the first aspect, in some implementations of the first aspect, the method further includes: the dynamic class weight classification loss L cls has the following formula:
[0045]
[0046] Parameter description:
[0047] N is the total number of classes in the dataset; is the class weight, N c is the number of samples of class c, ∈ = 1e-5 is a constant; y c is the true label; p c is the predicted probability, the class probability output by Softmax; γ is a hyperparameter;
[0048] The scale-sensitive localization loss L box has the following formula:
[0049]
[0050] Parameter description: is the target localization weight, and area(gt i ) is the area of the i-th ground truth box; IoU i is the intersection over union; ρ i is the Euclidean distance between the center points of the predicted box and the ground truth box; d i is the length of the diagonal of the minimum bounding box; is the prediction result of the model for the target position and size; is the true position and size of the target in the labeled data; is the aspect ratio difference term, is the term to measure the difference in aspect ratio or width-to-height ratio between the predicted box and the ground truth box, is the width and height of the i-th ground truth box, is the width and height of the i-th predicted box;
[0051] The Top-K hard sample confidence loss L obj is as follows:
[0052]
[0053] Parameter description: K = 0.2×N is used to screen the top 20% of difficult samples, where N is the total number of samples; is the true confidence level; p k is the predicted confidence level.
[0054] In a second aspect, to achieve the above object, the present invention discloses a Chinese herbal medicine recognition system based on YOLO-AMPMS, including:
[0055] A data processing module, configured to obtain Chinese herbal medicine images in multiple scenarios, generate a Chinese herbal medicine data set by processing the Chinese herbal medicine images in multiple scenarios, and preprocess the Chinese herbal medicine data set to obtain a processed Chinese herbal medicine data set, where the multiple scenarios include: sunny noon scenario, cloudy day scenario, multi-angle aerial photography scenario, and complex background scenario;
[0056] A Chinese herbal medicine recognition module, configured to input the processed Chinese herbal medicine data set into a pre-established YOLO11 model, and output a Chinese herbal medicine recognition result, where the Chinese herbal medicine recognition result includes the category, bounding box coordinates, and confidence level of the Chinese herbal medicine target, and the pre-established YOLO11 model is constructed by embedding a composite attention mechanism CAM in the backbone network and introducing a multi-scale prototype pool MSPP in the Neck network.
[0057] In another aspect of the present invention, to achieve the above object, a terminal device is disclosed, including a memory, a processor, and a computer program stored in the memory and capable of running on the processor. The memory stores a computer program capable of running on the processor. When the processor loads and executes the computer program, it adopts a Chinese herbal medicine recognition method based on YOLO-AMPMS as described above.
[0058] Advantages of the present invention:
[0059] The present invention reduces the missed detection rate of small targets through super-resolution reconstruction and multi-scale feature matching; reduces the false detection rate through attention mechanism and prototype pool optimization; to improve the discrimination accuracy of similar Chinese herbal medicines. Description of the drawings
[0060] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, for those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings;
[0061] Figure 1 is a schematic diagram of the method flow of the present invention;
[0062] Figure 2 is the overall architecture diagram of the embodiment of the present invention;
[0063] Figure 3 It is the structure diagram of the composite attention mechanism CAM according to the embodiment of the present invention;
[0064] Figure 4 It is the matching process of the multi-scale prototype pool MSPP according to the embodiment of the present invention;
[0065] Figure 5 It is the calculation process of the adaptive loss function according to the embodiment of the present invention;
[0066] Figure 6 It is the schematic diagram of the system structure of the present invention. Detailed implementation manners
[0067] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all of the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
[0068] Embodiment 1:
[0069] As Figure 1 shown, a Chinese herbal medicine recognition method based on YOLO-AMPMS includes the following steps:
[0070] S101: Obtain multi-scenario Chinese herbal medicine images, generate a Chinese herbal medicine data set by processing the multi-scenario Chinese herbal medicine images, and preprocess the Chinese herbal medicine data set to obtain a processed Chinese herbal medicine data set, where the multi-scenarios include: sunny noon scenario (light intensity ≥ 80000 lux), cloudy day scenario (light intensity ≤ 30000 lux), multi-angle aerial photography scenario (30° - 90°), and complex background scenario (soil proportion ≥ 40%, branch and leaf occlusion rate ≤ 30%).
[0071] The process of collecting and processing multi-scenario Chinese herbal medicine images is as follows:
[0072] Use a 12-million-pixel smart phone to collect Chinese herbal medicine images in the field, covering sunny noon (light intensity ≥ 80000 lux), cloudy day (light intensity ≤ 30000 lux), multi-angle aerial photography (30° - 90°), and complex background (soil proportion ≥ 40%, branch and leaf occlusion rate ≤ 30%) scenarios, and store the images in JPEG format;
[0073] Annotation processing
[0074] Use LabelImg to label the medicinal material bounding boxes in YOLO format and generate a.txt annotation file. The annotation format is <class_id><x_center><y_center> <width> <height>, the coordinate accuracy is retained to 4 decimal places;
[0075] Data augmentation, based on OpenCV 4.5.4, implement the following augmentation strategies:
[0076] Spatial transformation: randomly rotate the angle θ ∈ [-30°, 30°], and the scaling ratio s ∈ [0.8, 1.2];
[0077] Color perturbation: adjust the saturation ΔS ∈ [-20%, +20%] and the brightness ΔV ∈ [-15%, +15%] in the HSV color space;
[0078] Noise injection: add Gaussian noise with a mean of 0 and a standard deviation = 0.01;
[0079] Occlusion simulation: randomly generate 1 - 3 rectangular occlusion regions, the area of a single region ≤ 15% of the image area, and the total occlusion rate ≤ 30%.
[0080] Obtain approximately three thousand images (including labels) of the Chinese herbal medicine dataset, with a total of 5 classes, and the size of each image is 640×640.
[0081] S102: Input the processed Chinese herbal medicine dataset into the pre - established YOLO11 model, and output the Chinese herbal medicine recognition result. Among them, the Chinese herbal medicine recognition result includes the category, bounding box coordinates, and confidence of the Chinese herbal medicine target. The pre - established YOLO11 model is constructed by embedding a compound attention mechanism CAM in the backbone network and introducing a multi - scale prototype pool MSPP in the Neck network.
[0082] Specifically, the pre - established YOLO11 model:
[0083] Based on the PyTorch 1.10.0 framework, load the official pre - trained weights of YOLOv11;
[0084] The CAM module implementation
[0085] Channel attention branch
[0086] For the input feature map Perform global average pooling (GAP) to obtain the channel description vector Generate channel weights through two fully - connected layers (compression ratio r = 4) The formula is:
[0087] w c = σ(w2·δ(w1·z))
[0088] Where, is the weight of the fully connected layer, δ is the ReLU activation, δ(x) = max(0, x); σ is the Sigmoid function that maps the input to the interval (0, 1);
[0089] Spatial attention branch
[0090] Perform max pooling and average pooling on the input features along the channel dimension, and generate spatial weights after concatenation through a 7×7 convolution The formula is:
[0091] w s = σ(Conv 7×7 ([MaxPool(F), AvgPool(F)]))
[0092] Local-global attention branch
[0093] Use 3×3 depthwise separable convolution and 5×5 dilated convolution (dilation = 2) respectively to extract local details and global context features, and generate multi-scale weights after concatenation through a 1×1 convolution The formula is:
[0094] w lg = σ(Conv 1×1 ([Conv 3×3 (F), Conv 5×5 (F)]))
[0095] Dynamic fusion
[0096] Weightedly fuse the channel, spatial, and multi-scale weights through learnable parameters α, β, γ. The formula is:
[0097]
[0098] Among them, the initial values of α, β, γ are 0.5 and are optimized through backpropagation.
[0099] MSPP module configuration
[0100] Atrous Spatial Pyramid Pooling (ASPP)
[0101] For the input feature map Use 3×3 dilated convolution for parallel processing, and set two dilation rates to extract multi-scale features: dilation rate 6 (expanding the receptive field to 13×13 to capture medium-scale context features), dilation rate 12 (expanding the receptive field to 25×25 to capture large-scale global features), obtaining two groups of multi-scale feature maps Concatenate the two groups of features with the original input feature F to form a multi-scale feature tensor Perform feature fusion to enhance the model's cross-scale perception ability of Chinese herbal medicine textures.
[0102] Prototype library matching
[0103] First, initialize the prototype library and pre-define K = 32 Chinese herbal medicine feature prototypes P = {p1, p2,..., p 32}, each prototype Cluster all local feature blocks in the training set (such as local regions cropped from the feature map) through K-means clustering, and take the cluster center as the initial prototype;
[0104] Subsequently, calculate the feature-prototype similarity. For each spatial position (i, j) of the multi-scale F ASPP calculate the cosine similarity between its feature vector and all prototypes. The matching formula is:
[0105]
[0106] where τ = 0.1 is the temperature coefficient, which controls the sharpness of the matching weight distribution. The smaller τ is, the more concentrated the weights are on the most similar prototype;
[0107] Finally, perform weight assignment. Each position (i, j) generates a 32-dimensional weight vector indicating the matching degree of the feature at this position with each prototype; By weighted fusion of prototype features, enhance the discriminative feature expression:
[0108]
[0109] Prototype dynamic update
[0110] Every 1000 training iterations (about one training phase cycle), update the prototype library based on the features extracted by the current model. The formula is:
[0111]
[0112] where: is to sample feature blocks from the current training batch, and use the K-means algorithm to re-partition them into 32 classes to obtain new cluster centers The momentum coefficient is 0.9, aiming to retain the stability of historical prototypes; The learning rate is 0.1, aiming to gradually absorb the changes in the new feature distribution and avoid prototype mutations.
[0113] Adaptive training strategy
[0114] The adaptive loss function consists of three parts. The formula is as follows:
[0115] L total = λ cls ·L cls + λ box ·L box + λ obj · L obj
[0116] where λ cls , λ box , λ obj are learnable parameters, with initial values all being 1.0, and are dynamically adjusted through backpropagation.
[0117] Dynamic class weight classification loss
[0118] Objective: To solve the problem of class imbalance and improve the classification accuracy of tail classes (such as rare medicinal materials); Formula:
[0119]
[0120] Parameter description:
[0121] N: The total number of classes in the dataset;
[0122] Class weight (N c is the number of samples of class c, the fewer the samples, the higher the weight, ∈ = 1e - 5 is a very small constant to prevent numerical instability);
[0123] y c : True label (class label in one - hot encoding (the correct class is 1, and the rest are 0));
[0124] p c : Predicted probability, the class probability output by Softmax (the probability that the model predicts the current sample belongs to class c);
[0125] γ: Hyperparameter, controlling the loss weight of hard samples (low p c ), the larger γ is, the higher the loss weight of low - probability (hard samples), promoting the model to pay more attention to hard samples;
[0126] Scale - sensitive localization loss
[0127] Objective: To prevent the localization error of large targets from accounting for too high a proportion in the total loss during the training process, resulting in the model over - focusing on large targets and ignoring the localization accuracy of small targets;
[0128] Formula:
[0129]
[0130] Parameter description:
[0131] Target localization weight, the smaller the target size, the larger the weight;
[0132] area(gt i ):The area of the i-th ground truth box;
[0133] IoU i : Intersection over Union, the intersection over union of the predicted box and the ground truth box (Intersection over Union);
[0134] ρ i : The Euclidean distance between the centers of the predicted box and the ground truth box;
[0135] d i : The length of the diagonal of the smallest enclosing box, the length of the diagonal of the smallest rectangle containing the predicted box and the ground truth box;
[0136] : The prediction result of the model for the target position and size;
[0137] : The true position and size of the target in the labeled data;
[0138] : Aspect ratio difference term;
[0139] : An index that quantifies the shape difference between the two in terms of aspect ratio (width-to-height ratio) by calculating the squared difference of the arctangent values of the width-to-height ratios of the predicted box and the ground truth box and normalizing; are the width and height of the i-th ground truth box, are the width and height of the i-th predicted box;
[0140] Top-K hard sample confidence loss
[0141] Objective: Select the top 20% of samples with the highest sum of classification and localization losses and focus on optimizing hard examples;
[0142] Formula:
[0143]
[0144] Parameter description:
[0145] K = 0.2 × N: Select the top 20% hard samples (N is the total number of samples);
[0146] : True confidence (1 indicates the presence of a target, 0 indicates the background);
[0147] p k : Predicted confidence, the probability of the presence of the target predicted by the model (output through Sigmoid)
[0148] Specifically, the solution of the present invention will be further described below through embodiments:
[0149] Detection Performance Verification
[0150] Test Configuration Dataset: 3000 real - scene images (including occluded / rainy samples);
[0151] Hardware: NVIDIA GPU (single - card inference, 640×640 input);
[0152] Verification Content: Measure end - to - end FPS;
[0153] Calculate AP@50 and count the missed detection rate of small targets (≤32×32);
[0154] Compare the misjudgment rate of similar categories (such as Angelica sinensis vs Heracleum hemsleyanum);
[0155] Comparison Scheme Baseline: YOLOv11;
[0156] Verify the optimization effects of CAM, MSPP, and adaptive loss;
[0157] Table 1 Module Contribution Data
[0158]
[0159] Example 2: Second aspect, as Figure 6 shown, to achieve the above - mentioned purpose, the present invention discloses a Chinese herbal medicine recognition system based on YOLO - AMPMS, including:
[0160] A data processing module 11, configured to obtain multi - scene Chinese herbal medicine images, generate a Chinese herbal medicine dataset by processing the multi - scene Chinese herbal medicine images, and pre - process the Chinese herbal medicine dataset to obtain a pre - processed Chinese herbal medicine dataset, wherein the multi - scene includes: sunny noon scene, cloudy day scene, multi - angle aerial photography scene, and complex background scene;
[0161] A Chinese herbal medicine recognition module 12, configured to input the pre - processed Chinese herbal medicine dataset into a pre - established YOLO11 model and output a Chinese herbal medicine recognition result, wherein the Chinese herbal medicine recognition result includes the category, bounding box coordinates, and confidence level of the Chinese herbal medicine target, and the pre - established YOLO11 model is constructed by embedding a composite attention mechanism CAM in the backbone network and introducing a multi - scale prototype pool MSPP in the Neck network.
[0162] Based on the same inventive concept, the present invention further provides a computer device, which includes: one or more processors, and a memory for storing one or more computer programs; the program includes program instructions, and the processor is configured to execute the program instructions stored in the memory. The processor may be a Central Processing Unit (CPU), or may also be other general-purpose processors, Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field-Programmable Gate Arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. It is the computing core and control core of the terminal, and is used to implement one or more instructions. Specifically, it is used to load and execute one or more instructions in the computer storage medium to implement the above method.
[0163] It should be further noted that, based on the same inventive concept, the present invention further provides a computer storage medium, on which a computer program is stored, and the computer program, when run by a processor, executes the above method. The storage medium may adopt any combination of one or more computer-readable media. The computer-readable medium may be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electrical, magnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples (non-exhaustive list) of the computer-readable storage medium include: an electrical connection having one or more wires, a portable computer disk, a hard disk, a Random Access Memory (RAM), a Read Only Memory (ROM), an Erasable Programmable Read Only Memory (EPROM or flash memory), an optical fiber, a portable compact disk read only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, the computer-readable storage medium may be any tangible medium that contains or stores a program, and the program may be used by or in combination with an instruction execution system, apparatus, or device.
[0164] In the description of this specification, the descriptions referring to terms such as "one embodiment", "example", "specific example", etc. mean that the specific features, structures, materials, or characteristics described in connection with the embodiment or example are included in at least one embodiment or example of the present disclosure. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.
[0165] The above has shown and described the basic principles, main features and advantages of the present disclosure. Those skilled in the art should understand that the present disclosure is not limited by the above embodiments. What is described in the above embodiments and the specification only illustrates the principles of the present disclosure. Without departing from the spirit and scope of the present disclosure, the present disclosure will have various changes and improvements, and these changes and improvements all fall within the scope of the present disclosure claimed.< / height> < / width>
Claims
1. A Chinese herbal medicine recognition method based on YOLO-AMPMS, characterized in that, The method includes the following steps: Obtain multi-scenario Chinese herbal medicine images, generate a Chinese herbal medicine dataset by processing the multi-scenario Chinese herbal medicine images, and preprocess the Chinese herbal medicine dataset to obtain a preprocessed Chinese herbal medicine dataset. Among them, the multi-scenarios include: sunny noon scenario, cloudy day scenario, multi-angle aerial photography scenario, and complex background scenario; Input the preprocessed Chinese herbal medicine dataset into a pre-established YOLO11 model, and output a Chinese herbal medicine recognition result. Among them, the Chinese herbal medicine recognition result includes the category, bounding box coordinates, and confidence of the Chinese herbal medicine target. The pre-established YOLO11 model is constructed by embedding a composite attention mechanism CAM in the backbone network and introducing a multi-scale prototype pooling MSPP in the Neck network.
2. The Chinese herbal medicine recognition method based on YOLO-AMPMS according to claim 1, wherein, The process of generating a Chinese herbal medicine dataset by processing the multi-scenario Chinese herbal medicine images: After implementing enhancement strategies such as random rotation, brightness perturbation Gaussian noise, and random occlusion, a Chinese herbal medicine dataset is finally obtained.
3. A Chinese herbal medicine recognition method based on YOLO-AMPMS according to claim 1, characterized in that, The process of the composite attention mechanism CAM of the pre-established YOLO11 model includes: Channel attention branch, spatial attention branch, local-global attention branch, and dynamic fusion.
4. The Chinese herbal medicine recognition method based on YOLO-AMPMS according to claim 3, wherein, The process of the channel attention branch is as follows: Perform global average pooling (GAP) on the input feature map to obtain a channel description vector Generate channel weights through two fully connected layers The formula is as follows: w c = σ(w2 · δ(w1 · z)) Among them, is the weight of the fully connected layer, δ is the ReLU activation, δ(x) = max(0, x); σ is the Sigmoid function that maps the input to the interval (0, 1); The spatial attention branch is as follows: Perform max pooling and average pooling on the input features along the channel dimension, and generate spatial weights through convolution after concatenation The formula is as follows: w s = σ(Conv 7×7 ([MaxPool(F), AvgPool(F)])) The local-global attention branch is as follows: Depthwise separable convolution and dilated convolution are respectively used to extract local detail and global context features. After concatenation, 1×1 convolution is used to generate multi-scale weights The formula is as follows: w lg = σ(Conv 1×1 ([Conv 3×3 (F), Conv 5×5 (F)])) The dynamic fusion is as follows: The channel, spatial, and multi-scale weights are weighted and fused through learnable parameters α, β, γ. The formula is: Among them, α, β, γ are optimized by backpropagation.
5. The Chinese herbal medicine recognition method based on YOLO-AMPMS according to claim 4, wherein, The implementation process of the multi-scale prototype pooling MSPP of the pre-established YOLO11 model includes: Atrous spatial pyramid pooling ASPP For the input feature map Use 3×3 dilated convolution for parallel processing, set two dilation rates to extract multi-scale features, and obtain two sets of multi-scale feature maps Concatenate the two sets of features with the original input feature F to form a multi-scale feature tensor Perform feature fusion; Prototype library matching First, initialize the prototype library and pre-define K = 32 Chinese herbal medicine feature prototypes P = {p1, p2,..., p 32}, and for each prototype Cluster all local feature blocks in the training set through K-means clustering, and take the cluster center as the initial prototype; Subsequently, the feature-prototype similarity calculation is performed. For each spatial position (i, j) of the multi-scale F ASPP , the cosine similarity between its feature vector and all prototypes is calculated, and the matching formula is as follows: Among them, τ = 0.1 is the temperature coefficient, which controls the sharpness of the matching weight distribution; Finally, weight assignment is performed, and a 32-dimensional weight vector is generated for each position (i, j). It represents the matching degree between the feature at this position and each prototype; by weighted fusion of prototype features, the discriminative feature expression is enhanced: Prototype dynamic update Every 1000 training iterations, the prototype library is updated based on the features extracted by the current model. The formula is: Among them, feature blocks are sampled from the current training batch and re-partitioned into 32 classes using the K-means algorithm to obtain new cluster centers 6. The Chinese herbal medicine recognition method based on YOLO-AMPMS according to claim 1, characterized in that, The training process of the pre-established YOLO11 model is carried out by using an adaptive loss function to dynamically balance the classification, localization, and confidence loss weights.
7. The Chinese herbal medicine recognition method based on YOLO-AMPMS according to claim 6, wherein The formula of the adaptive loss function is as follows: L total = λ cls ·L cls + λ box ·L box + λ obj ·L obj where λ cls , λ box , λ obj are learnable parameters that are dynamically adjusted through backpropagation, L cls is the dynamic class weight classification loss, L box is the scale-sensitive localization loss, L obj is the Top-K hard sample confidence loss.
8. A Chinese herbal medicine recognition method based on YOLO-AMPMS according to claim 7, characterized in that, The dynamic class weight classification loss L cls has the following formula: Parameter description: N is the total number of categories in the dataset; is the category weight, N c is the number of samples of category c, ∈ = 1e-5 is a constant; y c is the true label; p c is the predicted probability, the category probability output by Softmax; γ is a hyperparameter; Scale-sensitive localization loss L box The formula is as follows: Parameter description: is the target localization weight, and area(gt i ) is the area of the i-th ground truth box; IoU i is the intersection over union; ρ i is the Euclidean distance between the center points of the predicted bounding box and the ground truth bounding box; d i is the length of the diagonal of the minimum bounding box; is the prediction result of the model for the target position and size; is the ground truth position and size of the target in the annotated data; is the aspect ratio difference term, is the term to measure the difference between the predicted bounding box and the ground truth bounding box in aspect ratio or width-to-height ratio, are the width and height of the i-th ground truth bounding box, are the width and height of the i-th predicted bounding box; The confidence loss \(L\) of the top-K difficult samples obj is as follows: Parameter description: K = 0.2×N is used to screen the top 20% of difficult samples, where N is the total number of samples; y k is the true confidence level; p k is the predicted confidence level.
9. A Chinese herbal medicine recognition system based on YOLO-AMPMS, characterized in that, Includes: A data processing module for obtaining multi-scenario Chinese herbal medicine images, generating a Chinese herbal medicine dataset by processing the multi-scenario Chinese herbal medicine images, and preprocessing the Chinese herbal medicine dataset to obtain a preprocessed Chinese herbal medicine dataset. Among them, the multi-scenarios include: sunny noon scenario, cloudy day scenario, multi-angle aerial photography scenario, and complex background scenario; A Chinese herbal medicine recognition module for inputting the preprocessed Chinese herbal medicine dataset into a pre-established YOLO11 model and outputting a Chinese herbal medicine recognition result. Among them, the Chinese herbal medicine recognition result includes the category, bounding box coordinates, and confidence of the Chinese herbal medicine target. The pre-established YOLO11 model is constructed by embedding a composite attention mechanism CAM in the backbone network and introducing a multi-scale prototype pooling MSPP in the Neck network.
10. A terminal device, comprising a memory, a processor, and a computer program stored in the memory and capable of running on the processor, characterized in that, The computer program capable of running on the processor is stored in the memory. When the processor loads and executes the computer program, a Chinese herbal medicine recognition method according to any one of claims 1 to 8 is adopted.