An enhanced hyperspectral framework method for storing medicinal plant insect damage classification
By constructing an enhanced hyperspectral framework method, utilizing near-infrared images and generative adversarial networks to enhance data, and combining multiple evaluation methods, we have achieved precise classification of pests in medicinal plants, solving the problem of insufficient accuracy in pest detection in existing technologies and improving classification accuracy.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- HENAN UNIVERSITY OF TECHNOLOGY
- Filing Date
- 2025-12-31
- Publication Date
- 2026-05-29
Smart Images

Figure CN122116114A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of information technology, and in particular to an enhanced hyperspectral framework method for storing pest classification of medicinal plants. Background Technology
[0002] Pest monitoring of medicinal plants is a crucial aspect of agricultural production and food safety, directly impacting the quality of medicinal materials and public health. Medicinal plants are susceptible to various pests during their growth. Failure to detect and accurately grade pests in a timely manner can not only affect yield but also lead to the presence of harmful residues, threatening the safety of the final product. Therefore, researching efficient and accurate pest detection technologies is particularly urgent and holds undeniable value in ensuring the quality of medicinal materials and maintaining market trust.
[0003] However, current methods for detecting pests in medicinal plants often struggle to cope with complex real-world scenarios. Many traditional methods are inadequate when faced with a wide variety of pests and varying degrees of infestation due to a lack of sufficient data. In particular, the high cost and difficulty of obtaining pest samples in real-world environments result in poor adaptability of detection methods across different scenarios, making it difficult to meet the needs of comprehensive monitoring.
[0004] A deeper technical challenge lies in accurately reflecting different levels of pest infestation and achieving precise grading assessments when data resources are limited. The level of pest infestation is a crucial factor, as it not only involves the severity of the infestation but is also closely related to the plant's overall health. Failure to effectively distinguish between mild and severe infestations can lead to misjudgments, such as ignoring mild infestations as a healthy condition or mistaking severe infestations for minor, unacceptable problems. This lack of differentiation directly impacts the effectiveness of subsequent treatment measures. For instance, in a medicinal plant cultivation base, failing to accurately assess the degree of infestation upon seeing pest marks on leaves could result in missing the optimal window for control, leading to losses across the entire cultivation area.
[0005] Therefore, how to develop a technical means that can accurately distinguish different levels of infection when data is insufficient and pest infestation levels are complex and variable has become a key issue in the field of medicinal plant pest monitoring. Summary of the Invention
[0006] This invention provides an enhanced hyperspectral framework method for storing pest classification of medicinal plants, mainly comprising:
[0007] The framework acquires and stores near-infrared hyperspectral images of medicinal plant samples, and constructs datasets containing healthy, mildly infected, and severely infected levels through controlled artificial infection to obtain real spectral data as a foundation. The framework employs a Wasserstein generative adversarial network model with gradient penalty to enhance the real spectral data, generating synthetic spectral data to balance class distribution and increase sample diversity. The model is trained adversarially to ensure the fidelity of the generated data. The framework utilizes principal component analysis, t-distributed random neighbor embedding, root mean square error, maximum mean difference, and slice Wasserstein distance to qualitatively and quantitatively evaluate the synthetic spectral data, verifying its global structural consistency, local feature consistency, and statistical similarity with the real spectral data. Based on the enhanced dataset, the framework applies convolutional neural network classifiers, support vector machine classifiers, and random forest classifiers for pest classification, with the convolutional neural network classifier achieving optimal performance and improving accuracy.
[0008] Furthermore, the controlled artificial infection process for constructing a dataset comprising healthy, mildly infected, and severely infected levels includes: acquiring and storing medicinal plant slices and adult pests; placing the stored medicinal plant slices in a constant temperature incubator and incubating them with the adult pests; screening samples at different infection levels in stages, wherein the healthy level samples and the mildly infected level samples are selected after the first stage of incubation, and the severely infected level samples are selected after the second stage of incubation; monitoring the infection pressure in the constant temperature incubator; and maintaining the initial pest population by replacing dead adult pests. Population density is determined by obtaining multiple samples and classifying them into three levels according to preset standards: healthy, mildly infected, and severely infected. Near-infrared hyperspectral images are acquired from the multiple samples using an imaging system covering a preset spectral range. Noise is eliminated by applying black-and-white reference correction to obtain corrected hyperspectral images. Regions of interest are segmented from the corrected hyperspectral images, the average reflectance of pixels within the regions of interest is calculated, effective spectral bands are extracted and normalized to a preset range, and the real spectral data is generated and divided into training and testing sets.
[0009] Furthermore, the augmentation of the real spectral data using a Wasserstein generative adversarial network model with gradient penalty includes: inputting the real spectral data from the training set into a generator and a discriminator, wherein the generator generates the synthetic spectral data from random noise, and the discriminator distinguishes between the real spectral data and the synthetic spectral data; optimizing the generator and the discriminator through adversarial training, replacing the Jensen-Shannon divergence with Wasserstein distance, and applying a gradient penalty term to penalize the gradient norm of the discriminator at the interpolation point to ensure Lipschitz continuity; setting parameters such as batch size, learning rate, training epochs, Beta value of the Adam optimizer, Leaky ReLU value, and Gaussian noise length, and performing the adversarial training until the model converges to generate diverse synthetic spectral data; combining the synthetic spectral data with the real spectral data to form the augmented dataset to balance the category distribution and increase the sample diversity for subsequent pest classification.
[0010] Furthermore, the qualitative and quantitative evaluation of the synthesized spectral data using principal component analysis, t-distributed random neighbor embedding, root mean square error, maximum mean difference, and slice Wasserstein distance includes: projecting the synthesized spectral data and the real spectral data into a low-dimensional space using principal component analysis, preserving variance and visualizing the consistency of the global distribution structure; capturing local neighborhood structure using t-distributed random neighbor embedding, and visualizing the clustering pattern matching between the synthesized spectral data and the real spectral data by minimizing the Kullback-Leibler divergence; and calculating the root mean square error as the point-by-point deviation between the synthesized spectral data and the real spectral data. The square root of the mean square error is calculated, where the root mean square error is equal to the square root of the sum of squares of the real reflectance values minus the generated reflectance values divided by the number of samples; the maximum average difference is calculated to measure the distribution difference in the regenerated kernel Hilbert space, where the maximum average difference is equal to the average kernel function between real samples minus the average kernel function between real and generated samples plus the average kernel function between generated samples; the slice Wasserstein distance is calculated by projecting onto a random one-dimensional subspace and averaging the one-dimensional Wasserstein distance to approximate the overall similarity. As the number of training rounds increases, the mean square error, the maximum average difference, and the slice Wasserstein distance decrease, verifying the statistical similarity.
[0011] Furthermore, the process of applying a convolutional neural network classifier, a support vector machine classifier, and a random forest classifier to classify pests based on the enhanced dataset includes: inputting the enhanced dataset into the convolutional neural network classifier, which includes stacked convolutional blocks to reduce bands to feature dimensions, flattening layers, and fully connected layers; applying dropout layers to prevent overfitting; and training using an AdamW optimizer and cosine annealing learning rate scheduling. Cross-entropy loss and label smoothing are employed to enhance generalization ability, and performance is evaluated through five-fold hierarchical cross-validation. The output softmax probability corresponds to the health level and the pest classification. The dataset is divided into mild and severe infection levels. The enhanced dataset is input to the support vector machine classifier, which uses radial basis function kernels to map to a high-dimensional space to construct a separating hyperplane. Regularization parameters and kernel coefficients are adjusted via grid search, and five-fold cross-validation is used to enhance robustness. The enhanced dataset is then input to the random forest classifier, which constructs multiple decision trees and aggregates predictions through majority voting. Hyperparameters such as the number of trees, maximum tree depth, and minimum leaf size are optimized, and five-fold cross-validation is used to evaluate performance. The convolutional neural network classifier achieves the highest accuracy on the enhanced dataset.
[0012] Furthermore, segmenting the region of interest from the corrected hyperspectral image includes: applying an adaptive thresholding algorithm to the average grayscale image to generate a binary mask; using morphological operations to remove noise and fill holes; extracting the region of interest through pixel-wise multiplication; calculating the average reflectance to represent spectral features; selecting effective spectral bands and applying min-max scaling normalization to a preset range to generate the real spectral data. Furthermore, optimizing the generator and the discriminator through adversarial training includes: if the discriminator output is close to a preset probability, determining that the generator has converged to generate indistinguishable synthetic spectral data; providing a gradient based on the Wasserstein distance and performing continuity through the gradient penalty term to ensure that the model improves the fidelity of the generated data under imbalanced data conditions.
[0013] Furthermore, the calculation of the root mean square error as the square root of the point-by-point deviation between the synthesized spectral data and the real spectral data includes: calculating the square of the difference between the real value and the generated value for each reflectance value, summing the results, dividing by the number of samples, and taking the square root to obtain the root mean square error; if the root mean square error is lower than a preset threshold, it is determined that the point-by-point fit is good, and the overall distribution alignment is confirmed by combining the maximum average difference and the slice Wasserstein distance.
[0014] The technical solutions provided by the embodiments of the present invention may include the following beneficial effects:
[0015] This invention discloses a method for classifying pests in medicinal plants based on near-infrared hyperspectral imaging and generative adversarial networks (GANs). Addressing the challenges of insufficient sample size, class imbalance, and difficulty in obtaining real data in medicinal plant pest detection, this method constructs a dataset containing healthy plants and different infection levels. It combines controlled artificial infection and hyperspectral imaging to obtain real spectral data, employs a GAN with gradient penalties to enhance data distribution and improve diversity, and utilizes various evaluation methods to verify the similarity of the synthesized data. Finally, it applies classifiers such as convolutional neural networks to achieve accurate pest classification based on the enhanced dataset. This invention significantly improves classification accuracy through the combination of data augmentation and deep learning, demonstrating significant application value in food safety control and providing efficient and reliable technical support for medicinal plant pest monitoring. Attached Figure Description
[0016] Figure 1 A flowchart of an enhanced hyperspectral framework method for storing pest classification of medicinal plants according to the present invention is provided; Figure 2 Sample images showing three different degrees of insect damage (healthy, slightly infected, and severely infected) are provided in this invention. Figure 3 An architecture diagram of the Generative Adversarial Network (GAN) in this invention is provided; Figure 4 The main flowchart of spectral data extraction and preprocessing in this invention is given; Figure 5 The average spectral reflectance curves of Astragalus membranaceus samples at three different infection levels are given in this invention; Figure 6 The confusion matrix diagram of the classification results of the three classifiers in this invention on a balanced dataset is given. Detailed Implementation
[0017] The technical solutions of the embodiments of the present invention will be clearly and thoroughly described below with reference to the accompanying drawings. The described embodiments are merely some embodiments of the present invention.
[0018] like Figure 1 This embodiment of an enhanced hyperspectral framework method for storing pest classification of medicinal plants may specifically include:
[0019] S1, the framework acquires and stores near-infrared hyperspectral images of medicinal plant samples, and constructs a dataset containing healthy, mildly infected, and severely infected levels through controlled artificial infection to obtain real spectral data as a basis.
[0020] To address the need for pest classification in storing medicinal plant samples, the method first starts from... Sample surfaceNear-infrared hyperspectral image data is acquired using a high-resolution imaging device to collect raw image information within a specific wavelength range, ensuring comprehensive coverage of sample characteristics. Reflectance information is extracted from the acquired near-infrared hyperspectral image data, and preprocessed to remove noise interference, yielding clear raw spectral data for subsequent classification. Based on the obtained raw spectral data, a dataset containing healthy, lightly infected, and heavily infected levels is constructed using controlled artificial infection methods. Samples with different infection levels are classified and labeled, forming a structured spectral data set, providing a foundation for accurate pest classification. Based on this structured spectral data set, feature extraction is performed on the spectral data for each infection level to determine the spectral differences under different infection levels, ensuring that the framework can store pest classification of medicinal plant samples based on real spectral data.
[0021] For example, when acquiring near-infrared hyperspectral image data from the sample surface for pest classification of stored medicinal plant samples, high-resolution imaging equipment such as short-wave infrared cameras can be used to acquire raw image information in the wavelength range of 900 to 1700 nanometers. This can capture changes in the chemical composition of the sample, which is beneficial to improving the sensitivity of the classification framework. This is because high resolution ensures that the image covers the full features of the sample, avoiding the omission of minor signs of pests, thus providing a reliable basis for subsequent processing.
[0022] In one possible implementation, after extracting the reflectance information of the sample from the acquired near-infrared hyperspectral image data, the reflectance information is preprocessed to remove noise interference. For example, an adaptive thresholding algorithm, such as median adaptive thresholding, is used to generate a binary mask (pixel value 0 or 1), and morphological operations are applied to fill the holes in the mask to obtain a corrected effective region template. Based on this template, filtering and repair are performed to obtain clear original spectral data with noise and missing points removed. This preprocessing helps reduce the interference of environmental noise on the spectral curve, making the spectral data more accurate and suitable for subsequent classification criteria construction, which can significantly improve the quality and classification accuracy of the dataset.
[0023] For example, Figure 2 Images of samples showing three different degrees of insect damage (healthy, slightly infested, and severely infested) are provided. Figure 2 As shown, it should be noted that when constructing a dataset containing healthy, mildly infected, and severely infected levels using controlled artificial infection methods based on the obtained raw spectral data, samples with different infection levels are classified and labeled. For example, samples without insect holes are labeled as healthy, samples with a few insect holes are labeled as mildly infected, and samples with many insect holes are labeled as severely infected, forming a structured spectral data set. This construction method is beneficial for simulating the progress of pests in actual storage environments, providing a diverse data foundation, and ensuring the robustness of the hierarchical framework.
[0024] For example, based on a structured spectral dataset, when extracting features from the spectral data for each level of infection, spectral difference features under different infection degrees are determined. These spectral difference features include differences in reflectance peaks and absorption bands, curve distortion and shift, and statistical distribution differences. For example, analyzing the difference in reflectance peaks in the 1000-1300 nm region can distinguish between healthy and infected samples. This ensures that the framework can store pest classification of medicinal plant samples based on real spectral data, which is beneficial to improving the accuracy and scalability of detection because feature extraction enhances the quantification of spectral differences and supports intelligent classification applications. The specific steps of feature extraction are as follows: First, the region of interest (ROI) is segmented from the corrected hyperspectral image (usually achieved by generating a binary mask using an adaptive threshold algorithm). Then, the reflectance of all pixels in the region is averaged across all bands by pixel-by-pixel calculation to form the initial spectral features. A preset effective band range (e.g., 950-1600 nm or 853.7-1701.8 nm) is used for filtering to eliminate the influence of environmental noise and edge effects. The data is then subjected to min-max scaling normalization (typically processed to the range of [-1, 1]) to optimize the stability and numerical consistency of model training. During the classification or evaluation phase, methods such as principal component analysis (PCA) are applied to reduce the dimensionality of the high-dimensional spectral data, preserving the main variation information that characterizes the degree of pest infestation, thereby forming a characteristic dataset.
[0025] In one possible implementation, the processes of image acquisition and reflectance extraction are mutually supportive. For example, high-resolution image data can be directly input into reflectance extraction to ensure that the preprocessed spectral data is clear. This connection is beneficial to the coherence of the overall framework and avoids data loss. At the same time, the construction of the dataset depends on the preprocessed spectrum to form a structured set, which is further connected with feature extraction to jointly improve the grading effect.
[0026] It should be noted that, from multiple perspectives, such as in the actual application of Astragalus membranaceus samples, obtaining comprehensive image coverage features can support the construction of diverse datasets, while feature extraction verifies infection differences. This mutual support is beneficial to the comprehensiveness of the framework. In another direction, such as testing on different plant samples, reflectance preprocessing reduces noise, which is beneficial to labeling accuracy. This forms a closed loop with feature determination, ensuring reliable grading.
[0027] For example, considering a mild infection scenario, image acquisition captures early changes, and after extracting reflectance, preprocessing removes interference. A dataset is constructed to label the mild level, and features such as absorption valley differences are extracted. This multi-directional support enhances the practicality of the hierarchical framework and is beneficial for food safety control.
[0028] For example, Figure 3 The architecture of Generative Adversarial Networks (GANs) is presented. For example... Figure 3 As shown in S2, the framework employs a Wasserstein generative adversarial network model with gradient penalty to enhance the real spectral data and generate synthetic spectral data to balance class distribution and increase sample diversity. The model is trained adversarially to ensure the fidelity of the generated data.
[0029] From the collected real spectral data, the region of interest for each sample is segmented to obtain raw spectral reflectance information. The reflectance of all pixels within the region is averaged using a pixel-by-pixel calculation method to form the first spectral feature dataset. This first spectral feature dataset is then filtered using a preset band range to obtain spectral information within the effective bands. The filtered data is then normalized to generate the second spectral feature dataset. Based on the second spectral feature dataset, adversarial training is used to augment the data, generating synthetic spectral data that closely resembles the distribution of real data, ensuring a balanced class distribution. The generated synthetic spectral data and the second spectral feature dataset are compared using pre-established evaluation metrics to determine the fidelity of the synthetic data, thus achieving effective augmentation of the real spectral data.
[0030] In one possible implementation, starting with the acquired real spectral data, the region of interest for each sample is first segmented. This segmentation is achieved by applying an adaptive thresholding algorithm to the average grayscale image, thereby generating a binary mask to isolate specific parts of medicinal plants such as Astragalus membranaceus slices and obtain the original spectral reflectance information. Then, by calculating pixel by pixel, the reflectance of all pixels in the region is averaged to form the first spectral feature dataset. This approach can reduce noise interference, improve data representativeness, and benefit the spectral accuracy of subsequent processing.
[0031] For example, for the first spectral feature dataset, a preset band range, such as 950 to 1600 nm, is used for filtering. This filtering process involves removing the part affected by environmental noise and edge effects, and obtaining spectral information within the effective band. Then, the filtered data is normalized by minimum and maximum scaling to adjust the values to the range of -1 to 1, generating the second spectral feature dataset. This helps to enhance the stability of model training, improve generation performance, and avoid bias caused by uneven data distribution.
[0032] In one possible implementation, the data is augmented through adversarial training based on the second spectral feature dataset. This adversarial training involves the generator producing synthetic data from random noise, while the discriminator distinguishes between real and synthetic samples. Through minimax game optimization, it is ensured that the generated synthetic spectral data has a distribution similar to that of real data and that the class distribution is balanced. This increases sample diversity, helps to solve the data imbalance problem, and improves the robustness of downstream classification tasks.
[0033] For example, the generated synthetic spectral data and the second spectral feature dataset are compared with pre-established evaluation metrics such as root mean square error. This comparison process includes calculating the pointwise deviation between the generated data and the real data, determining the fidelity of the synthetic data, thereby effectively enhancing the real spectral data. This method helps to verify the generation quality and balance the class distribution through high-fidelity synthetic data, resulting in better model generalization performance.
[0034] S3, the framework utilizes methods such as principal component analysis, t-distributed random neighbor embedding, root mean square error, maximum average difference, and slice Wasserstein distance to perform qualitative and quantitative evaluation of the synthesized spectral data, in order to verify its global structure, local features, and statistical similarity with real data.
[0035] Raw spectral information was extracted from the collected hyperspectral data of medicinal plants. The region of interest (ROI) for each sample was segmented, and the segmented region data was transformed into initial spectral distribution feature values for subsequent comparison and verification. For these initial spectral distribution feature values, dimensionality reduction was used to perform a preliminary comparison of the global structure, obtaining a dimensionality-reduced feature distribution map. This determined the location and distribution patterns of the data in the overall space, providing a foundation for subsequent verification of local features. Local feature points were extracted from the dimensionality-reduced feature distribution map, and these points were further compared to determine their variation trends and consistency within a small range, ensuring consistency with the local characteristics of the real data. Based on the variation trends of the local feature points, statistical similarity indicators were used to quantitatively evaluate the data, obtaining the final similarity measurement results. These results were used to verify the degree of agreement between the synthesized spectral data and the real data in terms of statistical characteristics, completing a comprehensive evaluation of the medicinal plant pest detection data.
[0036] Specifically, the generation steps are as follows:
[0037] For example, Figure 4 A flowchart illustrating the main processes of spectral data extraction and preprocessing is provided. Figure 4 As shown, 1. When extracting raw spectral information from the collected hyperspectral data of medicinal plants.
[0038] In one possible implementation, the image is first preprocessed to remove noise, for example, by generating a base image by averaging gray values at multiple wavelengths. Then, an adaptive thresholding method is applied to separate medicinal plants, such as slices of Astragalus membranaceus, from the background. This ensures the accuracy of segmentation because the adaptive threshold dynamically adjusts the threshold according to local pixel changes, avoiding erroneous segmentation caused by a fixed threshold. This is beneficial for obtaining clean region of interest data. The reflectance of pixels in these regions is then averaged to convert them into initial spectral distribution feature values. This conversion process can capture the overall spectral characteristics of the sample, providing a reliable basis for subsequent comparisons. For example, in mildly infected samples, these feature values will show slight changes in absorption peaks, thus supporting the preliminary comparison of the global structure.
[0039] 2. When using dimensionality reduction techniques to perform a preliminary comparison of the global structure based on the initial spectral distribution characteristic values.
[0040] In one possible implementation, principal component analysis (PCA) is used to project high-dimensional data into a low-dimensional space to obtain a dimensionality-reduced feature distribution map. For example, when processing the feature values of healthy and heavily infected samples, PCA retains the main variations in the data by calculating the covariance matrix and extracting the principal eigenvectors. This highlights the positional relationships and distribution patterns in the overall space, which is beneficial for identifying the macroscopic similarity between synthetic and real data because it reduces the influence of dimensional noise and lays the foundation for local feature verification. For example, the distribution map shows that the point clusters of synthetic data and real data overlap closely, which supports the effectiveness of data augmentation from one perspective. At the same time, from another perspective, such as cluster density, it can also mutually verify global consistency.
[0041] 3. When extracting local feature points from the dimensionality-reduced feature distribution map for refinement and comparison.
[0042] In one possible implementation, key points on the distribution map, such as cluster centers or edge points, are selected. Then, the Euclidean distance between these points is calculated to determine the trend and consistency of change within a small range. For example, for feature points with mild infection, the change in the spectral slope in their neighborhood is observed to see if it matches the real data. This ensures the consistency of local characteristics and is beneficial for detecting subtle differences because the refined comparison magnifies the local variation and avoids the problem of global averaging masking. From one aspect, such as trend smoothness, it can support the fidelity of the synthetic data. From another aspect, such as the consistency between points, it can also mutually verify the local reliability of the data and provide accurate input for quantitative evaluation.
[0043] 4. When conducting quantitative evaluation based on the changing trends of local feature points and statistical similarity indicators.
[0044] In one possible implementation, the root mean square error (RMSE) is calculated as an indicator to measure the difference. For example, the average of the square roots of the differences between the trend curves of synthetic and real data can be used to obtain the final similarity measurement result, which is helpful in verifying the degree of agreement in statistical characteristics. This is because the RMSE quantifies the point-to-point deviation, while the maximum average difference supports the comprehensiveness of the assessment from the perspective of the largest distribution gap. For example, in heavily infected data, a low error value indicates high similarity. From the perspective of the smoothness of the trend, it can mutually support the reliability of the overall verification, thereby completing a comprehensive assessment of the detection data of medicinal plant pests. This assessment ensures the practicality of the framework from a statistical perspective.
[0045] S4. The framework is based on the enhanced dataset and applies classifiers such as convolutional neural networks, support vector machines and random forests to classify pests. Among them, convolutional neural networks achieve the best performance, improving the accuracy from 73.62% of the original dataset to 88.39%.
[0046] Initial spectral information was obtained from collected hyperspectral data of medicinal plants. Samples at different infection levels were classified and labeled to form an original dataset containing healthy, mildly infected, and severely infected samples. The initial spectral information was acquired using near-infrared hyperspectral imaging equipment to ensure that the spectral band data of each sample completely covered the predetermined range. The data was then preliminarily cleaned to remove noise, resulting in a processed spectral dataset. Data augmentation was performed on the processed spectral dataset to expand the sample size and balance the data distribution across different infection levels by generating a generative model. The augmented spectral dataset, while maintaining the original spectral characteristics, increased diversity to ensure the representativeness of each category in subsequent classification tasks, generating an expanded spectral dataset. The expanded spectral dataset was divided into training and validation sets. Feature extraction was performed on the spectral data in the training set to obtain spectral feature values that characterize the degree of pest infection. The feature extraction process processed the spectral band data layer by layer, retaining the main information related to the infection level to form a characteristic spectral dataset. Classification rules were constructed for the characteristic spectral dataset to distinguish between different pest levels in medicinal plants. The classification rules are based on characteristic spectral data. By comparing preset thresholds and characteristic value distributions, the infection level category of the sample is determined, and the accurate identification of pest classification for medicinal plants is finally achieved.
[0047] Specifically, the generation steps are as follows:
[0048] 1. In one possible implementation, the process begins with the acquisition of hyperspectral data from medicinal plants such as Astragalus membranaceus slices. Initial spectral information is captured using near-infrared hyperspectral imaging equipment, which typically includes a spectrometer and imaging sensors capable of scanning the sample surface and recording reflectance data for each pixel across multiple bands. This acquisition method ensures the integrity of the spectral data, covering a range from near-infrared to visible light, thereby capturing subtle changes in the chemical composition of the Astragalus membranaceus slices. Samples are then classified and labeled according to different levels of infection; for example, slices without visible damage are labeled as healthy, slices with a few insect holes are labeled as mildly infected, and severely powdery slices are labeled as heavily infected, forming the initial dataset. This labeling aids subsequent data processing because it provides clear category references, avoids confusion, and improves the reliability of the dataset. The initial cleaning process involves removing noise, such as smoothing outomaly peaks using an averaging filter. This improves data quality, making the cleaned spectral dataset more suitable for further analysis and reducing the risk of misclassification.
[0049] 2. Specifically, data augmentation is performed on the processed spectral dataset by using generative models such as adversarial networks to synthesize new samples. These models learn the distribution of the original data to generate similar spectral curves, thereby expanding the sample size and balancing the distribution among healthy, mildly infected, and severely infected individuals.
[0050] For example, in cases of imbalanced samples, generating more heavily polluted spectral data to match other categories increases the diversity of the augmented dataset while preserving original spectral features such as peak positions and intensities, ensuring the representativeness of samples from each category in subsequent classification tasks. This operation alleviates the small sample size problem, improves the model's generalization ability, and thus makes classification more accurate and reliable.
[0051] 3. In one possible implementation, the expanded spectral dataset is divided into training and validation sets, for example, by a ratio of 7:3 (training:validation) to ensure the validation set can independently evaluate performance. Then, feature extraction is performed on the spectral data in the training set. This process involves layer-by-layer processing of the spectral band data, such as first applying principal component analysis to reduce dimensionality and preserve major variations, and then extracting features related to the infection level, such as the absorbance of specific bands. These features characterize the degree of pest infestation because they reflect changes in components such as polysaccharides in Astragalus membranaceus, forming a characteristic spectral dataset. The technical benefits of this approach are simplified data complexity, easier classifier processing, and improved efficiency and accuracy of the classification task.
[0052] 4. Specifically, classification rules are constructed for the characteristic spectral dataset. These rules are based on the distribution of feature values and are determined by comparing them with preset thresholds, such as an absorption rate threshold. For example, if a feature value exceeds the threshold, it is judged as severely infected. For instance, if Prob (severe infection) in the output probability distribution exceeds 0.8, the system determines that the Astragalus slice is severely infected. This comparison method ensures the objectivity of the judgment and is used for the pest classification task of medicinal plants such as Astragalus slices, ultimately achieving accurate identification. The construction of this rule can bring higher classification accuracy because it directly utilizes the results of enhancement and feature extraction, supporting the complete process from raw data to final classification. The preset threshold, such as the absorption rate threshold, is usually 0.5 or 20%. Since the framework adopts a data-driven deep learning and machine learning model, the threshold is a dynamic threshold rather than a static value. That is, the model (such as CNN or SVM) automatically constructs a decision boundary to distinguish between healthy, mild, and severe infections by learning thousands of spectral curve features.
[0053] S21, the controlled artificial infection includes placing medicinal plant slices in a constant temperature incubator to incubate with adult pests, screening samples with different infection levels in stages, and monitoring and replacing dead insects to maintain infection pressure, thereby obtaining a representative dataset.
[0054] Medicinal plant slices were placed in a constant-temperature incubator for controlled artificial infection by co-incubating with adult pests. Stable temperature, humidity, and light conditions were maintained to ensure consistent pest activity. Initial pest numbers and plant slice conditions were recorded to generate preliminary infection data. Based on this preliminary data, the plant slices were screened in stages, categorized into different infection levels according to characteristics such as the number of insect holes and the proportion of surface debris. The distribution information of the categorized samples was then obtained. The survival status of adult pests was monitored periodically from this distribution information. Dead individuals were promptly replaced with live adults to maintain continuous infection pressure and ensure the stability of infection conditions at each stage, constructing a representative infection level dataset. The characteristic information of each type of sample in this representative infection level dataset was organized and labeled, forming a complete data foundation for subsequent analysis and supporting controlled artificial infection research on the classification of pests affecting medicinal plants.
[0055] Specifically, the generation steps are as follows:
[0056] 1. For example, Astragalus membranaceus slices were placed in a constant temperature incubator and artificially infected in a controlled manner by co-incubating with adult medicinal beetles. The temperature was set at around 25 degrees Celsius, the humidity at around 70%, and the light cycle was 12 hours of light / 12 hours of darkness to ensure consistent pest activity. This provides a stable infection environment, which is beneficial to improving the reliability of subsequent data. The initial number of pests, such as 15, and the condition of the slices, such as intact, were recorded to form preliminary infection record data. This record helps to track the infection process and avoid data deviations caused by environmental fluctuations, thereby providing an accurate basis for grading.
[0057] 2. In one possible implementation, plant slices are screened in stages based on preliminary infection records. For example, after 30 days of incubation in the first stage, the slices are classified as mildly infected based on the number of insect holes (less than 5) and the surface debris ratio (less than 15%). After another 60 days of incubation in the second stage, the slices are classified as severely infected based on the number of insect holes (more than 5) or the debris coverage (more than 15%). This classification method can achieve a class balance, which is beneficial to enhancing the representativeness of the dataset and supports mutual verification of different infection levels through multi-stage screening.
[0058] 3. For example, based on the classified sample distribution information, the survival status of adult pests can be monitored regularly, such as checking twice a week. When dead individuals are found, they can be replaced with live adults of the same species in a timely manner to maintain continuous infection pressure and ensure the stability of infection conditions at each stage of the sample. This monitoring and replacement can bring continuity of infection pressure, which is conducive to constructing a representative infection level dataset, avoiding uneven infection caused by population density decline, thereby improving the practical value of the dataset in pest classification.
[0059] 4. In one possible implementation, for the constructed representative infection level dataset, the characteristic information of various types of samples is organized and labeled. For example, healthy samples are labeled as having no insect holes, mild samples as having a few minor damages, and severe samples as having significant damages. This forms a complete data foundation for subsequent analysis. Such organization and labeling can bring clarity to the data structure, which is conducive to supporting controlled artificial infection research on the classification of pests in medicinal plants. Furthermore, feature labeling enhances the targeting of the analysis, realizing the logical chain from infection control to classification application.
[0060] 5. For example, in actual operation, the above-mentioned infection record data is combined with the screening categories. For instance, the number of pests initially recorded is matched with the characteristics of insect holes in different stages to verify the effectiveness of infection pressure. This combination can provide support in multiple directions, such as mutual verification from environmental stability to category distribution, which is conducive to improving the reliability of the overall dataset. It also emphasizes the role of maintaining pressure through replacement mechanisms to avoid data deviation caused by infection interruption, thereby providing more accurate technical support in pest classification.
[0061] 6. In one possible implementation, when extending to labeling feature information, for example, by integrating sample distribution information with monitoring results to generate a correspondence table of labels such as infection level and debris ratio, this integration can bring about a superposition of technical effects, which is conducive to the formation of a thought chain from initial infection to final data foundation, and supports the rationality of classification through multiple aspects, such as the count of insect holes at different stages, to achieve comprehensive optimization of controlled artificial infection.
[0062] S22, the hyperspectral image acquisition uses an imaging system covering the range of 853.7 to 1701.8 nm with a resolution of 5 nm, performs black and white reference correction to eliminate noise, and extracts the average reflectance spectrum from the region of interest, which is then normalized to the range of [-1,1] to optimize model training.
[0063] For hyperspectral image acquisition, an imaging device covering the near-infrared range is used to scan the sample, acquiring raw image data containing multiple wavelength channels. This raw image is then corrected using a pre-established black-and-white reference image to eliminate dark current noise and the effects of light source inhomogeneity, resulting in corrected first image data. From this corrected first image data, the location of the region of interest (ROI) is determined. The pixel set of the target region is extracted using pixel-by-pixel segmentation, and the average reflectance value of all pixels within this region at each wavelength is calculated, forming an initial spectral curve representing the sample characteristics. The initial spectral curve is then normalized to a preset range to ensure consistent data distribution and maintain numerical stability during subsequent processing, resulting in a processed normalized spectral curve. This normalized spectral curve is then used as input and stored as a standard format file for subsequent feature extraction and classification tasks, ensuring seamless integration of the data into downstream processing workflows and achieving the goal of hyperspectral image data preprocessing.
[0064] For example, in hyperspectral image acquisition, an imaging device covering the near-infrared range is used to scan slices of medicinal plants such as Astragalus membranaceus. This captures wavelength information from 853.7 nm to 1701.8 nm. Such devices typically include a line-scan camera and a light source system, acquiring raw image data through line-by-line scanning, thus preserving the chemical composition details of the sample. Subsequently, correction is performed using a pre-established black-and-white reference image. The black reference is used to subtract dark current noise, i.e., the background signal of the sensor under no-light conditions, while the white reference corrects for light source inhomogeneity. The correction formula is: , This represents the corrected HSI image. , and The HSI images of the samples are used to ensure that the reflectance of each pixel accurately reflects the characteristics of the sample. This significantly improves data quality, avoids noise interference in subsequent analysis, and yields corrected first image data, which is beneficial for accurately detecting the level of pest infestation.
[0065] For example, to determine the location of the region of interest from the corrected first image data, the average grayscale image can be converted into a binary mask using an adaptive thresholding method. The region of interest usually corresponds to the outline of the Astragalus membranaceus slice, avoiding background interference. Then, the pixel set of the target region is extracted pixel by pixel, and the average reflectance value of these pixels at each wavelength is calculated to form an initial spectral curve. This method can capture the core spectral features of the sample in a concentrated manner, improving the accuracy of pest classification, because the average value reduces the random variation of individual pixels, resulting in a more stable feature representation.
[0066] For example, the data range of the initial spectral curve can be adjusted to normalize the values to the [-1,1] interval. This can be achieved through min-max scaling, which involves subtracting the minimum value from the original value, dividing by the range difference, and then adjusting to the target interval. This ensures the consistency of data distribution and optimizes the stability of model training, preventing gradient explosion or vanishing problems. Especially when used in generative adversarial networks, it improves the fidelity of synthetic data and yields the processed normalized spectral curve.
[0067] For example, the processed normalized spectral curves can be stored as standard format files, such as MAT or CSV, for subsequent feature extraction and classification tasks. This ensures that the data can be seamlessly integrated into downstream processes, such as being directly input into convolutional neural networks for pest classification. This enables an efficient data pipeline to achieve the goal of preprocessing hyperspectral image data and ultimately support a non-destructive framework for food safety testing.
[0068] S31, the qualitative assessment projects high-dimensional data to a low-dimensional space by principal component analysis to preserve variance, and uses t-distributed random neighbor embedding to capture local clustering patterns to visualize the distribution consistency between synthetic data and real data.
[0069] Raw spectral information is obtained from high-dimensional data. This raw spectral information undergoes preliminary dimensionality reduction, projecting it into a lower-dimensional space to facilitate subsequent visualization, generating a first dimensionality-reduced dataset. For this first dataset, linear dimensionality reduction is used to further process the data, preserving key variance information to form a second dimensionality-reduced dataset for subsequent distribution structure comparison. Local features are extracted from the second dataset, and nonlinear dimensionality reduction techniques are applied to capture the proximity relationships between data points, generating a third dimensionality-reduced dataset that highlights local clustering patterns. This third dataset is then compared with the distribution characteristics of real data. Visualization techniques are used to present the consistency of the synthetic and real data distributions in the lower-dimensional space, ensuring that the evaluation results meet the objectives of qualitative evaluation.
[0070] Specifically, the generation steps are as follows:
[0071] 1. When obtaining raw spectral information from high-dimensional data.
[0072] Understandably, this acquisition process involves the direct collection of spectral samples. For example, in a hyperspectral imaging system, multi-band reflectance data is obtained by scanning the sample surface. The benefit of doing so is to ensure data integrity and provide a reliable basis for subsequent dimensionality reduction.
[0073] Specifically,
[0074] In one embodiment, spectral information of medicinal plants such as Astragalus membranaceus slices is extracted. First, an adaptive threshold algorithm is used to segment the region of interest, and then the average pixel value within the region is calculated to form the original spectral curve. The purpose of this method is to reduce noise interference and improve data purity, thereby making the initial dimensionality reduction process more accurate. The generated first dimensionality reduction dataset can thus better reflect the essential characteristics of the original data, avoid the curse of dimensionality in high-dimensional space, and facilitate the smooth progress of visualization operations.
[0075] 2. When using linear dimensionality reduction methods for the first dimensionality reduction dataset, such as principal component analysis, the process involves calculating the covariance matrix of the data, then solving for the eigenvalues and eigenvectors, and projecting the data onto the principal component directions to retain the main variance information. The beneficial effect of doing so is to simplify the data structure while maintaining the global distribution characteristics.
[0076] Specifically,
[0077] In one embodiment, principal component analysis is applied to the spectral data, projecting 211 bands onto the first three principal components to form a second dimensionality-reduced dataset. The purpose of this projection is to highlight the main variability of the data. For example, the scatter distribution of real and synthetic spectra in the principal component space can be intuitively compared to determine global similarity, thus laying the foundation for subsequent comparison of distribution structures, avoiding information loss, and ensuring the comprehensiveness of the evaluation.
[0078] 3. When extracting local features from the second dimensionality reduction dataset.
[0079] Understandably, nonlinear dimensionality reduction techniques, such as t-distributed random neighbor embedding, map data points by minimizing the distribution divergence in high-dimensional and low-dimensional spaces. The aim is to map the original high-dimensional spectral data to two-dimensional or three-dimensional space, while capturing the proximity relationships between data points. The beneficial effect of doing so is to reveal local clustering patterns in the data and enhance the fine-grainedness of visualization.
[0080] Specifically,
[0081] In one embodiment, a t-distributed random neighbor embedding is applied to the second dimensionality-reduced dataset. In the original high-dimensional spectral space, the conditional probabilities between data points are calculated; that is, the similarity between data points is transformed into conditional probabilities, representing the likelihood of choosing another point as its neighbor given a given condition. A corresponding position is initialized for each high-dimensional point in the low-dimensional space (typically two or three dimensions). A t-distribution (rather than a Gaussian distribution) is used in the low-dimensional space to measure the similarity between points, which helps to address the crowding problem and makes different clusters clearer when visualized. The positions of the low-dimensional points are adjusted by iterative optimization (such as gradient descent) to minimize the Kullback-Leibler (KL) divergence between the high-dimensional and low-dimensional distributions. This ultimately generates a third dimensionality-reduced dataset. This capture highlights the cluster structure; for example, if synthetic data points form similar clusters with real data points in the low-dimensional space, it indicates high local consistency, thus supporting the reliability of the overall distribution assessment.
[0082] 4. When comparing the third dimensionality reduction dataset, for example, by using visualization methods such as scatter plots to present the distribution, the process involves overlaying the low-dimensional points of the synthetic data and the real data and observing the consistency of the distribution in the low-dimensional space, i.e. the degree of overlap. If the clustering patterns are highly overlapping, it proves that the data generated by the Wasserstein Generative Adversarial Network (WGAN-GP) used in this framework has extremely high fidelity. The beneficial effect of doing so is to intuitively verify consistency and ensure that the goal of qualitative evaluation is achieved.
[0083] Specifically,
[0084] In one embodiment, the distribution of the third dimensionality reduction dataset is compared with that of the real data, and two-dimensional or three-dimensional charts are drawn to analyze the separation or fusion of point groups. The purpose of this comparison is to confirm the fidelity of the synthetic data. For example, if the clustering patterns are highly overlapping, it proves that the generation method is effective, thereby improving the overall practical value of the data augmentation strategy and meeting the business objective of evaluating the consistency between the distribution of synthetic data and real data.
[0085] S32, the quantitative evaluation calculates the root mean square error to assess point-by-point deviation, the maximum average difference to measure distribution difference, and the slice Wasserstein distance to approximate overall similarity. As the number of training rounds increases, the index decreases, indicating that the model converges.
[0086] For point-by-point deviation evaluation of spectral data, the reflectance values of each band are first obtained from the original and generated spectral data. The difference between the two is calculated and quantified using the root mean square error (RMSE) method to obtain the overall evaluation result of point-by-point deviation. After obtaining the evaluation result of point-by-point deviation, for the measurement of distribution difference, the overall distribution characteristics are extracted from the aforementioned reflectance values. The maximum mean difference method is used to compare the distribution characteristics of the original and generated spectral data to determine the degree of difference between the distributions. After completing the measurement of distribution difference, for the approximate evaluation of overall similarity, local structural information is further extracted from the aforementioned distribution characteristics. The high-dimensional data is projected into multiple one-dimensional subspaces by slicing, the distance difference within each subspace is calculated, and these distance differences are averaged to obtain the evaluation value of overall similarity. Based on the obtained overall similarity evaluation value, the historical changes of the above point-by-point deviation, distribution difference, and overall similarity evaluation values are continuously recorded as the training rounds increase. By comparing the changing trends of different rounds, the regularity of the index decrease is judged, thereby verifying the convergence performance of the model in spectral data generation.
[0087] Specifically, the generation steps are as follows:
[0088] 1. Specifically, in the process of evaluating the point-by-point deviation of spectral data, after obtaining the reflectance values of each band from the original spectral data and the generated spectral data, the difference between the two is calculated and quantified by the root mean square error method. This can effectively identify the inconsistencies of the spectral curve at specific points. This helps to ensure that the generated data is close to the real data at the level of detail, thereby improving the reliability of subsequent model training.
[0089] For example, when processing the spectrum of Astragalus membranaceus samples, if the reflectance of a certain band is 0.5 in the original data and 0.48 in the generated data, the difference value is calculated and then summarized by the root mean square error to quantify the overall degree of deviation. The technical effect of this is that the model can more accurately simulate the reflectance characteristics of plant tissues and avoid the generation of too many errors that could lead to the failure of the classification task.
[0090] 2. In one embodiment, after obtaining the point-by-point deviation evaluation results, the overall distribution characteristics are extracted from the reflectance values and compared using the maximum average difference method to measure the distribution difference. This can capture the global pattern differences of the dataset. The purpose of this is to verify whether the generated data uniformly covers the distribution range of the real data, thereby enhancing the diversity of data augmentation.
[0091] For example, when dealing with the spectral distribution of healthy samples, if the reflectance of the original data exhibits a normal distribution across multiple bands while the generated data is biased to one side, the maximum mean difference method can determine the degree of difference by comparing the distribution center and edges. This has the beneficial effect of improving the model's ability to generalize to different infection levels and avoiding overfitting problems caused by distribution bias.
[0092] 3. Specifically, after completing the distribution difference measurement, for the approximate evaluation of overall similarity, local structural information is extracted from the distribution features and projected onto a one-dimensional subspace in a slicing manner to calculate the average distance difference, which can approximate the similarity of high-dimensional data. The reason for doing this is to provide multi-dimensional verification, ensure that the generated data is structurally aligned with the real data, and thus support more stable convergence judgment.
[0093] For example, in lightly infected samples, if local structures such as absorption valley features are small in distance in the projected subspace, the averaged evaluation value will be low. The resulting technical effect is to enhance the model's ability to capture complex spectral patterns and improve the accuracy of pest detection.
[0094] 4. In one embodiment, based on the overall similarity evaluation value, the point-by-point deviation distribution difference and the historical change data of the overall similarity are continuously recorded as the training rounds increase. By comparing the trend of change, the regularity of the index decline can be judged, which can verify the convergence performance of the model. The purpose of doing this is to dynamically monitor the training process and select the best round data for classification. The beneficial effect of this is to optimize the quality of the generated data and ensure efficient convergence in the generation of spectral data.
[0095] For example, if the metric decreases from high to low values from the early rounds to the later rounds, the trend comparison shows a regular decline, which supports the model in generating high-fidelity synthetic samples in practical applications and improving the performance of downstream tasks.
[0096] For example, Figure 5The average spectral reflectance curves of Astragalus membranaceus samples at three different infection levels are presented. Figure 5 As shown in S321, the training rounds are set to 10,000 times. The Adam optimizer and gradient penalty term are used to ensure training stability, and the spectrum generated at the 10,000th round is used for subsequent classification to achieve high-fidelity data augmentation.
[0097] Raw reflectance curves at different infection levels are obtained from pre-collected spectral data of medicinal plant samples, such as Astragalus membranaceus. These curves are normalized within a specified band range to ensure data consistency and lay the foundation for subsequent processing, resulting in the first processed spectral dataset. For this first processed spectral dataset, a sufficient number of training epochs are set to ensure convergence. A gradient penalty term is introduced during training to maintain stability, generating synthetic spectral curves that approximate real data, forming the second synthetic spectral dataset. Reflectance features of key bands are extracted from the second synthetic spectral dataset and compared with the original data to determine the consistency of peak positions and curve smoothness, resulting in the third validated spectral dataset. This third validated spectral dataset is used as augmented data for subsequent classification tasks, ensuring high data fidelity to support accurate differentiation of insect infestation levels in Astragalus membranaceus samples, achieving the goal of high-fidelity data augmentation.
[0098] In one embodiment, raw reflectance curves for different infection levels are obtained from pre-collected spectral data of Astragalus membranaceus samples, such as curves for healthy samples and mildly infected samples. The change in reflectance from a sharp rise to a plateau in the 900 to 1600 nm band is observed. This highlights the differences caused by infection and is beneficial to the accuracy of subsequent data processing. Then, these curves are normalized within a specified band range to ensure data consistency and lay the foundation for subsequent processing, resulting in a first-processed spectral dataset. This normalization reduces noise interference, improves data quality, and makes the generation process more reliable.
[0099] In one embodiment, for the first processed spectral dataset, the number of training rounds is set to a sufficient number to ensure convergence. For example, in the early stages of training, curves are generated that show high-frequency noise, while in the later stages, the curves tend to be smoother. This can gradually optimize the realism of the synthetic data and is beneficial for capturing the patterns of the real spectrum. A gradient penalty term is introduced during the training process to maintain the stability of the training and generate synthetic spectral curves that approximate the real data, forming a second synthetic spectral dataset. This penalty term can prevent pattern collapse, ensure the diversity and stability of the generated data, and thus improve the overall enhancement effect.
[0100] In one embodiment, reflectance features of key bands are extracted from the second synthetic spectral dataset. For example, the difference in absorption valleys between healthy and infected samples is compared in the water absorption region around 1450 nm. This verifies the matching degree of the generated curves in terms of absorption features and helps to confirm the high fidelity of the data. By comparing with the original data, the consistency of the generated synthetic spectra in terms of peak position and curve smoothness is judged, resulting in a third verified spectral dataset. This comparison can reveal nonlinear relationships, such as the decrease in reflectance caused by severe infection, thereby enhancing the applicability of the dataset.
[0101] In one embodiment, the third validated spectral dataset is used as augmented data for subsequent classification tasks. For example, after inputting this data into the classifier, the accuracy is significantly improved from the baseline level. This balances the imbalanced dataset, improves the model's generalization ability, and ensures high data fidelity to support accurate differentiation of pest infestation levels in Astragalus membranaceus samples. This achieves the goal of high-fidelity data augmentation, which provides a more solid foundation for pest detection and thus improves classification performance.
[0102] S41, the convolutional neural network model includes stacked convolutional blocks and fully connected layers, and is trained using cross-entropy loss and five-fold cross-validation to prevent overfitting and improve generalization ability.
[0103] For the construction of the convolutional neural network, the network architecture consists of multiple stacked convolutional blocks and fully connected layers. The convolutional blocks progressively extract local features from the input data, reducing the dimensionality of the high-dimensional input to a low-dimensional feature representation through layer-by-layer processing. The extracted features are then passed to the fully connected layers for further integration. During processing in the fully connected layers, the feature representation is mapped to the output space of the classification task. Layer-by-layer computation integrates the features into a probability distribution corresponding to the target category, ensuring that the classification relevance of the features is preserved and providing a basis for subsequent loss calculation. For loss calculation and optimization, the cross-entropy loss function is used to measure the difference between the predicted probability distribution and the true label. The network parameters are iteratively adjusted to reduce this difference. Simultaneously, five-fold cross-validation is introduced during training, dividing the dataset into multiple subsets, which are used alternately as validation sets to evaluate performance. During training iterations, for the results of each fold validation, the classification error is recorded and the parameter update direction is adjusted to ensure balanced network performance across different data subsets, thereby improving the generalization ability for the pest severity classification task.
[0104] For example, when constructing a convolutional neural network, the network architecture processes the input spectral data by stacking multiple convolutional blocks. Each of these blocks contains a convolutional layer, an activation function, and a pooling layer. The convolutional layers use filters to scan the input to capture local spectral patterns, such as reflectance peaks in specific bands, thereby progressively reducing the high-dimensional spectral input from hundreds of bands to a more compact feature representation. This dimensionality reduction helps reduce computational complexity and highlight key features related to pest infestation. These feature representations are then fed into fully connected layers, which connect all the local features, such as reflectance peaks in specific bands. By computing layer by layer, the scattered local features are integrated into a higher-level abstract representation, enabling the capture of the correspondence between spectral patterns (such as absorption peaks) and infection levels. This improves classification accuracy because it allows the network to learn complex relationships between features, thus better distinguishing between healthy, lightly infected, and heavily infected samples. By preserving the complete classification relevance, classification bias caused by information loss is avoided.
[0105] In one possible implementation, the fully connected layer processes the feature representation to the output space, for example, by transforming the features layer by layer through multiple hidden layers. Each layer uses a weight matrix to multiply the input vector and applies a non-linear activation, such as the ReLU function, to introduce non-linearity and prevent gradient vanishing. This layer-by-layer computation integrates the features into a probability distribution, which has the advantage of preserving classification relevance. For example, in pest detection, it ensures that the correspondence between spectral patterns, such as absorption peaks, and infection levels is not lost, providing a reliable basis for subsequent loss calculations and avoiding classification bias caused by information loss.
[0106] For example, regarding loss calculation and optimization, the cross-entropy loss function quantifies the difference between the predicted probability and the negative log-likelihood of the true label. For instance, for a sample, if the true label is heavily infected and the predicted probability is 0.8, the loss is low; otherwise, it is high. The difference is reduced by iteratively adjusting parameters such as convolutional kernel weights, fully connected layer weights, and bias terms through gradient descent. This method is beneficial for training stability because it directly optimizes classification decisions. At the same time, five-fold cross-validation is introduced, dividing the dataset, such as 1023 spectra, into five equal parts. One part is used as the validation set in turn to evaluate the model's performance on unseen data. The beneficial effect is to prevent overfitting and ensure that the model generalizes on different subsets.
[0107] In one possible implementation, the classification error is recorded for each fold validation result during training iterations, as shown in Table 1, along with the accuracy and... Figure 6 The confusion matrix is shown, and then the parameter update direction is adjusted. For example, if the first fold shows a high misclassification of mild infestation, the learning of relevant features is strengthened. This balanced performance is beneficial to the overall generalization ability. In the task of classifying the severity of pests, it enables the model to reliably handle variable spectral data, and ultimately achieve higher detection accuracy and robustness.
[0108] Table 1: Classification accuracy (%) of different classifiers on the original (imbalanced) dataset and the WGAN-GP (balanced) dataset.
[0109]
[0110] S42, the support vector machine uses radial basis function kernels and grid search to optimize parameters, while the random forest improves classification robustness by integrating decision trees and hyperparameter tuning. All classifiers have improved accuracy on augmented datasets, thereby supporting food safety control.
[0111] Initial spectral features are obtained from hyperspectral data. Samples with different levels of pest infestation are classified and labeled, resulting in three original datasets: healthy, lightly infested, and heavily infested. These original datasets contain spectral reflectance information across multiple bands for subsequent classification. A kernel function method is used to perform a nonlinear mapping on the spectral reflectance information in the original datasets, transforming it into a high-dimensional space to better separate sample categories with different infestation levels. The mapped high-dimensional data retains the distribution characteristics of the original spectral features, providing a foundation for subsequent parameter optimization. Based on this mapped high-dimensional data, a grid search method is used to adjust the classification boundary parameters to determine the optimal classification hyperplane, distinguishing sample categories with different infestation levels. The adjusted classification hyperplane effectively improves classification accuracy, supporting precise pest classification in food safety control. The adjusted classification hyperplane is applied to the enhanced spectral dataset to predict the classification of new samples, ensuring the classification results are consistent with the actual infestation level. The classification prediction results are directly used to determine the degree of pest infestation in the storage environment, ensuring the accurate implementation of food safety control.
[0112] Specifically, the generation steps are as follows:
[0113] 1. In one possible implementation, the process of obtaining initial spectral features from hyperspectral data involves scanning multiple bands of reflectance signals from slices of medicinal plants such as Astragalus membranaceus, for example, by capturing spectral curves within a wavelength range using a near-infrared hyperspectral imaging device. This captures details of chemical changes caused by pest infestation, which is beneficial for the accuracy of subsequent classification.
[0114] Specifically, when classifying and labeling samples with different levels of pest infestation, the difference in reflectance peaks can be used as a basis to classify healthy samples, which usually show uniform spectral curves. Slightly infested samples may show slight absorption band shifts, while heavily infested samples show obvious curve distortions. This labeling method helps to build a balanced original dataset and improve the generalization ability of the classification model.
[0115] For example, in a storage environment, this acquisition and labeling can identify potential contamination risks early, thereby reducing food safety hazards.
[0116] 2. In one possible implementation, the specific implementation of nonlinear mapping using kernel function methods for spectral reflectance information in the original dataset includes using radial basis function kernels to project low-dimensional spectral data into a high-dimensional space, for example, transforming the feature vectors of 211 bands into a higher-dimensional representation. This can effectively handle nonlinear class boundaries and is beneficial for separating similar but subtly different infected samples.
[0117] Specifically, this mapping preserves the distribution characteristics of the original spectral features, such as maintaining the clustering compactness of the smooth curve pattern of healthy samples in high dimensions, while the spread of infected samples is wider. This preservation lays the foundation for parameter optimization and can improve the overall classification robustness.
[0118] For example, from multiple perspectives, without mapping, a linear classifier might confuse mild and severe infection, but after mapping, the hyperplane can clearly distinguish them, thus supporting more accurate food safety control.
[0119] 3. In one possible implementation, the process of adjusting the classification boundary parameters based on the mapped high-dimensional data using a grid search method involves systematically traversing combinations of regularization parameters and kernel coefficients, such as testing different parameter pairs to find values that minimize the classification error. This approach can determine the optimal classification hyperplane and is beneficial for balancing model complexity and accuracy.
[0120] Specifically, this adjustment can effectively improve classification accuracy, such as reducing the misclassification rate of healthy samples in pest classification, supporting accurate judgment of food safety control. On the other hand, if the parameters are not optimized, the model may overfit the training data, but grid search ensures generalization to new samples.
[0121] For example, in practical applications, this method can significantly improve classification accuracy from the initial level and support real-time monitoring of pests in storage.
[0122] 4. In one possible implementation, the adjusted classification hyperplane is applied to the enhanced spectral dataset by inputting newly added synthetic samples for prediction, such as using additional spectral data generated by WGAN-GP to verify classification consistency. This ensures that the results match the actual level of infestation, which is beneficial for pest identification in the storage environment and for food safety assurance.
[0123] The prediction process refers to applying the adjusted optimal classification hyperplane (determined by Support Vector Machine (SVM) in high-dimensional space) to new samples: First, the newly added synthetic spectral data (generated by WGAN-GP) is normalized using the same method as the training set. Then, a kernel function (such as the Radial Basis Function (RBF) kernel) is used to project these low-dimensional spectral data into a high-dimensional feature space. The projected feature vectors are then substituted into the mathematical equations of the classification hyperplane. Based on the sample's position relative to the classification hyperplane in high-dimensional space, the system automatically outputs its category (healthy, lightly infested, or heavily infested). If the sample falls on a specific side of the hyperplane, it is determined to be the corresponding pest level.
[0124] The purpose of verifying classification consistency is to ensure that the augmented data generated by WGAN-GP logically follows the same classification rules as the real data. The specific verification method is as follows:
[0125] Label comparison method: Since WGAN-GP generates synthetic samples with class labels (e.g., specifying to generate heavily polluted spectra), the model's predictions are compared with the preset labels used during generation during validation. Consistency criterion: If the predictions of the vast majority of synthetic samples are consistent with their preset labels, it proves that the generated data has successfully captured the essential characteristics of the category.
[0126] Classification boundary stability analysis: Observe whether the position of the classification hyperplane shifts drastically after introducing synthetic samples. Consistency criterion: If the augmented dataset makes the classification boundary more stable and the accuracy on the validation set remains stable or improves (e.g., the frame ultimately achieves 88.39% accuracy), then classification consistency is verified.
[0127] Probability distribution verification: For classifiers such as CNNs, the probability distribution output by the Softmax layer is used for verification. If the probability of a synthetic sample in its corresponding class is significantly higher than that in other classes, it indicates that it has a high degree of statistical consistency in the feature space.
[0128] Specifically, this application can be used directly to determine the level of infection, such as quickly identifying heavily infected sections to prevent the spread of contamination. It supports the practicality of the overall framework from multiple directions. For example, by combining the aforementioned mapping and adjustment, an end-to-end pest classification process can be formed, improving detection efficiency and accuracy.
[0129] The above description is merely a preferred embodiment of this application and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of the invention involved in this application is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the concept of this application. For example, technical solutions formed by substituting the above features with (but not limited to) technical features with similar functions disclosed in this application.
Claims
1. An enhanced hyperspectral framework method for storing pest classification of medicinal plants, characterized in that, include: The framework acquires and stores near-infrared hyperspectral images of medicinal plant samples, and constructs a dataset containing healthy, mildly infected, and severely infected levels through controlled artificial infection to obtain real spectral data as a basis. The framework employs a Wasserstein generative adversarial network model with gradient penalty to augment the real spectral data and generate synthetic spectral data to balance class distribution and increase sample diversity. The model is trained adversarially to ensure the fidelity of the generated data. The framework utilizes principal component analysis, t-distributed random neighbor embedding, root mean square error, maximum mean difference, and slice Wasserstein distance to perform qualitative and quantitative evaluations of the synthesized spectral data, in order to verify its global structural consistency, local feature consistency, and statistical similarity with the real spectral data. The framework is based on an enhanced dataset and applies convolutional neural network classifiers, support vector machine classifiers, and random forest classifiers to classify pests. Among them, the convolutional neural network classifier achieves the best performance and improves accuracy.
2. The method as described in claim 1, characterized in that, The process of constructing a dataset containing healthy, mildly infected, and severely infected levels through controlled artificial infection includes: Obtain and store medicinal plant slices and adult pests. Place the medicinal plant slices in a constant temperature incubator and incubate them with the adult pests. Screen samples with different infection levels in stages. After the first stage of incubation, healthy samples and mildly infected samples are selected. After the second stage of incubation, samples with severe infection levels are selected. The infection pressure in the constant temperature incubator is monitored, and the initial pest population density is maintained by replacing dead adult pests. Multiple samples are obtained and classified into the healthy level, the mild infection level, and the severe infection level according to preset standards. Near-infrared hyperspectral images are acquired from the multiple samples. An imaging system is used to acquire images covering a preset spectral range. Black and white reference correction is applied to eliminate noise, resulting in a corrected hyperspectral image. The region of interest is segmented from the corrected hyperspectral image, the average reflectance of the pixels within the region of interest is calculated, the effective spectral bands are extracted and normalized to a preset range, the real spectral data is generated and divided into training set and test set.
3. The method as described in claim 1, characterized in that, The augmentation of the real spectral data using a Wasserstein generative adversarial network model with gradient penalty includes: The real spectral data is input from the training set to the generator and the discriminator, wherein the generator generates the synthetic spectral data from random noise, and the discriminator distinguishes between the real spectral data and the synthetic spectral data. The generator and the discriminator are optimized through adversarial training, the Jensen-Shannon divergence is replaced with Wasserstein distance, and a gradient penalty term is applied to penalize the gradient norm of the discriminator at the interpolation point to ensure Lipschitz continuity. Set parameters such as batch size, learning rate, training epochs, Adam optimizer Beta value, Leaky ReLU value, and Gaussian noise length, and perform adversarial training until the model converges to generate diverse synthetic spectral data; The enhanced dataset is formed by combining the synthetic spectral data with the real spectral data to balance the category distribution and increase the sample diversity for subsequent pest classification.
4. The method as described in claim 1, characterized in that, The qualitative and quantitative evaluation of the synthesized spectral data is performed using principal component analysis, t-distributed random neighbor embedding, root mean square error, maximum mean difference, and slice Wasserstein distance, including: The principal component analysis projected the synthetic and real spectral data into a low-dimensional space, preserving variance and visualizing the consistency of the global distribution structure. The t-distributed random neighbor embedding was used to capture the local neighborhood structure, and the clustering pattern matching between the synthetic and real spectral data was visualized by minimizing the Kullback-Leibler divergence. The root mean square error is calculated as the square root of the point-by-point deviation between the synthesized spectral data and the real spectral data, wherein the root mean square error is equal to the square root of the sum of the squares of the generated reflectance values minus the real reflectance values, divided by the number of samples. The maximum average difference is calculated to measure the distributional difference in the regenerated kernel Hilbert space, wherein the maximum average difference is equal to the kernel function average between real samples minus the kernel function average between real and generated samples plus the kernel function average between generated samples. The slice Wasserstein distance is calculated by projecting it onto a random one-dimensional subspace and averaging the one-dimensional Wasserstein distance to approximate the overall similarity. As the number of training rounds increases, the root mean square error, the maximum average difference, and the slice Wasserstein distance decrease, thus verifying the statistical similarity.
5. The method as described in claim 1, characterized in that, The process of classifying pests based on the enhanced dataset using convolutional neural network classifiers, support vector machine classifiers, and random forest classifiers includes: The enhanced dataset is input into the convolutional neural network classifier, which includes stacked convolutional blocks to reduce bands to feature dimensions, flattening layers and fully connected layers, applying dropout layers to prevent overfitting, and training using the AdamW optimizer and cosine annealing learning rate scheduling. Cross-entropy loss and label smoothing are used to enhance generalization ability. Performance is evaluated by five-fold hierarchical cross-validation. The softmax probability is output to correspond to the health level, the mild infection level and the severe infection level. The enhanced dataset is input into the support vector machine classifier, and a separating hyperplane is constructed by mapping the radial basis function kernel to a high-dimensional space. The regularization parameter and kernel coefficient are adjusted by grid search, and five-fold cross-validation is used to enhance robustness. The augmented dataset is input into the random forest classifier, and predictions are aggregated by constructing multiple decision trees and majority voting. Hyperparameters such as the number of trees, maximum tree depth, and minimum leaf size are optimized, and performance is evaluated using five-fold cross-validation. The convolutional neural network classifier achieves the highest accuracy on the augmented dataset.
6. The method as described in claim 2, characterized in that, The segmentation of the region of interest from the corrected hyperspectral image includes: An adaptive thresholding algorithm is applied to generate a binary mask from an average grayscale image, and morphological operations are used to remove noise and fill holes. The region of interest is extracted by pixel-by-pixel multiplication, the average reflectance is calculated to represent the spectral features, effective spectral bands are selected and minimum-maximum scaling is applied to normalize to a preset range, and the real spectral data is generated.
7. The method as described in claim 3, characterized in that, The optimization of the generator and the discriminator through adversarial training includes: If the discriminator outputs a probability close to a preset value, then it is determined that the generator has converged to generate indistinguishable synthetic spectral data. The gradient is provided based on the Wasserstein distance, and continuity is performed through the gradient penalty term to ensure that the model improves the fidelity of the generated data under imbalanced conditions.
8. The method as described in claim 4, characterized in that, The calculation of the root mean square error as the square root of the point-by-point deviation between the synthesized spectral data and the real spectral data includes: For each reflectance value, the squared difference between the true value and the generated value is calculated, summed, divided by the number of samples, and the square root is taken to obtain the root mean square error. If the root mean square error is lower than a preset threshold, then the point-by-point fit is determined to be good, and the overall distribution alignment is confirmed by combining the maximum average difference and the slice Wasserstein distance.