Condition grading method and device for traditional Chinese medicine decoction pieces and condition detection system
By using the target detection model trained by high-quality data sets, the quality evaluation of Chinese herbal medicines was solved, and the difficulty in building a phase scoring system for multiple varieties of Chinese herbal medicines in the existing technology was solved, and the effect of high accuracy and simplified construction process was achieved.
Patent Information
- Application Number
- CN202510101185.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-22
- Publication Date
- 2025-06-24
AI Technical Summary
The existing technology is difficult to effectively build a quality scoring system for multiple varieties of traditional Chinese herbal medicines, resulting in complex data processing and model construction.
A binary classification object detection model trained with high-quality data set is used to detect images of Chinese herbal medicines, extract confidence and divide grades through the quality evaluation mechanism, simplifying the construction process of the scoring system.
It significantly improves the accuracy and reliability of phase grading of traditional Chinese herbal medicines, simplifies the construction process of the scoring system, and is suitable for multiple varieties of traditional Chinese herbal medicines.
Smart Images

Figure CN120198705A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of traditional Chinese medicinal materials, and particularly to a method and device for grading the appearance quality of traditional Chinese medicine decoction pieces and an appearance quality detection system. Background Art
[0002] Traditional Chinese medicine decoction pieces refer to the medicinal materials that are processed from crude drugs and are suitable for decocting, boiling, or soaking. They are one of the basic dosage forms in traditional Chinese medicine treatment. There are a wide variety of traditional Chinese medicine decoction pieces, mainly including plant-based crude drugs, and also including a small amount of animal and mineral crude drugs. The active ingredients are mainly released through methods such as decocting, boiling, or soaking to help regulate the balance of yin and yang in the body and improve health conditions.
[0003] In traditional Chinese medicine treatment, factors such as the type, origin, processing technology, and year of the decoction pieces will affect their medicinal effects. Although the appearance quality can be used as a preliminary reference for the medicinal effect, the core of the medicinal effect depends on the content of active ingredients and their extraction methods. Since the production and processing of traditional Chinese medicine decoction pieces involve traditional handicrafts and complex multi-link processes, factors such as different production processes, the content of active ingredients in crude drugs, and storage conditions will affect the quality of the decoction pieces. Therefore, scientific and objective quality detection and evaluation of traditional Chinese medicine decoction pieces can, to a certain extent, reflect their medicinal effects by analyzing the appearance quality.
[0004] In the prior art, the appearance quality and quality of decoction pieces can be evaluated by combining quality scoring algorithms and multi-modal feature analysis (such as visual information, chemical composition analysis, mass spectrometry data, etc.). However, due to the wide variety of traditional Chinese medicine decoction pieces and the large differences in the active ingredients and quality characteristics of each type of decoction piece, the existing scoring standards are often not universal. Therefore, it is necessary to re-establish scoring standards for each type of decoction piece, resulting in the complexity of data processing and model construction. Accordingly, there is a problem in the prior art that it is difficult to establish an appearance quality scoring system for multi-variety traditional Chinese medicine decoction pieces. Summary of the Invention
[0005] Based on this, the purpose of the present invention is to provide a method for grading the appearance quality of traditional Chinese medicine decoction pieces.
[0006] A method for grading the appearance quality of traditional Chinese medicine decoction pieces includes the following steps:
[0007] S1. Obtain an image of traditional Chinese medicine decoction pieces with a monochromatic spectrum in an appearance quality detection box;
[0008] S2. Preprocess the image of traditional Chinese medicine decoction pieces with a monochromatic spectrum to obtain an image of traditional Chinese medicine decoction pieces with low interference;
[0009] S3. Use a high-quality appearance traditional Chinese medicine decoction piece model to detect the image of traditional Chinese medicine decoction pieces with low interference to obtain the decoction piece confidence level and prediction box of all traditional Chinese medicine decoction pieces; wherein, the high-quality appearance traditional Chinese medicine decoction piece model is an object detection model trained by binary classification using a high-quality appearance data set;
[0010] S4. Use a product appearance evaluation mechanism to analyze the confidence of the cut Chinese medicine, and obtain the grades of all current cut Chinese medicines.
[0011] For the product appearance grading method of the cut Chinese medicine described in the present invention, compared with the prior art, a binary classification object detection model trained with a high-quality appearance data set is used to extract the confidence of the current cut Chinese medicine related to the corresponding high-quality appearance characteristics, so as to effectively establish a product appearance scoring system matching the high-quality cut Chinese medicine, thereby effectively simplifying the construction process of the product appearance scoring system and significantly improving the accuracy and reliability of the product appearance grading of the cut Chinese medicine.
[0012] Furthermore, the high-quality cut Chinese medicine model includes a stacked residual feature extraction module, a feature fusion module, and a binary classification module;
[0013] The specific structure of the stacked residual feature extraction module is represented as follows:
[0014] Feature n = ResNet n (I Region )
[0015] In the formula, Feature n represents the cut Chinese medicine feature map of the nth layer obtained after passing through the nth layer of the stacked residual feature extraction module; ResNet n represents the stacked residual feature extraction operation n times. For the ResNet i (Feature i-1 ), its specific operation is represented as follows:
[0016] Feature i = Feature i-1 + ReLU(BN(Conv(Feature i-1 )))
[0017] In the formula, x represents the input feature map; Conv represents the convolution operation; BN represents batch normalization; ReLU represents the non-linear transformation, that is, the ReLU activation function, which is used to enhance the positive features; + is used to represent the residual connection;
[0018] The feature fusion module is used to fuse the cut Chinese medicine feature maps of several levels to obtain the fused cut Chinese medicine feature maps of several scales, and its specific representation is as follows:
[0019] fusion = FPN({Feature i | i ∈ [n - 4, n]})
[0020] Wherein, fusion represents the fused traditional Chinese medicine decoction pieces feature map at several scales, and FPN represents the Feature Pyramid Network, which is used to fuse the traditional Chinese medicine decoction pieces feature maps at different scales and output the fused traditional Chinese medicine decoction pieces feature maps at different scales;
[0021] The binary classification module is used to classify the fused traditional Chinese medicine decoction pieces feature map to obtain the decoction piece confidence and prediction box, which are specifically expressed as follows:
[0022] Confidence = sigmoid(FC(fusion))
[0023] Target = Regression(FC(fusion))
[0024] Wherein, Confidence represents the decoction piece confidence, and its range is [0, 1]; Target represents the coordinates of the prediction box of the position of the traditional Chinese medicine decoction piece; FC is used to represent the fully connected layer; sigmoid is the binary classification activation function; Regression represents the regression convolutional layer.
[0025] In the present invention, stacked residual modules are used to extract more detailed and representative high-quality features, which may include features closely related to high-quality standards such as the shape, color, and texture of the decoction pieces, so that the model can perform more accurate quality identification of traditional Chinese medicine decoction pieces. Especially when facing high-quality decoction pieces with small morphological changes, the residual module can help the model better capture subtle differences, significantly improving the reliability and accuracy of the evaluation.
[0026] Furthermore, the specific steps of the construction method of the high-quality dataset are expressed as follows:
[0027] D1. Use a quality inspection box to photograph traditional Chinese medicine decoction pieces to obtain images of a number of traditional Chinese medicine decoction pieces;
[0028] D2. Screen the quality of a number of traditional Chinese medicine decoction piece images respectively to obtain multiple groups of fully high-quality traditional Chinese medicine decoction piece images;
[0029] D3. Perform secondary screening on multiple groups of fully high-quality traditional Chinese medicine decoction piece images, screen out the high-quality traditional Chinese medicine decoction pieces in the intersection, and place them into the quality inspection box in batches and multiple times for photographing respectively to obtain multiple groups of high-quality traditional Chinese medicine decoction piece images;
[0030] D4. Label and perform data augmentation on the high-quality traditional Chinese medicine decoction piece images in sequence to obtain a high-quality dataset;
[0031] After obtaining the high-quality dataset, the high-quality traditional Chinese medicine decoction piece model is trained in the following manner, and the specific training steps are expressed as follows:
[0032] TA1: Input a high-quality dataset into an autoencoder for training, calculate the reconstruction error between the output of the autoencoder and the input traditional Chinese medicine decoction piece image, and obtain the reconstruction loss value. Among them, the autoencoder includes an encoder and a decoder.
[0033] TA2: Determine whether the current reconstruction loss value is lower than a reconstruction threshold. If not, use an optimizer to optimize the weights of the autoencoder according to the reconstruction loss value to obtain the current autoencoder, and execute step TA1. If so, complete the training of the current autoencoder to obtain the trained autoencoder.
[0034] TA3: Freeze the weights of the encoder in the autoencoder to obtain the frozen encoder.
[0035] TA4: Input the high-quality dataset into the frozen encoder for feature extraction to obtain the feature representation in the latent space.
[0036] TA5: Input the feature representation in the latent space into the high-quality traditional Chinese medicine decoction piece model for object detection to obtain the decoction piece confidence and prediction box.
[0037] TA6: Use cross-entropy loss and mean squared error to calculate the loss between the current decoction piece confidence and prediction box and the actual label to obtain the classification loss value and regression loss value.
[0038] TA7: Determine whether the current classification loss value and regression loss value are both lower than a classification threshold and a regression threshold. If not, use an optimizer to perform gradient update on the current high-quality traditional Chinese medicine decoction piece model according to the classification loss, and execute step TA4. If so, complete the training of the current high-quality traditional Chinese medicine decoction piece model to obtain the trained high-quality traditional Chinese medicine decoction piece model.
[0039] Through multiple quality screenings, the present invention ensures that the traditional Chinese medicine decoction piece images in the high-quality dataset have the representativeness of high quality, guarantees the purity and quality of the training dataset, and prevents images that do not meet the high-quality standards from participating in the training.
[0040] At the same time, after the dataset is constructed, the high-quality feature representation in the latent space is extracted through the autoencoder to remove redundant or irrelevant information, ensuring that the high-quality traditional Chinese medicine decoction piece model focuses on the core features of high-quality decoction pieces during the training process, avoiding the model overly relying on label information and ignoring the detailed features in the image, especially when there is only training data of a single type of traditional Chinese medicine decoction piece in the current high-quality dataset. Moreover, the low-dimensional representation of the latent space features provides more accurate and high-quality information for the model, enabling the model to better identify and focus on the key information in the decoction piece image, such as color, shape and other features, thereby improving the classification accuracy and robustness of the high-quality traditional Chinese medicine decoction piece model for high quality.
[0041] Further, the specific calculation of the product quality evaluation mechanism is as follows:
[0042]
[0043] In the formula, grade i represents the grade of the current i-th traditional Chinese medicine cut piece. Its grades include first grade, second grade, third grade, and fourth grade. The first grade indicates that the characteristics of the current traditional Chinese medicine cut piece are closest to the high-quality product data set; the second grade indicates that there are certain morphological changes in the characteristics of the current traditional Chinese medicine cut piece; the third grade indicates that there are obvious deformities or morphological defects in the current traditional Chinese medicine cut piece; the fourth grade indicates that the current traditional Chinese medicine cut piece has obvious color abnormalities; z1, z2, and z3 are confidence boundaries respectively, used to divide the grades of traditional Chinese medicine cut pieces.
[0044] Accordingly, the present invention divides the cut pieces into different grades based on the confidence of the high-quality traditional Chinese medicine cut piece model. The first grade indicates the closest characteristics to the high-quality product data set, and the fourth grade indicates obvious appearance abnormalities or other quality problems, thus quickly establishing a simple and clear product quality scoring system, effectively solving the problem of difficult establishment of the product quality scoring system for traditional Chinese medicine cut pieces.
[0045] Further, the specific calculation of the product quality evaluation mechanism is as follows:
[0046]
[0047] In the formula, grade i represents the grade of the current i-th traditional Chinese medicine cut piece. Its grades include first grade, second grade, third grade, and fourth grade. The first grade indicates that the characteristics of the current traditional Chinese medicine cut piece are closest to the high-quality product data set; the second grade indicates that there are certain morphological changes in the characteristics of the current traditional Chinese medicine cut piece; the third grade indicates that there are obvious deformities or morphological defects in the current traditional Chinese medicine cut piece; the fourth grade indicates that the current traditional Chinese medicine cut piece has obvious color abnormalities; the abnormality indicates that the current traditional Chinese medicine cut piece has an abnormality, and at the same time, a warning label is given to the current traditional Chinese medicine cut piece; z1, z2, z3, and z4 are confidence boundaries respectively, used to divide the grades of traditional Chinese medicine cut pieces;
[0048] Score i represents the comprehensive score of the current i-th traditional Chinese medicine cut piece, and its specific calculation is as follows:
[0049]
[0050] In the formula, Confidence i represents the cut piece confidence of the i-th traditional Chinese medicine cut piece; w confidence represents the weight coefficient corresponding to the cut piece confidence, and its specific calculation is:
[0051]
[0052] is the weight difference score of the current i-th traditional Chinese medicine cut piece, and its specific calculation is as follows:
[0053]
[0054] In the formula, Weight i represents the estimated weight of the current i-th traditional Chinese medicine cut piece, and its specific calculation is as follows:
[0055]
[0056] In the formula, Weight total represents the total weight of the traditional Chinese medicine cut pieces in the current batch; Area total is the total area of the traditional Chinese medicine cut pieces in the current batch, and its specific calculation is: where n represents the total number of traditional Chinese medicine cut pieces in the current batch, and Area i represents the area of the current i-th traditional Chinese medicine cut piece;
[0057] Weight expected,i represents the expected weight of the i-th traditional Chinese medicine cut piece in the current batch, and its specific calculation is as follows:
[0058] Weight expected,i = Area i × h avg × ρ avg
[0059] In the formula, h avg represents the preset average thickness of the current variety of traditional Chinese medicine cut piece; ρ avg represents the preset average density of the current variety of traditional Chinese medicine cut piece;
[0060] w weight represents the weight coefficient of the weight difference score of the traditional Chinese medicine cut piece, and its specific calculation is as follows:
[0061]
[0062] In the formula, Weight expected,min , Weight expected,max are respectively the minimum expected weight and the maximum expected weight of the traditional Chinese medicine cut pieces in the current batch, and their specific calculation is:
[0063] Weight expected,min = Area i × h avg × ρ min
[0064] Weightexpected,max = Area i × h avg × ρ max
[0065] where ρ min and ρ max represent the preset minimum density and maximum density of the current variety of traditional Chinese medicine decoction pieces.
[0066] The present invention also combines the confidence of traditional Chinese medicine decoction pieces with the weight dimension to conduct a more comprehensive evaluation of the product quality, so as to effectively identify and consider potential problems of adulteration or heavy losses of traditional Chinese medicine decoction pieces; among them, on the basis of the confidence, that is, the matching degree between the current traditional Chinese medicine decoction pieces and the high-quality product dataset, the present invention combines the weight difference score to consider the deviation between the actual weight and the expected weight of the traditional Chinese medicine decoction pieces, so as to help identify quality abnormalities caused by adulteration or heavy losses, and further effectively eliminate scoring errors caused by adulteration or heavy losses, and further improve the accuracy and reliability of the product quality evaluation.
[0067] A device for grading the product quality of traditional Chinese medicine decoction pieces includes a monochromatic spectral image acquisition unit, a monochromatic spectral preprocessing unit, a traditional Chinese medicine decoction piece classification unit, and a product quality grading unit for traditional Chinese medicine decoction pieces;
[0068] The monochromatic spectral image acquisition unit is used to acquire an image of traditional Chinese medicine decoction pieces with monochromatic spectrum in the product quality detection box;
[0069] The monochromatic spectral preprocessing unit is used to preprocess the image of traditional Chinese medicine decoction pieces with monochromatic spectrum to obtain an image of traditional Chinese medicine decoction pieces with low interference;
[0070] The traditional Chinese medicine decoction piece classification unit is used to detect the image of traditional Chinese medicine decoction pieces with low interference by using a high-quality traditional Chinese medicine decoction piece model to obtain the decoction piece confidence and prediction frame of all traditional Chinese medicine decoction pieces; among them, the high-quality traditional Chinese medicine decoction piece model is an object detection model trained by binary classification using a high-quality product dataset;
[0071] The product quality grading unit for traditional Chinese medicine decoction pieces is used to analyze the decoction piece confidence by using a product quality evaluation mechanism to obtain the grades of all current traditional Chinese medicine decoction pieces.
[0072] Furthermore, the high-quality traditional Chinese medicine decoction piece model includes a stacked residual feature extraction module, a feature fusion module, and a binary classification module;
[0073] The specific structure of the stacked residual feature extraction module is represented as follows:
[0074] Feature n = ResNet n (I Region )
[0075] In the formula, Feature n represents the Chinese herbal medicine slice feature map of the nth layer obtained after passing through the residual feature extraction module of the nth layer of stacking; ResNet n represents the residual feature extraction operation stacked n times. For the ResNet of the i-th layer i (Feature i-1 ), its specific operation is as follows:
[0076] Feature i = Feature i-1 + ReLU(BN(Conv(Feature i-1 )))
[0077] In the formula, x represents the input feature map; Conv represents the convolution operation; BN represents batch normalization; ReLU represents the non-linear transformation, that is, the ReLU activation function, which is used to enhance the positive features; + is used to represent the residual connection;
[0078] The feature fusion module is used to fuse the Chinese herbal medicine slice feature maps of several levels to obtain the fused Chinese herbal medicine slice feature maps of several scales, and its specific representation is as follows:
[0079] fusion = FPN({Feature i | i ∈ [n - 4, n]})
[0080] In the formula, fusion represents the fused Chinese herbal medicine slice feature maps of several scales, FPN represents the feature pyramid network, which is used to fuse the Chinese herbal medicine slice feature maps of different scales and output the fused Chinese herbal medicine slice feature maps of different scales;
[0081] The binary classification module is used to classify the fused Chinese herbal medicine slice feature maps to obtain the slice confidence and the prediction box, and its specific representation is as follows:
[0082] Confidence = sigmoid(FC(fusion))
[0083] Target = Regression(FC(fusion))
[0084] In the formula, Confidence represents the slice confidence, and its range is [0, 1]; Target represents the coordinates of the prediction box of the position of the Chinese herbal medicine slice; FC is used to represent the fully connected layer; sigmoid is the binary classification activation function; Regression represents the regression convolution layer.
[0085] Furthermore, the specific steps of the construction method of the high-quality product dataset are as follows:
[0086] D1. Use a product quality inspection box to take pictures of traditional Chinese medicine decoction pieces, and obtain images of a number of traditional Chinese medicine decoction pieces;
[0087] D2. Screen the images of a number of traditional Chinese medicine decoction pieces respectively to obtain multiple groups of images of traditional Chinese medicine decoction pieces with full-height product quality;
[0088] D3. Conduct a secondary screening on multiple groups of images of traditional Chinese medicine decoction pieces with full-height product quality, screen out the traditional Chinese medicine decoction pieces with high product quality in the intersection, and place them into the product quality inspection box in batches and multiple times respectively for taking pictures to obtain multiple groups of images of traditional Chinese medicine decoction pieces with high product quality;
[0089] D4. Label and perform data augmentation on the images of traditional Chinese medicine decoction pieces with high product quality in sequence to obtain a high-quality product dataset;
[0090] After obtaining the high-quality product dataset, train the high-quality traditional Chinese medicine decoction piece model through the following method. The specific training steps are as follows:
[0091] TA1: Input the high-quality product dataset into an autoencoder for training, and calculate the reconstruction error between the output of the autoencoder and the input image of the traditional Chinese medicine decoction piece to obtain a reconstruction loss value; wherein, the autoencoder includes an encoder and a decoder;
[0092] TA2: Judge whether the current reconstruction loss value is lower than a reconstruction threshold: if not, use an optimizer to optimize the weights of the autoencoder according to the reconstruction loss value to obtain the current autoencoder, and execute step TA1; if so, complete the training of the current autoencoder to obtain a trained autoencoder;
[0093] TA3: Freeze the weights of the encoder in the autoencoder to obtain a frozen encoder;
[0094] TA4: Input the high-quality product dataset into the frozen encoder for feature extraction to obtain a feature representation in the latent space;
[0095] TA5: Input the feature representation in the latent space into the high-quality traditional Chinese medicine decoction piece model for object detection to obtain the piece confidence and prediction box;
[0096] TA6: Calculate the loss between the current piece confidence and prediction box and the actual label using cross-entropy loss and mean squared error to obtain a classification loss value and a regression loss value;
[0097] TA7: Judge whether the current classification loss value and regression loss value are both lower than a classification threshold and a regression threshold: if not, use an optimizer to perform gradient update on the current high-quality traditional Chinese medicine decoction piece model according to the classification loss, and execute step TA4; if so, complete the training of the current high-quality traditional Chinese medicine decoction piece model to obtain a trained high-quality traditional Chinese medicine decoction piece model.
[0098] Furthermore, the specific calculation of the product quality evaluation mechanism is as follows:
[0099]
[0100] In the formula, grade i represents the grade of the current i-th traditional Chinese medicine cut piece. Its grades include first grade, second grade, third grade, and fourth grade. The first grade indicates that the characteristics of the current traditional Chinese medicine cut piece are closest to the high-quality product dataset; the second grade indicates that there are certain morphological changes in the characteristics of the current traditional Chinese medicine cut piece; the third grade indicates that there are obvious deformities or morphological defects in the current traditional Chinese medicine cut piece; the fourth grade indicates that there are obvious color abnormalities in the current traditional Chinese medicine cut piece; the abnormality indicates that there is an abnormality in the current traditional Chinese medicine cut piece, and at the same time, a warning label is given to the current traditional Chinese medicine cut piece; z1, z2, z3, and z4 are confidence boundaries respectively, used to divide the grades of traditional Chinese medicine cut pieces;
[0101] Score i represents the comprehensive score of the current i-th traditional Chinese medicine cut piece, and its specific calculation is as follows:
[0102]
[0103] In the formula, Confidence i represents the cut piece confidence of the i-th traditional Chinese medicine cut piece; w confidence represents the weight coefficient corresponding to the cut piece confidence, and its specific calculation is:
[0104]
[0105] is the weight difference score of the current i-th traditional Chinese medicine cut piece, and its specific calculation is as follows:
[0106]
[0107] In the formula, Weight i represents the estimated weight of the current i-th traditional Chinese medicine cut piece, and its specific calculation is as follows:
[0108]
[0109] In the formula, Weight total represents the total weight of the traditional Chinese medicine cut pieces in the current batch; Area total is the total area of the traditional Chinese medicine cut pieces in the current batch, and its specific calculation is: where n represents the total number of traditional Chinese medicine cut pieces in the current batch, and Area i represents the area of the current i-th traditional Chinese medicine cut piece;
[0110] Weightexpected,i Indicates the expected weight of the i-th traditional Chinese medicine cut piece in the current batch, and its specific calculation is as follows:
[0111] Weight expected,i = Area i × h avg × ρ avg
[0112] In the formula, h avg indicates the preset average thickness of the current variety of traditional Chinese medicine cut pieces; ρ avg indicates the preset average density of the current variety of traditional Chinese medicine cut pieces;
[0113] w weight represents the weight coefficient of the weight difference score of the traditional Chinese medicine cut piece, and its specific calculation is as follows:
[0114]
[0115] In the formula, Weight expected,min , Weight expected,max are respectively the minimum expected weight and the maximum expected weight of the traditional Chinese medicine cut pieces in the current batch, and their specific calculations are as follows:
[0116] Weight expected,min = Area i × h avg × ρ min
[0117] Weight expected,max = Area i × h avg × ρ max
[0118] Among them, ρ min and ρ max represent the preset minimum density and the preset maximum density of the current variety of traditional Chinese medicine cut pieces.
[0119] A appearance detection system for traditional Chinese medicine cut pieces, comprising an appearance detection box, a traditional Chinese medicine cut piece variety identification device, and a traditional Chinese medicine cut piece appearance grading device;
[0120] The appearance detection box is a closed box body, and is provided with a light source of monochromatic spectrum, a camera device and a weighing instrument;
[0121] Among them, the light source of monochromatic spectrum is used to illuminate the traditional Chinese medicine cut pieces in the box body;
[0122] The camera device is used to photograph the traditional Chinese medicine cut pieces in the box body, and input the photographed monochromatic spectrum traditional Chinese medicine cut piece image into the traditional Chinese medicine cut piece variety identification device;
[0123] The weighing instrument is used to measure the weight of the traditional Chinese medicine pieces in the box and send the weight of the current traditional Chinese medicine pieces to the product quality grading device of the traditional Chinese medicine pieces;
[0124] The variety identification device of the traditional Chinese medicine pieces is used to identify the variety of the input monochromatic spectrum image of the traditional Chinese medicine pieces and input the monochromatic spectrum image of the traditional Chinese medicine pieces and the corresponding variety identification result into the product quality grading device of the traditional Chinese medicine pieces; wherein, the variety identification result is used to enable the product quality grading device of the traditional Chinese medicine pieces to adjust the parameters of the corresponding variety;
[0125] The product quality grading device of the traditional Chinese medicine pieces is used to grade the product quality of the input monochromatic spectrum image of the traditional Chinese medicine pieces to obtain the grades of all the current traditional Chinese medicine pieces;
[0126] Among them, the product quality grading device of the traditional Chinese medicine pieces is the product quality grading device of the traditional Chinese medicine pieces described above.
[0127] For better understanding and implementation, the present invention will be described in detail below with reference to the accompanying drawings. Brief Description of the Drawings
[0128] Figure 1 It is a schematic diagram of the simple structure of the product quality grading device of the traditional Chinese medicine pieces described in the present invention;
[0129] Figure 2 It is a schematic diagram of the simple process of the product quality grading method of the traditional Chinese medicine pieces described in the present invention. Detailed Embodiment
[0130] In order to solve the problem that it is difficult to build a product quality scoring system for multi-variety traditional Chinese medicine pieces in the prior art, the present invention places the traditional Chinese medicine pieces in a product quality detection box, takes pictures of the traditional Chinese medicine pieces to obtain a monochromatic spectrum image of the traditional Chinese medicine pieces; and preprocesses the monochromatic spectrum image of the traditional Chinese medicine pieces to filter out the monochromatic spectrum, so as to obtain a low-interference image of the traditional Chinese medicine pieces, and inputs it into a high-quality traditional Chinese medicine piece model for classification to obtain the confidence level of the pieces; finally, a product quality evaluation mechanism is used to analyze the confidence level of the pieces to obtain the grade of the current traditional Chinese medicine pieces. Accordingly, the present invention uses the full-high-quality decision boundary in the high-quality traditional Chinese medicine piece model to identify the confidence level of the pieces and adjusts it in combination with the product quality evaluation mechanism, significantly reducing the dependence on a large amount of analysis and evaluation by professionals, thus simplifying the construction process of the product quality scoring system, significantly reducing the difficulty of building the product quality scoring system, and further realizing the standardization of the product quality evaluation of traditional Chinese medicine pieces.
[0131] Based on the above design, the present invention proposes a product quality grading method for traditional Chinese medicine pieces and a product quality grading device for traditional Chinese medicine pieces based on this method.
[0132] Please also refer toFigure 1 and Figure 2 , Figure 1 is a schematic diagram of the simple structure of the product appearance grading device for the traditional Chinese medicine decoction pieces described in the present invention, Figure 2 is a schematic diagram of the simple process of the product appearance grading method for the traditional Chinese medicine decoction pieces described in the present invention.
[0133] The product appearance grading device for the traditional Chinese medicine decoction pieces includes a monochromatic spectral image acquisition unit 1, a monochromatic spectral preprocessing unit 2, a traditional Chinese medicine decoction piece classification unit 3, and a product appearance grading unit 4 for the traditional Chinese medicine decoction pieces.
[0134] The monochromatic spectral image acquisition unit 1 is used to execute step S1: acquire the image of the traditional Chinese medicine decoction pieces with monochromatic spectrum in the product appearance detection box.
[0135] Among them, the variety of the current traditional Chinese medicine decoction piece is identified by manual or a classification neural network model. Since the classification neural network is common knowledge in the art, such as a convolutional classification neural network, and it is not the innovation of the present invention, the present invention does not specifically limit the technical means for identifying the variety of the current traditional Chinese medicine decoction piece;
[0136] The product appearance detection box is a closed box body, and is provided with a light source of monochromatic spectrum, a camera device, and a weighing instrument. The light source of monochromatic spectrum is used to illuminate the traditional Chinese medicine decoction pieces in the box body to ensure that the camera device can clearly capture the texture features of the traditional Chinese medicine decoction pieces;
[0137] The camera device is used to photograph the traditional Chinese medicine decoction pieces in the box body and input the photographed image of the traditional Chinese medicine decoction pieces with monochromatic spectrum into the monochromatic spectral image acquisition unit 1; further, the camera device can adopt a spectral camera to replenish spectral information of different wavelengths, so as to perform a more accurate analysis on the subtle differences in the appearance of the traditional Chinese medicine decoction pieces.
[0138] The weighing instrument is used to measure the weight of the traditional Chinese medicine decoction pieces in the box body and send the weight of the current traditional Chinese medicine decoction piece to the product appearance grading device for the traditional Chinese medicine decoction pieces described in the present invention.
[0139] It should be noted that, in order to ensure high-precision and low-noise of the photographed image, the camera device of the present invention adopts an industrial-grade camera to ensure minimizing the interference of noise. However, due to different budgets, camera devices with different performances can be adopted, so the present invention does not specifically limit the selection of its camera device here.
[0140] The monochromatic spectral preprocessing unit 2 is used to execute step S2: preprocess the image of the traditional Chinese medicine decoction pieces with monochromatic spectrum to obtain an image of the traditional Chinese medicine decoction pieces with low interference.
[0141] Specifically, the preprocessing includes illumination normalization and region of interest (ROI) processing. The illumination normalization is performed by locally normalizing the mean value of a monochromatic spectral image of traditional Chinese medicine decoction pieces to obtain a monochromatic spectral image of traditional Chinese medicine decoction pieces after illumination normalization, which is used to eliminate the influence caused by slight illumination non-uniformity. The specific calculation is as follows:
[0142]
[0143] In the formula, I norm (x, y) represents the monochromatic spectral image of traditional Chinese medicine decoction pieces after illumination normalization, where x and y are used to represent the pixel coordinates corresponding to the image; I(x, y) represents the monochromatic spectral image of traditional Chinese medicine decoction pieces, that is, the original image; L(x, y) represents the local mean value of the monochromatic spectral image of traditional Chinese medicine decoction pieces, and its specific calculation is as follows:
[0144]
[0145] In the formula, is the neighborhood of the pixel (x, y), with a default radius of 3 pixel units, and N represents the number of pixels in the neighborhood; accordingly, illumination normalization is used to eliminate the interference of potential illumination non-uniformity on texture features, thereby ensuring that texture details are clearly visible.
[0146] The ROI processing is performed by binary cropping on the monochromatic spectral image of traditional Chinese medicine decoction pieces after illumination normalization to obtain an image of traditional Chinese medicine decoction pieces with low interference, which is used to avoid edge interference and background interference of the input image on the model. The specific calculation is as follows:
[0147] I Region = I norm × I binary
[0148] In the formula, I Region represents the image of traditional Chinese medicine decoction pieces with low interference, and I binary represents the binary image, which is used to multiply with I norm to extract the region of interest belonging to the traditional Chinese medicine decoction pieces. The specific calculation is as follows:
[0149]
[0150] In the formula, Th is the preset pixel value threshold, which is used to determine the region corresponding to the traditional Chinese medicine decoction pieces. The threshold is selected and optimized according to the color pixel data or image analysis method corresponding to different types of traditional Chinese medicine decoction pieces, and is not specifically limited in the present invention.
[0151] Accordingly, while preserving the illumination uniformity and texture details, binary cropping is utilized to automatically extract the region of interest of traditional Chinese medicine decoction pieces, thereby effectively removing the background interference and edge noise in the image, and further ensuring the stability of subsequent image analysis.
[0152] The traditional Chinese medicine decoction piece classification unit 3 is used to execute step S3: detecting the traditional Chinese medicine decoction piece image with low interference by using a high-quality traditional Chinese medicine decoction piece model, and obtaining the decoction piece confidence and prediction box of all traditional Chinese medicine decoction pieces.
[0153] Specifically, the high-quality traditional Chinese medicine decoction piece model is an object detection model trained by binary classification using a high-quality data set, which specifically includes a stacked residual feature extraction module, a feature fusion module and a binary classification module. The stacked residual feature extraction module is used to perform multi-level feature extraction on the input low-interference traditional Chinese medicine decoction pieces to obtain several layers of traditional Chinese medicine decoction piece feature maps. The specific structure of its residual feature extraction module is represented as follows:
[0154] Feature n =ResNet n (I Region )
[0155] In the formula, Feature n represents the nth layer of traditional Chinese medicine decoction piece feature map obtained after passing through the nth layer of stacked residual feature extraction module; ResNet n represents the stacked residual feature extraction operation n times. For the ith layer of ResNet i (Feature i-1 ), its specific operation is represented as follows:
[0156] Feature i =Feature i-1 +ReLU(BN(Conv(Feature i-1 )))
[0157] In the formula, x represents the input feature map; Conv represents the convolution operation; BN represents batch normalization; ReLU represents the non-linear transformation, that is, the ReLU activation function, which is used to enhance the positive features; + is used to represent the residual connection, which is used to directly add the input feature map to the output feature map after the feature extraction operation, so as to avoid the disappearance of gradients caused by information loss.
[0158] The feature fusion module is used to perform feature fusion on several levels of traditional Chinese medicine decoction piece feature maps to obtain several scales of fused traditional Chinese medicine decoction piece feature maps, and its specific representation is as follows:
[0159] fusion=FPN({Feature i | i∈[n - 4, n]})
[0160] In the formula, fusion represents the fused traditional Chinese medicine decoction pieces feature map of several scales, and FPN represents the Feature Pyramid Networks, which is used to fuse the traditional Chinese medicine decoction pieces feature maps of different scales and output the fused traditional Chinese medicine decoction pieces feature maps of different scales.
[0161] The binary classification module is used to classify the fused traditional Chinese medicine decoction pieces feature map to obtain the decoction piece confidence and prediction box, and its specific representation is as follows:
[0162] Confidence = sigmoid(FC(fusion))
[0163] Target = Regression(FC(fusion))
[0164] In the formula, Confidence represents the decoction piece confidence, and its range is [0, 1]; Target represents the coordinates of the prediction box of the position of the traditional Chinese medicine decoction piece; FC is used to represent the Full Connected Layer, which is used to map the input feature map to a single output value; sigmoid is a binary classification activation function, which is used to compress the output value of the full connected layer to a probability value in the interval [0, 1], and is used to represent the probability that the input feature belongs to a high-quality product; Regression represents the regression convolutional layer, which is used to calculate the offset of the input feature map and combine the offset with the default box coordinates to obtain the prediction box coordinates corresponding to the current feature.
[0165] Among them, in order to further improve the positioning accuracy, the currently stacked residual feature extraction module, feature fusion module and the target detection model of the YOLO (You Only Look Once) series can be combined. The residual feature extraction module extracts the features of the traditional Chinese medicine decoction pieces, and the feature fusion module performs multi-scale fusion. Finally, the multi-scale classification and regression tasks are performed through the head network of the YOLO series target detection model to ensure that the target positioning and classification can be completed in a single forward propagation of the traditional Chinese medicine decoction pieces. However, considering that different versions of the YOLO model have differences in accuracy and speed, the present invention does not specifically limit the selection of the combined target detection model here.
[0166] Furthermore, the specific steps of the construction method of the high-quality product dataset for any kind of traditional Chinese medicine decoction piece are represented as follows:
[0167] D1. Use a product detection box to photograph the traditional Chinese medicine decoction pieces to obtain images of several traditional Chinese medicine decoction pieces.
[0168] Among them, by obtaining images in the appearance detection box, the consistency of the image acquisition environment in the training stage and the deployment stage can be ensured, so that the difference between the training data and the actual application environment is minimized, and further the environmental interference caused by changes in external factors such as light and background noise is effectively reduced, ensuring that the model can operate efficiently in the real environment and maintain a high prediction accuracy.
[0169] D2. Provide the images of several Chinese herbal medicine pieces to several third-party appraisal agencies respectively for appearance screening, and obtain multiple groups of images of Chinese herbal medicine pieces with full-height perfect appearance.
[0170] Among them, by providing the images of several Chinese herbal medicine pieces to multiple third-party appraisal agencies respectively for appearance screening, the diversity and objectivity of the annotation results can be ensured, thus avoiding possible biases or inconsistencies of a single agency, and ensuring that the images of Chinese herbal medicine pieces with high perfect appearance in the dataset are more representative and reliable; therefore, through the cross-validation of the appraisal results of multiple agencies, it helps to improve the accuracy and authority of data annotation, and further improve the quality of training data.
[0171] D3. Conduct secondary screening on multiple groups of images of Chinese herbal medicine pieces with full-height perfect appearance, screen out the Chinese herbal medicine pieces with high perfect appearance in the intersection, and place them into the appearance detection box in batches and multiple times for shooting respectively to obtain multiple groups of images of Chinese herbal medicine pieces with high perfect appearance.
[0172] Since there may be some slight differences in the appraisal results when multiple third-party agencies conduct appearance evaluation on the images of Chinese herbal medicine pieces, therefore, by secondary screening the Chinese herbal medicine pieces in the intersection, it is ensured that all the selected Chinese herbal medicine pieces are "Chinese herbal medicine pieces with high perfect appearance" unanimously recognized by all agencies, thus effectively eliminating the noise brought by subjective differences and inconsistent annotations, and ensuring the unity of the appearance determination of training data.
[0173] D4. Conduct annotation and data augmentation on the images of Chinese herbal medicine pieces with high perfect appearance in sequence to obtain a high-perfect-appearance dataset.
[0174] Among them, the annotation is used to frame the Chinese herbal medicine pieces in the image of the Chinese herbal medicine piece and set the corresponding label of high perfect appearance, so that there is a corresponding target box and a corresponding high-perfect-appearance label for all Chinese herbal medicine pieces; the data augmentation includes rotation, scaling, mirroring or translation, etc. Through data augmentation, the high-perfect-appearance dataset can cover a certain variety of images, thereby improving the stability of its model in actual application.
[0175] Furthermore, after obtaining the high-perfect-appearance dataset, the high-perfect-appearance Chinese herbal medicine piece model is trained in the following way, and the specific training steps are as follows:
[0176] TA1: Input a high-quality dataset into an autoencoder for training, calculate the reconstruction error between the output of the autoencoder and the input traditional Chinese medicine decoction piece image, and obtain the reconstruction loss value.
[0177] Among them, the autoencoder includes an encoder and a decoder. The encoder compresses the input image into low-dimensional features through a series of stacked convolutional layers and pooling layers, so as to refine the feature information of the image and retain the most critical feature information. The decoder restores the low-dimensional features of the encoder to an image as consistent as possible with the original image through stacked transposed convolutions and upsampling. The specific form of the autoencoder is as follows:
[0178]
[0179] In the formula, X represents the input image; represents the reconstructed image.
[0180] Accordingly, through the training of the autoencoder, the encoder learns how to extract the most representative features from the original image. In addition, the reconstruction error can be optionally the combined reconstruction loss of the Structure Similarity Index Measure (SSIM) and the perceptual error (VGG feature loss), which is used to ensure that the local features learned by the model can restore details as consistent as possible with the original image.
[0181] TA2: Judge whether the current reconstruction loss value is lower than a reconstruction threshold. If not, use an optimizer to optimize the weights of the autoencoder according to the reconstruction loss value to obtain the current autoencoder, and execute step TA1. If so, complete the training of the current autoencoder to obtain the trained autoencoder.
[0182] Accordingly, by setting the reconstruction threshold to evaluate the learning effect of the autoencoder. If the reconstruction error is higher than this reconstruction threshold, it indicates that the autoencoder fails to effectively learn the key information of the image. The optimizer will perform backpropagation on the weights of the autoencoder according to the reconstruction loss to update the weights and continue training. If the reconstruction error is lower than this reconstruction threshold, it is considered that the autoencoder has sufficiently learned the core features of the image and can reconstruct the image more accurately, then the training can be stopped, so that the autoencoder can effectively extract and retain the key features of high-quality traditional Chinese medicine decoction piece images.
[0183] TA3: Freeze the weights of the encoder in the autoencoder to obtain a frozen encoder.
[0184] Specifically, freeze the weights of the encoder in the autoencoder to ensure that during the subsequent training process of the high-quality Chinese herbal medicine slice model, the weights of the encoder will not be adjusted, thereby avoiding disrupting the learned image features during the feature extraction stage. At the same time, ensure that when performing classification tasks and regression tasks, the model only adjusts the weights in the high-quality Chinese herbal medicine slice model, thus focusing on the optimization of high-quality classification tasks and regression tasks.
[0185] TA4: Input the high-quality dataset into the frozen encoder for feature extraction to obtain the feature representation in the latent space.
[0186] Specifically, the frozen encoder performs feature extraction by combining a Dropout layer, which is used to randomly discard the activations of some neurons to reduce the dependence during the feature extraction process, thereby ensuring that the features extracted by the encoder are not limited to specific patterns and can better adapt to different inputs. As a result, the high-quality Chinese herbal medicine slice model can more accurately capture the potential high-quality features of the image, reduce the situation of false positive cases, and provide a more reliable feature representation for the high-quality Chinese herbal medicine slice model.
[0187] TA5: Input the feature representation in the latent space into the high-quality Chinese herbal medicine slice model for object detection to obtain the slice confidence and prediction box.
[0188] Since the feature representation in the latent space has better expressive power, it can extract the key information in the original image and remove redundant or irrelevant information. Therefore, inputting these low-dimensional features into the high-quality Chinese herbal medicine slice model can enable the model to better identify and focus on the core features in the image during the classification process, avoiding the interference of background noise or irrelevant information in the original image on the classification result, thereby improving the accuracy and robustness of the high-quality Chinese herbal medicine slice model classification.
[0189] TA6: Calculate the loss between the current slice confidence and prediction box and the actual label using cross-entropy loss (CE) and mean squared error (MSE) to obtain the classification loss value and regression loss value.
[0190] TA7: Determine whether the current classification loss value and regression loss value are both lower than a classification threshold and a regression threshold. If not, use the optimizer to perform gradient update on the current high-quality Chinese herbal medicine slice model according to the classification loss and execute step TA4. If so, complete the training of the current high-quality Chinese herbal medicine slice model to obtain the trained high-quality Chinese herbal medicine slice model.
[0191] Since the training dataset of the present invention only contains images of high-quality traditional Chinese medicine decoction pieces, the model may tend to directly predict as "high quality" to obtain a lower loss value, resulting in the model relying too much on labels during training and ignoring the extraction of different detailed features in high-quality decoction pieces;
[0192] Therefore, by refining the difference degree of cross-entropy loss instead of simple binaryization, while the model learns the overall classification label of high-quality decoction pieces, it also enables the model to learn how to extract key and fine-grained features from the image, thus avoiding simple label bias, prompting the model to focus on the details in the image, making the performance of the model more stable and accurate after deployment, and further improving the generalization ability of the model.
[0193] It should be noted that due to the wide variety of traditional Chinese medicine decoction pieces, each type of traditional Chinese medicine decoction piece may have different appearance features, textures, colors, and shapes, etc., resulting in different quality standards for each type of traditional Chinese medicine decoction piece; for example, some traditional Chinese medicine decoction pieces may require bright colors in appearance, while others may focus more on the integrity of their shapes or the texture structure on the surface;
[0194] Therefore, in order to ensure that the model can efficiently and accurately evaluate the quality of traditional Chinese medicine decoction pieces, it is necessary to construct a dedicated high-quality dataset for each type of traditional Chinese medicine decoction piece to ensure that each type of traditional Chinese medicine decoction piece can learn its unique high-quality features during training.
[0195] The quality grading unit 4 of the traditional Chinese medicine decoction piece is used to execute step S4: adopt a quality evaluation mechanism to analyze the confidence of the decoction piece and obtain the grades of all current traditional Chinese medicine decoction pieces.
[0196] Specifically, the specific calculation of the quality evaluation mechanism is expressed as follows:
[0197]
[0198] In the formula, grade iRepresents the grade of the current i-th traditional Chinese medicine cut piece. Its grades include first grade, second grade, third grade, and fourth grade. The first grade indicates that the characteristics of the current traditional Chinese medicine cut piece are closest to the high-quality product dataset and have obvious high-quality product characteristics; the second grade indicates that there are certain morphological changes in the characteristics of the current traditional Chinese medicine cut piece compared with the cut pieces in the high-quality product dataset; the third grade indicates that there are obvious deformities or morphological defects in the current traditional Chinese medicine cut piece, but the overall characteristics are still relatively obvious; the fourth grade indicates that the current traditional Chinese medicine cut piece has obvious color abnormalities (such as mildew, discoloration, etc.), and these abnormalities usually account for more than 30% of its total area, which may seriously affect its quality; z1, z2, and z3 are respectively confidence boundaries used to divide the grades of traditional Chinese medicine cut pieces. Their specific default values are 0.95, 0.8, and 0.7 respectively. Since the confidence boundaries corresponding to different varieties of traditional Chinese medicine cut pieces are different, their current default values are only used as the initial values of the cluster centers of clustering, and the final clustering results of different varieties are also very different. Therefore, the present application does not specifically limit the values of the confidence boundaries.
[0199] In the present invention, by using a dataset of pure high-quality products to train the binary object detection model of traditional Chinese medicine cut pieces, it is ensured that the model can learn the most ideal and highest-quality characteristics of traditional Chinese medicine cut pieces. Thus, based on the confidence of the model, the product quality is divided to accurately evaluate the matching degree of each sample with the high-quality characteristics. Furthermore, by extracting whether there are fine characteristics belonging to high-quality products in the cut pieces, different grades of cut pieces can be clearly distinguished through confidence. In addition, compared with the traditional scoring system based on manual feature extraction or complex rules, the present invention simplifies the construction process of the scoring system by directly using confidence as the basis for product quality division, avoiding manual intervention and complex preprocessing. Accordingly, by collecting datasets of different varieties of traditional Chinese medicine cut pieces, the automatic product quality division of multiple varieties of traditional Chinese medicine cut pieces is realized, significantly improving the universality and scalability of product quality grading.
[0200] In another embodiment, in order to ensure that possible adulteration problems can be effectively identified and considered during the product quality evaluation process, the present invention further combines the actual weight and the expected weight of the traditional Chinese medicine cut piece. Accordingly, the specific calculation representation of the product quality evaluation mechanism is as follows:
[0201]
[0202] In the formula, grade i Represents the grade of the current i-th traditional Chinese medicine cut piece. Its grades include first grade, second grade, third grade, fourth grade, and abnormal. The first grade indicates that the characteristics of the current traditional Chinese medicine cut piece are closest to the high-quality product dataset and have obvious high-quality product characteristics;
[0203] The second grade indicates that there are certain morphological changes in the characteristics of the current traditional Chinese medicine cut piece compared with the cut pieces in the high-quality product dataset;
[0204] The third level indicates that the current traditional Chinese medicine cut pieces have obvious deformities or morphological defects, but the overall characteristics are still relatively obvious;
[0205] The fourth level indicates that the current traditional Chinese medicine cut pieces have obvious color abnormalities (such as mildew, discoloration, etc.), and these abnormalities usually account for more than 30% of their total area, which may seriously affect their quality;
[0206] The abnormality indicates that there are abnormalities or counterfeiting suspicions in the current traditional Chinese medicine cut pieces, and further warning markings are made on the current traditional Chinese medicine cut pieces. It is necessary to investigate the abnormalities through manual intervention;
[0207] z1, z2, z3, and z4 are the confidence boundaries respectively, used to divide the grades of traditional Chinese medicine cut pieces. Their default values are 0.87, 0.65, 0.5, and 0.35. Since the confidence boundaries corresponding to different varieties of traditional Chinese medicine cut pieces are different, their current default values are only used as the initial values of the cluster centers of clustering, and the final clustering results of different varieties are also very different. Therefore, the application does not specifically limit the values of their confidence boundaries; Score i Represents the comprehensive score of the current i-th traditional Chinese medicine cut piece, and its specific calculation is as follows:
[0208]
[0209] In the formula, Confidence i Represents the cut piece confidence of the i-th traditional Chinese medicine cut piece; w confidence Represents the weight coefficient corresponding to the cut piece confidence, and its specific calculation is expressed as is the weight difference score of the current i-th traditional Chinese medicine cut piece, and its specific calculation is as follows:
[0210]
[0211] In the formula, Weight i Represents the estimated weight of the current i-th traditional Chinese medicine cut piece, and its specific calculation is as follows:
[0212]
[0213] In the formula, Weight total Represents the total weight of the traditional Chinese medicine cut pieces in the current batch, which is obtained by detecting with the weighing instrument of the appearance detection box; Area total Is the total area of the traditional Chinese medicine cut pieces in the current batch, and its specific calculation is expressed as: where n represents the total number of traditional Chinese medicine cut pieces in the current batch, Area iDenote the area of the current \(i\)-th traditional Chinese medicine cut piece, which is obtained by converting the current prediction box into the corresponding physical area. There is a fixed linear relationship for the conversion. Since different camera devices have different calibration methods and calibration data, there are different conversion matrices. The present invention does not specifically limit the area conversion method herein;
[0214] Furthermore, the area of the traditional Chinese medicine cut piece is obtained by multiplying the pixels in the coordinates of the current prediction box by the traditional Chinese medicine cut piece image with low interference, which is used to eliminate the pixels with pixel value of zero, so as to extract the effective area of the cut piece; and converting the effective area of the cut piece into the corresponding physical area, thereby more accurately obtaining the area of the contour of the irregular traditional Chinese medicine cut piece, and finally improving the accuracy of the weight difference score and further ensuring the accuracy of the appearance evaluation.
[0215] Weight expected,i Denote the expected weight of the \(i\)-th traditional Chinese medicine cut piece in the current batch, and its specific calculation is as follows:
[0216] Weight expected,i =Area i ×h avg ×ρ avg
[0217] In the formula, \(h\) avg denotes the preset average thickness of the current variety of traditional Chinese medicine cut piece, which is a known parameter and is usually determined by the average value of the sample thickness of the high-quality appearance dataset; \(\rho\) avg denotes the preset average density of the current variety of traditional Chinese medicine cut piece, which is a known parameter and is usually calculated as the average value according to the corresponding national standard density interval [\(\rho\) min , \(\rho\) max ;
[0218] w weight denotes the weight coefficient of the weight difference score of the traditional Chinese medicine cut piece, and its specific calculation is as follows:
[0219]
[0220] In the formula, Weight expected,min , Weight expected,max are respectively the minimum expected weight and the maximum expected weight of the traditional Chinese medicine cut pieces in the current batch, and their specific calculations are as follows:
[0221] Weight expected,min =Area i ×h avg ×ρ min
[0222] Weight expected,max =Area i ×havg × ρ max
[0223] where ρ min and ρ max represent the preset minimum density and maximum density of the current variety of traditional Chinese medicine decoction pieces, usually obtained according to the national standard density range [ρ min , ρ max corresponding to this variety;
[0224] wherein, Weight total ∈ [Weight expected,min , Weight expected,max means that if the weight of the current batch meets the expected weight range, the comprehensive score of the traditional Chinese medicine decoction pieces is calculated positively; if the weight of the current batch does not meet the expected weight range, the comprehensive score of the traditional Chinese medicine decoction pieces is calculated negatively.
[0225] The present invention conducts appearance evaluation by combining the confidence level of traditional Chinese medicine decoction pieces with the weight difference score, thereby effectively identifying and considering the adulteration problem; especially by combining the weight coefficient of the confidence level to ensure that when the confidence level is high, the appearance score will be more biased towards the positive, and vice versa, which affects the score reduction, thus reflecting the potential uncertainty of the appearance; at the same time, in order to improve the accuracy of appearance evaluation, the present invention evaluates the weight abnormality by calculating the ratio of the current traditional Chinese medicine decoction piece to the maximum weight difference in the batch, and combines the weight coefficient of this ratio, that is, the judgment of positive and negative weights, so that when the weight difference of the current decoction piece is large, the negative weight can make the score drop faster, thus reflecting the possible abnormality, and further effectively identifying the adulterated or overweight traditional Chinese medicine decoction pieces; accordingly, the present invention uses weight as the second index to supplement the possible adulteration and overweight problems, thereby more comprehensively ensuring the accuracy of the evaluation result.
[0226] Compared with the prior art, the present invention establishes an appearance scoring system that matches high-quality appearance by using a target detection model for binary classification with a high-quality appearance data set and combining the confidence level of this model, effectively simplifies the construction process of the appearance scoring system, and significantly improves the accuracy of evaluation; at the same time, during the training process, the self-encoder prompts the traditional Chinese medicine decoction piece model to learn how to extract deeper and higher-quality high-quality appearance features during training, avoids direct dependence on images during training, significantly reduces the interference of irrelevant information, and thus improves the classification accuracy.
[0227] In addition, the present invention further evaluates the appearance of traditional Chinese medicine decoction pieces by introducing the weight dimension, that is, the weight difference score, into the appearance evaluation mechanism, effectively identifies and eliminates potential adulteration or overweight problems, and ensures the authenticity and accuracy of the appearance evaluation result.
[0228] Based on the same inventive concept, the present application further provides an electronic device, which can be a server, a desktop computing device or a mobile computing device (such as, a laptop computing device, a handheld computing device, a tablet computer, a netbook, etc.) and other terminal devices. The device includes one or more processors and a memory, wherein the processor is configured to execute a program to implement the method for grading the appearance quality of traditional Chinese medicine decoction pieces in the embodiments of the present invention; the memory is used for storing a computer program executable by the processor.
[0229] Based on the same inventive concept, the present application further provides a computer-readable storage medium, corresponding to the embodiments of the method for grading the appearance quality of a kind of traditional Chinese medicine decoction pieces. The computer-readable storage medium stores a computer program thereon, and when the program is executed by a processor, it implements the steps of the method for grading the appearance quality of traditional Chinese medicine decoction pieces recorded in any of the above embodiments.
[0230] The present application can be in the form of a computer program product implemented on one or more storage media (including but not limited to disk memory, CD-ROM, optical memory, etc.) containing program codes therein. Computer-usable storage media include permanent and non-permanent, removable and non-removable media, and information storage can be implemented by any method or technology. The information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include but are not limited to: phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassette tapes, magnetic tape disk storage or other magnetic storage devices or any other non-transmission media, which can be used to store information that can be accessed by a computing device.
[0231] The above embodiments only represent several implementation manners of the present invention, and the description thereof is relatively specific and detailed, but it should not be construed as a limitation on the scope of the invention patent. It should be noted that for those of ordinary skill in the art, without departing from the inventive concept of the present invention, several modifications and improvements can still be made, and the present invention also intends to include these modifications and improvements.
Claims
1. A method for grading the quality of Chinese herbal medicine pieces, characterized in that: The following steps are involved: S1, obtaining a monochromatic spectrum image of a Chinese herbal medicine in a product detection box; S2, preprocessing the monochromatic spectrum image of Chinese herbal medicine pieces to obtain a low-interference image of Chinese herbal medicine pieces; S3, using the high-quality Chinese herbal medicine slice model to detect the low-interference Chinese herbal medicine slice images, and obtain the slice confidence and prediction frame of all Chinese herbal medicine slices; wherein the high-quality Chinese herbal medicine slice model is a target detection model that uses a high-quality dataset for binary classification training; S4. Use a quality assessment mechanism to analyze the confidence of Chinese medicine pieces and obtain the quality of all current Chinese medicine pieces.
2. The method for grading the quality of Chinese herbal medicine slices according to claim 1, characterized in that: The high-quality Chinese herbal medicine slice model includes a stacked residual feature extraction module, a feature fusion module and a binary classification module; The specific structure of the stacked residual feature extraction module is as follows: Feature n =ResNet n (I Region ) In the formula, Feature n Represents the feature map of Chinese herbal medicine pieces at the nth layer obtained after the residual feature extraction module is stacked at the nth layer; ResNet n Represents the residual feature extraction operation stacked n times, for the i-th layer of ResNet i (Feature i-1 ), the specific operation is as follows: Feature i =Feature i-1 +ReLU(BN(Conv(Feature i-1 ))) In the formula, x represents the input feature map; Conv represents the convolution operation; BN represents batch normalization; ReLU represents nonlinear transformation, that is, ReLU activation function, which is used to enhance positive features; + is used to represent residual connection; The feature fusion module is used to fuse the feature graphs of several levels of Chinese herbal medicine pieces to obtain fused Chinese herbal medicine piece feature graphs of several scales, which are specifically expressed as follows: fusion=FPN({Feature i |i∈[n-4,n]}) In the formula, fusion represents the fused Chinese herbal medicine feature maps of several scales, and FPN represents the feature pyramid network, which is used to fuse the Chinese herbal medicine feature maps of different scales and output the fused Chinese herbal medicine feature maps of different scales; The binary classification module is used to classify the fused Chinese herbal medicine slice feature map to obtain the slice confidence and prediction frame, which is specifically expressed as follows: Confidence=sigmoid(FC(fusion)) Target=Regression9FC(fusion)) In the formula, Confidence represents the confidence of the Chinese medicine pieces, and its range is [0,1]; Target represents the coordinates of the prediction box of the location of the Chinese medicine pieces; FC is used to represent the fully connected layer; sigmoid is the binary classification activation function; Regression represents the regression convolution layer.
3. The method for grading the quality of Chinese herbal medicine slices according to claim 2, characterized in that: The specific steps of constructing the high-quality data set are as follows: D1. Use a product inspection box to photograph the Chinese herbal medicine pieces and obtain images of several Chinese herbal medicine pieces; D2. Screen the images of several pieces of Chinese herbal medicine for quality respectively, and obtain multiple groups of images of Chinese herbal medicine pieces with full high quality; D3, performing secondary screening on multiple groups of high-quality Chinese herbal medicine slice images, screening out the high-quality Chinese herbal medicine slices in the intersection, and placing them in batches and multiple times into the quality detection box for shooting, to obtain multiple groups of high-quality Chinese herbal medicine slice images; D4. Label and enhance the high-quality images of Chinese herbal medicine pieces in sequence to obtain a high-quality dataset; After obtaining the high-quality data set, the high-quality Chinese herbal medicine slice model is trained in the following manner. The specific training steps are as follows: TA1: Input the high-quality data set into an autoencoder for training, and calculate the reconstruction error between the output of the autoencoder and the input Chinese herbal medicine slice image to obtain a reconstruction loss value; wherein the autoencoder includes an encoder and a decoder; TA2: Determine whether the current reconstruction loss value is lower than a reconstruction threshold: if not, use the optimizer to optimize the weight of the autoencoder according to the reconstruction loss value to obtain the current autoencoder, and execute step TA1; if yes, complete the training of the current autoencoder to obtain the trained autoencoder; TA3: Freeze the weights of the encoder in the autoencoder to obtain a frozen encoder; TA4: Input the high-quality dataset into the frozen encoder for feature extraction to obtain feature representation of the latent space; TA5: Input the feature representation of the latent space into the high-quality Chinese herbal medicine slice model for target detection to obtain the slice confidence and prediction box; TA6: Use cross entropy loss and mean square error to calculate the current slice confidence and the loss between the predicted box and the actual label to obtain the classification loss value and regression loss value; TA7: Determine whether the current classification loss value and regression loss value are both lower than a classification threshold and a regression threshold: If not, use the optimizer to perform gradient update on the current high-quality Chinese herbal medicine model according to the classification loss, and execute step TA4; If so, complete the training of the current high-quality Chinese herbal medicine model and obtain a trained high-quality Chinese herbal medicine model.
4. The method for grading the quality of Chinese herbal medicine slices according to claim 3, characterized in that: The specific calculation of the quality evaluation mechanism is as follows: In the formula, grade i Indicates the grade of the current i-th Chinese herbal medicine slice, which includes grade one, grade two, grade three and grade four. The grade one indicates that the characteristics of the current Chinese herbal medicine slice are closest to the high-quality data set; the grade two indicates that the characteristics of the current Chinese herbal medicine slice have certain morphological changes; the grade three indicates that the current Chinese herbal medicine slice has obvious deformity or morphological defects; the grade four indicates that the current Chinese herbal medicine slice has obvious color abnormality; z1, z2 and z3 are confidence boundaries, which are used to grade Chinese herbal medicines.
5. The method for grading the quality of Chinese herbal medicine slices according to claim 3, characterized in that: The specific calculation of the quality evaluation mechanism is as follows: In the formula, grade i Indicates the grade of the current i-th Chinese herbal medicine slice, which includes level one, level two, level three and level four. Level one indicates that the characteristics of the current Chinese herbal medicine slice are closest to the high-quality data set; level two indicates that the characteristics of the current Chinese herbal medicine slice have certain morphological changes; level three indicates that the current Chinese herbal medicine slice has obvious deformities or morphological defects; level four indicates that the current Chinese herbal medicine slice has obvious color abnormalities; the abnormality indicates that the current Chinese herbal medicine slice has an abnormality, and the current Chinese herbal medicine slice is marked with an early warning; z1, z2, z3 and z4 are confidence boundaries, which are used to divide the grades of Chinese herbal medicine slices; Score i It is represented as the comprehensive score of the current i-th Chinese herbal medicine piece, and its specific calculation is as follows: In the formula, Confidence i It is expressed as the confidence of the i-th Chinese medicine decoction piece; w confidence It is expressed as the weight coefficient corresponding to the confidence of the medicinal material, and its specific calculation is expressed as: is the weight difference score of the current i-th Chinese herbal medicine slice, and its specific calculation is as follows: In the formula, Weight i It represents the estimated weight of the current i-th Chinese herbal medicine slice, and its specific calculation is as follows: In the formula, Weight total Indicates the total weight of the current batch of Chinese herbal medicines; Area total is the total area of the current batch of Chinese herbal medicine pieces, and its specific calculation is expressed as: Where n represents the total number of Chinese herbal medicine pieces in the current batch, Area i Indicates the area of the current i-th Chinese herbal medicine piece; Weight expected,i It represents the expected weight of the i-th Chinese herbal medicine slice in the current batch. Its specific calculation is as follows: Weight expected,i =Area i ×h avg ×ρ avg In the formula, h avg Indicates the preset average thickness of the current Chinese herbal medicine variety; ρ avg Indicates the preset average density of the current Chinese herbal medicine variety; w weight It is expressed as the weight coefficient of the weight difference score of the Chinese herbal medicine pieces, and its specific calculation is as follows: In the formula, Weight expected,min ,Weight expected,max They are the minimum expected weight and maximum expected weight of the current batch of Chinese herbal medicine pieces, respectively. The specific calculation is expressed as: Weight expected,min =Area i ×h avg ×ρ min Weight expected,max =Area i ×h avg ×ρ max Among them, ρ min and ρ max Represents the preset minimum density and maximum density of the current Chinese herbal medicine variety.
6. A device for grading the quality of Chinese herbal medicine pieces, characterized in that: It includes a monochrome spectrum image acquisition unit, a monochrome spectrum preprocessing unit, a Chinese herbal medicine piece classification unit and a Chinese herbal medicine piece phase grading unit; The monochromatic spectrum image acquisition unit is used to acquire the monochromatic spectrum image of the Chinese herbal medicine pieces in the product inspection box; The monochromatic spectrum preprocessing unit is used to preprocess the monochromatic spectrum Chinese herbal medicine slice image to obtain a low-interference Chinese herbal medicine slice image; The Chinese herbal medicine slice classification unit is used to detect low-interference Chinese herbal medicine slice images using a high-quality Chinese herbal medicine slice model to obtain the slice confidence and prediction frame of all Chinese herbal medicine slices; wherein the high-quality Chinese herbal medicine slice model is a target detection model that uses a high-quality dataset for binary classification training; The Chinese herbal medicine piece quality grading unit is used to analyze the confidence of the pieces using a quality evaluation mechanism to obtain the quality of all current Chinese herbal medicine pieces.
7. The Chinese herbal medicine piece quality grading device according to claim 6, characterized in that: The high-quality Chinese herbal medicine slice model includes a stacked residual feature extraction module, a feature fusion module and a binary classification module; The specific structure of the stacked residual feature extraction module is as follows: Feature n =ResNet n (I Region ) In the formula, Feature n Represents the feature map of Chinese herbal medicine pieces at the nth layer obtained after the residual feature extraction module is stacked at the nth layer; ResNet n Represents the residual feature extraction operation stacked n times, for the i-th layer of ResNet i (Feature i-1 ), the specific operation is as follows: Feature i =Feature i-1 +ReLU(BN(Conv(Feature i-1 ))) In the formula, x represents the input feature map; Conv represents the convolution operation; BN represents batch normalization; ReLU represents nonlinear transformation, that is, ReLU activation function, which is used to enhance positive features; + is used to represent residual connection; The feature fusion module is used to fuse the feature graphs of several levels of Chinese herbal medicine pieces to obtain fused Chinese herbal medicine piece feature graphs of several scales, which are specifically expressed as follows: fusion=FPN({Feature i |i∈[n-4,n]}) In the formula, fusion represents the fused Chinese herbal medicine feature maps of several scales, and FPN represents the feature pyramid network, which is used to fuse the Chinese herbal medicine feature maps of different scales and output the fused Chinese herbal medicine feature maps of different scales; The binary classification module is used to classify the fused Chinese herbal medicine slice feature map to obtain the slice confidence and prediction frame, which is specifically expressed as follows: Confidence=sigmoid(FC(fusion)) Target=Regression(FC(fusion)) In the formula, Confidence represents the confidence of the Chinese medicine pieces, and its range is [0, 1]; Target represents the coordinates of the prediction box of the location of the Chinese medicine pieces; FC is used to represent the fully connected layer; sigmoid is the binary classification activation function; Regression represents the regression convolution layer.
8. The Chinese herbal medicine piece quality grading device according to claim 7, characterized in that: The specific steps of constructing the high-quality data set are as follows: D1. Use a product inspection box to photograph the Chinese herbal medicine pieces and obtain images of several Chinese herbal medicine pieces; D2. Screen the images of several pieces of Chinese herbal medicine for quality respectively, and obtain multiple groups of images of Chinese herbal medicine pieces with full high quality; D3, performing secondary screening on multiple groups of high-quality Chinese herbal medicine slice images, screening out the high-quality Chinese herbal medicine slices in the intersection, and placing them in batches and multiple times into the quality detection box for shooting, to obtain multiple groups of high-quality Chinese herbal medicine slice images; D4. Label and enhance the high-quality images of Chinese herbal medicine pieces in sequence to obtain a high-quality dataset; After obtaining the high-quality data set, the high-quality Chinese herbal medicine slice model is trained in the following manner. The specific training steps are as follows: TA1: Input the high-quality data set into an autoencoder for training, and calculate the reconstruction error between the output of the autoencoder and the input Chinese herbal medicine slice image to obtain a reconstruction loss value; wherein the autoencoder includes an encoder and a decoder; TA2: Determine whether the current reconstruction loss value is lower than a reconstruction threshold: if not, use the optimizer to optimize the weight of the autoencoder according to the reconstruction loss value to obtain the current autoencoder, and execute step TA1; if yes, complete the training of the current autoencoder to obtain the trained autoencoder; TA3: Freeze the weights of the encoder in the autoencoder to obtain a frozen encoder; TA4: Input the high-quality dataset into the frozen encoder for feature extraction to obtain feature representation of the latent space; TA5: Input the feature representation of the latent space into the high-quality Chinese herbal medicine slice model for target detection to obtain the slice confidence and prediction box; TA6: Use cross entropy loss and mean square error to calculate the current slice confidence and the loss between the predicted box and the actual label to obtain the classification loss value and regression loss value; TA7: Determine whether the current classification loss value and regression loss value are both lower than a classification threshold and a regression threshold: If not, use the optimizer to perform gradient update on the current high-quality Chinese herbal medicine model according to the classification loss, and execute step TA4; If so, complete the training of the current high-quality Chinese herbal medicine model and obtain a trained high-quality Chinese herbal medicine model.
9. The Chinese herbal medicine piece quality grading device according to claim 8, characterized in that: The specific calculation of the quality evaluation mechanism is as follows: In the formula, grade i Indicates the grade of the current i-th Chinese herbal medicine slice, which includes level one, level two, level three and level four. Level one indicates that the characteristics of the current Chinese herbal medicine slice are closest to the high-quality data set; level two indicates that the characteristics of the current Chinese herbal medicine slice have certain morphological changes; level three indicates that the current Chinese herbal medicine slice has obvious deformities or morphological defects; level four indicates that the current Chinese herbal medicine slice has obvious color abnormalities; the abnormality indicates that the current Chinese herbal medicine slice has an abnormality, and the current Chinese herbal medicine slice is marked with an early warning; z1, z2, z3 and z4 are confidence boundaries, which are used to divide the grades of Chinese herbal medicine slices; Score i It is represented as the comprehensive score of the current i-th Chinese herbal medicine piece, and its specific calculation is as follows: In the formula, Confidence i It is expressed as the confidence of the i-th Chinese medicine decoction piece; w confidence It is expressed as the weight coefficient corresponding to the confidence of the medicinal material, and its specific calculation is expressed as: is the weight difference score of the current i-th Chinese herbal medicine slice, and its specific calculation is expressed as follows: In the formula, Weight i Indicates the estimated weight of the current i-th Chinese herbal medicine slice, and its specific calculation is as follows: In the formula, Weight total Indicates the total weight of the current batch of Chinese herbal medicines; Area total is the total area of the current batch of Chinese herbal medicine pieces, and its specific calculation is expressed as: Where n represents the total number of Chinese herbal medicine pieces in the current batch, Area i Indicates the area of the current i-th Chinese herbal medicine piece; Weight expected,i It represents the expected weight of the i-th Chinese herbal medicine slice in the current batch. Its specific calculation is as follows: Weight expected,i =Area i ×h avg ×ρ avg In the formula, h avg Indicates the preset average thickness of the current Chinese herbal medicine variety; ρ avg Indicates the preset average density of the current Chinese herbal medicine variety; w weight It is expressed as the weight coefficient of the weight difference score of the Chinese herbal medicine pieces, and its specific calculation is as follows: In the formula, Weight expected,min ,Weight expected,max They are the minimum expected weight and maximum expected weight of the current batch of Chinese herbal medicine pieces, respectively. The specific calculation is expressed as: Weight expected,min =Area i ×h avg ×ρ min Weight expected,max =Area i ×h avg ×ρ max Among them, ρ min and ρ max Represents the preset minimum density and maximum density of the current Chinese herbal medicine variety.
10. A Chinese herbal medicine quality detection system, characterized in that: It includes a product quality inspection box, a Chinese herbal medicine variety identification device, and a Chinese herbal medicine product quality grading device; The product quality inspection box is a closed box, and is provided with a monochromatic spectrum light source, a camera device and a weighing instrument; Wherein, the monochromatic spectrum light source is used to illuminate the Chinese herbal medicine pieces in the box; The camera device is used to photograph the Chinese herbal medicine pieces in the box, and input the photographed monochromatic spectrum images of the Chinese herbal medicine pieces into the Chinese herbal medicine piece variety identification device; The weighing instrument is used to measure the weight of the Chinese herbal medicine pieces in the box and send the current weight of the Chinese herbal medicine pieces to the Chinese herbal medicine piece quality grading device; The Chinese herbal medicine piece variety identification device is used to identify the variety of the input monochromatic spectrum Chinese herbal medicine piece image, and input the monochromatic spectrum Chinese herbal medicine piece image and the corresponding variety identification result to the Chinese herbal medicine piece quality grading device; wherein the variety identification result is used to enable the Chinese herbal medicine piece quality grading device to adjust the parameters of the corresponding variety; The Chinese herbal medicine piece quality grading device is used to grade the quality of the input monochromatic spectrum Chinese herbal medicine piece images to obtain the quality of all current Chinese herbal medicine pieces; Wherein, the Chinese herbal medicine quality grading device is the Chinese herbal medicine quality grading device of any one of claims 6 to 9 described above.