A hyperspectral detection method for authenticity of traditional Chinese medicine based on neural network
By using multi-level convolutional layers, double-branch attention network and feature cross-fusion network in the authenticity detection of traditional Chinese medicine materials, the spatial and spectral characteristics of traditional Chinese medicine hyperspectral images are extracted, and the low detection accuracy and feature fusion efficiency in the existing technology are solved. The problem has achieved more efficient detection of authenticity of traditional Chinese medicine.
Patent Information
- Application Number
- CN202411346579.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-26
- Publication Date
- 2024-12-06
- Estimated Expiration
- 2044-09-26
AI Technical Summary
The existing Chinese medicine authenticity detection methods are difficult to achieve high detection accuracy when facing subtle spectral characteristics, and the fusion efficiency of spatial and spectral characteristics of different scales is low, resulting in some features loss.
Using the neural network-based hyperspectral detection method for authenticity of traditional Chinese medicine, the spatial and spectral characteristics of traditional Chinese medicine hyperspectral images are extracted through multi-level convolutional layers, dual-branch attention network and feature cross-fusion network, and deep feature fusion is carried out to improve the Detection accuracy.
It effectively improves the accuracy of authenticity detection of traditional Chinese medicine, can more precisely segment and classify traditional Chinese medicinal materials, and improves the efficiency and accuracy of detection.
Smart Images

Figure CN118865143B_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of automated processing of Chinese medicinal materials, and in particular relates to a hyperspectral detection method for authenticity of Chinese medicinal materials based on a neural network. Background Art
[0002] At present, the authenticity detection of traditional Chinese medicine is mainly based on physical and chemical analysis, but this method has the pain points of long identification time and destructiveness to traditional Chinese medicine. Therefore, non-destructive and efficient authenticity detection of traditional Chinese medicine has become an urgent problem to be solved. In order to achieve efficient, accurate and non-destructive detection of the authenticity of traditional Chinese medicine, this method uses a hyperspectral imaging system to collect traditional Chinese medicine data, and then uses a dual-branch attention and feature cross-fusion network for efficient, accurate and automated segmentation detection.
[0003] The purpose of Chinese medicine authenticity detection is to separate counterfeits from genuine products. The authenticity detection method of Chinese medicine based on RGB images is to extract features from Chinese medicine RGB images using deep neural networks such as Resnet50, and then perform detection analysis. This method often fails to achieve good results when facing the authenticity detection task of detecting samples with small feature differences. In recent years, the rapid development of hyperspectral imaging technology has improved human ability to understand the world. The quality detection method of Chinese medicine that combines hyperspectral imaging technology with semantic segmentation has the advantages of high detection accuracy, fast detection speed and wide detection range, and has become a very promising method. 1DCNN uses the spectral data of hyperspectral images as pixel-level spectral vector input and extracts features from spectral information to complete the image classification task. R-PCA-CNN integrates the spatial information extraction module based on 1DCNN. By introducing random component analysis (R-PCA) before CNN, the spatial and spectral features of hyperspectral images can be combined. Recently, the Transformer-based method Sert introduces the attention mechanism into segmentation detection, and captures the contextual information of the image through the attention mechanism to achieve more accurate segmentation and classification.
[0004] In the field of authenticity detection of traditional Chinese medicine, the authenticity detection method based on hyperspectral images has been widely used and can perform non-destructive and efficient detection of traditional Chinese medicine. However, there are still some problems with the current hyperspectral detection method of traditional Chinese medicine, including the low efficiency of using the spatial information and spectral information of hyperspectral images of traditional Chinese medicine, which makes it difficult to achieve high detection accuracy when facing the authenticity of traditional Chinese medicine with only slight differences in spectral features. At the same time, when fusing spatial features and spectral features of different scales, the current method is mainly weighted summation, which does not take into account the differences between the features of the two different scales, resulting in the loss of some features. Summary of the invention
[0005] In view of the above technical problems, the present invention provides a hyperspectral detection method for authenticity of traditional Chinese medicine based on neural network.
[0006] The technical solution adopted by the present invention to solve the technical problem is:
[0007] A method for detecting the authenticity of traditional Chinese medicines by hyperspectral detection based on a neural network, the method comprising the following steps:
[0008] S100: Acquire the hyperspectral image of the Chinese medicine to be detected and add labels to obtain the original hyperspectral dataset of Chinese medicine;
[0009] S200: preprocessing the original traditional Chinese medicine hyperspectral dataset to obtain a preprocessed dataset;
[0010] S300: Build a hyperspectral detection neural network model, including multi-level convolutional layers, a dual-branch attention network, a feature cross-fusion network and a prediction module. The multi-level convolutional layer is used to learn local features to obtain intermediate features. The dual-branch attention network is used to extract spatial features and spectral features based on intermediate features to obtain deep spatial features and deep spectral features. The feature cross-fusion network is used to fuse deep spatial features and deep spectral features to obtain deep features. The deep features are used by the prediction module to obtain the category label prediction of each pixel.
[0011] S400: The hyperspectral detection neural network model is trained based on the preprocessed data set and the preset loss function, and the network parameters are updated by back propagation to obtain the trained hyperspectral detection neural network model, and the authenticity detection of Chinese medicinal materials is completed based on the trained hyperspectral detection neural network model.
[0012] Preferably, S200 includes:
[0013] The original hyperspectral image of traditional Chinese medicine is corrected by using whiteboard correction and blackboard correction to eliminate the influence of illumination change and voltage fluctuation of data acquisition equipment on data acquisition. Specifically:
[0014] ;
[0015] in, is the original hyperspectral image of traditional Chinese medicine. A completely black image. For all white images, The data are corrected.
[0016] Preferably, S300 includes:
[0017] S310: The hyperspectral image of traditional Chinese medicine is subjected to local feature learning through a multi-level convolutional layer and the spatial resolution of the feature map is reduced to obtain intermediate features;
[0018] S320: Expand the intermediate features along the spatial dimension and the spectral dimension respectively to obtain an original spatial feature sequence and an original spectral feature sequence, and then perform spatial context information learning on the original spatial feature sequence through a spatial attention branch to obtain deep spatial features, and perform spectral context information learning on the original spectral feature sequence through a spectral attention branch to obtain deep spectral features;
[0019] S330: The deep spatial features and the deep spectral features are fused through a feature cross fusion network to obtain deep features;
[0020] S340: The deep features are then passed through a feature upsampling layer to obtain global deep features, and the global feature vector is mapped to a category score vector through a linear layer, and activated through a Softmax layer to obtain a predicted label for each pixel.
[0021] Preferably, the multi-level convolutional layer in S310 includes a convolutional layer and a downsampling layer. The convolutional layer is used to extract local features from the input hyperspectral image. The downsampling layer applies maximum pooling to the input local features to obtain the original low-resolution features fused with the global features, applies 2D convolution to the original low-resolution features for feature enhancement, and concatenates the enhanced low-resolution features and the original low-resolution features through residual connections to obtain new low-resolution features.
[0022] Preferably, S310 specifically includes:
[0023] ;
[0024] in, is the intermediate feature, As the input hyperspectral image, Represents a multi-level convolutional layer.
[0025] Preferably, S320 includes:
[0026] S321: Expand the intermediate features along the spatial dimension and the spectral dimension respectively to obtain the original spatial feature sequence and the original spectral feature sequence, specifically:
[0027] ;
[0028] ;
[0029] in, is the intermediate feature, is the original spatial feature sequence, is the original spectral feature sequence, is the shape change operation;
[0030] S322: The original spatial feature sequence is subjected to spatial context information learning through the spatial attention branch to obtain deep spatial features, specifically:
[0031] ;
[0032] in, is the deep space feature, is the original spatial feature sequence, represents the spatial attention branch, and has:
[0033] ;
[0034] ;
[0035] ;
[0036] ;
[0037] ;
[0038] in, are the query, key, and value of attention respectively, for Activation function, , are the weight parameters learned by the linear layer for the input features, represents a linear layer, For the spatial attention branch The output, is the input feature, corresponding to , , ;
[0039] S323: The original spectral feature sequence is subjected to spectral context information learning through the spectral attention branch to obtain deep spectral features, specifically:
[0040] ;
[0041] in, is the deep spectral feature, is the original spectral feature sequence, represents the spectral attention branch, and has:
[0042] ;
[0043] ;
[0044] ;
[0045] ;
[0046] ;
[0047] in, are the query, key, and value of attention respectively, for Activation function, , are the weight parameters learned by the linear layer for the input features, represents a linear layer, Spectral attention branch The output, is the input feature, corresponding to , , .
[0048] Preferably, S330 specifically includes:
[0049] ;
[0050] in, is the deep feature after feature fusion, is the deep space feature, is the deep spectral feature, represents a feature cross-fusion network, where:
[0051] ;
[0052] ;
[0053] ;
[0054] ;
[0055] ;
[0056] in, is the deep space feature, is the deep spectral feature, is the maximum pooling operation, for Convolution operation, for Activate the operation, is the deep spatial feature weight, Deep spectral feature weights, To enhance the deep spatial features, For the enhanced deep spectral features, It is the deep feature after feature cross fusion.
[0057] Preferably, the feature upsampling layer in S340 uses bilinear interpolation to restore the spatial resolution of the input deep features to the same size as the input hyperspectral image.
[0058] Preferably, S400 includes:
[0059] S410: Input the preprocessed data into the hyperspectral detection neural network model to obtain the predicted probability of the category label corresponding to the input data;
[0060] S420: applying a preset loss function to the predicted probability of the class label of the network model and the class label in the real label, and calculating the difference between the model prediction and the real label;
[0061] S430: According to the difference between the model prediction and the true label, the gradient of the difference with respect to each parameter in each layer of the network is calculated. The specific formula is as follows:
[0062] ;
[0063] Among them, L is the preset loss function, is the calculated difference value, is the derivative of the activation function, is the output value of the network layer. To seek guidance;
[0064] S440: Update network weights. The specific formula is as follows:
[0065] ;
[0066] in For the The original weights of the layer network, For the The derivative of the original weight of the layer network with respect to the loss function, is the preset learning rate, its value is 0.02;
[0067] S450: Repeat the above steps for 300 rounds and the training is completed.
[0068] Preferably, the preset loss function is specifically:
[0069] ;
[0070] Where L is the loss value, is the real label The value of a pixel, such as 1 for a genuine product and 2 for a fake product; For the model The pixel is predicted as the probability of each class label; Represents the sum; the smaller the loss value L, the smaller the difference between the model prediction and the true label.
[0071] The above-mentioned method for hyperspectral detection of the authenticity of traditional Chinese medicine based on neural network builds a hyperspectral detection neural network model, proposes a dual-branch attention network and a feature cross-fusion network, and combines convolution and attention to better extract the local and contextual features of space and spectrum in the hyperspectral images of traditional Chinese medicine, so that the neural network model obtains features in more spatial and spectral dimensions, and performs efficient feature extraction and feature cross-fusion on the spatial and spectral features of the hyperspectral images of traditional Chinese medicine, effectively improving the accuracy of authenticity detection of traditional Chinese medicine. BRIEF DESCRIPTION OF THE DRAWINGS
[0072] Figure 1 This is a flow chart of a method for detecting the authenticity of Chinese medicinal materials using a neural network based hyperspectral method in one embodiment of the present invention;
[0073] Figure 2 is an original hyperspectral image in one embodiment of the present invention;
[0074] Figure 3 for Figure 2 The annotations corresponding to the original hyperspectral image shown;
[0075] Figure 4 for Figure 2 An example of detection results corresponding to the original hyperspectral image shown;
[0076] Figure 5 for Figure 2 The corrected hyperspectral image obtained from the original hyperspectral image shown;
[0077] Figure 6 Schematic diagram of the training process of a dual-branch attention and feature cross-fusion network in one embodiment of the present invention. DETAILED DESCRIPTION
[0078] In order to enable those skilled in the art to better understand the technical solution of the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings.
[0079] In one embodiment, Figure 1 As shown, a method for detecting the authenticity of Chinese medicinal materials by hyperspectral method based on neural network comprises the following steps:
[0080] S100: Acquire the hyperspectral image of the Chinese medicine to be tested and add labels to obtain the original hyperspectral data set of Chinese medicine; further, the hyperspectral spectrum contains many spectral bands. In this embodiment, the near-infrared spectral range is used. First, simulate the genuine adulteration, add different mass percentages of counterfeit products into the genuine product, and obtain the binary adulteration of the test sample; collect the near-infrared spectrum of the sample binary adulteration, annotate and add labels as the original hyperspectral data set of Chinese medicine; Figures 2 to 4 As shown;
[0081] S200: preprocessing the original traditional Chinese medicine hyperspectral dataset to obtain a preprocessed dataset;
[0082] S300: Build a hyperspectral detection neural network model, including multi-level convolutional layers, a dual-branch attention network, a feature cross-fusion network and a prediction module. The multi-level convolutional layer is used to learn local features to obtain intermediate features. The dual-branch attention network is used to extract spatial features and spectral features based on intermediate features to obtain deep spatial features and deep spectral features. The feature cross-fusion network is used to fuse deep spatial features and deep spectral features to obtain deep features. The deep features are used by the prediction module to obtain the category label prediction of each pixel.
[0083] S400: The hyperspectral detection neural network model is trained based on the preprocessed data set and the preset loss function, and the network parameters are updated by back propagation to obtain a trained hyperspectral detection neural network model, and the authenticity detection of Chinese medicinal materials is completed based on the trained hyperspectral detection neural network model.
[0084] The above-mentioned method for hyperspectral detection of the authenticity of traditional Chinese medicine based on neural network builds a hyperspectral detection neural network model, proposes a dual-branch attention network and a feature cross-fusion network, and combines convolution and attention to better extract the local and contextual features of space and spectrum in the hyperspectral images of traditional Chinese medicine, so that the neural network model obtains features in more spatial and spectral dimensions, and performs efficient feature extraction and feature cross-fusion on the spatial and spectral features of the hyperspectral images of traditional Chinese medicine, effectively improving the accuracy of authenticity detection of traditional Chinese medicine.
[0085] In one embodiment, S200 includes:
[0086] The original hyperspectral image of traditional Chinese medicine is corrected by using whiteboard correction and blackboard correction to eliminate the influence of illumination change and voltage fluctuation of data acquisition equipment on data acquisition. Specifically:
[0087] ;
[0088] in, is the original hyperspectral image of traditional Chinese medicine. A completely black image. For all white images, The data are corrected.
[0089] Specifically, the full black image refers to a full black calibration image with a reflectivity of about 0 obtained by covering the camera lens, and the full white image refers to a full white calibration image with a reflectivity of about 1 obtained by placing a white plate, such as Figure 5 shown.
[0090] In one embodiment, Figure 6 As shown, S300 includes:
[0091] S310: Hyperspectral images of traditional Chinese medicine Through multi-level convolutional layers, local features are learned and the spatial resolution of feature maps is reduced to obtain intermediate features. ;in, is the width of the input hyperspectral image, is the height of the input hyperspectral image, is the number of channels of the input hyperspectral image, is the width of the middle feature, The height of the middle feature, is the number of channels of the intermediate features;
[0092] S320: Expand the intermediate features along the spatial dimension and the spectral dimension respectively to obtain the original spatial feature sequence and the original spectral feature sequence , and then the original spatial feature sequence is used to learn the spatial context information through the spatial attention branch SSA to obtain the deep spatial feature The original spectral feature sequence is passed through the spectral attention branch SEA to learn the spectral context information and obtain the deep spectral feature ;
[0093] S330: The deep spatial features and deep spectral features are fused through the feature cross fusion network CFF to obtain the deep features. ;
[0094] S340: The deep features are then passed through the feature upsampling layer FUS to obtain the global deep features The global feature vector is mapped into a category score vector through a linear layer, and the predicted label of each pixel is obtained through activation of the Softmax layer.
[0095] In one embodiment, the multi-level convolutional layer in S310 includes a convolutional layer and a downsampling layer. The convolutional layer is used to extract local features from the input hyperspectral image. The downsampling layer applies maximum pooling to the input local features to obtain original low-resolution features fused with global features. 2D convolution is applied to the original low-resolution features for feature enhancement. The enhanced low-resolution features and the original low-resolution features are spliced with residual connections to obtain new low-resolution features.
[0096] Specifically, Figure 6 As shown, three convolutional layers SC from SC1 to SC3 are used for exemplary description.
[0097] In one embodiment, S310 specifically includes:
[0098] ;
[0099] in, is the intermediate feature, As the input hyperspectral image, Represents a multi-level convolutional layer.
[0100] In one embodiment, S320 includes:
[0101] S321: Expand the intermediate features along the spatial dimension and the spectral dimension respectively to obtain the original spatial feature sequence and the original spectral feature sequence, specifically:
[0102] ;
[0103] ;
[0104] in, is the intermediate feature, is the original spatial feature sequence, is the original spectral feature sequence, is the shape change operation;
[0105] S322: The original spatial feature sequence is subjected to spatial context information learning through the spatial attention branch to obtain deep spatial features, specifically:
[0106] ;
[0107] in, is the deep space feature, is the original spatial feature sequence, represents the spatial attention branch, and has:
[0108] ;
[0109] ;
[0110] ;
[0111] ;
[0112] ;
[0113] in, are the query, key, and value of attention respectively, for Activation function, , are the weight parameters learned by the linear layer for the input features, represents a linear layer, For the spatial attention branch The output, is the input feature, corresponding to , , ;
[0114] S323: The original spectral feature sequence is subjected to spectral context information learning through the spectral attention branch to obtain deep spectral features, specifically:
[0115] ;
[0116] in, is the deep spectral feature, is the original spectral feature sequence, represents the spectral attention branch, and has:
[0117] ;
[0118] ;
[0119] ;
[0120] ;
[0121] ;
[0122] in, are the query, key, and value of attention respectively, for Activation function, , are the weight parameters learned by the linear layer for the input features, represents a linear layer, Spectral attention branch The output, is the input feature, corresponding to , , .
[0123] In one embodiment, S330 specifically includes:
[0124] ;
[0125] in, is the deep feature after feature fusion, For deep space features, is the deep spectral feature, represents a feature cross-fusion network, where:
[0126] ;
[0127] ;
[0128] ;
[0129] ;
[0130] ;
[0131] in, For deep space features, is the deep spectral feature, is the maximum pooling operation, for Convolution operation, for Activate the operation, is the deep spatial feature weight, Deep spectral feature weights, To enhance the deep spatial features, For the enhanced deep spectral features, It is the deep feature after feature cross fusion.
[0132] In one embodiment, the feature upsampling layer in S340 uses bilinear interpolation to restore the spatial resolution of the input deep features to the same size as the input hyperspectral image.
[0133] In one embodiment, S400 includes:
[0134] S410: Input the preprocessed data into the hyperspectral detection neural network model to obtain the predicted probability of the category label corresponding to the input data;
[0135] S420: applying a preset loss function to the predicted probability of the class label of the network model and the class label in the real label, and calculating the difference between the model prediction and the real label;
[0136] S430: According to the difference between the model prediction and the true label, the gradient of the difference with respect to each parameter in each layer of the network is calculated. The specific formula is as follows:
[0137] ;
[0138] Among them, L is the preset loss function, is the calculated difference value, is the derivative of the activation function, is the output value of the network layer. To seek guidance;
[0139] S440: Update network weights. The specific formula is as follows:
[0140] ;
[0141] in For the The original weights of the layer network, For the The derivative of the original weight of the layer network with respect to the loss function, is the preset learning rate, its value is 0.02;
[0142] S450: Repeat the above steps for 300 rounds and the training is completed.
[0143] In this embodiment, during training, use The optimizer is used to train the hierarchical neural model, with a learning rate of 0.001, a momentum parameter of 0.9, a weight decay of 0.0001, a batch size of 2, and a regularization λ of 0.5. During the test, the hyperspectral image is sent to the trained feature extraction model after data preprocessing, and the hyperspectral image is converted into a feature vector representation, and finally sent to the classifier for prediction. The cross entropy loss is used to calculate the loss of the classifier, and the average interaction ratio mIoU and accuracy Acc are used for training and evaluation. The network model based on dual-branch attention and feature cross-fusion has good performance and usability in the task of authenticity detection of traditional Chinese medicine, and can provide support for the automated analysis and intelligent detection of the quality of traditional Chinese medicine.
[0144] In one embodiment, the preset loss function is specifically:
[0145] ;
[0146] Where L is the loss value, is the real label The value of a pixel, such as 1 for a genuine product and 2 for a fake product; For the model The pixel is predicted as the probability of each class label; Represents the sum; the smaller the loss value L, the smaller the difference between the model prediction and the true label.
[0147] mIoU is specifically:
[0148] ;
[0149] in represents the categories of all samples, Represents the true category Predicted as category , Represents the true category Predicted as category , Represents the true category Predicted as category .
[0150] The accuracy Acc is specifically:
[0151] ;
[0152] in represents the categories of all samples, Represents the true category Predicted as category , Represents the true category Predicted as category , Represents the true category Predicted as category .
[0153] Furthermore, after the model is established, only the hyperspectral image of the sample to be tested is needed to accurately identify the sample and its adulterants. It has the advantages of being objective, simple, fast and non-destructive, and can be used for batch identification.
[0154] During the experiment, the results of the method of this embodiment were compared with those of the prior art, as shown in Table 1:
[0155] Table 1
[0156]
[0157] In Table 1, Unet and DeepLabv3 are both existing well-known convolution-based methods, SegFormer, Mask2Former and Spectral are all existing well-known Transformer-based methods, and Our is the test result of the method of this embodiment. As shown in Table 1, the detection accuracy of this embodiment has achieved better results in terms of average cross entropy loss MIoU and accuracy MAcc compared with the existing well-known methods. Therefore, the dual-branch attention and feature cross-fusion network of this embodiment has good performance and usability in the task of authenticity of traditional Chinese medicine, and can provide support for automated analysis and intelligent diagnosis of quality detection of traditional Chinese medicine. In addition, an ablation experiment was designed for the dual-branch attention and feature cross-fusion network of this embodiment, and the experimental results are shown in Table 2.
[0158] Table 2 Ablation experiment results
[0159]
[0160] In Table 2, " "Selected means that the module is not included in the model," " " represents that the module is not added to the model, SSA and SEA represent the addition of the spatial attention branch SSA and the spectral attention branch SEA, and CFF represents the addition of the feature cross fusion layer CCF. As shown in Table 2, the spatial attention branch SSA, the spectral attention branch SEA and the feature cross fusion layer CFF of the method in this embodiment can significantly improve the two-phase indicators of average cross entropy loss MIoU and accuracy MAcc. Therefore, the dual-branch attention and feature cross fusion network of this embodiment has good performance and usability in the task of authenticity detection of traditional Chinese medicine, and can provide support for automated analysis and intelligent diagnosis of quality detection of traditional Chinese medicine.
[0161] In summary, the hyperspectral detection method for authenticity of traditional Chinese medicine in this embodiment includes using a dual-branch attention and feature cross-fusion network to detect the authenticity of traditional Chinese medicine, including passing the hyperspectral image of the traditional Chinese medicine to be detected through a multi-level convolutional layer The local features are learned and the spatial resolution of the feature map is reduced. The output features are then expanded along the spatial and spectral dimensions to obtain the original spatial feature sequence and the original spatial feature sequence. The spatial attention branch SAA is used to learn the spatial context information of the original spatial feature sequence to obtain the deep spatial features. At the same time, the spectral attention branch SEA is used to learn the spectral context information of the original spectral feature sequence to obtain the deep spectral features. The deep spatial features and deep spectral features are passed through the feature cross fusion layer CFF and the feature upsampling layer FUS to obtain the deep global features with the same spatial resolution as the input hyperspectral image, and mapped to the category score vector through the linear layer. After activation by the Softmax layer, the predicted label of each pixel is obtained. The hyperspectral detection method for authenticity of traditional Chinese medicine in this embodiment is based on the dual-branch attention and feature cross fusion network for authenticity detection of traditional Chinese medicine. It can efficiently extract the spatial and spectral features of hyperspectral images and can perform efficient and refined detection of authentic traditional Chinese medicine. On the constructed hyperspectral detection dataset of traditional Chinese medicine authenticity, the mIoU of traditional Chinese medicine authenticity detection is increased from 92.6% to 98.3%.
[0162] The above is a detailed introduction to a method for detecting the authenticity of Chinese medicinal materials based on a neural network using high-spectral spectra. This article uses specific examples to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the core idea of the present invention. It should be pointed out that for those skilled in the art, several improvements and modifications can be made to the present invention without departing from the principles of the present invention, and these improvements and modifications also fall within the scope of protection of the claims of the present invention.
Claims
1. A method for detecting the authenticity of Chinese herbal medicines by using a hyperspectral method based on a neural network, characterized in that: The method comprises the following steps: S100: Acquire the hyperspectral image of the Chinese medicine to be detected and add labels to obtain the original hyperspectral dataset of Chinese medicine; S200: preprocessing the original traditional Chinese medicine hyperspectral dataset to obtain a preprocessed dataset; S300: Build a hyperspectral detection neural network model, including multi-level convolutional layers, a dual-branch attention network, a feature cross-fusion network and a prediction module. The multi-level convolutional layer is used to learn local features to obtain intermediate features. The dual-branch attention network is used to extract spatial features and spectral features based on intermediate features to obtain deep spatial features and deep spectral features. The feature cross-fusion network is used to fuse deep spatial features and deep spectral features to obtain deep features. The deep features are used by the prediction module to obtain the category label prediction of each pixel. S400: training the hyperspectral detection neural network model based on the preprocessed data set and the preset loss function, back-propagating to update the network parameters, obtaining a trained hyperspectral detection neural network model, and completing the authenticity detection of Chinese medicinal materials based on the trained hyperspectral detection neural network model; S400 includes: S410: Input the preprocessed data into the hyperspectral detection neural network model to obtain the predicted probability of the category label corresponding to the input data; S420: applying a preset loss function to the predicted probability of the class labels of the network model and the class labels in the real labels, and calculating the difference between the model prediction and the real labels; S430: According to the difference between the model prediction and the true label, the gradient of the difference with respect to each parameter in each layer of the network is calculated. The specific formula is as follows: ; Among them, L is the preset loss function, is the calculated difference value, is the derivative of the activation function, is the output value of the network layer. To seek guidance; S440: Update network weights. The specific formula is as follows: ; in For the The original weights of the layer network, For the The derivative of the original weight of the layer network with respect to the loss function, is the preset learning rate, its value is 0.02; S450: Repeat the above steps for 300 rounds and the training is completed.
2. The method according to claim 1, characterized in that S200 includes: The original hyperspectral image of traditional Chinese medicine is corrected by using whiteboard correction and blackboard correction to eliminate the influence of illumination change and voltage fluctuation of data acquisition equipment on data acquisition. Specifically: ; in, is the original hyperspectral image of traditional Chinese medicine. A completely black image. For all white images, The data are corrected.
3. The method according to claim 2, characterized in that S300 includes: S310: The hyperspectral image of traditional Chinese medicine is subjected to local feature learning through a multi-level convolutional layer and the spatial resolution of the feature map is reduced to obtain intermediate features; S320: Expand the intermediate features along the spatial dimension and the spectral dimension respectively to obtain an original spatial feature sequence and an original spectral feature sequence, and then perform spatial context information learning on the original spatial feature sequence through a spatial attention branch to obtain deep spatial features, and perform spectral context information learning on the original spectral feature sequence through a spectral attention branch to obtain deep spectral features; S330: The deep spatial features and the deep spectral features are fused through a feature cross fusion network to obtain deep features; S340: The deep features are then passed through a feature upsampling layer to obtain global deep features, and the global feature vector is mapped to a category score vector through a linear layer, and activated through a Softmax layer to obtain a predicted label for each pixel.
4. The method according to claim 3, characterized in that The multi-level convolutional layers in S310 include convolutional layers and downsampling layers. The convolutional layers are used to extract local features from the input hyperspectral image. The downsampling layers apply maximum pooling to the input local features to obtain the original low-resolution features fused with the global features. 2D convolution is applied to the original low-resolution features for feature enhancement. The enhanced low-resolution features and the original low-resolution features are concatenated with the residual connection to obtain new low-resolution features.
5. The method according to claim 4, characterized in that S310 is specifically: ; in, is the intermediate feature, As the input hyperspectral image, Represents a multi-level convolutional layer.
6. The method according to claim 4, characterized in that S320 includes: S321: Expand the intermediate features along the spatial dimension and the spectral dimension respectively to obtain the original spatial feature sequence and the original spectral feature sequence, specifically: ; ; in, is the intermediate feature, is the original spatial feature sequence, is the original spectral feature sequence, is the shape change operation; S322: The original spatial feature sequence is subjected to spatial context information learning through the spatial attention branch to obtain deep spatial features, specifically: ; in, For deep space features, is the original spatial feature sequence, represents the spatial attention branch, and has: ; ; ; ; ; in, are the query, key, and value of attention respectively, for Activation function, , are the weight parameters learned by the linear layer for the input features, represents a linear layer, For the spatial attention branch The output, is the input feature, corresponding to , , ; S323: The original spectral feature sequence is subjected to spectral context information learning through the spectral attention branch to obtain deep spectral features, specifically: ; in, is the deep spectral feature, is the original spectral feature sequence, represents the spectral attention branch, and has: ; ; ; ; ; in, are the query, key, and value of attention respectively, for Activation function, , are the weight parameters learned by the linear layer for the input features, represents a linear layer, Spectral attention branch The output, is the input feature, corresponding to , , .
7. The method according to claim 6, characterized in that S330 is specifically: ; in, is the deep feature after feature fusion, For deep space features, is the deep spectral feature, represents a feature cross-fusion network, where: ; ; ; ; ; in, For deep space features, is the deep spectral feature, is the maximum pooling operation, for Convolution operation, for Activate the operation, is the deep spatial feature weight, Deep spectral feature weights, For the enhanced deep spatial features, For the enhanced deep spectral features, It is the deep feature after feature cross fusion.
8. The method according to claim 7, characterized in that The feature upsampling layer in S340 uses bilinear interpolation to restore the spatial resolution of the input deep features to the same size as the input hyperspectral image.
9. The method according to claim 1, characterized in that: The preset loss function is: ; Where L is the loss value, is the real label The value of the pixel, the genuine product is 1, and the fake product is 2; For the model The pixel is predicted as the probability of each class label; The smaller the loss value L, the smaller the difference between the model prediction and the true label.
Citation Information
Patent Citations
Hyperspectral traditional Chinese medicinal material identification method based on two-channel compression attention network
CN115979973A
