A method for detecting tea moisture content based on spectral fusion and convolutional neural network
The tea moisture content detection method based on spectral fusion and convolutional neural network solves the problems of long traditional measurement time and low accuracy of single spectrum, and realizes fast, accurate and real-time detection of tea moisture content.
Patent Information
- Application Number
- CN202510103071.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-22
- Publication Date
- 2025-09-30
- Estimated Expiration
- 2045-01-22
AI Technical Summary
Traditional methods of measuring tea moisture content are time-consuming and destroy tea nutrients. Single spectrum prediction has low accuracy and cannot achieve real-time detection.
Spectral fusion and convolutional neural network are used to construct tea atlas and texture feature datasets to perform low-level and mid-level feature fusion, and the moisture content of tea is predicted using Conv module, attention module and prediction module.
It achieves fast and accurate prediction of tea moisture content, supports real-time detection, reduces model redundant information, and improves prediction accuracy.
Smart Images

Figure CN119810669B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of tea processing, and in particular to a method for detecting the moisture content of tea leaves based on spectral fusion and convolutional neural networks. Background Art
[0002] Tea moisture content is a key parameter in assessing tea quality. An appropriate moisture content preserves the tea's aroma, flavor, and color. Excessively high or low moisture content can affect the tea's quality and flavor. By studying tea moisture content, we can determine the optimal moisture range, thereby improving the tea's quality and flavor.
[0003] The traditional method for measuring the moisture content of tea is to use the constant temperature oven method. The results of the constant temperature oven method are accurate, stable, and have small errors, but the measurement cycle is long, taking at least half an hour or even more. In addition, the internal nutrients of the tea will be destroyed during the high-temperature drying process, which cannot meet the needs of on-site real-time testing in tea processing, trade, storage, etc.
[0004] While some studies have used spectral technology to predict tea moisture content, these studies typically rely on a single spectrum, failing to fully utilize the spectral information, potentially resulting in low prediction accuracy. Furthermore, using full-band spectra to predict moisture content requires significant resources, making it difficult to implement on hardware for real-time tea moisture detection. Summary of the Invention
[0005] In order to address the shortcomings of the above-mentioned prior art, the present invention proposes a tea moisture content detection method based on spectral fusion and convolutional neural network, in order to achieve rapid and accurate prediction of tea moisture content, thereby improving the accuracy of tea moisture content prediction and laying a favorable foundation for real-time detection of tea moisture content during processing.
[0006] In order to achieve the above-mentioned object, the present invention adopts the following technical solutions:
[0007] The tea moisture content detection method based on spectral fusion and convolutional neural network of the present invention is characterized in that it is carried out according to the following steps:
[0008] Step 1: Construct a tea atlas fusion dataset ,in, represents the tea spectral feature dataset; Represents the tea texture feature dataset; the atlas fusion data of any tea sample is recorded as , where t represents the spectral feature vector of the tea sample, where Indicates the Spectral response of each band; Indicates the number of bands; represents the texture feature vector of the tea sample, where Indicates the Texture feature values; Represents the number of texture features; let the true moisture content of the tea sample be ;
[0009] Step 2: Calculate the normalized Texture features , thus obtaining the standardized texture feature vector ,in, is the mean value of the texture characteristics of the tea sample, is the standard deviation of the texture characteristics of the tea sample;
[0010] Step 3: and Perform fusion of different feature levels to obtain low-level fusion tea feature vectors and the intermediate fusion tea feature vector ;
[0011] Step 4: Perform correction to obtain the corrected low-level fusion feature vector ,in, Indicates the A corrected low-level fusion characteristic of tea leaves;
[0012] Step 5: Follow the process from step 4.1 to step 4.3 to Processing is performed to obtain the corrected intermediate fusion feature vector ,in, Indicates the A corrected mid-level blend of tea characteristics;
[0013] Step 6: Construct a tea moisture content prediction network, including Conv module, attention module and prediction module, and and Processing, the corresponding Predicted moisture content and Predicted moisture content ;
[0014] Step 7: Right and Take the weighted average to get the predicted moisture content mean ;in, The corresponding weight, express The corresponding weight;
[0015] Step 8: Based on and Constructing the mean square error loss function ;
[0016] Step 9: Fusion dataset based on tea atlas , use SGDM optimizer to train the tea moisture content prediction network and calculate the mean square error loss function To update the network parameters until the mean square error loss function The training process continues until convergence, thus obtaining a trained tea moisture content regression model and using it on the ZYNQ development board for regression prediction of tea moisture content.
[0017] The tea moisture content detection method based on spectral fusion and convolutional neural network described in the present invention is also characterized in that step 3 is performed as follows:
[0018] Step 3.1: and After splicing, we get the low-level fusion tea feature vector ;in, Indicates the A low-grade blend of tea characteristics; represents the number of features after low-level fusion; and ;
[0019] Step 3.2: Use SPA algorithm to and Perform feature screening to obtain the filtered spectral feature vector And the filtered texture feature vector ,in, After filtering Spectral characteristics of each band; Indicates the number of spectral features after screening; After filtering Texture values; Indicates the number of texture features after filtering;
[0020] Step 3.3: and After splicing, we get the intermediate fusion tea feature vector ,in, Indicates the A mid-level blend of tea characteristics; represents the number of features after low-level fusion; and .
[0021] Furthermore, step 4 is performed as follows:
[0022] Step 4.1: Calculate the feature mean of low-level fusion ;
[0023] Step 4.2: Build Linear regression equation ,in, For the Baseline offset, For the Baseline shift amount;
[0024] Step 4.3: Calculate the corrected Low-level fusion features .
[0025] Furthermore, step 6 is performed as follows:
[0026] Step 6.1: Input into the Conv module and pass through After processing by parallel convolution units, the spectral feature vector is obtained ,in, Representative The spectral features output by parallel convolution units;
[0027] Step 6.2: The attention module consists of fully connected layers, an element-wise addition layer, an adaptive compression layer, excitation layer, activation function SoftMax layer, element-wise multiplication layers, and Processing is performed to obtain the low-level fusion multiplication feature vector of tea leaves ;
[0028] Step 6.3: The prediction module consists of Fully connected layers;
[0029] Will After the low-level fusion features of each tea are spliced, they are expanded into a one-dimensional feature vector according to the channel dimension and input Dimensionality reduction is performed in the fully connected layers to obtain Predicted moisture content ;
[0030] Step 6.4: Follow the process from step 6.2 to step 6.3 to Processing to obtain Predicted moisture content .
[0031] Furthermore, step 6.2 is performed as follows:
[0032] Step 6.2.1: Input into the attention module, Fully connected layer pairs After unified dimension processing, we get Low-level fusion and integration characteristics of tea ; thus obtaining The same low-level fusion and integration characteristics of tea leaves ;
[0033] Step 6.2.2: Input into the element-by-element addition layer for processing to obtain the low-level fusion addition features of tea leaves ;
[0034] Step 6.2.3: Input into the adaptive compression layer for processing to obtain the low-level fusion adaptive compression features of tea leaves ;
[0035] Step 6.2.4: Enter respectively In the parallel excitation layers, we get Low-level fusion stimulation characteristics of tea ;in, Indicates the Individual tea leaves low-grade fusion excitation characteristics;
[0036] Step 6.2.5: Enter to The activation function SoftMax layer is processed to obtain the Low-level fusion normalized features of tea leaves ;
[0037] Step 6.2.6: and Enter to The element-by-element multiplication layer is used to process the low-grade fusion multiplication characteristics of tea , thus obtaining the low-level fusion multiplication feature vector of tea leaves .
[0038] The electronic device of the present invention includes a memory and a processor, and is characterized in that the memory is used to store a program that supports the processor to execute the tea moisture content detection method, and the processor is configured to execute the program stored in the memory.
[0039] The present invention provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, which is characterized in that the computer program executes the steps of the tea moisture content detection method when the computer program is run by a processor.
[0040] Compared with the prior art, the present invention has the following beneficial effects:
[0041] 1. This paper proposes a spectral fusion method. Hyperspectral images are captured in a darkroom to obtain spectral and texture data of tea leaves. These data contain characteristic information about the moisture content of the tea leaves. The two are fused at low and mid-level, respectively, and then weighted averaged. On the one hand, this method overcomes the limitations of a single spectrum, fully utilizes the rich spectral resources of hyperspectral images, and enhances the reliability of using spectral technology to predict tea moisture content. On the other hand, feature filtering reduces a large amount of redundant information, significantly reducing the number of parameters in the training process, making it easier to port to hardware and laying the foundation for rapid detection of tea moisture content.
[0042] 2. This paper designs a tea moisture content prediction model. Multiple parallel Conv modules extract spectral features at different scales. The output features are then fed into the prediction module through the fully connected layer, element-by-element addition layer, adaptive compression layer, excitation layer, activation function SoftMax layer, and element-by-element multiplication layer in the attention mechanism module. This approach allows the model to retain key information while reducing redundant features, improving the model's learning ability for tea spectral data and the accuracy of moisture content prediction. This enables non-invasive monitoring of tea moisture content, supporting intelligent control of the production process. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] Figure 1 It is a specific embodiment diagram of the present invention;
[0044] Figure 2 is a flow chart of the spectrum fusion method of the present invention;
[0045] Figure 3 This is a structural diagram of the tea moisture content prediction model of the present invention;
[0046] Figure 4 A diagram of a method for transplanting hardware for the model of the present invention. DETAILED DESCRIPTION
[0047] In this embodiment, a method for detecting the moisture content of tea leaves based on spectral fusion and convolutional neural network is provided. Figure 1As shown in the figure, the extraction and fusion of tea spectral features and texture features are realized on the PC side. The fusion features are trained using the designed prediction model. The model is transplanted to the ZYNQ development board, and the visual distribution of tea moisture content is realized. The HDMI cable is used to communicate with the ZYNQ development board, and the visual distribution of tea moisture content is displayed on the display.
[0048] The spectral acquisition device includes: a hyperspectral camera, two halogen lamps, two lamp stands, a shooting platform, and a calibration whiteboard. The tea moisture content detection method is performed according to the following steps:
[0049] Step 1: Construct a tea atlas fusion dataset ,in, represents the tea spectral feature dataset; Represents the tea texture feature dataset; the atlas fusion data of any tea sample is recorded as , where t represents the spectral feature vector of the tea sample, where Indicates the Spectral response of each band; Indicates the number of bands; Represents the texture feature vector of the tea sample, where Indicates the Texture feature values; Represents the number of texture features; let the true moisture content of the tea sample be ;
[0050] In this embodiment, the total sample size of the tea spectrum fusion dataset is 600, and the dimension of the tea spectrum feature vector is , the dimension of the tea texture feature vector calculated using the gray level co-occurrence matrix is ,include Angular second moment, entropy, contrast, inverse difference matrix, and correlation in four directions.
[0051] Step 2: Calculate the normalized Texture features , thus obtaining the standardized texture feature vector ,in, is the mean value of texture features of tea samples, is the standard deviation of the texture characteristics of tea samples;
[0052] Step 3: and Perform fusion of different feature levels to obtain low-level fusion tea feature vectors and the intermediate fusion tea feature vector ;
[0053] Step 3.1: and After splicing, we get the low-level fusion tea feature vector ;in, Indicates the A low-grade blend of tea characteristics; represents the number of features after low-level fusion; and c= + ;
[0054] Step 3.2: Use SPA algorithm to and Perform feature screening to obtain the filtered spectral feature vector And the filtered texture feature vector ,in, After filtering Spectral characteristics of each band; Indicates the number of spectral features after screening; After filtering Texture values; Indicates the number of texture features after filtering.
[0055] Step 3.3: and After splicing, we get the intermediate fusion tea feature vector ,in, Indicates the A mid-level blend of tea characteristics; Represents the number of features after low-level fusion; and d= + ;
[0056] In this embodiment, the low-level and intermediate fusion methods are as follows: Figure 2 As shown, the number of tea features after low-level fusion is 224; the dimension of the spectral feature vector after screening is , the selected features are 397.3, 420.3, 533.8, 566.1, 684.6, 756.5, 801.7, 819.9, 826.1, 859.4, 908.2, 988.1, 1003.5nm; the dimension of the texture feature vector after screening is , respectively, the entropy in the 0° direction, the angular second moment in the 45° direction, the correlation in the 90° direction, and the entropy in the 135° direction; the number of tea features after intermediate fusion is 17.
[0057] Step 4: Perform correction to obtain the corrected low-level fusion feature vector ,in, Indicates the A corrected low-level fusion characteristic of tea leaves;
[0058] Step 4.1: Calculate the feature mean of low-level fusion ;
[0059] Step 4.2: Build Linear regression equation ,in, For the Baseline offset, For the Baseline shift amount;
[0060] Step 4.3: Calculate the corrected Low-level fusion features .
[0061] Step 5: Follow the process from step 4.1 to step 4.3 to Processing is performed to obtain the corrected intermediate fusion feature vector ,in, Indicates the A corrected mid-level blend of tea characteristics;
[0062] Step 6: Construct a tea moisture content prediction network, including: Conv module, attention module and prediction module;
[0063] In this embodiment, the model is designed as follows Figure 3 As shown, the Conv module consists of 3 parallel Convs, the first Conv consists of 8 convolution kernels with a size of , a one-dimensional convolution layer with a stride of 1, a batch normalization layer, a ReLU activation function layer and a kernel size of , an average pooling layer with a step size of 1; the second Conv consists of 16 convolution kernels with a size of , a one-dimensional convolution layer with a stride of 1, a batch normalization layer, a ReLU activation function layer and a kernel size of , an average pooling layer with a step size of 1; the third Conv consists of 32 convolution kernels with a size of , a one-dimensional convolution layer with a stride of 1, a batch normalization layer, a ReLU activation function layer and a kernel size of , an average pooling layer with a step size of 1;
[0064] Step 6.1: Input into the Conv module and pass through After processing by parallel convolution units, the spectral feature vector is obtained ,in, Representative The spectral features output by parallel convolution units;
[0065] In this embodiment, Input into the Conv module and processed by three parallel Conv modules to obtain multi-scale spectral features , where low-level fusion 、 、 The dimensions are 、 、 .
[0066] Step 6.2: The attention module consists of fully connected layers, an element-wise addition layer, an adaptive compression layer, excitation layer, activation function SoftMax layer, element-wise multiplication layers;
[0067] Step 6.2.1: Input attention module, Fully connected layer pairs After unified dimension processing, we get Low-level fusion and integration characteristics of tea ; thus obtaining The same low-level fusion and integration characteristics of tea leaves ;
[0068] In this embodiment, the fully connected layer 、 、 After unified dimension processing, the same integrated features of the three dimensions are obtained. 、 、 .
[0069] Step 6.2.2: Input into the element-by-element addition layer for processing to obtain the low-level fusion addition features of tea leaves In this embodiment, the element-by-element addition layer is processed to obtain the added feature , the dimension is .
[0070] Step 6.2.3: Input into the adaptive compression layer for processing to obtain the low-level fusion adaptive compression features of tea leaves ;
[0071] In this embodiment, the adaptive compression feature is obtained after the adaptive compression layer is processed. , the dimension is ;
[0072] Step 6.2.4: Enter respectively In the parallel excitation layers, we get Low-level fusion stimulation characteristics of tea ;in, Indicates the Individual tea leaves low-grade fusion excitation characteristics;
[0073] In this embodiment, after three parallel excitation layers, the convolution kernel sizes of the one-dimensional convolution layers in the three parallel excitation layers are all , the step size is 1, the number of convolution kernels is 1, and we get The dimension is .
[0074] Step 6.2.5: Enter to The activation function SoftMax layer is processed to obtain the Low-level fusion normalized features of tea leaves In this embodiment, 、 、 Normalized features are obtained after processing with the SoftMax activation function 、 、 .
[0075] Step 6.2.6: and Enter to The element-by-element multiplication layer is used to process the low-grade fusion multiplication characteristics of tea , thus obtaining the low-level fusion multiplication feature vector of tea leaves ;
[0076] In this embodiment, 、 、 and 、 、 Perform element-by-element multiplication to obtain the result of the low-level fusion feature vector after passing through the attention module 、 、 , the dimensions are 、 、 .
[0077] Step 6.3: The prediction module consists of fully connected layers; input into the prediction module, After the low-level fusion features of each tea are spliced, they are expanded into a one-dimensional feature vector according to the channel dimension and input into the fully connected layer for dimensionality reduction processing to obtain Predicted moisture content ;
[0078] Step 6.4: Follow the process of steps 6.2 to 6.3 to Processing to obtain Predicted moisture content ;
[0079] In this embodiment, the dimension of the intermediate fused spectral feature vector after passing through the Conv module is 、 、 The dimension of the tea leaves’ intermediate fusion multiplication feature vector after the attention module is 、 、 .
[0080] Step 7: Right and Take the weighted average to get the predicted moisture content mean ;in express The corresponding weight, express Corresponding weights; in this embodiment, .
[0081] Step 8: Based on and Constructing the mean square error loss function ;
[0082] Step 9: Fusion dataset based on tea atlas , use SGDM optimizer to train the tea moisture content prediction network and calculate the mean square error loss function To update the network parameters until the mean square error loss function The training process continues until convergence, thus obtaining a trained tea moisture content regression model and using it on the ZYNQ development board for regression prediction of tea moisture content.
[0083] In this embodiment, the mean square error loss function . Transplant this model to the ZYNQ development board. The specific implementation plan is as follows Figure 4As shown in the figure, the FPGA ROM stores a quantized weight file, which transmits the spectral data to the ZYNQ processing system module. The DDR memory module receives and stores the near-infrared spectral data, and the ARM processor completes the DDR read and write operations through a cyclic read and write state machine. The ARM processor module uses the Softmax operation to calculate the spectral features, obtain the tea moisture content, generate a distribution map, and transmit it to the HDMI display for display.
[0084] In this embodiment, an electronic device includes a memory and a processor, wherein the memory is used to store a program that supports the processor to execute the above method, and the processor is configured to execute the program stored in the memory.
[0085] In this embodiment, a computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the above method are executed.
Claims
1. A method for detecting tea moisture content based on spectral fusion and convolutional neural network, characterized in that: The steps are as follows: Step 1: Construct a tea atlas fusion dataset ,in, represents the tea spectral feature dataset; Represents the tea texture feature dataset; the atlas fusion data of any tea sample is recorded as , where t represents the spectral feature vector of the tea sample, where Indicates the Spectral response of each band; Indicates the number of bands; represents the texture feature vector of the tea sample, where Indicates the Texture feature values; Represents the number of texture features; let the true moisture content of the tea sample be ; Step 2: Calculate the normalized Texture features , thus obtaining the standardized texture feature vector ,in, is the mean value of the texture characteristics of the tea sample, is the standard deviation of the texture characteristics of the tea sample; Step 3: and Perform fusion of different feature levels to obtain low-level fusion tea feature vectors and the intermediate fusion tea feature vector ; Step 4: Perform correction to obtain the corrected low-level fusion feature vector ,in, Indicates the Corrected low-level fusion characteristics of tea leaves; Step 5: Follow the process from step 4.1 to step 4.3 to Processing is performed to obtain the corrected intermediate fusion feature vector ,in, Indicates the A corrected mid-level blend of tea characteristics; Step 6: Construct a tea moisture content prediction network, including Conv module, attention module and prediction module, and and Processing, the corresponding Predicted moisture content and Predicted moisture content ; Step 7: Right and Take the weighted average to get the predicted moisture content mean ;in, The corresponding weight, express The corresponding weight; Step 8: Based on and Constructing the mean square error loss function ; Step 9: Fusion dataset based on tea atlas , use SGDM optimizer to train the tea moisture content prediction network and calculate the mean square error loss function To update the network parameters until the mean square error loss function The training process continues until convergence, thus obtaining a trained tea moisture content regression model and using it on the ZYNQ development board for regression prediction of tea moisture content.
2. The method for detecting tea moisture content based on spectral fusion and convolutional neural network according to claim 1, characterized in that: Step 3 is performed as follows: Step 3.1: and After splicing, we get the low-level fused tea feature vector ;in, Indicates the A low-grade blend of tea characteristics; represents the number of features after low-level fusion; and ; Step 3.2: Use SPA algorithm to and Perform feature screening to obtain the filtered spectral feature vector And the filtered texture feature vector ,in, After filtering Spectral characteristics of each band; Indicates the number of spectral features after screening; After filtering Texture values; Indicates the number of texture features after filtering; Step 3.3: and After splicing, we get the intermediate fusion tea feature vector ,in, Indicates the A mid-level blend of tea characteristics; represents the number of features after low-level fusion; and .
3. The method for detecting tea moisture content based on spectral fusion and convolutional neural network according to claim 1, characterized in that: Step 4 is performed as follows: Step 4.1: Calculate the feature mean of low-level fusion ; Step 4.2: Build Linear regression equation ,in, For the Baseline offset, For the A baseline shift; Step 4.3: Calculate the corrected Low-level fusion features .
4. The method for detecting tea moisture content based on spectral fusion and convolutional neural network according to claim 1, characterized in that: Step 6 is performed as follows: Step 6.1: Input into the Conv module and pass through After processing by parallel convolution units, the spectral feature vector is obtained ,in, Representative The spectral features output by parallel convolution units; Step 6.2: The attention module consists of fully connected layers, an element-wise addition layer, an adaptive compression layer, excitation layer, activation function SoftMax layer, element-wise multiplication layers, and Processing is performed to obtain the low-level fusion multiplication feature vector of tea leaves ; Step 6.3: The prediction module consists of Fully connected layers; Will After the low-level fusion features of each tea are spliced, they are expanded into a one-dimensional feature vector according to the channel dimension and input Dimensionality reduction is performed in the fully connected layers to obtain Predicted moisture content ; Step 6.4: Follow the process from step 6.2 to step 6.3 to Processing to obtain Predicted moisture content .
5. The method for detecting tea moisture content based on spectral fusion and convolutional neural network according to claim 4, characterized in that: Step 6.2 is performed as follows: Step 6.2.1: Input into the attention module, Fully connected layer pairs After unified dimension processing, we get Low-level fusion and integration characteristics of tea ; thus obtaining The same low-level fusion and integration characteristics of tea leaves ; Step 6.2.2: Input into the element-by-element addition layer for processing to obtain the low-level fusion addition features of tea leaves ; Step 6.2.3: Input into the adaptive compression layer for processing to obtain the low-level fusion adaptive compression features of tea leaves ; Step 6.2.4: Enter respectively In the parallel excitation layers, we get Low-level fusion stimulation characteristics of tea ;in, Indicates the Individual tea leaves low-grade fusion excitation characteristics; Step 6.2.5: Enter to The activation function SoftMax layer is processed to obtain the Low-level fusion normalized features of tea leaves ; Step 6.2.6: and Enter to The element-by-element multiplication layer is used to process the low-grade fusion multiplication characteristics of tea , thus obtaining the low-level fusion multiplication feature vector of tea leaves .
6. An electronic device comprising a memory and a processor, characterized in that: The memory is used to store a program that supports the processor to execute the tea moisture content detection method according to any one of claims 1 to 5, and the processor is configured to execute the program stored in the memory.
7. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the tea moisture content detection method according to any one of claims 1 to 5 are executed.