A tea tree variety identification method, device, medium and product
Patent Information
- Application Number
- CN202610816156.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-08
- Publication Date
- 2026-08-18
AI Technical Summary
然而,将传统GAN及基础WGAN模型应用于茶树高光谱数据生成时,仍缺乏对不同茶树品种高光谱数据的特征波段表征,导致生成的光谱数据与真实数据存在一定偏差,从而影响茶树品种识别模型的准确性与鲁棒性
本申请提供了一种茶树品种识别方法、设备、介质及产品,获取待测茶树的茶叶高光谱图像;对待测茶树的茶叶高光谱图像进行预处理,得到预处理后的光谱数据;根据预处理后的光谱数据,利用茶树品种识别模型,确定待测茶树的品种;其中,茶树品种识别模型是利用原始光谱数据集和增强光谱数据集对支持向量机进行训练得到的;增强光谱数据集是利用改进条件生成对抗网络对原始光谱数据集进行数据增强得到的。本申请改进条件生成对抗网络可有效缓解茶树品种高光谱识别中的小样本与高维度等问题,利用改进条件生成对抗网络对原始光谱数据集进行数据增强得到增强光谱数据集,对支持向量机进行训练,可实现茶树品种的快速精准鉴别。
Smart Images

Figure CN122597995A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of tea tree variety identification, and in particular to a method, equipment, medium and product for tea tree variety identification. Background Technology
[0002] Tea (Camellia sinensis) is one of the world's most important economic crops, and China boasts abundant tea germplasm resources. Rapid and non-destructive identification of tea varieties is crucial for the breeding of high-quality varieties, brand protection, and cultivation management. Different tea varieties exhibit significant differences in tea quality components, phenotypic characteristics, and stress resistance. Currently, traditional methods for tea variety identification rely heavily on accumulated manual experience and knowledge, which suffers from high subjectivity, low efficiency, and high labor intensity. Therefore, there is an urgent need to develop a rapid and non-destructive method for tea variety identification.
[0003] Hyperspectral imaging technology can simultaneously acquire two-dimensional spatial and one-dimensional spectral information of samples, providing a new technical means for rapid and non-destructive identification of tea varieties. In actual tea variety identification, obtaining high-quality tea germplasm resource samples requires strict control over harvesting time, location, and growth environment. Furthermore, hyperspectral data acquisition is complex, and variety labeling requires the expertise of breeding specialists, resulting in high costs for large-scale sample collection and labeling. Therefore, the small sample size problem has become a major bottleneck limiting the application of hyperspectral imaging technology. Experts and scholars from various countries have achieved some research results in tea variety detection using hyperspectral imaging technology. For example, using hyperspectral imaging technology combined with the Support Vector Machine (SVM) algorithm, the identification accuracy of three different tea varieties (50 samples of each variety, totaling 150 samples) reached 100%. Based on the feature selection variable iterative space shrinkage approach (VISSA) and the Firefly algorithm (FA) optimized SVM model using hyperspectral imaging technology, the identification accuracy of five green tea varieties (80 samples of each variety, totaling 400 samples) reached 96%. Applying fluorescence hyperspectral imaging technology combined with the Artificial Bee Colony Support Vector Machine (ABC-SVM) model, rapid and non-destructive identification of four tea varieties (80 samples of each variety, totaling 320 samples) can be achieved. Low-rank stacked autoencoders (Low-rank stacked autoencoders) can also be used to identify tea varieties. The hyperspectral data dimensionality reduction and classification method using auto-encoder (LR-SAE) achieved an accuracy of 97.99% in identifying 400 tea varieties (80 samples per variety). This study demonstrates that combining spectral technology with machine learning algorithms can effectively identify different tea varieties, but the model's accuracy is often limited by the size of the sample dataset.
[0004] Generative artificial intelligence algorithms, as a data augmentation strategy, offer a new solution for few-shot learning. Currently, mainstream generative learning methods can be divided into two categories: one is the autoencoder architecture and its variants, such as the diffusion model (DM); the other is the generative network-based architecture, such as generative adversarial networks (GANs). The diffusion model, which generates data by progressively adding and removing Gaussian noise, easily disrupts the continuous and smooth physical properties of hyperspectral data and suffers from drawbacks such as numerous training steps and high computational costs. In contrast, generative adversarial networks, by introducing adversarial learning mechanisms, improve the realism and fitting effect of generated data, thereby obtaining high-quality spectral data. GANs, through adversarial training between the generator and discriminator, can effectively learn the distribution of training data and generate new samples. Building upon GANs, Conditional Generative Adversarial Networks (CGANs) are further improved by introducing conditional information such as class labels and using conditional probability mechanisms to control data generation. Semi-supervised generative adversarial networks (SGANs) are models that combine generative adversarial networks and semi-supervised learning. They can train classifiers with limited labeled data or large amounts of unlabeled data, and their discriminators can be used for classifying real samples and distinguishing between real and fake samples, achieving optimization of classification and adversarial training. For research on generative adversarial networks under small sample conditions, an improved Deep Convolution Generative Adversarial Network (DCGAN) model was constructed to build a Fake Tea data augmentation algorithm framework. Combined with the YOLOv7 object detection network, the mean average precision (mAP) of Longjing 43 tea shoots reached 89.14%. A gradient-penalized Wasserstein GAN (AC-WGAN-GP) architecture based on an auxiliary classifier was constructed, demonstrating the feasibility of using labeled fake samples as a data augmentation method in small-sample hyperspectral image classification. Wasserstein GAN (WGAN) addresses the problems of training instability and mode collapse in traditional GANs by improving the loss function, enabling GAN networks to be widely used in various generative model tasks. However, when traditional GAN and basic WGAN models are applied to generate hyperspectral data of tea trees, there is still a lack of characteristic band representation of hyperspectral data of different tea tree varieties. This results in a certain deviation between the generated spectral data and the real data, which affects the accuracy and robustness of the tea tree variety identification model. Summary of the Invention
[0005] The purpose of this application is to provide a method, device, medium, and product for identifying tea tree varieties, so as to improve the accuracy and robustness of tea tree variety identification.
[0006] To achieve the above objectives, this application provides the following solution: Firstly, this application provides a method for identifying tea tree varieties, including: Acquire hyperspectral images of tea leaves from the tea plant to be tested; the hyperspectral images of tea leaves include tea sample, standard white board, and background area; The hyperspectral image of the tea leaves of the tea tree to be tested is preprocessed to obtain preprocessed spectral data; Based on the preprocessed spectral data, the variety of the tea tree to be tested is determined using a tea tree variety identification model. The tea tree variety identification model is obtained by training a support vector machine using the original spectral dataset and the enhanced spectral dataset. The enhanced spectral dataset is obtained by augmenting the original spectral dataset using an improved conditional generative adversarial network. The improved conditional generative adversarial network includes a generator and a discriminator. The generator generates enhanced spectral data corresponding to the tea tree variety based on a Gaussian noise vector and a tea tree category label. The discriminator determines the authenticity of the enhanced spectral data and classifies the enhanced spectral data according to the tea tree variety.
[0007] In one embodiment, the hyperspectral image of the tea leaves from the tea tree to be tested is preprocessed to obtain preprocessed spectral data, specifically including: The hyperspectral image of the tea leaves from the tea plant to be tested is corrected by black and white correction to obtain the corrected hyperspectral image of the tea leaves; Based on the corrected hyperspectral image of tea leaves, the original grayscale values of the tea sample and the standard white board were extracted using ENVI 5.3 software to obtain the original grayscale image of tea leaves. The original grayscale image of the tea leaves was masked using Python's OpenCV library to obtain a hyperspectral image containing only the target sample. Extract the region of interest (ROI) of the target sample from the hyperspectral image containing only the target sample; Obtain the spectral information of all pixels within the region of interest, and take the average value as the spectral data of the target sample; The spectral data of the target sample is smoothed using Savitzky-Golay filtering to obtain preprocessed spectral data.
[0008] In one embodiment, an improved conditional generative adversarial network is used to augment the original spectral dataset to obtain an augmented spectral dataset, specifically including: Obtain the original spectral dataset; the original spectral dataset contains the real spectral data of multiple tea tree variety samples and the variety category label corresponding to each tea tree variety sample; Construct an initial improved conditional generative adversarial network; The generator and the discriminator are jointly adversarially trained using the original spectral dataset to obtain an improved conditional generative adversarial network. The generator of the improved conditional generative adversarial network is used as a data augmenter. Gaussian noise vectors and variety category labels are input to generate enhanced spectral data in batches, forming an enhanced spectral dataset.
[0009] In one embodiment, the generator and the discriminator are jointly trained adversarially using the original spectral dataset to obtain an improved conditional generative adversarial network, specifically including: Input the Gaussian noise vector and the variety category label into the current generator to generate enhanced spectral data corresponding to the variety category label; The real spectral data and the corresponding variety category label, as well as the enhanced spectral data and the corresponding variety category label, are input into the current discriminator, and the current discriminator outputs the authenticity score and the category prediction probability. Based on the authenticity score and the predicted category probability, the generator loss and discriminator loss are determined by combining a multi-task loss function; the multi-task loss function includes: a loss term based on the Wasserstein GAN framework with gradient penalty, an auxiliary classification loss term, and a feature-weighted loss term; Based on the generator loss and the discriminator loss, update the network parameters of the current generator and the current discriminator respectively, and proceed to the next round of training; Training continues until the preset number of training rounds or the loss function convergence condition is reached, at which point the training ends and the improved conditional generative adversarial network is obtained.
[0010] In one embodiment, the generator includes: a first embedding layer, a first splicing layer, a plurality of first fully connected layers, and a first output layer; each first fully connected layer is followed by a batch normalization layer and a linear unit activation function with leakage correction.
[0011] In one embodiment, the discriminator includes: a second embedding layer, a second splicing layer, a plurality of second fully connected layers, and a second output layer; each second fully connected layer is followed by a linear unit activation function with leakage correction and a Dropout layer.
[0012] In one embodiment, the loss function of the generator is expressed as: The loss function of the discriminator is expressed as: ; ; , ~ U [0, 1]; in, The generator loss function; This indicates enhanced spectral data that follows the distribution of the generated data. ; To enhance spectral data; To determine the authenticity score of the enhanced spectral data output by the true and false branches of the sample; To assist in classification loss terms; For classification loss weights; c represents the category prediction probability of the enhanced spectral data output for the variety category branch; c is the one-hot encoded value of the variety category label. For feature-weighted loss terms; Weight the loss values for the features; The mean center of the true spectral data; The feature importance vector consists of elements representing the feature importance of the real spectral data in each band, calculated using the random frog-jumping algorithm. The discriminator loss function; Represents true spectral data and follows the true data distribution. ; For the discriminator's truth scoring branch, output a scalar for adversarial training and gradient penalty; Indicates the random interpolation point The mathematical expectation; The gradient for the discriminator's score on the authenticity of the interpolation points; These are random interpolation points between real spectral data and enhanced spectral data. This is a gradient penalty hyperparameter; This indicates element-wise multiplication; It is the square of the L2 norm.
[0013] Secondly, this application provides a computer device, including: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the above-described tea variety identification method.
[0014] Thirdly, this application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the above-described tea variety identification method.
[0015] Fourthly, this application provides a computer program product, including a computer program that, when executed by a processor, implements the above-described tea variety identification method.
[0016] According to the specific embodiments provided in this application, this application has the following technical effects: This application provides a method, device, medium, and product for tea tree variety identification. The method involves acquiring hyperspectral images of tea leaves from a tea tree to be tested; preprocessing the hyperspectral images to obtain preprocessed spectral data; and using a tea tree variety identification model based on the preprocessed spectral data to determine the variety of the tea tree. The tea tree variety identification model is obtained by training a support vector machine using both the original spectral dataset and an enhanced spectral dataset. The enhanced spectral dataset is obtained by augmenting the original spectral dataset using an improved conditional generative adversarial network (GAN). This improved GAN effectively alleviates the problems of small sample size and high dimensionality in hyperspectral tea tree variety identification. By using the improved GAN to augment the original spectral dataset to obtain an enhanced spectral dataset, and then training the support vector machine, rapid and accurate identification of tea tree varieties can be achieved. Attached Figure Description
[0017] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0018] Figure 1 A flowchart illustrating a tea tree variety identification method provided in an embodiment of this application; Figure 2 This is a schematic diagram of a hyperspectral imaging system provided in an embodiment of this application; Figure 3 This application provides illustrations of different tea tree varieties as an embodiment of the present application. Figure 4 A schematic diagram illustrating the spectral data extraction process of a typical tea sample provided in an embodiment of this application; Figure 5 This is a structural diagram of an ICGAN model provided in an embodiment of this application; Figure 6 A graph showing the reflectance of a real sample as a function of wavelength, provided as an embodiment of this application; Figure 7 A graph showing the reflectance of a generated sample as a function of wavelength, provided in an embodiment of this application; Figure 8 This is a schematic diagram of the structure of a computer device provided in an embodiment of this application. Detailed Implementation
[0019] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0020] To make the above-mentioned objectives, features and advantages of this application more apparent and understandable, the application will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0021] In one exemplary embodiment, such as Figure 1 As shown, a method for identifying tea tree varieties is provided, including the following steps: S1: Obtain a hyperspectral image of the tea leaves from the tea tree to be tested; the hyperspectral image of the tea leaves includes a tea sample, a standard white board, and a background area.
[0022] S2: Preprocess the hyperspectral image of the tea leaves of the tea tree to be tested to obtain preprocessed spectral data.
[0023] In one embodiment, S2 specifically includes: S21: Perform black and white correction on the hyperspectral image of the tea leaves of the tea tree to be tested to obtain the corrected hyperspectral image of the tea leaves; S22: Based on the corrected hyperspectral image of the tea leaves, use ENVI 5.3 software to extract the original grayscale values of the tea leaf sample and the standard white board to obtain the original grayscale image of the tea leaves.
[0024] S23: Use Python's OpenCV library to perform masking on the original grayscale image of the tea leaves to obtain a hyperspectral image containing only the target sample.
[0025] S24: Extract the region of interest of the target sample from the hyperspectral image containing only the target sample.
[0026] S25: Obtain the spectral information of all pixels in the region of interest, and take the average value as the spectral data of the target sample.
[0027] S26: The spectral data of the target sample is smoothed using Savitzky-Golay filtering to obtain preprocessed spectral data.
[0028] S3: Based on the preprocessed spectral data, the variety of the tea tree to be tested is determined using a tea tree variety identification model; wherein, the tea tree variety identification model is obtained by training a support vector machine using the original spectral dataset and the enhanced spectral dataset; the enhanced spectral dataset is obtained by augmenting the original spectral dataset using an improved conditional generative adversarial network; the improved conditional generative adversarial network includes a generator and a discriminator, the generator is used to generate enhanced spectral data corresponding to the tea tree variety based on the Gaussian noise vector and the tea tree category label; the discriminator is used to determine the authenticity of the enhanced spectral data and to classify the enhanced spectral data into varieties.
[0029] In one embodiment, an improved conditional generative adversarial network is used to augment the original spectral dataset to obtain an augmented spectral dataset, specifically including: Step 1: Obtain the original spectral dataset; the original spectral dataset contains the real spectral data of multiple tea tree variety samples and the variety category label corresponding to each tea tree variety sample.
[0030] In this embodiment, five tea varieties (Meizhan, Jinmudan, Jinguanyin, Fuyun No. 7, and Baicha Gongmei) were selected and planted at the experimental base of the Tea Research Institute of the F Province Academy of Agricultural Sciences. All fresh tea leaves were harvested on May 21, 2025. Samples of one bud and two or three leaves were taken from the tender shoots of the tea trees, with 800 leaves per variety. These were divided into 20 batches (40 leaves per batch, evenly spread out) for hyperspectral data collection, resulting in a total of 4000 samples (5 varieties × 40 fresh tea leaves × 20 replicates). To ensure the stability and comparability of the spectral characteristics of different varieties, tea trees with consistent growth and growing environment were selected. After being labeled by professionals, spectral data of different tea varieties were immediately collected using a hyperspectral imaging system. The hyperspectral imaging system is as follows: Figure 2 As shown, different tea tree varieties, such as Figure 3 As shown. However, this hyperspectral imaging system is cumbersome to operate and time-consuming for each acquisition, resulting in a limited number of samples that can be collected in a single batch. Therefore, obtaining a large number of hyperspectral datasets of different tea varieties within a limited experimental period is quite difficult.
[0031] To reduce the impact of system noise and uneven illumination on the original hyperspectral image, a black and white reference image needs to be obtained under the same conditions for correction. The black reference image is obtained by turning off the light source and completely covering the lens with an opaque lens cap, while the white reference image is acquired using a white polytetrafluoroethylene plate. Black and white correction is performed according to formula (1) to obtain the corrected hyperspectral image of tea leaves.
[0032] I =[ I raw - Idark ] / [ I white - I dark (1) In the formula: I is the corrected hyperspectral image of tea leaves; I raw Original image; I white This is a reference image for a standard whiteboard (reflectivity ≈ 100%). I dark The reference image is black (reflectivity ≈ 0%).
[0033] Each acquired hyperspectral image includes the target sample, a standard white board, and a background region. To accurately extract the spectral information of the samples, the original grayscale values of the target sample and the standard white board in the corrected tea hyperspectral image were extracted using ENVI 5.3 software. Then, the original grayscale images were masked using Python's OpenCV library. Simultaneously, all samples in each batch were extracted as a Region of Interest (ROI), and the spectral information of all pixels within the ROI was obtained. The average value was then used as the spectral data for that sample. The specific process is as follows: Figure 4 As shown in the figure. Twenty samples were collected from each variety, resulting in a total of 100 spectral data points (5 varieties × 20 replicates) for subsequent spectral data analysis. After extraction of the raw spectral data, Savitzky-Golay (SG) filtering was used for smoothing. A first-order polynomial was used to fit the spectral data within the window of size 5 to eliminate the influence of random noise in the spectral data on the effective information of the samples.
[0034] The original grayscale values of the target sample and the standard whiteboard were extracted using ENVI 5.3 software. The specific operation process is as follows: First, the original grayscale values of the target sample and the standard whiteboard were extracted using ENVI 5.3 software. After launching ENVI 5.3 software, the acquired hyperspectral image file was imported. The “ROI Tool” was selected, and irregular ROIs were manually drawn in the standard whiteboard area and the target sample area, respectively, to ensure that the ROI completely covered the target area and did not include background pixels. Then, the grayscale values of all pixels in each ROI were extracted using the software’s “Statistics” function. The average grayscale value of each ROI was automatically calculated and saved as the original grayscale value of that area (whiteboard or tea sample), and the original grayscale image of the tea was obtained for subsequent image correction.
[0035] After grayscale value extraction, the original hyperspectral image is masked using Python's OpenCV library. The specific steps are as follows: First, the original grayscale image of tea leaves exported from ENVI 5.3 software is converted into an array format recognizable by OpenCV. Second, based on the difference in grayscale values between the target sample and the background region, the Otsu adaptive thresholding algorithm is used to automatically determine the optimal threshold for distinguishing the sample from the background, ensuring effective separation of the target sample from background interference and avoiding missed sample selection or misselection of the background. Third, a binary mask image is generated based on the determined threshold, where the target sample region corresponds to the white region (pixel value of 255) of the binary mask image, and the background region corresponds to the black region (pixel value of 0) of the binary mask image. Fourth, the generated binary mask image is bitwise ANDed with the original hyperspectral image to remove interfering pixels in the background region, retaining only the effective pixels in the target sample region, resulting in a hyperspectral image containing only the target sample, thus avoiding the influence of background noise on subsequent spectral extraction.
[0036] After masking, all samples in each batch are extracted as Region of Interest (ROI). The specific extraction process is as follows: First, import the masked hyperspectral image containing only the target samples. Use the cv2.selectROI() function from Python's OpenCV library to select the effective region of each target sample, avoiding image edges and residual background pixels during selection to ensure that the ROI only contains the effective region of the target samples. Second, perform pixel filtering on each selected ROI. By setting a reasonable grayscale value range threshold (determined based on the original grayscale values of the previously extracted samples), filter out noisy pixels outside the range to further purify the ROI region. Third, use Python programming to extract the spectral information of all pixels within each ROI, calculate the spectral mean of all pixels within the ROI, and use this mean as the final spectral data of the corresponding sample to ensure the accuracy and representativeness of the spectral information. The specific process is as follows: Figure 4 As shown; the fourth step is to complete the ROI extraction for all samples in each batch using the above method, collecting 20 samples for each variety, and obtaining a total of 100 spectral data (5 varieties × 20 replicates) for subsequent spectral data analysis.
[0037] Step 2: Construct the initial improved conditional generative adversarial network.
[0038] In one embodiment, the generator includes: a first embedding layer, a first splicing layer, a plurality of first fully connected layers, and a first output layer; each first fully connected layer is followed by a batch normalization layer and a linear unit activation function with leakage correction.
[0039] In one embodiment, the discriminator includes: a second embedding layer, a second splicing layer, a plurality of second fully connected layers, and a second output layer; each second fully connected layer is followed by a linear unit activation function with leakage correction and a Dropout layer.
[0040] In this embodiment, an improved conditional generative adversarial network (ICGAN) is proposed for one-dimensional spectral data augmentation, primarily based on the Wasserstein distance generative adversarial network with gradient penalty (WGAN-GP) framework. Furthermore, a spectral consistency constraint based on feature importance is introduced to ensure the fidelity and physical consistency of the generated spectra.
[0041] The constructed ICGAN model structure is as follows: Figure 5 As shown, the system mainly consists of a generator (G) and a discriminator (D). A multilayer perceptron (MLP) structure was designed for one-dimensional spectral data of tea leaves. The curve of reflectance of the real sample as a function of wavelength is shown in the figure. Figure 6 As shown, the curve of the reflectance of the generated sample as a function of wavelength is as follows: Figure 7 As shown.
[0042] The generator's input consists of a Gaussian noise vector z (100 dimensions) and variety category labels c (5 tea varieties). The specific process is as follows: First, the variety category labels c are mapped to a 100-dimensional dense vector through the first embedding layer, and then the Gaussian noise vector is concatenated with the category label vector using the first concatenation layer to form a 200-dimensional vector. Second, it passes through three first fully connected layers (128, 256, and 512 neurons respectively), with batch normalization (BN) and Leaky-ReLU activation functions applied after each layer, with a negative slope coefficient of 0.2. Finally, the first output layer uses the hyperbolic tangent (Tanh) activation function to constrain the output within the range [-1, 1], and generates a one-dimensional vector of tea hyperspectral data (enhanced spectral data) G(z|c) of length 224.
[0043] The discriminator can not only distinguish the authenticity of samples but also classify variety category labels. Its input consists of sample spectral data x (real or generated) and variety category labels c. The specific process is as follows: First, the variety category label c is mapped to a dense vector through a second embedding layer. Then, a second concatenation layer concatenates the sample spectral data x with the category label vector to form a 448-dimensional vector. Next, it passes through three second fully connected layers (512, 256, and 128 neurons respectively), each followed by a Leaky-ReLU activation function (negative slope coefficient of 0.2) and Dropout (ratio of 0.3). Finally, the second output layer adopts a dual-output architecture (including true / false discrimination and category classification). Specifically, it estimates the Wasserstein distance by maximizing the difference between the scores of real and generated samples and outputs the probability distribution of the sample belonging to different tea varieties through a Softmax layer.
[0044] Step 3: Use the original spectral dataset to perform joint adversarial training on the generator and the discriminator to obtain an improved conditional generative adversarial network.
[0045] In one embodiment, step 3 specifically includes: Step 31: Input the Gaussian noise vector and variety category label into the current generator to generate enhanced spectral data corresponding to the variety category label.
[0046] Step 32: Input the real spectral data and the corresponding variety category label, as well as the enhanced spectral data and the corresponding variety category label, into the current discriminator, and the current discriminator outputs the authenticity score and the category prediction probability.
[0047] Step 33: Based on the authenticity score and the predicted category probability, determine the generator loss and discriminator loss by combining the multi-task loss function; the multi-task loss function includes: a loss term based on the WGAN-GP (Wasserstein GAN with gradient penalty) framework, an auxiliary classification loss term, and a feature-weighted loss term.
[0048] To further improve the generation of visible / near-infrared spectral data of real tea leaves using ICGAN and alleviate the gradient vanishing and mode collapse problems encountered by generative adversarial networks during training, a multi-task loss function is introduced to jointly optimize the generator based on the original generative adversarial network loss. This enhances the learning ability of the generated spectra on feature bands, thereby improving the quality and classification performance of the generated spectral data.
[0049] (1) Introduce the WGAN-GP architecture.
[0050] In traditional GAN networks, the objective of the generator under the optimal discriminator is equivalent to minimizing the Jensen-Shannon (JS) divergence between the real data distribution and the generated data distribution, which leads to the vanishing gradient phenomenon in high-dimensional spaces. This embodiment introduces the WGAN-GP network, which uses Wasserstein distance instead of JS divergence and constrains the discriminator weights based on 1-Lipschitz continuity. Its loss function adds a gradient penalty (GP) term to constrain the gradient norm of sample points, solving the gradient clipping problem of the WGAN model and improving the training stability of the generator and discriminator.
[0051] (2) Auxiliary classification loss.
[0052] To ensure that the generated spectral data possesses specific tea variety characteristics, this embodiment incorporates an auxiliary classification loss (L) into the loss function. cls This improves the semantic consistency and edge continuity of generated samples, mitigating the pattern collapse problem. The discriminator D consists of two output branches: one for determining whether a sample is true or false, and the other for determining whether a sample is true or false. val (Output a continuous scalar for calculating the Wasserstein distance correlation loss) and the variety classification branch D. cls (The probability distributions of each category are obtained after Softmax activation, which are used to calculate the auxiliary classification loss L) cls L cls As an auxiliary loss term, it is weighted... The total loss function is added to both the generator and the discriminator, constraining the generator to produce spectra that match the characteristics of the target variety, while simultaneously constraining the discriminator to perform both true / false detection and variety classification tasks. That is, L cls D cls The cross-entropy loss between the output and the target tea variety c (unique heat code) is calculated as shown in formula (2): (2) In the formula: N is the total number of tea varieties; The one-hot encoded value for the target category (1 for the target category, 0 for the rest); This represents the predicted probability of the class classification branch of the discriminator for the i-th class.
[0053] (3) Feature-weighted loss.
[0054] Considering the varying contributions of different spectral bands to tea variety classification, this embodiment employs a feature-weighted loss to guide the generator to prioritize fitting feature bands. Therefore, before training, the feature importance of the real spectral dataset is acquired separately. The Random Frog algorithm is used to calculate the feature importance vector I for each band (each element in I corresponds to the importance of a band; a larger value indicates a higher contribution of that band to variety classification), and the mean center of the real spectrum for each tea category is calculated. Feature-weighted loss L feat To generate spectra and The difference, multiplied element-wise by I, becomes the square of the L2 norm, i.e. and weight Introducing the total generator loss guides the generator to prioritize fitting spectral bands that are more important for variety classification.
[0055] In summary, for the task of generating spectra of tea varieties with small samples, this embodiment designs an improved ICGAN multi-task composite loss function, which integrates the stable training characteristics of WGAN-GP, variety classification constraints and feature weighting constraints. The loss functions of the generator and discriminator are shown in formulas (3) and (4).
[0056] In one embodiment, the loss function of the generator is expressed as: (3) The loss function of the discriminator is expressed as: (4) (5) , ~ U [0, 1] (6) in, The generator loss function; This indicates enhanced spectral data that follows the distribution of the generated data. ; To enhance spectral data; To determine the authenticity score of the enhanced spectral data output by the true and false branches of the sample; To assist in classification loss terms; For classification loss weights; c represents the category prediction probability of the enhanced spectral data output for the variety category branch; c is the one-hot encoded value of the variety category label. For feature-weighted loss terms; Weight the loss values for the features; The mean center of the true spectral data; The feature importance vector consists of elements representing the feature importance of the real spectral data in each band, calculated using the random frog-jumping algorithm. The discriminator loss function; Represents true spectral data and follows the true data distribution. ; The discriminator's authenticity scoring branch outputs a scalar used for adversarial training and gradient penalty; Indicates the random interpolation point The mathematical expectation; The gradient for the discriminator's score on the authenticity of the interpolation points; These are random interpolation points between real spectral data and enhanced spectral data. This is a gradient penalty hyperparameter; This indicates element-wise multiplication; It is the square of the L2 norm.
[0057] Step 34: Update the network parameters of the current generator and the current discriminator according to the generator loss and the discriminator loss respectively, and enter the next round of training.
[0058] Step 35: Continue training until the preset number of training rounds or the loss function convergence condition is reached, then end the training and obtain the improved conditional generative adversarial network.
[0059] Step 4: Using the generator of the improved conditional generative adversarial network as a data augmenter, input Gaussian noise vectors and variety category labels to generate enhanced spectral data in batches, thus forming an enhanced spectral dataset.
[0060] In this embodiment, t-Distributed stochastic neighbor embedding (t-SNE) and Fréchet inception distance (FID) are used to visualize and evaluate the quality of the generated samples (enhanced spectral dataset). t-SNE is a non-linear dimensionality reduction technique that aims to project data from a high-dimensional space to a low-dimensional space while preserving local similarity. In a t-SNE plot, a close mixture of generated and real data indicates good quality generated samples, closely approximating the distribution of the real data. FID quantifies the difference in distribution by calculating the mean and covariance matrices of the real and generated data in the high-dimensional feature space; a smaller FID value indicates better quality generated data.
[0061] This embodiment employs a stratified random sampling method, dividing the original dataset (original spectral dataset and enhanced spectral dataset) into a modeling set and a prediction set at a 3:2 ratio. Three machine learning models—Support Vector Machine (SVM), Random Forest (RF), and Gradient Boosting Decision Tree (GBDT)—are selected to compare and evaluate the effectiveness of the enhanced spectral data. Based on this, the best-performing model is selected for subsequent accurate identification of different tea varieties. SVM is a classic supervised learning algorithm that solves the optimal hyperplane by optimizing a convex quadratic programming problem. A Radial Basis Function (RBF) is used as the kernel function to map the original spectral space to a high-dimensional space, making the originally linearly inseparable data linearly separable in the high-dimensional space. RF is an ensemble learning method that improves the model's accuracy and robustness by training multiple decision trees and using a majority voting mechanism. GBDT is an ensemble learning model based on the Boosting algorithm. It combines several weak learners (decision trees) into a strong learner and accumulates and superimposes the prediction results of multiple decision trees as the final prediction output of the model.
[0062] To evaluate the performance of the recognition model, accuracy, precision, recall and F1 score are calculated using the confusion matrix, as shown in formulas (5) to (8).
[0063] (7) (8) (9) (10) In the formula: True positive (TP) represents the number of positive samples correctly identified as positive by the model; True negative (TN) represents the number of negative samples correctly identified as negative by the model; False positive (FP) represents the number of negative samples incorrectly identified as positive by the model; False negative (FN) represents the number of positive samples incorrectly identified as negative by the model.
[0064] To address the challenges of high dimensionality and costly acquisition of large-scale sample data in tea hyperspectral data, this embodiment uses five tea varieties as research objects. A visible / near-infrared hyperspectral imaging system is employed to collect spectral information of tea leaves. An improved Conditional Generative Adversarial Network (ICGAN) is proposed for enhancing small-sample hyperspectral data. A multi-task loss function is designed, combining auxiliary classification loss, feature weighting loss, and the WGAN-GP framework to improve the quality and stability of the generated data. Furthermore, a fast and non-destructive identification method for tea varieties is established by integrating three machine learning models. Results show that different tea varieties exhibit certain differences in spectral characteristics, with the "Fuyun 7" variety showing significant differences from other varieties. The improved ICGAN network enhances the quality of small-sample spectral data generation and outperforms the basic CGAN. It integrates the WGAN-GP framework, auxiliary classification loss, and feature weighting mechanism. The feature importance vector extracted through the random frog-jumping algorithm allows the generator to focus more on learning the characteristic bands for variety identification, ensuring that the generated samples retain the typical spectral characteristics of real tea varieties. Furthermore, qualitative and quantitative evaluations using t-SNE and FID show that ICGAN highly matches the spatial distribution of the original samples, effectively solving the pattern collapse problem of traditional GANs. After data augmentation using generative adversarial networks, the predictive performance of all models is significantly improved. Among them, after ICGAN augmentation, the prediction accuracy of SVM, RF, and GBDT models is improved by 5.00 percentage points, 2.50 percentage points, and 20.00 percentage points respectively compared with the real modeling set. The ICGAN-SVM model has the best performance in identifying tea varieties, with a prediction accuracy of up to 95.00%. The results indicate that ICGAN can effectively alleviate the problems of small sample size and high dimensionality in hyperspectral identification of tea varieties. The combination of ICGAN and SVM can achieve rapid and accurate identification of tea varieties, providing a fast and non-destructive method for the protection of high-quality tea germplasm resources and the traceability of tea brands.
[0065] In one exemplary embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the above-described tea variety identification method.
[0066] In one exemplary embodiment, a computer-readable storage medium is provided storing a computer program that, when executed by a processor, implements the tea variety identification method described above.
[0067] In one exemplary embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the above-described tea variety identification method.
[0068] In one exemplary embodiment, a computer device is provided, which may be a server or a terminal, and its internal structure diagram may be as follows. Figure 8As shown, this computer device includes a processor, memory, input / output (I / O) interfaces, and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is also connected to the system bus via the I / O interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides the environment for the operating system and computer programs stored in the non-volatile storage media to run. The I / O interfaces are used for exchanging information between the processor and external devices. The communication interface is used for communicating with external terminals via a network connection. When the computer program is executed by the processor, it implements a tea variety identification method.
[0069] Those skilled in the art will understand that Figure 8 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0070] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of the relevant data must comply with relevant regulations.
[0071] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments described above. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM).
[0072] The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, etc., and are not limited to these.
[0073] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0074] This document uses specific examples to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the methods and core ideas of this application. Furthermore, those skilled in the art will recognize that, based on the ideas of this application, there will be changes in the specific implementation methods and application scope. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. A method for identifying tea tree varieties, characterized in that, include: Obtain hyperspectral images of tea leaves from the tea plant to be tested; The hyperspectral image of the tea includes a tea sample, a standard white board, and a background area; The hyperspectral image of the tea leaves of the tea tree to be tested is preprocessed to obtain preprocessed spectral data; Based on the preprocessed spectral data, the variety of the tea tree to be tested is determined using a tea tree variety identification model. The tea tree variety identification model is obtained by training a support vector machine using the original spectral dataset and the enhanced spectral dataset. The enhanced spectral dataset is obtained by augmenting the original spectral dataset using an improved conditional generative adversarial network. The improved conditional generative adversarial network includes a generator and a discriminator. The generator generates enhanced spectral data corresponding to the tea tree variety based on a Gaussian noise vector and a tea tree category label. The discriminator determines the authenticity of the enhanced spectral data and classifies the enhanced spectral data according to the tea tree variety.
2. The tea tree variety identification method according to claim 1, characterized in that, The hyperspectral image of the tea leaves from the tea plant to be tested is preprocessed to obtain preprocessed spectral data, specifically including: The hyperspectral image of the tea leaves from the tea plant to be tested is corrected by black and white correction to obtain the corrected hyperspectral image of the tea leaves; Based on the corrected hyperspectral image of tea leaves, the original grayscale values of the tea sample and the standard white board were extracted using ENVI 5.3 software to obtain the original grayscale image of tea leaves. The original grayscale image of the tea leaves was masked using Python's OpenCV library to obtain a hyperspectral image containing only the target sample. Extract the region of interest (ROI) of the target sample from the hyperspectral image containing only the target sample; Obtain the spectral information of all pixels within the region of interest, and take the average value as the spectral data of the target sample; The spectral data of the target sample is smoothed using Savitzky-Golay filtering to obtain preprocessed spectral data.
3. The tea tree variety identification method according to claim 1, characterized in that, The original spectral dataset is augmented using an improved conditional generative adversarial network to obtain an augmented spectral dataset, which specifically includes: Obtain the original spectral dataset; the original spectral dataset contains the real spectral data of multiple tea tree variety samples and the variety category label corresponding to each tea tree variety sample; Construct an initial improved conditional generative adversarial network; The generator and the discriminator are jointly adversarially trained using the original spectral dataset to obtain an improved conditional generative adversarial network. The generator of the improved conditional generative adversarial network is used as a data augmenter. Gaussian noise vectors and variety category labels are input to generate enhanced spectral data in batches, forming an enhanced spectral dataset.
4. The tea tree variety identification method according to claim 3, characterized in that, The generator and discriminator are jointly trained adversarially using the original spectral dataset to obtain an improved conditional generative adversarial network, specifically including: Input the Gaussian noise vector and the variety category label into the current generator to generate enhanced spectral data corresponding to the variety category label; The real spectral data and the corresponding variety category label, as well as the enhanced spectral data and the corresponding variety category label, are input into the current discriminator, and the current discriminator outputs the authenticity score and the category prediction probability. Based on the authenticity score and the predicted category probability, the generator loss and discriminator loss are determined by combining a multi-task loss function; the multi-task loss function includes: a loss term based on the Wasserstein GAN framework with gradient penalty, an auxiliary classification loss term, and a feature-weighted loss term; Based on the generator loss and the discriminator loss, update the network parameters of the current generator and the current discriminator respectively, and proceed to the next round of training; Training continues until the preset number of training rounds or the loss function convergence condition is reached, at which point the training ends and the improved conditional generative adversarial network is obtained.
5. The tea tree variety identification method according to claim 1, characterized in that, The generator includes: a first embedding layer, a first splicing layer, multiple first fully connected layers, and a first output layer; each first fully connected layer is followed by a batch normalization layer and a linear unit activation function with leakage correction.
6. The tea tree variety identification method according to claim 1, characterized in that, The discriminator includes: a second embedding layer, a second splicing layer, multiple second fully connected layers, and a second output layer; each second fully connected layer is followed by a linear unit activation function with leakage correction and a Dropout layer.
7. The tea tree variety identification method according to claim 1, characterized in that, The loss function of the generator is expressed as: ; The loss function of the discriminator is expressed as: ; ; , ~ U [0,1]; in, The generator loss function; This indicates enhanced spectral data that follows the distribution of the generated data. ; To enhance spectral data; To determine the authenticity score of the enhanced spectral data output by the true and false branches of the sample; To assist in classification loss terms; For classification loss weights; c represents the category prediction probability of the enhanced spectral data output for the variety category branch; c is the one-hot encoded value of the variety category label. For feature-weighted loss terms; Weight the loss values for the features; The mean center of the true spectral data; The feature importance vector consists of elements representing the feature importance of the real spectral data in each band, calculated using the random frog-jumping algorithm. The discriminator loss function; Represents true spectral data and follows the true data distribution. ; For the discriminator's truth scoring branch, output a scalar for adversarial training and gradient penalty; Indicates the random interpolation point The mathematical expectation; The gradient for the discriminator's score on the authenticity of the interpolation points; These are random interpolation points between real spectral data and enhanced spectral data. This is a gradient penalty hyperparameter; This indicates element-wise multiplication; It is the square of the L2 norm.
8. A computer device, comprising: A memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that the processor executes the computer program to implement the tea variety identification method according to any one of claims 1-7.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When executed by a processor, the computer program implements the tea variety identification method according to any one of claims 1-7.
10. A computer program product, comprising a computer program, characterized in that, When executed by a processor, the computer program implements the tea variety identification method according to any one of claims 1-7.