A shell-on walnut fat content detection model, detection method, system and equipment based on near-infrared spectroscopy

By constructing a near-infrared spectroscopy-based model for detecting the fat content of shelled walnuts, and utilizing spectral migration correction and characteristic wavelength screening techniques, the problem of requiring shell breaking for walnut fat content detection was solved. This enabled non-destructive and rapid fat content determination, suitable for large-scale factory operations and intelligent quality sorting.

CN122448792APending Publication Date: 2026-07-24BEIJING TECH & BUSINESS UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
BEIJING TECH & BUSINESS UNIV
Filing Date
2026-06-02
Publication Date
2026-07-24

AI Technical Summary

Technical Problem

Current methods for testing the fat content of walnuts require cracking the shell before testing, which cannot achieve truly non-destructive testing and is difficult to meet the needs of large-scale factory operations and intelligent quality sorting.

Method used

A model for detecting the fat content of shelled walnuts based on near-infrared spectroscopy was constructed. Through standard normal variable transformation, multivariate scattering correction, and normalization preprocessing, combined with piecewise direct standardization algorithm and Bayesian optimization algorithm, a nonlinear model for feature wavelength screening and global optimization was established to achieve non-destructive detection at the spectral level.

Benefits of technology

This technology enables rapid and accurate determination of walnut fat content without breaking the shell, reducing testing costs and improving testing efficiency and stability, making it suitable for large-scale promotion and use.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122448792A_ABST
    Figure CN122448792A_ABST
Patent Text Reader

Abstract

The present application relates to the technical field of nondestructive testing of agricultural products, and particularly relates to a shelled walnut fat content detection model, a detection method, a system and equipment based on near-infrared spectroscopy.The present application establishes a paired sample spectrum-chemical value data matrix of the shelled and unshelled states of the same walnut, migrates and corrects the spectrum of the shelled walnut to eliminate the interference of the shell, and then on the basis of the optimized characteristic wavelength, constructs and utilizes a global optimization algorithm to automatically optimize the key network structure parameters of the prediction model to obtain the shelled walnut fat content detection model.In actual application, only the near-infrared spectrum data of the shelled walnut sample to be detected needs to be input into the detection model, and the nondestructive determination of the fat content can be quickly completed.The method does not damage the sample, does not consume chemical reagents, and has a low operation threshold, and provides an efficient and reliable technical means for the online quality grading, variety breeding and oil processing of walnuts.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of non-destructive testing technology for agricultural products, specifically to a model, method, system, and equipment for detecting the fat content of shelled walnuts based on near-infrared spectroscopy. Background Technology

[0002] Walnuts are one of the most popular nuts worldwide, and their significant nutritional and economic value primarily stems from the rich fat content of the walnut kernel. Walnut fat is mainly composed of unsaturated fatty acids, particularly alpha-linolenic acid and linoleic acid, which play a vital role in maintaining cardiovascular health and nervous system function. Therefore, the ability to quickly and accurately determine the fat content of walnut kernels is of great significance for guiding walnut variety selection, quality evaluation, grading and processing, and the development of high-value-added products (such as cold-pressed walnut oil and fortified foods).

[0003] Currently, the commonly used method for detecting fat content is the traditional chemical method, such as Soxhlet extraction. Although this method provides accurate results, it is complex, time-consuming, and labor-intensive, making it difficult to meet the needs of modern agricultural production and food processing industries for real-time, online, non-destructive screening of large batches of samples. Existing research uses near-infrared spectroscopy to detect fat content in food. For example, the study on the detection of soluble protein, fat, and tannin content in walnut kernels based on near-infrared spectroscopy (Luo Langqin. Study on the detection of soluble protein, fat, and tannin content in walnut kernels based on near-infrared spectroscopy [D]. Tarim University, 2023) discloses the use of a single variety of walnut kernels as samples, collecting their corresponding diffuse reflectance spectra, and constructing a BP neural network model after multivariate scattering correction and first derivative combination preprocessing for the detection of fat content in walnut kernels. Although this method improves the speed of walnut fat content detection, it still requires breaking the shell to detect fat content, failing to achieve truly non-destructive testing and hindering large-scale factory operations and intelligent quality sorting. Summary of the Invention

[0004] Therefore, the purpose of this invention is to provide a model, method, system and equipment for detecting the fat content of shelled walnuts based on near-infrared spectroscopy, so as to solve the problem that the existing method for determining the fat content of walnuts requires breaking the shell before detection, which makes it impossible to achieve truly non-destructive detection.

[0005] To solve the above-mentioned technical problems, the present invention provides the following technical solution:

[0006] A model for detecting fat content in shelled walnuts based on near-infrared spectroscopy includes the following steps, which are then constructed as follows:

[0007] (1) Obtain a sample set of target walnuts, and obtain the near-infrared spectral data of each sample of shelled walnuts and corresponding walnut kernels, as well as the chemical value of walnut kernel fat content;

[0008] (2) Perform any one of the following preprocessing methods on the near-infrared spectral data of walnut kernels: standard normal variable transformation, multivariate scattering correction, and normalization, and construct a fat content detection model based on the whole band to determine the optimal preprocessing method.

[0009] (3) Using the near-infrared spectrum of the shelled walnut and the corresponding near-infrared spectrum of the walnut kernel as the calibration object, establish the conversion relationship within the full band or local wavelength window, perform calibration processing on the near-infrared spectrum of the shelled walnut, and obtain the calibrated near-infrared spectrum data; use the optimal preprocessing method obtained in step (2) to process the calibrated near-infrared spectrum data, and obtain the optimal preprocessed near-infrared spectrum data.

[0010] (4) Select characteristic wavelengths from the preprocessed near-infrared spectral data, construct a fat content detection model based on characteristic wavelengths, and determine the optimal subset of characteristic wavelengths related to fat content;

[0011] (5) Globally optimize the fat content detection model corresponding to the optimal feature wavelength subset obtained in step (4). The global optimization is to optimize the key network structure parameters of the fat content detection model to obtain the final fat content detection model for walnuts in shell.

[0012] This invention simultaneously acquires the diffuse reflectance spectra of walnut samples with shells and walnut kernels after shelling. By correcting the spectral data with shells, the spectral response in the shelled state is simulated, thereby "stripping away" the influence of the shell at the spectral level. Further, optimal preprocessing methods are used for preprocessing, and feature wavelengths highly correlated with fat content are extracted from the migrated spectral data. Combined with a global optimization algorithm, the key network structure parameters of the best model for detecting fat content in walnuts with shells (i.e., a fat content model based on feature wavelengths highly correlated with fat content) are automatically optimized. Finally, a high-precision detection model for fat content in walnuts with shells is constructed.

[0013] The construction method of this invention can effectively remove the influence of walnut shell on fat content detection, laying the foundation for achieving truly non-destructive detection of fat content in walnuts.

[0014] The correction process, based on paired spectral datasets from the sample set, establishes a linear transformation relationship from the shelled spectrum to the corresponding walnut kernel spectrum within each spectral window, achieving systematic correction across the entire spectrum. After the transfer, the similarity between the shelled spectra of each variety and the target walnut kernel spectrum is significantly improved.

[0015] Preferably, the basic model of the fat content detection model is a nonlinear model; the global optimization algorithm is a heuristic global optimization algorithm, and the heuristic global optimization algorithm is a Bayesian optimization algorithm. The nonlinear model can be any one of SVR, LSSVR, or MLP models.

[0016] Preferably, the nonlinear model is a multilayer perceptron model, and the key network structure parameters of the multilayer perceptron model are the number of neurons in the first hidden layer and the second hidden layer; the first hidden layer has 31 neurons, and the second hidden layer has 29 neurons. The final model (PDS-SNV-VCPA-BA-MLP) constructed using this optimized structure exhibits superior prediction performance, achieving near-optimal fitting and prediction results on both the calibration set and the independent prediction set.

[0017] Preferably, the optimal preprocessing method in step (2) is standard normal variable transformation; the correction processing in step (3) is performed using a segmented direct standardization algorithm; and the variable clustering algorithm in step (4) is used to screen feature variables and obtain the optimal feature wavelength subset related to fat content.

[0018] Piecewise Direct Standardization (PDS) effectively compensates for spectral differences caused by variations in the physical state of samples (such as the presence of an outer shell) while preserving the spectral characteristics of the target components. Standard Normal Variable Transform (SNV) effectively corrects for spectral intensity changes caused by differences in physical state, making the spectra of different samples more comparable. Variable Clustering Algorithm (VCPA) has strong global optimization capabilities; this method can achieve dimensionality reduction and information purification of high-dimensional spectral data, laying the foundation for subsequent construction of high-performance prediction models.

[0019] Preferably, in step (1), the sample set consists of different varieties of walnuts from the same region; the near-infrared spectral data is the average spectral data of each sample, which is obtained by arithmetically averaging the spectral data of three different geometric positions on the equatorial horizontal axis of each sample. This ensures that the collected spectra can comprehensively reflect the surface characteristics of the walnut in different directions on the equatorial plane.

[0020] Furthermore, the three different geometric locations are the three sampling points corresponding to the equal division of the equatorial transverse axis of the sample into three parts.

[0021] This invention uses a multi-variety mixed sample for modeling, which can effectively cover the common phenotypic variation range of walnuts, thereby enhancing the model's adaptability to actual samples from different sources.

[0022] Preferably, the optimal processing method corresponding to different fat content detection models is determined after evaluation by the evaluation index of the prediction model. The evaluation index is the correlation coefficient of the calibration set, the root mean square error of the calibration set, the correlation coefficient of the test set, the root mean square error of the test set, and the relative standard deviation.

[0023] The second technical solution of the present invention is:

[0024] A non-destructive method for detecting the fat content in walnuts in their shells, characterized by the following steps: collecting near-infrared spectral data of the walnuts in their shells to be tested, inputting the obtained near-infrared spectral data of the walnuts in their shells into the aforementioned fat content detection model, obtaining the fat content of the walnuts in their shells and outputting it.

[0025] This invention eliminates the need for complex chemical pretreatment. It simply requires inputting the near-infrared spectral data of the shelled walnut sample directly into the fat content detection model constructed using the aforementioned method, enabling rapid and non-destructive determination of fat content. This method does not damage the sample, consumes no chemical reagents, reduces testing costs, and is more environmentally friendly and safe. It provides an efficient and reliable technical means for online quality grading, variety selection, and oil processing of walnuts.

[0026] Preferably, the fat content detection model is a PDS-SNV-VCPA-BA-MLP combined model.

[0027] The third technical solution of the present invention is:

[0028] A system for detecting fat content in shelled walnuts based on near-infrared spectroscopy, comprising:

[0029] (1) Data acquisition module, used to acquire the sample set of target walnuts and the near-infrared spectral data of shelled walnuts and walnut kernels of each sample in the sample set and the chemical value of fat content of walnut kernels;

[0030] (3) Preprocessing and screening module, which is used to perform any one of the following preprocessing methods on the near-infrared spectral data of walnut kernels: standard normal variable transformation, multivariate scattering correction, and normalization, and to construct a fat content detection model based on the whole band to determine the optimal preprocessing method;

[0031] (4) Correction processing module: taking the near-infrared spectrum of the shelled walnut and the corresponding near-infrared spectrum of the walnut kernel as the correction object, establish the conversion relationship in the whole band or local wavelength window, perform correction processing on the near-infrared spectrum of the shelled walnut, and obtain the corrected near-infrared spectrum data; use the optimal preprocessing method obtained in step (3) to process the corrected near-infrared spectrum data, and obtain the optimal preprocessed near-infrared spectrum data.

[0032] (5) Feature variable screening module: Select feature wavelengths from the pre-processed near-infrared spectral data, construct a fat content detection model based on feature wavelengths, and determine the optimal feature wavelength subset related to fat content;

[0033] (6) Optimization module: global optimization of the fat content detection model corresponding to the optimal feature wavelength subset obtained in step (5). The global optimization is to optimize the key network structure parameters of the fat content detection model to obtain the final fat content detection model of walnuts in shell.

[0034] The fourth technical solution of the present invention is:

[0035] A computer-readable storage medium storing a computer program, wherein the computer program causes a computer to perform the above-described non-destructive testing method for fat content in shelled walnuts.

[0036] The fifth technical solution of the present invention is:

[0037] An electronic device includes the aforementioned computer-readable storage medium and a processor coupled to the computer-readable storage medium; when a computer program stored in the computer-readable storage medium is executed by the processor, it enables non-destructive testing of the fat content in shelled walnuts.

[0038] This invention integrates a fat content detection model for shelled walnuts with near-infrared spectroscopy analysis into an electronic device, achieving full automation of the process from spectral acquisition, data preprocessing, model prediction, and result output. This significantly improves detection efficiency, reduces human error, and enhances the stability and reliability of the detection results.

[0039] Meanwhile, the detection method is embedded in the hardware equipment, has a low operating threshold, does not require professional modeling and data analysis capabilities, and is easy to implement rapid screening and quality grading in field, purchasing station, production line and other on-site scenarios, making it suitable for large-scale promotion and use. Attached Figure Description

[0040] Figure 1 The images shown are near-infrared spectra of walnut kernel samples in Example 1 of this invention; where (a) is the original spectrum, (b) is the Max-min preprocessing result, (c) is the SNV preprocessing result, and (d) is the MSC preprocessing result.

[0041] Figure 2 This is a graph showing the results of the determination of walnut kernel fat content of five varieties of walnuts in Example 1 of the present invention;

[0042] Figure 3The image shows the original spectral PDS migration correction results in Example 1 of this invention; where (a) and (b) are the comparison of the original data and average spectral distribution of the first three samples (Gift), (c) and (d) are the comparison of the original data and average spectral distribution of the first three samples (Liaoning No. 1), (e) and (f) are the comparison of the original data and average spectral distribution of the first three samples (Fragrant), (g) and (h) are the comparison of the original data and average spectral distribution of the first three samples (Fragrant), and (i) and (j) are the comparison of the original data and average spectral distribution of the first three samples (Zhonglin No. 1).

[0043] Figure 4 The images show the characteristic wavelength screening and results based on CARS, MASS, and VCPA in Embodiment 1 of the present invention; where (a), (b), and (c) are the characteristic wavelength screening processes of CARS, MASS, and VCPA, respectively, and (d) is a comparison of the spectral characteristic band results.

[0044] Figure 5 The prediction results of the PDS-SNV-VCPA-MLP model in Embodiment 1 of this invention;

[0045] Figure 6 This is the process for selecting key network parameters of MLP based on Bayesian optimization in Embodiment 1 of the present invention;

[0046] Figure 7 The results are the predictions of the PDS-SNV-VCPA-BA-MLP model in Embodiment 1 of this invention. Detailed Implementation

[0047] Near-infrared spectroscopy is a rapid and non-destructive testing technique based on the principle of molecular vibrational spectroscopy. With its outstanding advantages such as fast analysis speed, no need for complex sample pretreatment, and the ability to perform in-situ or online detection, it has been successfully applied in the quantitative analysis of various components (such as moisture, protein, and starch) in agricultural products and food.

[0048] To address the problems of complex procedures and the inability to achieve truly non-destructive testing in existing walnut fat content determination methods, which affect subsequent product processing, this invention utilizes near-infrared spectroscopy to construct a method for detecting the fat content of shelled walnuts. The physical basis of this technology is the overtone and combination frequency absorption of hydrogen-containing groups in the near-infrared region, where the main characteristic groups of fat molecules exhibit sensitive absorption bands. However, directly applying this technology to determine the internal fat content of shelled walnuts faces a significant problem: the hard and structurally heterogeneous walnut shell severely scatters, absorbs, and attenuates incident near-infrared light. This results in the effective chemical information from the walnut kernel fat being masked by strong background noise and physical interference in the spectral signal directly acquired from the shelled sample. This leads to low accuracy and poor robustness in prediction models directly based on the shell spectrum, becoming a major bottleneck restricting the practical application of near-infrared spectroscopy in the field of internal quality detection of shelled nuts.

[0049] To further address the aforementioned issue of "shell" interference, this invention incorporates transfer correction during model construction. Piecewise Direct Standardization (PDS), a data-driven spectral transfer technique, uses mathematical transformations to map the spectral feature space from highly interfering sources (such as shelled walnuts) to a feature space highly similar to low-interference or target sources (such as pure walnut kernels), thereby "compensating" or "removing" the influence of physical interference at the algorithmic level. The introduction of this algorithm effectively solves the shell interference problem in detecting fat content in shelled walnuts, laying a solid foundation for further constructing the optimal detection model.

[0050] Meanwhile, advanced machine learning modeling methods, especially artificial neural networks (such as multilayer perceptrons) and support vector machines capable of handling complex nonlinear relationships, have demonstrated strong advantages in resolving deep correlations between spectra and target properties. Furthermore, combining efficient feature wavelength selection algorithms (such as CARS, MASS, and VCPA) to reduce the dimensionality of high-dimensional spectral data, and utilizing automated hyperparameter optimization methods (such as Bayesian optimization and genetic algorithms) to fine-tune the model structure, are common and effective strategies for constructing high-performance, high-generalization quantitative models.

[0051] In summary, to overcome the technical limitations of existing detection technologies in rapidly and accurately determining the internal fat content of walnuts without damaging their integrity, this invention proposes a novel near-infrared spectral analysis method that integrates spectral migration correction, characteristic wavelength optimization, and intelligent modeling optimization.

[0052] To accurately evaluate the effectiveness of different modeling methods in predicting the fat content of walnut kernels and to construct the optimal model, this invention systematically establishes four quantitative prediction models for comparison and validation based on the spectral data of walnut kernel samples and their corresponding standard chemical values ​​of fat content. First, a basic linear model is constructed using partial least squares regression (PLSR), which effectively solves the problem of multicollinearity among variables by projecting high-dimensional spectral data and chemical values ​​into a low-dimensional latent variable space. Second, considering the potentially complex nonlinear relationship between spectrum and fat content, two nonlinear algorithms based on the support vector machine framework are introduced: support vector regression (SVR) and least squares support vector regression (LSSVR). Furthermore, a classic feedforward neural network model—multilayer perceptron (MLP)—is used. The MLP model structure includes one input layer, two hidden layers, and one output layer. Finally, all samples are randomly divided into a calibration set and an independent test set, used for model training and generalization ability testing, respectively. By applying the above four models to the full-wavelength spectrum and feature wavelength subsets extracted by CARS, MASS, and VCPA algorithms, this invention comprehensively evaluates the combined impact of data preprocessing and variable selection strategies on the performance of the final prediction model.

[0053] This invention uses the calibration set correlation coefficient (Rc) to quantify the linear correlation between model predictions and measured chemical values; a value closer to 1 indicates a higher degree of model fit to the training data. The root mean square error of the calibration set (RMSEC) characterizes the average prediction bias of the model on the training set; a lower value indicates better model calibration accuracy. Furthermore, for external validation performance, the test set correlation coefficient (Rp) and test set root mean square error (RMSEP) are introduced to evaluate the model's prediction accuracy and stability on independent test sets, respectively. To further comprehensively evaluate model performance, the relative standard deviation (RPD) is calculated. According to prediction model evaluation metrics in related studies, an RPD greater than 2.5 generally indicates excellent quantitative analysis capabilities. Based on these key indicators, this invention will systematically compare and screen all constructed prediction models with different preprocessing, different characteristic wavelength subsets, and different algorithms to determine the optimal non-destructive detection model for the fat content of shelled walnuts.

[0054] The technical solution of the present invention will be further described below with reference to specific embodiments.

[0055] Example 1

[0056] The near-infrared spectroscopy-based model for detecting fat content in shelled walnuts in this embodiment is constructed using the following steps:

[0057] Step 1: Collecting Walnut Samples: This example selected five representative walnut varieties from Shanxi Province, including: Liwu, Liaoning No. 1, Qingxiang, Xiangling, and Zhonglin No. 1. All walnut samples were mature, plump, with intact shells, free from mechanical damage, pests, diseases, and mold, and were healthy fruits. All samples were stored in a constant temperature and dry environment at 4°C before the experiment to maintain their physicochemical stability.

[0058] This embodiment uses a mixed sample of multiple varieties for modeling, which can effectively cover the common phenotypic variation range of walnuts, thereby enhancing the model's adaptability to actual samples from different sources.

[0059] Step 2: Collect near-infrared spectral data of shelled walnuts and corresponding walnut kernels, as well as the fat content of walnut kernels: Randomly number the collected walnut samples, and sequentially perform near-infrared spectral scanning of shelled walnuts and walnut kernels, and subsequently determine the standard fat content of walnut kernels.

[0060] (1) In this embodiment, a Fourier transform near-infrared spectrometer (model: Antaris II, manufacturer: ThermoFisher Scientific, USA) was used to acquire spectral data of walnut samples. The instrument parameters were set as follows: the spectral scanning range covered the near-infrared band from 1000 nm to 2500 nm, and the spectral resolution was set to 4 cm⁻¹.

[0061] To obtain reliable data representing the overall spectral characteristics of the samples and minimize single-point measurement errors caused by the randomness of measurement locations, this embodiment implements standardized sampling with multi-point repeated scanning for each walnut sample (including both shelled and shelled kernels). A single shelled walnut sample is stably placed at the center of the integrating sphere sampling window of the spectrometer. To ensure that the acquired spectra comprehensively reflect the surface characteristics of the walnut's equatorial plane from different angles, the sample is manually and precisely rotated along a fixed axis, and spectral scans are performed at three evenly distributed geometric positions (i.e., rotated 120° sequentially). Finally, the spectral data obtained from the same shelled sample at the three different positions are arithmetically averaged to generate an average spectral curve representing the sample, which is used for all subsequent analyses.

[0062] After completing the spectral acquisition of each shelled sample, the shell was carefully broken open immediately, and the whole walnut kernel was removed. Three different regions on the surface of the kernel were then selected for spectral scanning, and the results of the three scans were averaged to obtain the average spectral curve representing the kernel. All acquired spectral data were saved in absorbance units and exported for subsequent chemometric analysis. The results are as follows: Figure 1 As shown in (a).

[0063] Figure 1(a) Near-infrared spectra of all walnut kernel samples in the 1000-2500 nm wavelength range are shown. From the overall spectral morphology, the spectral curves of different samples exhibit a high degree of consistency in absorption peak positions and trends, reflecting similar main chemical compositions of the sample matrices. Simultaneously, differences in absorption intensity at specific wavelengths can be observed among the different samples, providing a data basis for analyzing differences in fat content among them. The presence of characteristic absorption bands directly related to fat molecule structure is the fundamental spectroscopic basis for achieving non-destructive and rapid quantitative detection of walnut kernel fat content in this embodiment. Analysis results show that the acquired spectral data have a good signal-to-noise ratio, stable baseline, and no obvious abnormalities or distortions.

[0064] (2) To obtain the chemical reference values ​​necessary for constructing a near-infrared spectroscopy quantitative model, this embodiment performed a standardized chemical determination of the fat content in walnut kernel samples. The determination process was carried out in accordance with "NY / T 4-1982 Method for Determination of Crude Fat in Cereal and Oilseed Crop Seeds". Each walnut kernel sample was measured twice in parallel, and the arithmetic mean of the two measurements was taken as the final chemical value of the fat content of the sample. The results are as follows. Figure 2 As shown.

[0065] Figure 2 The data presents the fat content distribution of five walnut varieties. Overall, the Qingxiang variety has the highest median fat content, ranging from approximately 68% to 70%, with a relatively wide distribution range; Zhonglin No. 1 is second, with a median content of approximately 68%; Xiangling has a median fat content of approximately 66%, with a relatively concentrated distribution; and Lijin and Liaoning No. 1 have lower median fat content. In summary, the fat content data in the sample set used in this embodiment possesses both good dispersion and continuity. Dispersion broadens the concentration prediction range of the model, while continuity ensures that the model can perform smooth and accurate interpolation predictions within this range. This data foundation is crucial for preventing model overfitting and enhancing its adaptability to unknown samples, providing a validation basis for the subsequent development of high-precision non-destructive testing models.

[0066] Step 3: Screening Near-Infrared Spectroscopy Preprocessing Methods: To effectively extract spectral features related to fat content and suppress the negative impact of these irrelevant variations on the subsequent quantitative model, this embodiment preprocesses the raw spectral data of walnut kernels before modeling. Specifically, three preprocessing methods widely used in near-infrared spectroscopy analysis and designed for different interference sources were selected and compared: SNV, MSC, and Max-min. The preprocessing results are shown below. Figure 1 As shown in (b), (c) and (d).

[0067] This embodiment compares the prediction effects of the original spectrum and the spectral data processed by SNV, MSC and Max-min respectively under various modeling algorithms based on the spectral spectrum and the chemical value of fat content of walnut kernel samples. The results are shown in Table 1.

[0068] As shown in Table 1, the results indicate that when using the raw spectral data, the prediction performance of both the linear model (PLSR) and the nonlinear model (SVR, LSSVR) is unsatisfactory. The correlation coefficient between the training and test sets is low, while the root mean square error is high. This is mainly attributed to the fact that interference information such as physical scattering and baseline drift in the raw spectra severely masks the effective chemical features related to fat. In contrast, after the above three preprocessing methods, the prediction accuracy of all models is significantly and consistently improved. Among them, SNV shows the best optimization effect in both the linear and nonlinear models.

[0069] Furthermore, this embodiment also constructed an MLP model based on SNV preprocessed spectra. This model achieved the best prediction results at the current stage, with correlation coefficients of 0.970 and 0.955 between the calibration set and the test set, respectively, and the root mean square error also decreased to a low level. This result demonstrates that SNV has advantages in effectively eliminating the spectral multiplicative effect caused by differences in the physical state of the sample surface, and can better extract spectral features related to fat content.

[0070] Therefore, subsequent spectral migration correction and modeling analysis of shelled samples will uniformly adopt SNV as the standard preprocessing method to ensure the consistency and comparability of the data foundation.

[0071] Table 1. Predictive effects of different pretreatments on fat content in walnut kernels

[0072]

[0073] The raw near-infrared spectra acquired typically contain valid information from the target chemical components (such as fats), but are also mixed with interference signals caused by a variety of non-chemical factors, including physical scattering effects of the sample surface, instrument background noise, and spectral baseline drift caused by environmental fluctuations.

[0074] Standard normal variate (SNV) is a commonly used method to eliminate multiplicative scattering effects caused by differences in sample particle size, surface scattering, and optical path length. It can effectively correct spectral intensity variations caused by differences in physical states, making the spectra of different samples more comparable. Multiplicative scatter correction (MSC) is mainly used to correct spectral baseline shifts and amplitude variations caused by light scattering. Max-min normalization aims to map the absorbance value of each spectrum to a specific numerical range to eliminate absolute intensity differences caused by variations in sample size or measurement conditions. All spectral preprocessing operations were performed in the Matlab R2024b software environment and applied to the original spectral data of walnut kernels to systematically explore the effect of different preprocessing strategies on improving the quality of spectral data from samples in different states, laying a high-quality data foundation for subsequent feature selection and model construction.

[0075] Step 4: Near-infrared spectral migration correction processing:

[0076] (1) To address the strong scattering and absorption interference of the shell of walnuts on near-infrared light signals and to achieve effective spectral information characterizing the fat composition of walnut kernels without breaking the shell, this embodiment introduces a segmented direct normalization (PDS) algorithm. The PDS algorithm is used to perform transfer correction on the original spectra of the shelled walnuts: the correction process is based on paired spectral datasets of five walnut varieties. By establishing a linear transformation relationship from the shelled spectrum to the corresponding walnut kernel spectrum within each spectral window, a systematic correction of the entire spectrum is achieved. After transfer, the similarity between the shelled spectra of each variety and the target walnut kernel spectrum is significantly improved. The correction results are shown in Table 2 and... Figure 3 As shown.

[0077] As shown in Table 2, the overall correlation between the migrated spectrum and the target spectrum is above 0.990. This indicates that the PDS algorithm can effectively eliminate scattering and absorption interference caused by differences in physical properties such as shell thickness and texture, and successfully "convert" the shelled spectrum to a feature space that is highly consistent with the shelled walnut kernel spectrum. Figure 3 The spectral curve comparison visually demonstrates the migration effect. The original shelled spectrum and the walnut kernel spectrum show significant shifts in several characteristic absorption regions, while the PDS-corrected spectral curve largely overlaps with the target spectrum in both overall trend and fine structure. This result confirms that the PDS-based migration method can effectively "strip away" interference from the shell information.

[0078] Table 2. Near-infrared spectral migration correction results of walnuts in shells

[0079]

[0080] (2) To verify the effectiveness of the spectral transfer, this embodiment further performed SNV preprocessing on the spectral dataset after PDS correction and used MLP to construct a quantitative analysis model. The verification results are shown in Table 3. The results show that the constructed PDS-SNV-MLP combined model can effectively predict the fat content of shelled walnuts, and all evaluation indicators of the model have reached an acceptable level. However, compared with the control model constructed directly based on the SNV preprocessed spectrum of walnut kernels, the prediction accuracy of this combined model is slightly lower. This difference may be due to the correction residual error introduced by the spectral transfer process itself, that is, when mapping the shelled spectrum to the spectral space of walnut kernels, it is difficult to completely eliminate all nonlinear interferences caused by the physical properties of the shell.

[0081] Table 3. Prediction results of different preprocessing methods in MLP models

[0082]

[0083] PDS is an advanced spectral correction technology. Its core lies in establishing a quantitative conversion relationship between the spectrum of a shelled sample (source domain) and the spectrum of a shelled walnut kernel (target domain) in a local wavelength range through piecewise linear regression. This effectively compensates for spectral differences caused by differences in the physical state of the sample (such as the presence of a shell) while preserving the spectral characteristics of the target components.

[0084] Step 5: Feature Wavelength Selection: This embodiment employs three feature selection methods: Competitive Adaptive Reweighted Sampling (CARS), Model Adaptive Space Shrinkage (MASS), and Variable Combination Population Algorithm (VCPA). These methods extract feature wavelengths from the spectral-transferred data, identifying a small but information-dense subset of feature wavelengths from the full spectrum. These subsets will serve as the core input variables for building the subsequent fat content prediction model, aiming to achieve optimal model prediction accuracy and robustness with the fewest variables. After selection, 124, 108, and 116 feature wavelengths highly correlated with fat content (e.g., ...) were chosen from the 1557 wavelength variables in the full spectrum. Figure 4 (As shown).

[0085] Subsequently, MLP prediction models were constructed based on these feature wavelength subsets and their performance was verified (as shown in Table 3). According to the results in Table 3, after feature wavelength screening, the prediction accuracy of all models was significantly improved compared to models using the full wavelength or those only undergoing transfer and preprocessing. Among them, the PDS-SNV-VCPA-MLP model constructed based on the VCPA screening results performed best. This also demonstrates that feature wavelength screening can effectively remove a large amount of noise and redundant spectral information unrelated to the target component. Due to its global optimization characteristics, the VCPA algorithm exhibits superior variable selection capabilities in this embodiment. The specific prediction results of the PDS-SNV-VCPA-MLP model are as follows: Figure 5 As shown.

[0086] Near-infrared spectral data is characterized by high dimensionality and significant multicollinearity among wavelength variables. Direct modeling using the full-band spectrum not only introduces substantial redundancy and noise, significantly increasing computational complexity, but also easily leads to overfitting, thus weakening its generalization and predictive ability. Therefore, selecting the most relevant and information-rich characteristic wavelengths from high-dimensional spectral data is a crucial step in constructing a concise, efficient, and robust quantitative analysis model.

[0087] Step Six: Bayesian Optimization-Based MLP Model: Based on the input variables obtained through PDS transfer correction, SNV preprocessing, and VCPA feature wavelength selection, to further improve the predictive performance and stability of the multilayer perceptron model, this embodiment introduces the Bayesian optimization algorithm (BA) to automatically and globally optimize the key network structure parameters of the MLP (i.e., the number of neurons in the first and second hidden layers). The selection process for these key network structure parameters is as follows: Figure 6 As shown.

[0088] After Bayesian optimization with a preset number of iterations, the optimal network structure configuration for this dataset was obtained: the first hidden layer contains 31 neurons, and the second hidden layer contains 29 neurons. The final model (PDS-SNV-VCPA-BA-MLP) built using this optimized structure exhibits superior prediction performance, achieving near-optimal fitting and prediction results on both the calibration set and the independent prediction set (e.g., Figure 7 (As shown). Compared with the baseline model without Bayesian optimization, the optimized model has a significantly reduced prediction error, and both prediction accuracy and robustness are improved.

[0089] Example 2

[0090] The non-destructive detection method for fat content in shelled walnuts in this embodiment adopts the following steps: using the fat content detection model for shelled walnuts constructed in Example 1, namely the PDS-SNV-VCPA-BA-MLP model, the near-infrared spectral data of the shelled walnuts of the sample to be tested are input into the detection model to obtain and output the fat content of the shelled walnut kernels.

[0091] Example 3

[0092] The computer-readable storage medium of this embodiment stores a computer program, wherein the computer program causes a computer to execute the non-destructive testing method for fat content in walnuts in shells according to Embodiment 2.

[0093] Example 4

[0094] The electronic device of this embodiment includes the readable storage medium of embodiment 3 and a processor coupled to the readable storage medium. When the computer program stored in the computer-readable storage medium is executed by the processor, it realizes non-destructive detection of the fat content in shelled walnuts.

[0095] Obviously, the above embodiments are merely illustrative examples for clear explanation and are not intended to limit the implementation. Those skilled in the art will recognize that other variations or modifications can be made based on the above description. It is neither necessary nor possible to exhaustively list all possible implementations here. However, obvious variations or modifications derived therefrom are still within the scope of protection of the claims of this patent application.

Claims

1. A model for detecting fat content in shelled walnuts based on near-infrared spectroscopy, characterized in that, The following steps are required to build it: (1) Obtain a sample set of target walnuts, and obtain the near-infrared spectral data of each sample of shelled walnuts and corresponding walnut kernels, as well as the chemical value of walnut kernel fat content; (2) Perform any one of the following preprocessing methods on the near-infrared spectral data of walnut kernels: standard normal variable transformation, multivariate scattering correction, and normalization, and construct a fat content detection model based on the whole band to determine the optimal preprocessing method. (3) Using the near-infrared spectrum of the shelled walnut and the corresponding near-infrared spectrum of the walnut kernel as the calibration object, establish the conversion relationship within the full band or local wavelength window, perform calibration processing on the near-infrared spectrum of the shelled walnut, and obtain the calibrated near-infrared spectrum data; use the optimal preprocessing method obtained in step (2) to process the calibrated near-infrared spectrum data, and obtain the optimal preprocessed near-infrared spectrum data. (4) Select characteristic wavelengths from the preprocessed near-infrared spectral data, construct a fat content detection model based on characteristic wavelengths, and determine the optimal subset of characteristic wavelengths related to fat content; (5) Perform global optimization on the fat content detection model corresponding to the optimal feature wavelength subset obtained in step (4). The global optimization is to optimize the key network structure parameters of the fat content detection model to obtain the final fat content detection model for walnuts in shell.

2. The model for detecting fat content in shelled walnuts based on near-infrared spectroscopy according to claim 1, characterized in that, The basic model of the fat content detection model is a nonlinear model; the global optimization algorithm is a heuristic global optimization algorithm, which is a Bayesian optimization algorithm.

3. The model for detecting fat content in shelled walnuts based on near-infrared spectroscopy according to claim 2, characterized in that, The nonlinear model is a multilayer perceptron model. The key network structure parameters of the multilayer perceptron model are the number of neurons in the first hidden layer and the second hidden layer; the first hidden layer has 31 neurons and the second hidden layer has 29 neurons.

4. The model for detecting fat content in shelled walnuts based on near-infrared spectroscopy according to claim 1, characterized in that, In step (2), the optimal preprocessing method is standard normal variable transformation; in step (3), the correction processing is performed using a segmented direct standardization algorithm; in step (4), the variable clustering algorithm is used to screen feature variables and obtain the optimal feature wavelength subset related to fat content.

5. The model for detecting fat content in shelled walnuts based on near-infrared spectroscopy according to any one of claims 1-4, characterized in that, In step (1), the sample set consists of different varieties of walnuts from the same region; the near-infrared spectral data is the average spectral data of each sample, which is obtained by arithmetically averaging the spectral data of three different geometric positions on the equatorial horizontal axis of each sample.

6. The model for detecting fat content in shelled walnuts based on near-infrared spectroscopy according to any one of claims 1-4, characterized in that, The optimal processing method for different fat content detection models is determined by evaluating the prediction model using evaluation indicators, which are the correlation coefficient of the calibration set, the root mean square error of the calibration set, the correlation coefficient of the test set, the root mean square error of the test set, and the relative standard deviation.

7. A non-destructive method for detecting the fat content in shelled walnuts, characterized in that, Includes the following steps: Near-infrared spectral data of shelled walnuts are collected, and the obtained near-infrared spectral data of shelled walnuts are input into the fat content detection model described in any one of claims 1-6 to obtain and output the fat content of shelled walnuts.

8. A system for detecting fat content in shelled walnuts based on near-infrared spectroscopy, characterized in that, include: (1) Data acquisition module, used to acquire the sample set of target walnuts and the near-infrared spectral data of shelled walnuts and walnut kernels of each sample in the sample set and the chemical value of fat content of walnut kernels; (3) Preprocessing and screening module, which is used to perform any one of the following preprocessing methods on the near-infrared spectral data of walnut kernels: standard normal variable transformation, multivariate scattering correction, and normalization, and to construct a fat content detection model based on the whole band to determine the optimal preprocessing method; (4) Correction processing module: taking the near-infrared spectrum of the shelled walnut and the corresponding near-infrared spectrum of the walnut kernel as the correction object, establish the conversion relationship in the whole band or local wavelength window, perform correction processing on the near-infrared spectrum of the shelled walnut, and obtain the corrected near-infrared spectrum data; use the optimal preprocessing method obtained in step (3) to process the corrected near-infrared spectrum data, and obtain the optimal preprocessed near-infrared spectrum data. (5) Feature variable screening module: Select feature wavelengths from the pre-processed near-infrared spectral data, construct a fat content detection model based on feature wavelengths, and determine the optimal feature wavelength subset related to fat content; (6) Optimization module: global optimization of the fat content detection model corresponding to the optimal feature wavelength subset obtained in step (5). The global optimization is to optimize the key network structure parameters of the fat content detection model to obtain the final fat content detection model of walnuts in shell.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, wherein the computer program causes a computer to perform the non-destructive testing method for fat content in shelled walnuts as described in claim 7.

10. An electronic device, characterized in that, The invention includes the computer-readable storage medium of claim 9 and a processor coupled to the computer-readable storage medium; when the computer program stored in the computer-readable storage medium is executed by the processor, it enables non-destructive testing of the fat content in shelled walnuts.