A method for evaluating the quality of American ginseng based on multi-task deep learning, a computer readable storage medium and a computer program product
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HENAN UNIVERSITY OF TECHNOLOGY
- Filing Date
- 2024-12-12
- Publication Date
- 2026-06-19
Smart Images

Figure CN119622520B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of American ginseng quality assessment technology, and in particular to an American ginseng quality assessment method based on multi-task deep learning, a computer-readable storage medium, and a computer program product. Background Technology
[0002] The quality assessment of American ginseng mainly relies on its origin and ginsenoside content. Traditional methods such as manual inspection and chemical analysis (e.g., high-performance liquid chromatography) are subject to problems such as high subjectivity, high destructiveness, and long processing time, making them unsuitable for large-scale real-time detection. For example, spectroscopic techniques (such as hyperspectral imaging and Raman spectroscopy) are non-destructive testing methods, but their application is limited due to complex processing and insufficient sensitivity. Near-infrared spectroscopy (NIR) has advantages such as being non-destructive and rapid, but traditional machine learning methods have shortcomings in feature extraction and nonlinear modeling, resulting in limited prediction accuracy. While existing deep learning methods can help improve the accuracy of spectral analysis, their feature extraction capabilities in multi-task learning are still limited, making it difficult to effectively distinguish features from different tasks.
[0003] Therefore, given the shortcomings of traditional methods in terms of real-time performance and non-destructive testing, how to simultaneously achieve non-destructive traceability of the origin of American ginseng and prediction of total ginsenoside content, thereby improving the accuracy and efficiency of testing, has become a pressing technical problem to be solved in this field.
[0004] The above information is provided as background information only to aid in understanding this disclosure and does not constitute an assertion or admission that any of the above content can be used as prior art relative to this disclosure. Summary of the Invention
[0005] The purpose of this invention is to provide a method for evaluating the quality of American ginseng based on multi-task deep learning, a computer-readable storage medium, and a computer program product, so as to solve or at least partially solve the technical problems existing in the prior art.
[0006] To achieve this objective, the present invention adopts the following technical solution:
[0007] In a first aspect, the present invention provides a method for evaluating the quality of American ginseng based on multi-task deep learning, comprising:
[0008] Prepare American ginseng samples from different origins and cut them into slices to obtain multiple American ginseng samples; each American ginseng sample includes several slices of American ginseng from the same origin;
[0009] Near-infrared spectral data of each American ginseng sample were collected; and the ginsenoside content of each American ginseng sample was determined to obtain the label data of each American ginseng sample; wherein, the label data of the American ginseng sample includes the ginsenoside content and origin information of the American ginseng sample;
[0010] Based on the collected near-infrared spectral data and the obtained label data, a quality detection model for American ginseng was constructed and trained.
[0011] Based on the constructed American ginseng quality detection model, feature extraction was performed on the near-infrared spectral data of the American ginseng to be evaluated, and the origin traceability and ginsenoside content were predicted.
[0012] The American ginseng quality detection model includes a backbone network for extracting feature information from the near-infrared spectral data of American ginseng, a classification head for tracing the origin of American ginseng, and a regression head for predicting the ginsenoside content of American ginseng.
[0013] Optionally, the backbone network includes three cascaded Res-Attention modules, each of which contains three sub-modules: a residual module, a self-attention module, and a channel attention module.
[0014] The residual module is used to process the input near-infrared spectral data of American ginseng through convolutional layers and activation functions; the self-attention module is used to calculate the correlation between each position in the sequence and other positions, capturing global information and dependencies between bands; the channel attention module is used to assign weights to each channel, highlighting important task-related features.
[0015] Optionally, the input near-infrared spectral data of American ginseng is processed through a convolutional layer and an activation function, specifically including:
[0016] The input near-infrared spectral data x of American ginseng is processed through a convolutional layer and activation function to generate residual mapping. Then The input near-infrared spectral data x of American ginseng is added to the final output through an activation function. ;
[0017] The calculation of the correlation between each position in the sequence and other positions captures global information and inter-band dependencies, specifically including:
[0018] The residual module output The convolutional layers generate query vector Q, key vector K, and value vector V, respectively. The similarity between query vector Q and key vector K is calculated by dot product to obtain the relevance score. ;
[0019] The relevance scores are normalized using the softmax function to obtain the weighted features.
[0020] ;
[0021] Learnable parameters Adjusting the influence of the self-attention mechanism before outputting, i.e. ;
[0022] The process of assigning weights to each channel to highlight important task-related features specifically includes:
[0023] The output of the self-attention module Global average pooling is used to obtain the global features of each channel. , expressed as:
[0024] , where x c The data input to the channel attention module is c, where c is the number of channels and L is the feature length of each channel.
[0025] Global features Channel weights are generated using two 1x1 convolutional layers and a sigmoid function:
[0026] ;
[0027] The output after channel weighting is: .
[0028] Optionally, the final loss function of the American ginseng quality detection model is designed as a weighted sum of the classification task loss and the regression task loss:
[0029] ;
[0030] Where α and β are the loss weights for classification and regression tasks, respectively, both set to 0.5.
[0031] Optionally, the collection of near-infrared spectral data for each American ginseng sample specifically includes:
[0032] Near-infrared spectral data of each American ginseng sample were acquired in the range of 950 to 1650 nm with a resolution of 0.5 nm, and the original spectral data were reduced from 1401 dimensions to 280 dimensions using a sliding window technique.
[0033] After collecting the near-infrared spectral data of each American ginseng sample, the process further includes: preprocessing the near-infrared spectral data, specifically as follows:
[0034] The 280-dimensional near-infrared spectral data were preprocessed using Savitsky-Gorye smoothing and differentiation, standard normal transformation, and Z-fraction normalization.
[0035] Optionally, before extracting features from the near-infrared spectral data of the American ginseng to be evaluated based on the constructed American ginseng quality detection model, and before performing origin traceability and predicting ginsenoside content, the method further includes:
[0036] All American ginseng samples were divided according to a predetermined ratio into a training set for training the American ginseng quality detection model, a validation set for verifying the training effect after each round of model training, and a test set for testing the trained American ginseng quality detection model; and
[0037] The constructed American ginseng quality detection model was evaluated using a test set.
[0038] Optionally, the evaluation of the constructed American ginseng quality detection model using a test set specifically includes:
[0039] The near-infrared spectral data of the collected test set were input into the trained American ginseng quality detection model to evaluate its performance in tracing the origin of American ginseng and predicting its ginsenoside content. Specific evaluation parameters included those for the origin tracing task, the ginsenoside content prediction task, and the ginsenoside content prediction task.
[0040] The specific parameters in the origin traceability task include:
[0041] Overall accuracy, representing the proportion of correctly classified samples in the test set, is as follows:
[0042] ,in, It is correctly classified as the first The number of samples in each class, where c is the number of classes and N is the number of samples in the test set;
[0043] Precision, used to measure the proportion of correctly predicted positive samples out of all samples predicted positive, i.e.:
[0044] ,in, It is incorrectly classified as the first Number of samples in the class;
[0045] Recall is a measure of the proportion of correctly predicted positive samples among all true positive samples.
[0046] ,in, It truly belongs to the first Number of samples that were misclassified but not classified:
[0047] The parameters in the ginsenoside content prediction task specifically include:
[0048] The coefficient of determination measures the goodness of fit between the predicted and actual values.
[0049] ;
[0050] Root mean square error (RMSE) measures the error between the predicted and actual values.
[0051] ;
[0052] Residual prediction bias is used to represent the stability of model predictions, i.e.:
[0053] ;
[0054] In the above formula, N is the total number of test samples. and The first The true and predicted values of each sample and The mean of the true and predicted values of the test sample;
[0055] The process of constructing and training a quality detection model for American ginseng based on the collected near-infrared spectral data and the obtained label data is specifically implemented as follows:
[0056] A quality detection model for American ginseng was constructed and trained based on the near-infrared spectral data and label data in the training set.
[0057] Optionally, the step of dividing all American ginseng samples into a training set for training the American ginseng quality detection model, a validation set for verifying the training effect after each round of model training, and a test set for testing the trained American ginseng quality detection model, specifically includes:
[0058] All American ginseng samples were divided into training, validation, and test sets in a 5:1:4 ratio.
[0059] The Kennard-Stone method is used to ensure uniform sample distribution, and the number of training set samples is increased by unsupervised spectral data enhancement.
[0060] Optionally, the step of preparing American ginseng samples from different origins and cutting them into slices yields multiple American ginseng samples, specifically including...
[0061] American ginseng samples were selected from four geographical regions: Weihai in Shandong, Baishan in Jilin, Montreal in Canada, and Wisconsin in the United States. All American ginseng samples were cut into American ginseng slices of uniform size. Five to eight slices of American ginseng from the same place of origin constituted one American ginseng sample, resulting in a total of 150 samples.
[0062] 150 samples were stored at 2°C.
[0063] Optionally, the ginsenoside content of the American ginseng samples was detected by HPLC high-performance liquid chromatography.
[0064] The ginsenoside content of the American ginseng samples included the content of six main ginsenosides: Rg1, Re, Rb1, Rc, Rb2, and Rd.
[0065] Secondly, this invention provides a ginseng quality assessment system based on multi-task deep learning, comprising:
[0066] A slicing device is used to cut prepared American ginseng samples from different origins into slices to obtain multiple American ginseng samples; wherein each American ginseng sample includes several slices of American ginseng from the same origin;
[0067] Near-infrared spectrometer, used to collect near-infrared spectral data for each American ginseng sample;
[0068] HPLC (High Performance Liquid Chromatography) is used to determine the ginsenoside content of each American ginseng sample and obtain the label data of each American ginseng sample; wherein, the label data of the American ginseng sample includes the ginsenoside content and origin information of the American ginseng sample;
[0069] The deep learning module is used to build and train a quality detection model for American ginseng based on the collected near-infrared spectral data and the obtained label data.
[0070] The quality assessment module is used to extract features from the near-infrared spectral data of the American ginseng to be assessed based on the constructed American ginseng quality detection model, and to perform origin traceability and prediction of ginsenoside content.
[0071] The American ginseng quality detection model includes a backbone network for extracting feature information from the near-infrared spectral data of American ginseng, a classification head for tracing the origin of American ginseng, and a regression head for predicting the ginsenoside content of American ginseng.
[0072] Optionally, the backbone network includes three cascaded Res-Attention modules, each of which contains three sub-modules: a residual module, a self-attention module, and a channel attention module.
[0073] The residual module is used to process the input near-infrared spectral data of American ginseng through convolutional layers and activation functions; the self-attention module is used to calculate the correlation between each position in the sequence and other positions, capturing global information and dependencies between bands; the channel attention module is used to assign weights to each channel, highlighting important task-related features.
[0074] Optionally, the input near-infrared spectral data of American ginseng is processed through a convolutional layer and an activation function, specifically including:
[0075] The input near-infrared spectral data x of American ginseng is processed through a convolutional layer and activation function to generate residual mapping. Then The input near-infrared spectral data x of American ginseng is added to the final output through an activation function. ;
[0076] The calculation of the correlation between each position in the sequence and other positions captures global information and inter-band dependencies, specifically including:
[0077] The residual module output The convolutional layers generate query vector Q, key vector K, and value vector V, respectively. The similarity between query vector Q and key vector K is calculated by dot product to obtain the relevance score. ;
[0078] The relevance scores are normalized using the softmax function to obtain the weighted features. ;
[0079] Learnable parameters Adjusting the influence of the self-attention mechanism before outputting, i.e. ;
[0080] The process of assigning weights to each channel to highlight important task-related features specifically includes:
[0081] The output of the self-attention module Global average pooling is used to obtain the global features of each channel. , expressed as:
[0082] , where x c The data input to the channel attention module is c, where c is the number of channels and L is the feature length of each channel.
[0083] Global features Channel weights are generated using two 1x1 convolutional layers and a sigmoid function:
[0084] ;
[0085] The output after channel weighting is: .
[0086] Optionally, the final loss function of the American ginseng quality detection model is designed as a weighted sum of the classification task loss and the regression task loss:
[0087] ;
[0088] Where α and β are the loss weights for classification and regression tasks, respectively, both set to 0.5.
[0089] Optionally, the collection of near-infrared spectral data for each American ginseng sample specifically includes:
[0090] Near-infrared spectral data of each American ginseng sample were acquired in the range of 950 to 1650 nm with a resolution of 0.5 nm, and the original spectral data were reduced from 1401 dimensions to 280 dimensions using a sliding window technique.
[0091] After collecting the near-infrared spectral data of each American ginseng sample, the process further includes: preprocessing the near-infrared spectral data, specifically as follows:
[0092] The 280-dimensional near-infrared spectral data were preprocessed using Savitsky-Gorye smoothing and differentiation, standard normal transformation, and Z-fraction normalization.
[0093] Optionally, the American ginseng samples include a training set divided according to a predetermined ratio for training the American ginseng quality detection model, a validation set for verifying the training effect after each round of model training, and a test set for testing the trained American ginseng quality detection model.
[0094] The deep learning module is specifically used to evaluate the constructed American ginseng quality detection model using a test set.
[0095] Optionally, the evaluation of the constructed American ginseng quality detection model using a test set specifically includes:
[0096] The near-infrared spectral data of the collected test set were input into the trained American ginseng quality detection model to evaluate its performance in tracing the origin of American ginseng and predicting its ginsenoside content. Specific evaluation parameters included those for the origin tracing task, the ginsenoside content prediction task, and the ginsenoside content prediction task.
[0097] The specific parameters in the origin traceability task include:
[0098] Overall accuracy, representing the proportion of correctly classified samples in the test set, is as follows:
[0099] ,in, It is correctly classified as the first The number of samples in each class, where c is the number of classes and N is the number of samples in the test set;
[0100] Precision, used to measure the proportion of correctly predicted positive samples out of all samples predicted positive, i.e.:
[0101] ,in, It is incorrectly classified as the first Number of samples in the class;
[0102] Recall is a measure of the proportion of correctly predicted positive samples among all true positive samples.
[0103] ,in, It truly belongs to the first Number of samples that were misclassified but not classified:
[0104] The parameters in the ginsenoside content prediction task specifically include:
[0105] The coefficient of determination measures the goodness of fit between the predicted and actual values.
[0106] ;
[0107] Root mean square error (RMSE) measures the error between the predicted and actual values.
[0108] ;
[0109] Residual prediction bias is used to represent the stability of model predictions, i.e.:
[0110] ;
[0111] In the above formula, N is the total number of test samples. and The first The true and predicted values of each sample and The mean of the true and predicted values of the test sample;
[0112] The process of constructing and training a quality detection model for American ginseng based on the collected near-infrared spectral data and the obtained label data is specifically implemented as follows:
[0113] A quality detection model for American ginseng was constructed and trained based on the near-infrared spectral data and label data in the training set.
[0114] Optionally, the American ginseng samples are divided into a training set, a validation set, and a test set in a ratio of 5:1:4;
[0115] The Kennard-Stone method is used to ensure uniform sample distribution, and the number of training set samples is increased by unsupervised spectral data enhancement.
[0116] Optionally, the prepared American ginseng samples from different origins specifically include American ginseng samples from four geographical regions: Weihai in Shandong, Baishan in Jilin, Montreal in Canada, and Wisconsin in the United States; all American ginseng samples are cut into American ginseng slices of uniform size, and 5-8 slices of American ginseng from the same origin constitute one American ginseng sample, resulting in a total of 150 samples.
[0117] The 150 samples were stored in a refrigerated environment at 2°C.
[0118] Optionally, the ginsenoside content of the American ginseng samples was detected by HPLC high-performance liquid chromatography.
[0119] The ginsenoside content of the American ginseng samples included the content of six main ginsenosides: Rg1, Re, Rb1, Rc, Rb2, and Rd.
[0120] Thirdly, the present invention also provides a computer-readable storage medium storing at least one instruction, which is loaded and executed by a processor to implement the above-described method for evaluating the quality of American ginseng based on multi-task deep learning.
[0121] Fourthly, the present invention also provides a computer program product, including a computer program / instruction, which, when executed by a processor, implements the above-described method for evaluating the quality of American ginseng based on multi-task deep learning.
[0122] Compared with the prior art, the present invention has the following beneficial effects:
[0123] This invention provides a multi-task detection method based on near-infrared spectroscopy and deep learning. By constructing an improved multi-task deep neural network, the feature extraction capability is enhanced, enabling the simultaneous non-destructive traceability of the origin of American ginseng and prediction of the total ginsenoside content. This improves the accuracy and efficiency of detection and solves the shortcomings of traditional methods in terms of real-time performance and non-destructive detection.
[0124] The present invention has other features and advantages, which will be apparent from or will be set forth in detail in the accompanying drawings and the following detailed description, which together serve to explain the particular principles of the invention. Attached Figure Description
[0125] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0126] Figure 1 This is a flowchart of a method for evaluating the quality of American ginseng based on multi-task deep learning, provided by an embodiment of the present invention.
[0127] Figure 2 This is a schematic diagram of the American ginseng sample provided in an embodiment of the present invention.
[0128] Figure 3 This is a near-infrared spectral data image of the collected American ginseng sample provided in an embodiment of the present invention.
[0129] Figure 4 This is a schematic diagram illustrating the working principle of a ginseng quality testing model provided in an embodiment of the present invention.
[0130] Figure 5 This is a schematic diagram illustrating the working principle of the three Res-Attention modules provided in this embodiment of the invention.
[0131] Figure 6 This is a schematic diagram of the architecture of a ginseng quality assessment system based on multi-task deep learning provided in an embodiment of the present invention.
[0132] In the diagram: 10, slicing device; 20, detection device; 21, near-infrared spectrometer; 22, HPLC high-performance liquid chromatograph; 30, deep learning module; 40, quality assessment module. Detailed Implementation
[0133] To illustrate the possible application scenarios, technical principles, implementable specific solutions, and achievable objectives and effects of this application in detail, the following description, in conjunction with the listed specific embodiments and accompanying drawings, provides a detailed explanation. The embodiments described herein are merely illustrative of the technical solutions of this application and are therefore intended to limit the scope of protection of this application.
[0134] In this document, the term "embodiment" means that a specific feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The term "embodiment" appearing in various places throughout the specification does not necessarily refer to the same embodiment, nor does it specifically limit its independence or connection with other embodiments. In principle, in this application, as long as there are no technical contradictions or conflicts, the technical features mentioned in each embodiment can be combined in any way to form corresponding implementable technical solutions.
[0135] Unless otherwise defined, the technical terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application pertains; the use of related terms herein is merely for the purpose of describing particular embodiments and is not intended to limit this application.
[0136] In the description of this application, the term "and / or" is used to describe the logical relationship between objects, indicating that three relationships can exist. For example, A and / or B means: A exists, B exists, and A and B exist simultaneously. Additionally, the character " / " in this document generally indicates that the preceding and following objects have an "or" logical relationship.
[0137] In this application, terms such as “first” and “second” are used only to distinguish one entity or operation from another, and do not necessarily require or imply any actual quantity, hierarchy or order relationship between these entities or operations.
[0138] Unless otherwise specified, the use of terms such as “comprising,” “including,” “having,” or other similar expressions in this application is intended to cover non-exclusive inclusion, which does not exclude the presence of additional elements in a process, method, or product that includes the stated elements, such that a process, method, or product that includes a list of elements may include not only those defined elements but also other elements not expressly listed, or elements inherent to such a process, method, or product.
[0139] As understood in the Examination Guidelines, in this application, expressions such as "greater than," "less than," and "exceeding" are understood to exclude the stated number; expressions such as "above," "below," and "within" are understood to include the stated number. Furthermore, in the description of the embodiments in this application, "multiple" means two or more (including two), and similar expressions related to "multiple" are also understood in this way, such as "multiple groups" and "multiple times," unless otherwise explicitly specified.
[0140] In the description of the embodiments of this application, the space-related expressions used, such as "center," "longitudinal," "lateral," "length," "width," "thickness," "upper," "lower," "front," "rear," "left," "right," "vertical," "horizontal," "vertical," "top," "bottom," "inner," "outer," "clockwise," "counterclockwise," "axial," "radial," and "circumferential," indicate the orientation or positional relationship based on the orientation or positional relationship shown in the specific embodiments or drawings. They are only for the purpose of describing the specific embodiments of this application or for the reader's understanding, and do not indicate or imply that the device or component referred to must have a specific position, a specific orientation, or be constructed or operated in a specific orientation. Therefore, they should not be construed as limitations on the embodiments of this application.
[0141] Unless otherwise expressly specified or limited, the terms "installation," "connection," "linking," "fixing," and "setting," as used in the description of the embodiments of this application, should be interpreted broadly. For example, "connection" can be a fixed connection, a detachable connection, or an integral setting; it can be a mechanical connection, an electrical connection, or a communication connection; it can be a direct connection or an indirect connection through an intermediate medium; it can be the internal connection of two components or the interaction between two components. For those skilled in the art to which this application pertains, the specific meaning of the above terms in the embodiments of this application can be understood according to the specific circumstances.
[0142] Example 1:
[0143] Please see Figure 1 , Figure 1 This is a flowchart of a method for evaluating the quality of American ginseng based on multi-task deep learning, provided by an embodiment of the present invention. The method includes:
[0144] Step 110: Prepare American ginseng samples from different origins and cut them into slices to obtain multiple American ginseng samples.
[0145] For example, such as Figure 2 As shown, Figure 2 This is a schematic diagram of the American ginseng samples provided in an embodiment of the present invention. In this embodiment, the American ginseng samples are selected from four geographical regions: Weihai in Shandong, Baishan in Jilin, Montreal in Canada, and Wisconsin in the United States.
[0146] All American ginseng samples were cut into uniformly sized slices. 5-8 slices from the same origin were grouped into one sample, resulting in 150 sample groups, including 40 from Shandong, 40 from Jilin, 35 from Canada, and 35 from the United States. All 150 sample groups were stored at 2°C to ensure data consistency during near-infrared spectroscopy analysis.
[0147] Step 121: Collect near-infrared spectral data for each American ginseng sample.
[0148] As an optional implementation, in this embodiment, the NIR (Near Infrared) spectral data of each sample are acquired using a Swedish Botong DA 7250 NIR (Near Infrared) analyzer in the range of 950 to 1650 nm, with a resolution of 0.5 nm. Figure 3 As shown, Figure 3 This is a near-infrared spectral data image of the collected American ginseng sample provided in an embodiment of the present invention;
[0149] The instrument has a built-in tungsten halide light source. After a 30-minute warm-up period, it acquires spectral data and uses a sliding window technique to reduce the original spectrum from 1401 dimensions to 280 dimensions to reduce redundant information. The formula for calculating the dimension is (1650-950) divided by 0.5.
[0150] It is understood that sliding window technology is a conventional technique, so its specific operation process and principle will not be described in detail in this embodiment.
[0151] Step 122: Determine the ginsenoside content of each American ginseng sample and obtain the label data for each American ginseng sample.
[0152] It should be noted that in step 122, the label data of the American ginseng sample includes the ginsenoside content and place of origin information of the American ginseng sample;
[0153] As an optional implementation method, in this embodiment, the concentration of ginsenosides in the sample can be detected by a high-performance liquid chromatograph from Shimadzu Corporation of Japan. Specifically, in this embodiment, a total of 6 major ginsenosides (Rg1, Re, Rb1, Rc, Rb2, Rd) were analyzed, and the specific content of each sample was determined to provide a reference for subsequent modeling.
[0154] Step 130: Preprocess the near-infrared spectral data.
[0155] The raw NIR spectral data were preprocessed by Savitzky-Gore smoothing and differentiation (SGS&D), standard normal transformation (SNV), and Z-score normalization. SGS&D removed high-frequency noise, SNV corrected the slope differences of the spectral data, and Z-score normalization further improved the spectral discrimination and the quality of the model input data.
[0156] It is understandable that the above three preprocessing methods are also conventional technical means, so their specific formulas or principles will not be elaborated in this embodiment.
[0157] Step 140: Based on the collected near-infrared spectral data and the obtained label data, construct and train a quality detection model for American ginseng.
[0158] Please refer to Figure 4 and Figure 5 , Figure 4 This is a schematic diagram illustrating the working principle of a ginseng quality testing model provided in an embodiment of the present invention. Figure 5 This is a schematic diagram illustrating the working principle of the three Res-Attention modules provided in this embodiment of the invention;
[0159] This embodiment uses a hybrid multi-task multi-module deep learning network (MMTDL) to efficiently extract features from the near-infrared spectral data of American ginseng by integrating residual modules, self-attention modules, and channel attention modules, so as to achieve the tasks of tracing the origin and predicting the total ginsenoside content.
[0160] The backbone network of the American ginseng quality inspection model is used to extract shared features from 280-band near-infrared spectral data x of American ginseng. The model backbone consists of three cascaded Res-Attention modules. The Res-Attention module is a network structure combining ResNet and attention mechanisms, which can be used for image processing tasks; for example... Figure 4 As shown, Figure 4 In the diagram, (a) represents the overall structure of MMTDL, while (b), (c), and (d) represent three Res-Attention modules, respectively.
[0161] Specifically, each Res-Attention module contains three sub-modules: the residual module, the self-attention module, and the channel attention module.
[0162] First, for the residual module, the corresponding Figure 5 In (e), the introduction of shortcut connections alleviates the vanishing and exploding gradient problems while preserving the integrity of feature information.
[0163] The input near-infrared spectral data x of American ginseng is processed by convolutional layers and activation functions to generate residual mappings. ;
[0164] Then The input near-infrared spectral data x of American ginseng is added to the final output through an activation function. ;
[0165] Furthermore, for the self-attention module, the corresponding Figure 5 (f) captures global information and inter-band dependencies by calculating the correlation between each position in the sequence and other positions:
[0166] The output of the residual module The convolutional layers generate query vector Q, key vector K, and value vector V, respectively. The similarity between query vector Q and key vector K is calculated by dot product to obtain the relevance score. ;
[0167] The relevance scores are normalized using the softmax function to obtain the weighted features. ;
[0168] Learnable parameters Adjusting the influence of the self-attention mechanism before outputting, i.e. ;
[0169] Finally, for the channel attention module, the corresponding Figure 5 In (g), the key feature is to highlight important task-related characteristics by assigning weights to each channel.
[0170] The output of the self-attention module Global average pooling is used to obtain the global features of each channel. , expressed as:
[0171] , where x c The data input to the channel attention module is c, where c is the number of channels and L is the feature length of each channel.
[0172] Global features Channel weights are generated using two 1x1 convolutional layers and a sigmoid function:
[0173] ;
[0174] The output after channel weighting is: .
[0175] In the above formula, Output corresponds to Figure 4 Output 1 corresponds to Output 2, and Output '' corresponds to Output 3.
[0176] It should be noted that the input data x is processed by three cascaded Res-Attention modules to extract deep shared features. Subsequently, the features are flattened into a one-dimensional vector and then subjected to feature dimensionality reduction and further extraction through a fully connected layer. Finally, the output is passed to the prediction heads of the classification task and the regression task, respectively.
[0177] Specifically, the quality testing model for American ginseng includes:
[0178] The classification head is used for label classification for origin traceability. The network contains four neurons, uses the softmax function to generate the category probability distribution, and uses the cross-entropy loss function to calculate the difference between the output and the true label.
[0179] The regression head is used to predict continuous values of total ginsenoside content and outputs a single regression value. The mean squared error (MSE) is used as the loss function to measure the difference between the predicted value and the true value.
[0180] Furthermore, to balance multi-task training, the model construction in this embodiment also involves loss function design, specifically:
[0181] The final loss function is a weighted sum of the classification task loss and the regression task loss:
[0182] Loss_total=α×Loss_classfiatinon+β×Loss_regression;
[0183] α and β are the loss weights for classification and regression tasks, respectively, and are both set to 0.5 to achieve better model performance in multi-task learning.
[0184] After the model is built, training and testing are required. To ensure the training effect, this embodiment also verifies the model effect after each round of training on the training set. Therefore, this embodiment pre-divides all American ginseng samples into a training set for training the American ginseng quality detection model, a validation set for verifying the training effect after each round of model training, and a test set for testing the trained American ginseng quality detection model. For example, this embodiment is specifically implemented as follows:
[0185] All American ginseng samples were divided into training, validation, and test sets in a 5:1:4 ratio.
[0186] The Kennard-Stone method is used to ensure uniform sample distribution, and the number of training set samples is increased by unsupervised spectral data enhancement.
[0187] The Kennard-Stone method is a publicly available technology, so its principle will not be described in detail in this embodiment.
[0188] Based on the aforementioned dataset, this method was also compared with three traditional machine learning models (Support Vector Machine (SVM), Random Forest (RF), and Partial Least Squares Discriminant Analysis (PLS-DA)) and a deep learning model (1DCNN, a one-dimensional convolutional neural network). The final experimental results were the average of 10 repeated experiments to verify the effectiveness of the MMTDL model proposed in this embodiment. The experimental results demonstrate that the prediction accuracy of the MMTDL model proposed in this embodiment is significantly higher than that of existing methods.
[0189] Specifically, after the model is built and trained, this embodiment also evaluates the constructed American ginseng quality detection model using a test set; this includes:
[0190] The near-infrared spectral data of the collected test set were input into the trained American ginseng quality detection model to evaluate its performance in tracing the origin of American ginseng and predicting its ginsenoside content. Specific evaluation parameters included those for the origin tracing task, the ginsenoside content prediction task, and the ginsenoside content prediction task.
[0191] The specific parameters in the origin traceability task include:
[0192] Overall accuracy, representing the proportion of correctly classified samples in the test set, is as follows:
[0193] ,in, It is correctly classified as the first The number of samples in each class, where c is the number of classes and N is the number of samples in the test set;
[0194] Precision, used to measure the proportion of correctly predicted positive samples out of all samples predicted positive, i.e.:
[0195] ,in, It is incorrectly classified as the first Number of samples in the class;
[0196] Recall is a measure of the proportion of correctly predicted positive samples among all true positive samples.
[0197] ,in, It truly belongs to the first Number of samples that were misclassified but not classified:
[0198] The parameters in the ginsenoside content prediction task specifically include:
[0199] The coefficient of determination measures the goodness of fit between predicted and actual values.
[0200] ;
[0201] Root mean square error (RMSE) measures the error between the predicted and actual values.
[0202] ;
[0203] Residual prediction bias is used to represent the stability of model predictions, i.e.:
[0204] ;
[0205] In the above formula, N is the total number of test samples. and The first The true and predicted values of each sample and The mean of the true and predicted values of the test sample;
[0206] To provide further explanation, step 140 is specifically implemented as follows: Based on the near-infrared spectral data and label data of the training set, construct and train the American ginseng quality detection model.
[0207] Step 150: Based on the constructed American ginseng quality detection model, feature extraction is performed on the near-infrared spectral data of the American ginseng to be evaluated to trace its origin and predict its ginsenoside content.
[0208] For ease of understanding, it should be noted that in this embodiment, both ginsenoside content and place of origin are label data. The spectrum is x data, and the label is y data (one column is the place of origin label, and the other column is the ginsenoside content). Both need to be input during training. Figure 4 Task A and Task B in the diagram correspond to the classification task and the regression task, respectively.
[0209] It should be noted that, in this embodiment, a verification set is not mandatory.
[0210] In summary, the American ginseng quality assessment method based on multi-task deep learning provided in this embodiment achieves real-time non-destructive testing and improves testing efficiency; moreover, the algorithm structure is simple, easy to implement and promote; it can simultaneously realize the functions of origin traceability and total ginsenoside content prediction, expanding the application scenarios; and the prediction accuracy is higher than that of existing methods, making it more practical.
[0211] Example 2:
[0212] Please refer to Figure 6 , Figure 6 This is a schematic diagram of the architecture of a ginseng quality assessment system based on multi-task deep learning provided in an embodiment of the present invention. The system specifically includes:
[0213] The slicing device 10 is used to cut the prepared American ginseng samples from different origins into slices to obtain multiple American ginseng samples; wherein each American ginseng sample includes several slices of American ginseng from the same origin.
[0214] The detection device 20 includes a near-infrared spectrometer 21 and a high-performance liquid chromatograph 22; the near-infrared spectrometer 21 is used to collect near-infrared spectral data of each American ginseng sample; the high-performance liquid chromatograph 22 is used to determine the ginsenoside content of each American ginseng sample and obtain the label data of each American ginseng sample; wherein, the label data of the American ginseng sample includes the ginsenoside content and origin information of the American ginseng sample;
[0215] The deep learning module 30 is used to build and train a ginseng quality detection model based on the collected near-infrared spectral data and the obtained label data.
[0216] The quality assessment module 40 is used to extract features from the near-infrared spectral data of the American ginseng to be assessed based on the constructed American ginseng quality detection model, and to perform origin traceability and prediction of ginsenoside content.
[0217] The American ginseng quality detection model includes a backbone network for extracting feature information from the near-infrared spectral data of American ginseng, a classification head for tracing the origin of American ginseng, and a regression head for predicting the ginsenoside content of American ginseng.
[0218] Specifically, the backbone network consists of three cascaded Res-Attention modules, each of which contains three sub-modules: a residual module, a self-attention module, and a channel attention module.
[0219] The residual module processes the input near-infrared spectral data of American ginseng through convolutional layers and activation functions; the self-attention module calculates the correlation between each position in the sequence and other positions, capturing global information and dependencies between bands; and the channel attention module assigns weights to each channel, highlighting important task-related features.
[0220] For example, in this embodiment, the near-infrared spectrometer 21 is a DA 7250 NIR (Near Infrared) analyzer from Boton, Sweden, and the HPLC high-performance liquid chromatograph 22 is a high-performance liquid chromatograph from Shimadzu, Japan.
[0221] Since the specific data processing procedure has been described in detail in Example 1, it will not be repeated in this example.
[0222] Based on the same concept, embodiments of the present invention also provide a computer-readable storage medium storing at least one instruction, which is loaded and executed by a processor to implement a method for evaluating the quality of American ginseng based on multi-task deep learning provided in embodiments of the present invention.
[0223] Any combination of one or more computer-readable media may be used. A computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. A computer-readable storage medium can be, for example—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples (a non-exhaustive list) of computer-readable storage media include: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this document, a computer-readable storage medium can be any tangible medium that contains or stores a program that can be used by or in connection with an instruction execution system, apparatus, or device.
[0224] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, capable of sending, propagating, or transmitting programs for use by or in connection with an instruction execution system, apparatus, or device.
[0225] Program code contained on a computer-readable medium may be transmitted using any suitable medium, including—but not limited to—wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.
[0226] Computer program code for performing the operations of this invention can be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, and C++, as well as conventional procedural programming languages such as "C" or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0227] Based on the same concept, embodiments of the present invention also provide a computer program product, including a computer program / instruction, which, when executed by a processor, implements a method for evaluating the quality of American ginseng based on multi-task deep learning provided in embodiments of the present invention.
[0228] Computer program products may be loaded onto computer devices, and the components of computer devices may include, but are not limited to: one or more processors or processing units, system memory, and buses connecting different system components (including system memory and processing units).
[0229] Computer devices typically include a variety of computer system-readable media. These media can be any available media that can be accessed by a computer device, including volatile and non-volatile media, and removable and non-removable media.
[0230] System memory may include computer system readable media in the form of volatile memory, such as random access memory (RAM) and / or cache memory. The computer device may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, the storage system may be used to read and write non-removable, non-volatile magnetic media. The computer program product has a set (e.g., at least one) of program modules configured to perform the functions of the various embodiments of the present invention.
[0231] A program / utility having a set (at least one) of program modules can be stored, for example, in memory. Such program modules include, but are not limited to, an operating system, one or more applications, other program modules, and program data. Each or some combination of these examples may include an implementation of a network environment. The program modules typically perform the functions and / or methods described in the embodiments of this invention.
[0232] Computer devices can also communicate with one or more external devices (such as keyboards, pointing devices, monitors, etc.), one or more devices that enable users to interact with the computer device, and / or any device that enables the computer device to communicate with one or more other computing devices (such as network interface cards, modems, etc.). This communication can be performed through input / output (I / O) interfaces. Furthermore, computer devices can communicate with one or more networks (such as local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) via network adapters. As shown in the figure, the network adapter communicates with other modules of the computer device via a bus. It should be understood that other hardware and / or software modules can be used in conjunction with the computer device, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0233] The processing unit executes various functional applications and data processing by running programs stored in the system memory, such as implementing a method for evaluating the quality of American ginseng based on multi-task deep learning provided in this embodiment of the invention.
[0234] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware, or by a program instructing related hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as a USB flash drive, a portable hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0235] The above-described embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for quality assessment of American ginseng based on multi-task deep learning, characterized in that, include: Prepare American ginseng samples from different origins and cut them into slices to obtain multiple American ginseng samples; each American ginseng sample includes several slices of American ginseng from the same origin; Near-infrared spectral data of each American ginseng sample were collected; and the ginsenoside content of each American ginseng sample was determined to obtain the label data of each American ginseng sample; wherein, the label data of the American ginseng sample includes the ginsenoside content and origin information of the American ginseng sample; Based on the collected near-infrared spectral data and the obtained label data, a quality detection model for American ginseng was constructed and trained. Based on the constructed American ginseng quality detection model, feature extraction was performed on the near-infrared spectral data of the American ginseng to be evaluated, and the origin traceability and ginsenoside content were predicted. The American ginseng quality detection model includes a backbone network for extracting feature information from the near-infrared spectral data of American ginseng, a classification head for tracing the origin of American ginseng, and a regression head for predicting the ginsenoside content of American ginseng. The backbone network includes three cascaded Res-Attention modules, each of which contains three sub-modules: a residual module, a self-attention module, and a channel attention module. The residual module is used to process the input near-infrared spectral data of American ginseng through convolutional layers and activation functions; the self-attention module is used to calculate the correlation between each position in the sequence and other positions, capturing global information and the dependencies between bands; the channel attention module is used to assign weights to each channel, highlighting important features relevant to the task. The input near-infrared spectral data of American ginseng is processed through convolutional layers and activation functions, specifically including: For the input near-infrared spectral data of American ginseng After processing by convolutional layers and activation functions, residual mappings are generated. Then Compared with the input near-infrared spectral data of American ginseng The sums are then processed by an activation function to generate the final output. ; The calculation of the correlation between each position in the sequence and other positions captures global information and inter-band dependencies, specifically including: The residual module output The convolutional layers generate query vector Q, key vector K, and value vector V, respectively. The similarity between query vector Q and key vector K is calculated by dot product to obtain the relevance score. ; The relevance scores are normalized using the softmax function to obtain the weighted features. ; Learnable parameters Adjusting the influence of the self-attention mechanism before outputting, i.e. ; The process of assigning weights to each channel to highlight important task-related features specifically includes: The output of the self-attention module Global average pooling is used to obtain the global features of each channel. , expressed as: , where x c The data input to the channel attention module is c, where c is the number of channels and L is the feature length of each channel. Global features Channel weights are generated using two 1x1 convolutional layers and a sigmoid function: ; The output after channel weighting is: .
2. The method for quality assessment of American ginseng based on multi-task deep learning according to claim 1, characterized in that, The final loss function of the American ginseng quality inspection model is designed as a weighted sum of the classification task loss and the regression task loss: ; Where α and β are the loss weights for classification and regression tasks, respectively, both set to 0.
5.
3. The method for evaluating the quality of American ginseng based on multi-task deep learning according to claim 1, characterized in that, The collection of near-infrared spectral data for each American ginseng sample specifically includes: Near-infrared spectral data of each American ginseng sample were acquired in the range of 950 to 1650 nm with a resolution of 0.5 nm, and the original spectral data were reduced from 1401 dimensions to 280 dimensions using a sliding window technique. After collecting the near-infrared spectral data of each American ginseng sample, the process further includes: preprocessing the near-infrared spectral data, specifically as follows: The 280-dimensional near-infrared spectral data were preprocessed using Savitsky-Gorye smoothing and differentiation, standard normal transformation, and Z-fraction normalization.
4. The method for quality assessment of American ginseng based on multi-task deep learning according to claim 3, characterized in that, Before extracting features from the near-infrared spectral data of the American ginseng to be evaluated based on the constructed American ginseng quality detection model, and before performing origin traceability and predicting ginsenoside content, the following steps are also included: All American ginseng samples were divided according to a predetermined ratio into a training set for training the American ginseng quality detection model, a validation set for verifying the training effect after each round of model training, and a test set for testing the trained American ginseng quality detection model; and The constructed American ginseng quality detection model was evaluated using a test set.
5. The method for evaluating the quality of American ginseng based on multi-task deep learning according to claim 4, characterized in that, The evaluation of the constructed American ginseng quality detection model using a test set specifically includes: The near-infrared spectral data of the collected test set were input into the trained American ginseng quality detection model to evaluate its performance in tracing the origin of American ginseng and predicting its ginsenoside content. Specific evaluation parameters included those for the origin tracing task, the ginsenoside content prediction task, and the ginsenoside content prediction task. The specific parameters in the origin traceability task include: Overall accuracy, representing the proportion of correctly classified samples in the test set, is as follows: ,in, is the number of samples correctly classified into class i, c is the number of classes, and N is the number of samples in the test set; Precision, used to measure the proportion of correctly predicted positive samples out of all samples predicted positive, i.e.: ,in, It is the number of samples misclassified into class i; Recall is a measure of the proportion of correctly predicted positive samples among all true positive samples. ,in, This is the number of samples that truly belong to class i but have been misclassified: The parameters in the ginsenoside content prediction task specifically include: The coefficient of determination measures the goodness of fit between the predicted and actual values. ; Root mean square error (RMSE) measures the error between the predicted and actual values. ; Residual prediction bias is used to represent the stability of model predictions, i.e.: ; In the above formula, N is the total number of test samples. and These are the true value and the predicted value of the i-th sample, respectively. and The mean of the true and predicted values of the test sample; The process of constructing and training a quality detection model for American ginseng based on the collected near-infrared spectral data and the obtained label data is specifically implemented as follows: A quality detection model for American ginseng was constructed and trained based on the near-infrared spectral data and label data in the training set.
6. The method for quality assessment of American ginseng based on multi-task deep learning according to claim 5, characterized in that, The process of dividing all American ginseng samples into a training set for training the American ginseng quality detection model, a validation set for verifying the training effect after each round of model training, and a test set for testing the trained American ginseng quality detection model, specifically includes: All American ginseng samples were divided into training, validation, and test sets in a 5:1:4 ratio. The Kennard-Stone method is used to ensure uniform sample distribution, and the number of training set samples is increased by unsupervised spectral data enhancement.
7. A computer-readable storage medium storing at least one instruction, characterized in that, The instructions are loaded and executed by the processor to implement a method for evaluating the quality of American ginseng based on multi-task deep learning as described in any one of claims 1-6.
8. A computer program product, including a computer program / instruction, characterized in that, When the computer program / instruction is executed by the processor, it implements the American ginseng quality assessment method based on multi-task deep learning as described in any one of claims 1-6.