Rapid nondestructive detection method and system for grain components, computer equipment and storage medium
By using deep learning models and data preprocessing techniques, the problems of long detection time, high cost, and low accuracy under small sample conditions in existing grain component detection methods have been solved, achieving rapid, non-destructive, and high-precision grain component detection.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-12
- Publication Date
- 2026-03-24
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing methods for detecting grain components are time-consuming, costly, complex, and potentially destructive. Furthermore, deep learning models are prone to overfitting and have poor generalization ability under small sample conditions. Traditional machine learning methods also have shortcomings in feature extraction and nonlinear modeling.
A deep learning model consisting of a multi-scale feature extraction network, a feature fusion network, and a prediction network is employed. Combined with composite smoothing multi-scale denoising and data expansion techniques, near-infrared spectral data is preprocessed and features are extracted. Residual, self-attention, and channel attention mechanisms are used for feature fusion, and finally, grain composition is predicted through regression.
It significantly improves the accuracy and robustness of grain component detection under small sample conditions, and achieves rapid, non-destructive, and high-precision detection.
Smart Images

Figure CN121720971A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of grain component detection technology, specifically to a rapid and non-destructive detection method, system, computer equipment, and storage medium for grain components. Background Technology
[0002] Food quality testing is a crucial step in ensuring nutrition and safety in the food industry and agricultural production. Existing testing methods, such as the Kjeldahl method and high-performance liquid chromatography (HPLC), while highly accurate, are generally time-consuming, costly, complex, and destructive, making them unsuitable for large-scale and real-time testing. Near-infrared spectroscopy (NIR) is widely used for detecting dry matter content in fruits and protein content in grains due to its speed, non-destructive nature, and simple sample pretreatment. However, NIR spectral data typically has high dimensionality, high noise levels, and strong collinearity, and suffers from small sample sizes. This leads to limitations in feature extraction and nonlinear modeling of traditional machine learning methods (such as PLS, SVM, and RF), resulting in limited prediction accuracy. While single deep learning models have some feature extraction capabilities, they are prone to overfitting and poor generalization under small sample conditions. Existing ensemble methods also often suffer from insufficient feature utilization and a lack of interpretability. Summary of the Invention
[0003] To address the shortcomings of existing technologies, this invention provides a rapid and non-destructive detection method, system, computer equipment, and storage medium for grain components, which effectively improves the detection accuracy and robustness under small sample conditions.
[0004] To achieve the above objectives, the specific solution adopted by the present invention is as follows: a rapid and non-destructive method for detecting grain components, comprising the following steps: The raw near-infrared spectral data of grains are obtained and preprocessed to obtain the reference near-infrared spectral data. The preprocessing methods include composite smoothing multi-scale noise reduction and scattering correction. The grain composition is obtained by inputting benchmark near-infrared spectral data into a pre-trained detection model. The detection model includes a multi-scale feature extraction network, a feature fusion network, and a prediction network. The detection model uses the benchmark near-infrared spectral data to perform detection, including: A multi-scale feature extraction network is used to perform preliminary feature extraction on the benchmark near-infrared spectral data to obtain primary features; A multi-scale feature extraction network is used to perform multi-scale parallel feature extraction on primary features to obtain multiple secondary features; A feature fusion network is used to concatenate and fuse primary features and all secondary features to obtain fused features; The composition of grains is obtained by using a prediction network based on fusion features to predict the composition.
[0005] As a further optimization of the above-mentioned rapid and non-destructive detection method for grain components, the method for compound smoothing and multi-scale noise reduction of the raw near-infrared spectral data includes: The original near-infrared spectral data is first denoised using wavelet denoising. The raw near-infrared spectral data, after the first noise reduction process, is subjected to a second noise reduction process using an SG filter.
[0006] As a further optimization of the aforementioned rapid and non-destructive detection method for grain components, the following methods are used for data expansion of the original near-infrared spectral data after composite smoothing, multi-scale noise reduction, and scattering correction: Adding a Gaussian perturbation to the original near-infrared spectral data after composite smoothing multi-scale noise reduction and scattering correction yields an extended layer of data. Wavelength shifting is applied to the first layer of extended data to obtain the second layer of extended data; Intensity scaling was applied to the second-layer extended data to obtain the baseline near-infrared spectral data.
[0007] As a further optimization of the above-mentioned rapid and non-destructive detection method for grain components: the multi-scale feature extraction network includes a front-end one-dimensional convolutional neural network and multiple back-end one-dimensional convolutional neural networks. The front-end one-dimensional convolutional neural network is used to perform preliminary feature extraction on the reference near-infrared spectral data to obtain primary features, and the back-end one-dimensional convolutional neural networks are used to extract features from the primary features to obtain secondary features. The extraction scale of different back-end one-dimensional convolutional neural networks is different.
[0008] As a further optimization of the above-mentioned rapid and non-destructive detection method for grain components: the feature fusion network includes multiple feature fusion modules arranged in sequence, and each feature fusion module includes a one-dimensional convolutional unit, a residual connection unit, a self-attention unit, a channel attention unit, and an activation function arranged in sequence.
[0009] As a further optimization of the above-mentioned rapid and non-destructive detection method for grain components: the prediction network includes two fully connected regression subnetworks arranged in sequence, and the fully connected regression subnetwork includes a batch normalization unit, a fully connected unit and an activation function arranged in sequence.
[0010] As a further optimization of the above-mentioned rapid and non-destructive detection method for grain components, the loss function of the detection model is set as the mean square error loss function.
[0011] A rapid and non-destructive testing system for grain components is provided to implement the aforementioned rapid and non-destructive testing method for grain components. The system comprises: The data acquisition module is used to acquire the raw near-infrared spectral data of grains and preprocess it to obtain the reference near-infrared spectral data. The model running module is used to run a pre-trained detection model to detect the grain composition from the benchmark near-infrared spectral data; The human-computer interaction module is used to display the composition of grains.
[0012] Computer equipment, including: Memory, used to store computer programs; A processor is used to read and execute the computer program to implement the above-described method for rapid and non-destructive detection of grain components.
[0013] A storage medium for storing a computer program that, when executed, implements the aforementioned method for rapid and non-destructive detection of grain components.
[0014] Beneficial effects: This invention first expands a small amount of raw near-infrared spectral data to obtain richer data to support the detection process under small sample conditions. Then, the detection model of this invention achieves the synergy of serial pre-feature extraction and parallel multi-scale feature extraction through a multi-scale feature extraction network composed of a front-end one-dimensional convolutional neural network and four rear-end one-dimensional convolutional neural networks, which fully improves the hierarchy and richness of the extracted features. Then, through a fusion module containing residual, self-attention and channel attention mechanisms, it can form a fusion feature that fully integrates all characteristics of the near-infrared spectral data. Finally, the regression prediction head outputs the food component content, effectively improving the detection accuracy and robustness under small sample conditions. Attached Figure Description
[0015] Figure 1 This is a flowchart of the present invention; Figure 2 This is a structural diagram of the detection model of the present invention; Figure 3 This is a comparison chart of the evaluation results of the present invention and the comparative model; Figure 4 It is a scatter plot of the prediction results of the invention model and the comparison model; Figure 5 This is a comparison chart of the ablation experiment results of the model of this invention on the maize kernel dataset; Figure 6 This is a feature importance analysis diagram of the model of this invention on the corn kernel dataset; Figure 7 This is the result of two-dimensional correlation spectral analysis of the model of this invention on a maize kernel dataset. Detailed Implementation
[0016] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0017] like Figure 1 As shown, the present invention first provides a rapid and non-destructive detection method for grain components, including S1 to S2.
[0018] S1. Obtain raw near-infrared spectral data of grain kernels and preprocess them to obtain baseline near-infrared spectral data. The preprocessing method includes compound smoothing multi-scale noise reduction and scattering correction. In one embodiment of the present invention, the detection method of the present invention is applied to the detection of corn kernel components, and a spectrometer of model SW2860 is used to collect raw near-infrared spectral data in the range of 900-1700 nm. After obtaining the raw near-infrared spectral data, compound smoothing multi-scale noise reduction can remove high-frequency noise in the raw near-infrared spectral data to enhance spectral details and improve the accuracy of the final detection results; scattering correction can eliminate scattering differences between different corn kernels; and data expansion can expand more data within a reasonable range based on the existing raw near-infrared spectral data, improving the accuracy of the detection results with richer data without the need for frequent spectral acquisition.
[0019] Furthermore, methods for compound smoothing and multi-scale noise reduction of raw near-infrared spectral data include S11 to S12. Scattering correction is a conventional technique in this field; for example, adaptive standard normal variable correction can be used, which will not be elaborated here.
[0020] S11. The original near-infrared spectral data is subjected to the first noise reduction process by wavelet noise reduction.
[0021] S12. Perform a second noise reduction process on the original near-infrared spectral data after the first noise reduction process using an SG (Savitzky–Golay) filter.
[0022] Wavelet denoising and SG filter denoising are both conventional techniques in this field, and their processes and principles will not be elaborated here.
[0023] In the process of training the detection model, in order to increase the number of samples, the data that has been smoothed by multiple scales and has been corrected by scattering can also be expanded. The specific methods include S13 to S15.
[0024] S13. Add Gaussian perturbation to the original near-infrared spectral data after composite smoothing, multi-scale noise reduction and scattering correction to obtain an extended layer of data.
[0025] S14. Wavelength shifting is performed on the first layer of extended data to obtain the second layer of extended data.
[0026] S15. Intensity scaling is performed on the second-layer extended data to obtain the reference near-infrared spectral data.
[0027] Gaussian perturbation, wavelength shift, and intensity scaling are all conventional techniques in this field, and their processes and principles will not be elaborated upon here.
[0028] S2. Input the benchmark near-infrared spectral data into a pre-trained detection model to detect grain components. The detection model includes a multi-scale feature extraction network, a feature fusion network, and a prediction network. The loss function of the detection model is set to the mean squared error loss function. Figure 2 As shown, the structures of the multi-scale feature extraction network, feature fusion network, and prediction network are as follows.
[0029] The multi-scale feature extraction network includes a front-end one-dimensional convolutional neural network and multiple back-end one-dimensional convolutional neural networks. The front-end one-dimensional convolutional neural network is used to perform preliminary feature extraction on the benchmark near-infrared spectral data to obtain primary features, and the back-end one-dimensional convolutional neural networks are used to extract secondary features from the primary features. The extraction scale of different back-end one-dimensional convolutional neural networks is different.
[0030] The feature fusion network comprises multiple sequentially arranged feature fusion modules, each consisting of a one-dimensional convolutional unit, a residual connection unit, a self-attention unit, a channel attention unit, and an activation function. The residual connection unit ensures the model's stability during deep training, the self-attention unit models long-range feature dependencies, and the channel attention unit adaptively weights key spectral channels. Furthermore, through multi-level interactions, the feature fusion network effectively highlights useful features and suppresses noise, achieving higher-order spectral information fusion.
[0031] The prediction network consists of two sequentially arranged fully connected regression subnetworks, each containing a batch normalization unit, a fully connected unit, and an activation function. Furthermore, a Dropout regularization unit can be introduced into the fully connected regression subnetwork to enhance non-linear expressiveness and prevent overfitting.
[0032] The mathematical form of the mean squared error loss function is as follows: Where N is the total number of samples, y i The true component content of the i-th sample. To predict the network's output, by minimizing the mean squared error, the model can continuously adjust its parameters during training, reducing the deviation between the predicted results and the true values, thereby improving the accuracy and stability of quantitative analysis.
[0033] Based on the above network structure, the detection model uses methods S21 to S24 to detect the benchmark near-infrared spectral data.
[0034] S21. A multi-scale feature extraction network is used to perform preliminary feature extraction on the benchmark near-infrared spectral data to obtain primary features. Specifically, primary features are extracted through a front-end one-dimensional convolutional neural network. Primary features are the low-level structural features in the benchmark near-infrared spectral data, such as the overall absorption trend and local peak morphology. The form of primary features is a feature map containing low-level structural features. In addition, the primary features form two output branches. The first output branch is input into the subsequent one-dimensional convolutional network to further extract secondary features, while the second output branch is temporarily retained.
[0035] S22. A multi-scale feature extraction network is used to extract multiple secondary features from the primary features using parallel multi-scale feature extraction. Specifically, secondary features are extracted using a post-one-dimensional convolutional neural network. Different post-one-dimensional convolutional neural networks have different structures, mainly in the size of the convolutional kernel and the receptive field, thus forming different processing scales. In one embodiment of the invention, four post-one-dimensional convolutional neural networks are configured, with kernel sizes of 3×3, 5×5, 7×7, and 9×9, respectively. Among the four post-one-dimensional convolutional neural networks, the one with the smaller kernel size is used to capture detailed features and narrowband absorption peaks, while the one with the larger kernel size is used to capture the overall trend and global model across a wide band.
[0036] S23. A feature fusion network is used to concatenate and fuse primary features and all secondary features to obtain fused features. More specifically, the second output branch of the primary features is concatenated with the secondary features output by all subsequent one-dimensional convolutional neural networks along the channel dimension to form fused features. The fused features are specifically represented as multi-scale feature tensors, which are then fed into the prediction network for prediction. By fusing primary and secondary features, the feature information in the benchmark near-infrared spectral data can be fully utilized, thereby improving the accuracy of the final detection results.
[0037] S24. Grain composition is obtained by using a prediction network based on fusion features to predict the composition.
[0038] To verify the effectiveness of this invention, corn kernel samples were collected from eight major corn-producing areas in China: Anyang (Henan), Hebi (Henan), Bozhou (Anhui), Heze (Shandong), Hengshui (Hebei), Handan (Hebei), Jiamusi (Heilongjiang), and Qiqihar (Heilongjiang). A total of 356 bags of corn kernel samples were collected. The composition of the corn kernel samples was then accurately determined using existing methods such as the Kjeldahl nitrogen determination method and high-performance liquid chromatography. Finally, the method of this invention was used to test the corn kernel samples. Existing detection algorithms based on traditional machine learning models PLS, KNN, XGBoost, and AdaBoost, as well as detection algorithms based on deep learning models 1D-CNN, ResNet1D, VGG1D, and Transformer, were used as comparative examples. Multiple tests were performed, and the average value was taken as the result for comparison. These comparative detection algorithms are all existing technologies in the field and will not be described in detail here. Furthermore, the coefficient of determination, root mean square error, and residual prediction bias were used as indicators to evaluate the performance of this invention. The experimental results are compared below, and the detection model of the present invention will be referred to as MDER below.
[0039] Figure 3 This is a scatter plot of the prediction results of the model of this invention and the comparison model. In the plot, the blue scatter points represent the correspondence between predicted and actual values, and the red line is the fitted line. Figure 2 As can be seen, the scatter distribution of the model (MDER) of this invention is closest to the 1:1 reference line, and its prediction accuracy is significantly better than other models.
[0040] Figure 4 This is a scatter plot of the prediction results of the model of this invention and the comparison model. In the plot, the blue scatter points represent the correspondence between predicted and actual values, and the red line is the fitted line. Figure 4 As can be seen, the scatter distribution of the model (MDER) of this invention is closest to the 1:1 reference line, and its prediction accuracy is significantly better than other models.
[0041] Figure 5 This is a comparison of the ablation experiment results of the model of this invention on the maize kernel dataset. The figure shows the performance changes of the complete model (MDER) and the model after removing the self-attention (SA), channel attention (CA), and residual connection (Res) modules. Figure 5 It can be seen that removing any module leads to a decrease in performance, with the removal of residual connections having the greatest impact, indicating that each module plays an important role in improving the accuracy and stability of the model.
[0042] Figure 6 This is a feature importance analysis diagram of the model of this invention on a maize kernel dataset. The diagram shows the importance ranking of key wavelengths calculated by the SHAP algorithm, with blue and red dots representing the direction and intensity of the wavelength's contribution to the prediction results. Figure 6 It can be seen that the model of this invention can identify key spectral bands that are closely related to the content of components, providing a basis for subsequent instrument simplification and model interpretation.
[0043] Figure 7 This figure shows the two-dimensional correlation spectral analysis results of the model of this invention on a maize kernel dataset. In the figure, (a) is the spectral correlation plot of the original maize dataset; (b) is the spectral correlation plot of the maize dataset after data augmentation; and (c) is the effect diagram of the spectral differences before and after augmentation. Figure 7 As can be seen, the correlation structure between spectra is more obvious after data augmentation, which is consistent with the key bands identified by the model, further verifying the effectiveness and rationality of the method of the present invention.
[0044] The present invention further provides a rapid non-destructive testing system for grain components, used to implement the above-mentioned rapid non-destructive testing method for grain components. The system includes a data acquisition module, a model running module, and a human-computer interaction module.
[0045] The data acquisition module is used to acquire the raw near-infrared spectral data of grains and preprocess it to obtain the baseline near-infrared spectral data.
[0046] The model running module is used to run a pre-trained detection model to detect the grain composition from the benchmark near-infrared spectral data.
[0047] The human-computer interaction module is used to display the composition of grains.
[0048] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems and devices described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here. In the several embodiments provided in this disclosure, it should be understood that the disclosed systems, devices, and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of modules is only a logical functional division; in actual implementation, there may be other division methods. Furthermore, multiple modules or components may be combined or integrated into another system, or some features may be ignored or not executed. Another point is that the displayed or discussed mutual coupling or direct coupling or communication connection may be through some communication interfaces; the indirect coupling or communication connection of devices or modules may be electrical, mechanical, or other forms.
[0049] The present invention also provides a computer device, including a memory and a processor.
[0050] Memory is used to store computer programs.
[0051] A processor is used to read and execute the computer program to implement the above-described method for rapid and non-destructive detection of grain components.
[0052] Finally, the present invention provides a storage medium for storing a computer program, which, when executed, implements the above-described method for rapid and non-destructive detection of grain components.
[0053] The memory, as a carrier of resources, can be a read-only memory, random access memory, disk, or optical disk, etc. The resources stored on it can include the operating system, computer programs, etc., and the storage method can be temporary or permanent storage. The operating system is used to manage and control the various hardware devices and computer programs on the electronic device, and can be Windows Server, Netware, Unix, Linux, etc. In addition to including computer programs capable of performing the adaptive emotion regulation method based on personalized reconfigurable music disclosed in any of the foregoing embodiments, the computer programs may further include computer programs capable of performing other specific tasks. The processor can be a general-purpose processor product based on architectures such as x86, IA64, RISC, MIPS, and ARM.
[0054] The above description of the disclosed embodiments enables those skilled in the art to make or use the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A rapid and non-destructive method for detecting grain components, characterized in that, Includes the following steps: The raw near-infrared spectral data of grains are obtained and preprocessed to obtain the reference near-infrared spectral data. The preprocessing methods include composite smoothing multi-scale noise reduction and scattering correction. The grain composition is obtained by inputting benchmark near-infrared spectral data into a pre-trained detection model. The detection model includes a multi-scale feature extraction network, a feature fusion network, and a prediction network. The detection model uses the benchmark near-infrared spectral data to perform detection, including: A multi-scale feature extraction network is used to perform preliminary feature extraction on the benchmark near-infrared spectral data to obtain primary features; A multi-scale feature extraction network is used to perform multi-scale parallel feature extraction on primary features to obtain multiple secondary features; A feature fusion network is used to concatenate and fuse primary features and all secondary features to obtain fused features; The composition of grains is obtained by using a prediction network based on fusion features to predict the composition.
2. The rapid and non-destructive detection method for grain components as described in claim 1, characterized in that, Methods for compound smoothing and multi-scale noise reduction of raw near-infrared spectral data include: The original near-infrared spectral data is first denoised using wavelet denoising. The raw near-infrared spectral data, after the first noise reduction process, is subjected to a second noise reduction process using an SG filter.
3. The rapid and non-destructive detection method for grain components as described in claim 1, characterized in that, The multi-scale feature extraction network includes a front-end one-dimensional convolutional neural network and multiple back-end one-dimensional convolutional neural networks. The front-end one-dimensional convolutional neural network is used to perform preliminary feature extraction on the benchmark near-infrared spectral data to obtain primary features, and the back-end one-dimensional convolutional neural networks are used to extract secondary features from the primary features. The extraction scale of different back-end one-dimensional convolutional neural networks is different.
4. The rapid and non-destructive detection method for grain components as described in claim 1, characterized in that, The feature fusion network includes multiple feature fusion modules arranged in sequence. Each feature fusion module includes a one-dimensional convolutional unit, a residual connection unit, a self-attention unit, a channel attention unit, and an activation function arranged in sequence.
5. The rapid and non-destructive detection method for grain components as described in claim 1, characterized in that, The prediction network includes two fully connected regression subnetworks arranged sequentially. Each fully connected regression subnetwork includes a batch normalization unit, a fully connected unit, and an activation function arranged sequentially.
6. The rapid and non-destructive detection method for grain components as described in claim 1, characterized in that, The loss function of the detection model is set as the mean squared error loss function.
7. A rapid and non-destructive detection system for grain components, characterized in that, The system for implementing a rapid and non-destructive detection method for grain components as described in any one of claims 1-6 includes: The data acquisition module is used to acquire the raw near-infrared spectral data of grains and preprocess it to obtain the reference near-infrared spectral data. The model running module is used to run a pre-trained detection model to detect the grain composition from the benchmark near-infrared spectral data; The human-computer interaction module is used to display the composition of grains.
8. A computer device, characterized in that, include: Memory, used to store computer programs; A processor for reading and executing the computer program to implement a rapid and non-destructive detection method for grain components as described in any one of claims 1-6.
9. A storage medium, characterized in that, Used to store a computer program, which, when executed, implements a rapid and non-destructive detection method for grain components as described in any one of claims 1-6.