A Non-destructive Detection Method for Walnut Inner Seed Coat Color Based on Neural Network Fine-tuning Correction
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-05-27
- Publication Date
- 2026-08-14
AI Technical Summary
然而,这种“黑盒”映射方式存在明显的缺陷:一是模型无法在物理或算法层面上剥离外壳干扰,容易使神经网络错误地将外壳的光谱杂质特征作为分类依据,导致模型陷入局部最优,泛化能力极差;二是现有光谱预处理方法如标准正态变量变换(SNV)、多元散射校正(MSC)等虽然能够部分降低散射影响,但难以有效消除核桃外壳所引入的系统性光谱干扰
[0048]本发明的有益效果是:(1)本发明的一种基于神经网络微调校正的带壳核桃内种皮色泽的快速无损检测方法能够在不破坏核桃外壳的情况下实现完整带壳核桃内种皮色泽的快速无损检测。(2)打破传统黑盒模型映射,实现了对外壳干扰的剥离,本发明首创性地利用核桃仁光谱对一维卷积神经网络进行预训练,使模型学习仁光谱的结构特征;随后在微调阶段引入残差校正机制,让网络专注于学习预测外壳带来的结构性干扰残差。这种“先认识本质、再剥离干扰”的双阶段架构,在算法内部实现了外壳与种仁信号的非线性解耦,从根本上解决外壳光谱掩盖种仁特征的技术难题。(3)引入了基于皮尔逊相关系数的壳层特征动态惩罚辅助约束,主动抑制外壳的干扰;传统深度学习在微调时容易产生过拟合,本发明在微调训练中,将核桃壳光谱作为“约束”引入,实时计算网络输出的校正光谱与核桃壳光谱的皮尔逊相关系数,并在其超过预设阈值(0.1-0.2)时施加动态加权惩罚。这种对抗性约束极大地提升了模型的泛化能力。(4)设计了多维度联合损失函数,有机融合了均方误差损失、一阶差分误差损失以及分类交叉熵损失实现了光谱保真重建与目标分类任务的协同优化,检测准确率与稳定性显著优于传统方法。此外,通过变量空间收缩(VISSA)方法筛选与色泽高度相关的特征波长,再结合极致梯度提升(XGBoost)模型进一步提高了色泽检测模型的精度和稳定性。
Smart Images

Figure QLYQS_41 
Figure QLYQS_47 
Figure QLYQS_57
Abstract
Description
Technical Field
[0002] This invention belongs to the field of non-destructive testing technology for agricultural product quality, and relates to a non-destructive testing method for the color of the inner seed coat of walnuts based on neural network fine-tuning correction. Background Technology
[0004] Walnuts, belonging to the genus Juglans of the family Juglandaceae, are one of my country's important economic forest fruits, characterized by their wide cultivation area, diverse varieties, and high commercial value. Walnut kernels are rich in fat, protein, carbohydrates, minerals, and various vitamins, possessing high nutritional value and market demand. A whole walnut typically consists of a hard outer shell, an inner seed coat, and the kernel. The inner seed coat, tightly covering the kernel surface, is a crucial factor influencing the walnut's appearance and commercial grade. The color of the inner seed coat is usually closely related to its maturity, storage conditions, and quality changes. Generally, walnuts with lighter-colored inner seed coats, appearing milky white or light yellow, have superior commercial quality; while a darker inner seed coat, brown or dark brown, often indicates increased quality deterioration and reduced commercial value. Accurate identification of the inner seed coat color is crucial in the grading, processing, and distribution of walnuts. However, because the outer shell obscures the internal structure, the color of the inner seed coat of a whole, shelled walnut is difficult to directly perceive through conventional visual methods. Current detection methods mostly rely on manually cracking the shells and observing the color of the walnut kernels. This method not only damages the sample but also has low detection efficiency and high subjectivity, making it difficult to meet the needs of rapid, non-destructive online detection of walnuts in their shells in large-scale production. Therefore, there is an urgent need for a rapid, non-destructive detection method for the color of the inner seed coat of walnuts in their shells.
[0005] Near-infrared spectroscopy (NIRS) technology, characterized by its rapid, non-destructive, and environmentally friendly nature, has been widely applied in the field of agricultural product quality evaluation and component detection. Its basic principle lies in the fact that the overtone and combination frequency absorption of hydrogen-containing groups in organic molecules typically produces a response in the near-infrared band, reflecting information about the chemical bonds, functional groups, and related components within the sample. Changes in the color of the inner seed coat of walnuts are usually accompanied by changes in its internal composition and quality state. Therefore, NIRS can be used to obtain spectral information related to the color of the inner seed coat, enabling rapid and non-destructive identification of walnut inner seed coat color. However, for whole, shelled walnuts, the strong light scattering and absorption effects of the shell during NIRS acquisition result in a large amount of shell information in the acquired spectrum, weakening the information related to the inner seed coat and thus reducing the accuracy and stability of inner seed coat color identification.
[0006] Existing technologies typically employ end-to-end deep learning models or conventional machine learning methods to directly establish a mapping between the complete shell spectrum and the kernel color category. However, this "black box" mapping method has significant drawbacks: First, the model cannot physically or algorithmically remove shell interference, easily causing the neural network to incorrectly use the spectral impurity features of the shell as the classification basis, leading to the model getting stuck in local optima and exhibiting extremely poor generalization ability. Second, while existing spectral preprocessing methods such as Standard Normal Variable Transform (SNV) and Multivariate Scattering Correction (MSC) can partially reduce the influence of scattering, they are insufficient to effectively eliminate the systematic spectral interference introduced by the walnut shell. Therefore, overcoming the limitations of traditional "black box" models and achieving the removal of shell interference from the complete walnut spectrum within the algorithm is a crucial technical bottleneck that urgently needs to be addressed to achieve high-precision, non-destructive detection of the kernel color within walnuts. Summary of the Invention
[0008] To address the aforementioned problems in existing technologies, this invention provides a non-destructive detection method for the inner seed coat color of walnuts based on neural network fine-tuning correction. First, the intrinsic spectral characteristics of the walnut kernel are learned through pre-training of a one-dimensional neural network. Second, a non-linear mapping from the spectrum of a complete walnut to the spectrum of the walnut kernel is learned through fine-tuning training. Finally, residual correction, a joint loss function, and walnut shell spectral auxiliary constraints are combined to suppress interference from the outer shell, resulting in the final corrected spectrum of the walnut kernel. This enables rapid, non-destructive, and high-precision detection of the inner seed coat color of complete walnuts with shells.
[0009] The technical solution adopted by this invention to solve its technical problem is: a non-destructive detection method for the inner seed coat color of walnuts based on neural network fine-tuning correction, characterized in that the steps of the method are as follows:
[0010] Step 1: Establishment of a spectral correction model based on neural network fine-tuning;
[0011] Step 1.1: Select whole, intact walnut samples that are uniform in size, free from mold and mechanical damage. indivual;
[0012] Step 1.2, regarding the above Near-infrared spectroscopy was performed on each intact walnut sample with its shell intact. The spectral acquisition method was diffuse transmission, and the environmental conditions were 25 ℃ and 40% relative humidity.
[0013] Step 1.3, after completing the spectral acquisition, the above... One complete walnut sample with its shell intact was cracked open to obtain the corresponding walnut kernel and shell. The color of the inner seed coat of the walnut kernel was graded using a colorimetric card, and the walnut samples were divided into two categories based on the color of the inner seed coat: walnut samples with a pale yellow inner seed coat were classified into one category, and the number of samples in this category was denoted as [number missing]. The category label is assigned a value of 0; walnut samples with brown or dark brown inner seed coats are classified into another category, and the number of such samples is denoted as [missing information]. The category label is assigned a value of 1; where, ;
[0014] Step 1.4, from the above Selected from walnut samples These samples were used as modeling samples for spectral correction, and these were extracted. The near-infrared spectra of complete shelled walnuts corresponding to each sample were used to construct a complete shelled walnut spectral matrix, denoted as [missing information]. ,in , The number of wavelength points;
[0015] Step 1.5, obtain the information described in Step 1.4. The walnut kernels corresponding to each walnut sample were crushed separately to obtain... We collected walnut kernel powder samples; then, we collected near-infrared spectra of each sample to construct a walnut kernel spectral matrix, denoted as [missing information]. ,in , The number of wavelength points;
[0016] Step 1.6, select from Step 1.4 The walnut shells corresponding to each walnut sample were then crushed to obtain... A sample of walnut shell powder; for Near-infrared spectra were collected from 10 walnut shell powder samples sequentially, and a walnut shell spectral matrix was constructed, denoted as [missing information]. ,in , The number of wavelength points;
[0017] Step 1.7: Since the near-infrared raw spectrum contains information about the sample's own chemical composition, it may also be affected by noise, baseline drift, and light scattering. Therefore, the spectral matrix of the complete shelled walnut is analyzed separately. Walnut kernel spectral matrix and walnut shell spectral matrix Spectral preprocessing is performed, including smoothing and denoising, baseline correction, and normalization. The preprocessed spectral matrices of the complete shelled walnut, the kernel, and the shell are denoted as follows: , and ;
[0018] Step 1.8: Since the near-infrared spectrum of a whole shelled walnut contains mixed information from both the shell and the kernel, the shell information can interfere with the detection of the inner seed coat color. Therefore, a one-dimensional neural network spectral correction model is constructed. First, the spectral features of the kernel are learned through pre-training. Then, the nonlinear mapping relationship between the spectrum of a whole shelled walnut and the kernel spectrum is learned through residual correction. In the fine-tuning stage, the shell spectrum is introduced as an auxiliary constraint sample. The joint loss function is adjusted by dynamically calculating the Pearson correlation coefficient between the corrected kernel spectrum and the corresponding shell spectrum, thereby correcting the interference from the shell.
[0019] Step 1.9: Construct a one-dimensional neural network adapted to the one-dimensional sequence features of near-infrared spectra, which sequentially includes an input layer, a one-dimensional convolutional layer, a batch normalization layer, an activation function layer, a feature extraction layer, a reconstruction layer, and an output layer. The input layer is used to receive a single near-infrared spectral sample, wherein the number of neurons corresponds to the wavelength of the near-infrared spectrum of a single sample. The quantity is consistent, and the input dimension is The system uses 2-4 one-dimensional convolutional layers with kernel sizes of 3-7 and strides of 1, employing the same padding method. The number of kernels is configured from 64 to 128 to 256 to 128. Multiple convolutional operations are used to extract absorption peaks, troughs, and local variation features from the spectrum. Each one-dimensional convolutional layer is followed by a batch normalization layer to standardize the features output by the convolutional layers, eliminate internal covariate bias, accelerate network training convergence, and improve the model's generalization ability. The calculation formula is as follows: ,in, These are the feature values output by the convolutional layer; This represents the mean of the current batch of samples; This represents the variance of the current batch of samples; It is a stability constant used to prevent the denominator from being zero; These are the normalized feature values; Activation function layer: After the batch normalization layer, an activation function layer is connected, using the ReLU activation function, expressed as follows: This is used to introduce nonlinear mapping capabilities into the network, fitting the complex nonlinear relationship between the complete walnut spectrum and the walnut kernel spectrum; Feature extraction layer: After convolutional feature extraction, a feature extraction layer is set to fuse global spectral information. The feature extraction layer includes a global average pooling layer and a fully connected layer. Let the output feature obtained after the last one-dimensional convolution be: ,in For the number of channels, Given the feature length for each channel, the output after global average pooling is expressed as: ,in, For the first The output values of each channel after global average pooling are combined to obtain a one-dimensional feature vector. Reconstruction layer: 1-2 fully connected layers are set, with the number of neurons decreasing in the order of 512→L, used to map the fused global features back to a feature space consistent with the original spectral dimensions; Output layer: The number of neurons is equal to the number of wavelength points. Consistent, output dimension is A linear activation function is used to ensure that the output spectral values are continuous, which is used to output the walnut kernel-corrected spectrum in the output layer. ;
[0020] Step 1.10, define the input-output mapping relationship of the one-dimensional neural network: Let the input be a single preprocessed complete walnut spectrum sample. ,in , The absorbance values of the sample at different wavelengths are given; the output spectrum of the one-dimensional neural network for this sample is given. ,in This represents the walnut kernel correction spectrum output by the neural network. For a one-dimensional neural network, the set of all trainable parameters is given. Indicates parameters For a one-dimensional neural network nonlinear mapping function;
[0021] Step 1.11: Pre-train the one-dimensional neural network to enable it to learn the intrinsic spectral structure features of walnut kernels in advance. Using the walnut kernel spectrum itself as the network input and target output, establish a spectral self-reconstruction mapping relationship: ,in For the input of a single walnut kernel spectral sample, This represents the walnut kernel correction spectrum output by the neural network. This is the set of network parameters for the pre-training phase.
[0022] Step 1.12, pre-training data partitioning, dividing the pre-processed walnut kernel spectral matrix The pre-training data is divided into training and testing sets in a 7:3 ratio for iterative optimization of network parameters and control of pre-training convergence.
[0023] Step 1.13: Set the loss function and training parameters for the pre-training stage to complete network pre-training. The mean squared error is used as the loss function during pre-training to measure the difference between the neural network's output spectrum and the actual walnut kernel spectrum. Its expression is: ,in Indicates the network output spectrum at the th The value at each wavelength point, The true walnut kernel spectrum is shown in the first... The value of each wavelength point;
[0024] Step 1.14: Minimize the pre-training loss function using the gradient descent algorithm, and adjust the network parameters. Iterative updates are performed to allow the neural network to fully learn the core features of the walnut kernel spectrum, such as its intrinsic structure, absorption peak distribution, and spectral trends. After pre-training, the optimal network parameters are saved. ;
[0025] Step 1.15: Fine-tune the one-dimensional neural network based on the pre-trained parameters to establish a correction model from the complete walnut spectrum to the corrected walnut kernel spectrum, and save the network parameters after pre-training. The preprocessed complete shelled walnut spectral matrix was used as the initial parameter for fine-tuning training. As the input dataset for fine-tuning, the corresponding preprocessed walnut kernel spectral matrix Output dataset as the target for fine-tuning;
[0026] Step 1.16, fine-tune the data partitioning, The corresponding dataset is divided into a 7:3 ratio for fine-tuning the training and testing sets, which are used for iterative optimization of network parameters and fine-tuning convergence control.
[0027] Step 1.17, Fine-tuning the mapping relationship: Using the spectrum of a complete shelled walnut as network input and the spectrum of the walnut kernel as a reference, establish a nonlinear mapping relationship from the complete walnut spectrum to the walnut kernel spectrum: ,in This is the complete walnut spectrum after preprocessing. The corrected spectrum of walnut kernels is obtained after network correction. This is the set of fine-tuned network parameters, derived from the initial parameters. Obtained through iterative updates;
[0028] Step 1.18, during the fine-tuning training process, the one-dimensional neural network processes each input complete walnut spectral sample. The process involves sequential operations such as convolution, batch normalization, activation, feature extraction, and feature reconstruction, through a nonlinear mapping function. Output walnut kernel calibrated spectrum Network parameters Continuous iterative optimization during training improves the output. Constantly approaching the true spectrum of walnut kernels ;
[0029] Step 1.19: The fine-tuning training phase does not involve blind end-to-end fitting, but introduces a shell interference residual correction mechanism and physical feature auxiliary constraints to improve the network's ability to suppress walnut shell interference.
[0030] Interference Residual Definition: The walnut shell interference information contained in the complete walnut spectrum is defined as the shell interference residual, denoted as . , ;
[0031] A one-dimensional convolutional neural network is specifically designed to learn the mapping relationship between the complete walnut spectrum and the shell interference residual, expressed as: ,in This is the complete walnut spectrum after preprocessing. These are the network parameters during the fine-tuning process;
[0032] Residual correction calculation: The network specifically learns the nonlinear "interference residual" caused by the shell in the spectrum of a whole walnut. During the fine-tuning forward propagation, the predicted shell interference residual is subtracted from the spectrum of a whole walnut with shell to dynamically reconstruct the corrected spectrum of the walnut kernel. The expression is as follows: ;
[0033] Step 1.20: Construct the joint loss function for the fine-tuning stage. To ensure that the corrected equivalent spectrum of the walnut kernel is close to the spectrum of the real walnut kernel while retaining the spectral features related to the color of the walnut kernel, which is beneficial for subsequent kernel color detection, a multi-dimensional joint loss function is constructed, the expression of which is: ,in For the joint loss function, Corrected spectrum in the Each wavelength point value, For the true walnut kernel spectrum in the first The value of each wavelength point; The cross-entropy loss is used to incorporate walnut kernel color category information during the neural network fine-tuning stage, thereby enhancing the correlation between the calibration spectrum and walnut kernel color. ,in This is a label indicating the true color of walnuts. The class probabilities predicted by the model; , , For the loss weight coefficients, satisfying ,in The mean squared error loss weight is preferably set between 0.5 and 0.7. This is the weight for the first-order difference error loss, preferably set to 0.2-0.3. The preferred value for the cross-entropy loss weight is 0.1-0.2, which can be flexibly adjusted according to actual detection needs.
[0034] Step 1.21: Introduce walnut shell spectroscopy as an auxiliary constraint to enhance the network's ability to suppress shell information. The preprocessed walnut shell spectral matrix... As auxiliary constraint samples, the fine-tuning training process is introduced, and the corrected spectrum of the walnut kernel output is calculated after each iteration update of the network parameters. Corresponding walnut shell spectrum The Pearson correlation coefficient was used to measure the feature similarity between the equivalent spectrum of the walnut kernel and the spectrum of the walnut shell during the iteration process. A similarity threshold of 0.1-0.2 was set. When the similarity exceeded the threshold, a corresponding weighted penalty was applied to the joint loss function so that the loss value increased with the increase of similarity. This dynamic weighted penalty method can guide the network to reduce the interference of shell features through parameter adjustment and ensure that the corrected spectrum retains only the intrinsic features of the walnut kernel.
[0035] During network training, gradients are calculated and network parameters are iteratively updated using only the training set. Meanwhile, after each training epoch, the generalization performance of the network model is evaluated using the test set. When the test set loss reaches its minimum and no longer decreases significantly, an early stopping mechanism is triggered, and the network parameters that perform best on the test set at this time are saved as the optimal network parameters.
[0036] Step 1.22: After fine-tuning, save the final optimal network parameters. A one-dimensional neural network correction model was obtained, which has the ability to eliminate interference from the walnut shell and converts the complete shelled walnut spectrum into the corrected walnut kernel spectrum.
[0037] Step 2: Establishing a classification model for the color of the inner seed coat of walnuts;
[0038] Step 2.1, in Of the walnut samples, after removing those already selected in step 1.4 After selecting one sample, a certain number of walnut samples are then chosen as classification modeling samples for the inner seed coat color of walnuts, totaling [number missing]. One, and extract the The near-infrared spectra of complete shelled walnuts corresponding to each sample; the near-infrared spectra are preprocessed according to step 1.7 to obtain the preprocessed spectral data matrix, denoted as . , ;
[0039] Step 2.2: Using the one-dimensional convolutional neural network correction model established in steps 1.9 to 1.22, the spectral matrix is... The spectra of each intact shelled walnut sample were calibrated to obtain... The calibrated spectral matrix of walnut kernels for each sample is denoted as . ;
[0040] Step 2.3, calibrate the spectral matrix of walnut kernels. Feature extraction was performed using a variable space shrinkage method. The initial variable space consisted of all wavelength variables in the walnut kernel calibration spectral matrix. Based on the contribution of each wavelength variable to the classification of walnut inner seed coat color during the modeling process, the variable space was iteratively shrunk. In each iteration, the importance evaluation index of each wavelength variable was calculated, and wavelength variables were retained or removed according to their importance, gradually removing wavelength variables with small classification contributions or high redundancy from the variable space. After multiple iterations, a set of feature wavelength variables that significantly contribute to the classification of walnut inner seed coat color was obtained. ,in To determine the number of characteristic wavelengths obtained through screening, For the first One characteristic wavelength;
[0041] The characteristic wavelength variable sets obtained in steps 2.4 and 2.3 are used to correct the spectral matrix of walnut kernels. Extract the spectral variables at the corresponding characteristic wavelengths. Constructing the corrected characteristic spectral matrix of walnut kernels ;
[0042] Step 2.5, take the characteristic spectral matrix obtained in step 2.4. Color category value of walnut inner seed coat To establish a correlation, the Extreme Gradient Boosting (XGBoost) method was used to build a classification and detection model for seed coat color within walnut seeds. The model form is as follows: , among which The category value represents the color of the inner seed coat of walnuts, with light yellow samples denoted as 0 and brown and dark brown samples denoted as 1; the model established after training is denoted as... ;
[0043] Step 3: Prediction of the inner seed coat and kernel color of unknown intact walnut samples;
[0044] Step 3.1, for For each intact walnut sample to be tested, near-infrared spectra were collected sequentially under the same conditions as in step 1.2, and the spectral matrix was obtained. ;
[0045] Step 3.2, adjust the spectral matrix according to step 1.7. Preprocessing was performed to obtain the complete spectral matrix of shelled walnuts. ;
[0046] Step 3.3: Using the one-dimensional convolutional neural network correction model established in steps 1.9 to 1.22, the spectral matrix is... The spectra of each intact shelled walnut sample were calibrated to obtain the walnut kernel calibrated spectral matrix of the sample to be tested. ;
[0047] Step 3.4, based on the set of characteristic wavelength variables determined in Step 2.3 From the walnut kernel calibration spectral matrix in step 2.3, extract the spectral variables at the corresponding characteristic wavelengths to construct the characteristic spectral matrix of the sample to be tested, and substitute it into the XGBoost classification prediction model established in step 2.5. In the middle, we get This method predicts the color category of the inner seed coat of a complete, shelled walnut sample, thereby enabling rapid and non-destructive detection of the color of the inner seed coat of a complete walnut.
[0048] The beneficial effects of this invention are: (1) The fast and non-destructive detection method for the inner seed coat color of walnuts with shells based on neural network fine-tuning correction can achieve fast and non-destructive detection of the inner seed coat color of intact walnuts without damaging the walnut shell. (2) Breaking the traditional black-box model mapping, this invention achieves the removal of shell interference. This invention innovatively uses the walnut kernel spectrum to pre-train a one-dimensional convolutional neural network, enabling the model to learn the structural features of the kernel spectrum; then, a residual correction mechanism is introduced in the fine-tuning stage, allowing the network to focus on learning and predicting the structural interference residuals brought by the shell. This two-stage architecture of "first understanding the essence, then removing interference" realizes the nonlinear decoupling of the shell and kernel signals within the algorithm, fundamentally solving the technical problem of the shell spectrum masking the kernel features. (3) A dynamic penalty auxiliary constraint based on the shell feature based on the Pearson correlation coefficient is introduced to actively suppress the interference of the shell. Traditional deep learning is prone to overfitting during fine-tuning. In this invention, the walnut shell spectrum is introduced as a "constraint" in the fine-tuning training. The Pearson correlation coefficient between the corrected spectrum output by the network and the walnut shell spectrum is calculated in real time, and a dynamic weighted penalty is applied when it exceeds a preset threshold (0.1-0.2). This adversarial constraint greatly improves the generalization ability of the model. (4) A multi-dimensional joint loss function is designed, which organically integrates the mean square error loss, the first-order difference error loss and the classification cross-entropy loss to achieve the synergistic optimization of the spectral fidelity reconstruction and the target classification task. The detection accuracy and stability are significantly better than traditional methods. In addition, the feature wavelengths that are highly correlated with color are screened by the variable space contraction (VISSA) method, and then combined with the extreme gradient boosting (XGBoost) model to further improve the accuracy and stability of the color detection model. Detailed Implementation
[0050] To further illustrate the technical means and methods adopted by the present invention to achieve its intended purpose, the technical solutions in the embodiments of the present invention are described clearly and in detail below with reference to specific examples. The described embodiments are only used to explain the present invention and are not intended to limit the present invention.
[0051] In an embodiment of the present invention, a rapid and non-destructive method for detecting the color of the inner seed coat of walnuts based on near-infrared spectroscopy is used to detect a batch of intact shelled walnut samples. The method mainly includes the following steps:
[0052] Step 1: Establishment of a spectral correction model based on neural network fine-tuning;
[0053] Step 1.1: Select whole, intact walnut samples that are uniform in size, free from mold and mechanical damage. indivual;
[0054] Step 1.2, regarding the above Near-infrared spectroscopy was performed on each intact walnut sample with its shell intact. The spectral acquisition method was diffuse transmission, and the environmental conditions were 25 ℃ and 40% relative humidity.
[0055] Step 1.3, after completing the spectral acquisition, the above... One complete walnut sample with its shell intact was cracked open to obtain the corresponding walnut kernel and shell. The color of the inner seed coat of the walnut kernel was graded using a colorimetric card, and the walnut samples were divided into two categories based on the color of the inner seed coat: walnut samples with a pale yellow inner seed coat were classified into one category, and the number of samples in this category was denoted as [number missing]. The category label is assigned a value of 0; walnut samples with brown or dark brown inner seed coats are classified into another category, and the number of such samples is denoted as [missing information]. The category label is assigned a value of 1; where, ;
[0056] Step 1.4, from the above Selected from walnut samples These samples were used as modeling samples for spectral correction, and these were extracted. The near-infrared spectra of complete shelled walnuts corresponding to each sample were used to construct a complete shelled walnut spectral matrix, denoted as [missing information]. ,in , The number of wavelength points;
[0057] Step 1.5, obtain the information described in Step 1.4. The walnut kernels corresponding to each walnut sample were crushed separately to obtain... We collected walnut kernel powder samples; then, we collected near-infrared spectra of each sample to construct a walnut kernel spectral matrix, denoted as [missing information]. ,in , The number of wavelength points;
[0058] Step 1.6, select from Step 1.4 The walnut shells corresponding to each walnut sample were then crushed to obtain... A sample of walnut shell powder; for Near-infrared spectra were collected from 10 walnut shell powder samples sequentially, and a walnut shell spectral matrix was constructed, denoted as [missing information]. ,in , The number of wavelength points;
[0059] Step 1.7: Since the near-infrared raw spectrum contains information about the sample's own chemical composition, it may also be affected by noise, baseline drift, and light scattering. Therefore, the spectral matrix of the complete shelled walnut is analyzed separately. Walnut kernel spectral matrix and walnut shell spectral matrix Spectral preprocessing is performed, including smoothing and denoising, baseline correction, and normalization. The preprocessed spectral matrices of the complete shelled walnut, the kernel, and the shell are denoted as follows: , and ;
[0060] Step 1.8: Since the near-infrared spectrum of a whole shelled walnut contains mixed information from both the shell and the kernel, the shell information can interfere with the detection of the inner seed coat color. Therefore, a one-dimensional neural network spectral correction model is constructed. First, the spectral features of the kernel are learned through pre-training. Then, the nonlinear mapping relationship between the spectrum of a whole shelled walnut and the kernel spectrum is learned through residual correction. In the fine-tuning stage, the shell spectrum is introduced as an auxiliary constraint sample. The joint loss function is adjusted by dynamically calculating the Pearson correlation coefficient between the corrected kernel spectrum and the corresponding shell spectrum, thereby correcting the interference from the shell.
[0061] Step 1.9: Construct a one-dimensional neural network adapted to the one-dimensional sequence features of near-infrared spectra, which sequentially includes an input layer, a one-dimensional convolutional layer, a batch normalization layer, an activation function layer, a feature extraction layer, a reconstruction layer, and an output layer. The input layer is used to receive a single near-infrared spectral sample, wherein the number of neurons corresponds to the wavelength of the near-infrared spectrum of a single sample. The quantity is consistent, and the input dimension is The system uses 2-4 one-dimensional convolutional layers with kernel sizes of 3-7 and strides of 1, employing the same padding method. The number of kernels is configured from 64 to 128 to 256 to 128. Multiple convolutional operations are used to extract absorption peaks, troughs, and local variation features from the spectrum. Each one-dimensional convolutional layer is followed by a batch normalization layer to standardize the features output by the convolutional layers, eliminate internal covariate bias, accelerate network training convergence, and improve the model's generalization ability. The calculation formula is as follows: ,in, These are the feature values output by the convolutional layer; This represents the mean of the current batch of samples; This represents the variance of the current batch of samples; It is a stability constant used to prevent the denominator from being zero; These are the normalized feature values; Activation function layer: After the batch normalization layer, an activation function layer is connected, using the ReLU activation function, expressed as follows: This is used to introduce nonlinear mapping capabilities into the network, fitting the complex nonlinear relationship between the complete walnut spectrum and the walnut kernel spectrum; Feature extraction layer: After convolutional feature extraction, a feature extraction layer is set to fuse global spectral information. The feature extraction layer includes a global average pooling layer and a fully connected layer. Let the output feature obtained after the last one-dimensional convolution be: ,in For the number of channels, Given the feature length for each channel, the output after global average pooling is expressed as: ,in, For the first The output values of each channel after global average pooling are combined to obtain a one-dimensional feature vector. Reconstruction layer: 1-2 fully connected layers are set, with the number of neurons decreasing in the order of 512→L, used to map the fused global features back to a feature space consistent with the original spectral dimensions; Output layer: The number of neurons is equal to the number of wavelength points. Consistent, output dimension is A linear activation function is used to ensure that the output spectral values are continuous, which is used to output the walnut kernel-corrected spectrum in the output layer. ;
[0062] Step 1.10, define the input-output mapping relationship of the one-dimensional neural network: Let the input be a single preprocessed complete walnut spectrum sample. ,in , The absorbance values of the sample at different wavelengths are given; the output spectrum of the one-dimensional neural network for this sample is given. ,in This represents the walnut kernel correction spectrum output by the neural network. For a one-dimensional neural network, the set of all trainable parameters is given. Indicates parameters For a one-dimensional neural network nonlinear mapping function;
[0063] Step 1.11: Pre-train the one-dimensional neural network to enable it to learn the intrinsic spectral structure features of walnut kernels in advance. Using the walnut kernel spectrum itself as the network input and target output, establish a spectral self-reconstruction mapping relationship: ,in For the input of a single walnut kernel spectral sample, This represents the walnut kernel correction spectrum output by the neural network. This is the set of network parameters for the pre-training phase.
[0064] Step 1.12, pre-training data partitioning, dividing the pre-processed walnut kernel spectral matrix The pre-training data is divided into training and testing sets in a 7:3 ratio for iterative optimization of network parameters and control of pre-training convergence.
[0065] Step 1.13: Set the loss function and training parameters for the pre-training stage to complete network pre-training. The mean squared error is used as the loss function during pre-training to measure the difference between the neural network's output spectrum and the actual walnut kernel spectrum. Its expression is: ,in Indicates the network output spectrum at the th The value at each wavelength point, The true walnut kernel spectrum is shown in the first... The value of each wavelength point;
[0066] Step 1.14: Minimize the pre-training loss function using the gradient descent algorithm, and adjust the network parameters. Iterative updates are performed to allow the neural network to fully learn the core features of the walnut kernel spectrum, such as its intrinsic structure, absorption peak distribution, and spectral trends. After pre-training, the optimal network parameters are saved. ;
[0067] Step 1.15: Fine-tune the one-dimensional neural network based on the pre-trained parameters to establish a correction model from the complete walnut spectrum to the corrected walnut kernel spectrum, and save the network parameters after pre-training. The preprocessed complete shelled walnut spectral matrix was used as the initial parameter for fine-tuning training. As the input dataset for fine-tuning, the corresponding preprocessed walnut kernel spectral matrix Output dataset as the target for fine-tuning;
[0068] Step 1.16, fine-tune the data partitioning, The corresponding dataset is divided into a 7:3 ratio for fine-tuning the training and testing sets, which are used for iterative optimization of network parameters and fine-tuning convergence control.
[0069] Step 1.17, Fine-tuning the mapping relationship: Using the spectrum of a complete shelled walnut as network input and the spectrum of the walnut kernel as a reference, establish a nonlinear mapping relationship from the complete walnut spectrum to the walnut kernel spectrum: ,in This is the complete walnut spectrum after preprocessing. The corrected spectrum of walnut kernels is obtained after network correction. This is the set of fine-tuned network parameters, derived from the initial parameters. Obtained through iterative updates;
[0070] Step 1.18, during the fine-tuning training process, the one-dimensional neural network processes each input complete walnut spectral sample. The process involves sequential operations such as convolution, batch normalization, activation, feature extraction, and feature reconstruction, through a nonlinear mapping function. Output walnut kernel calibrated spectrum Network parameters Continuous iterative optimization during training improves the output. Constantly approaching the true spectrum of walnut kernels ;
[0071] Step 1.19: The fine-tuning training phase does not involve blind end-to-end fitting, but introduces a shell interference residual correction mechanism and physical feature auxiliary constraints to improve the network's ability to suppress walnut shell interference.
[0072] Interference Residual Definition: The walnut shell interference information contained in the complete walnut spectrum is defined as the shell interference residual, denoted as . , ;
[0073] A one-dimensional convolutional neural network is specifically designed to learn the mapping relationship between the complete walnut spectrum and the shell interference residual, expressed as: ,in This is the complete walnut spectrum after preprocessing. These are the network parameters during the fine-tuning process;
[0074] Residual correction calculation: The network specifically learns the nonlinear "interference residual" caused by the shell in the spectrum of a whole walnut. During the fine-tuning forward propagation, the predicted shell interference residual is subtracted from the spectrum of a whole walnut with shell to dynamically reconstruct the corrected spectrum of the walnut kernel. The expression is as follows: ;
[0075] Step 1.20: Construct the joint loss function for the fine-tuning stage. To ensure that the corrected equivalent spectrum of the walnut kernel is close to the spectrum of the real walnut kernel while retaining the spectral features related to the color of the walnut kernel, which is beneficial for subsequent kernel color detection, a multi-dimensional joint loss function is constructed, the expression of which is: ,in For the joint loss function, Corrected spectrum in the Each wavelength point value, For the true walnut kernel spectrum in the first The value of each wavelength point; The cross-entropy loss is used to incorporate walnut kernel color category information during the neural network fine-tuning stage, thereby enhancing the correlation between the calibration spectrum and walnut kernel color. ,in This is a label indicating the true color of walnuts. The class probabilities predicted by the model; , , For the loss weight coefficients, satisfying ,in The mean squared error loss weight is preferably set between 0.5 and 0.7. This is the weight for the first-order difference error loss, preferably set to 0.2-0.3. The preferred value for the cross-entropy loss weight is 0.1-0.2, which can be flexibly adjusted according to actual detection needs.
[0076] Step 1.21: Introduce walnut shell spectroscopy as an auxiliary constraint to enhance the network's ability to suppress shell information. The preprocessed walnut shell spectral matrix... As auxiliary constraint samples, the fine-tuning training process is introduced, and the corrected spectrum of the walnut kernel output is calculated after each iteration update of the network parameters. Corresponding walnut shell spectrum The Pearson correlation coefficient was used to measure the feature similarity between the equivalent spectrum of the walnut kernel and the spectrum of the walnut shell during the iteration process. A similarity threshold of 0.1-0.2 was set. When the similarity exceeded the threshold, a corresponding weighted penalty was applied to the joint loss function so that the loss value increased with the increase of similarity. This dynamic weighted penalty method can guide the network to reduce the interference of shell features through parameter adjustment and ensure that the corrected spectrum retains only the intrinsic features of the walnut kernel.
[0077] During network training, gradients are calculated and network parameters are iteratively updated using only the training set. Meanwhile, after each training epoch, the generalization performance of the network model is evaluated using the test set. When the test set loss reaches its minimum and no longer decreases significantly, an early stopping mechanism is triggered, and the network parameters that perform best on the test set at this time are saved as the optimal network parameters.
[0078] Step 1.22: After fine-tuning, save the final optimal network parameters. A one-dimensional neural network correction model was obtained, which has the ability to eliminate interference from the walnut shell and converts the complete shelled walnut spectrum into the corrected walnut kernel spectrum.
[0079] Step 2: Establishing a classification model for the color of the inner seed coat of walnuts;
[0080] Step 2.1, in Of the walnut samples, after removing those already selected in step 1.4 After selecting one sample, a certain number of walnut samples are then chosen as classification modeling samples for the inner seed coat color of walnuts, totaling [number missing]. One, and extract the The near-infrared spectra of complete shelled walnuts corresponding to each sample; the near-infrared spectra are preprocessed according to step 1.7 to obtain the preprocessed spectral data matrix, denoted as . , ;
[0081] Step 2.2: Using the one-dimensional convolutional neural network correction model established in steps 1.9 to 1.22, the spectral matrix is... The spectra of each intact shelled walnut sample were calibrated to obtain... The calibrated spectral matrix of walnut kernels for each sample is denoted as . ;
[0082] Step 2.3, calibrate the spectral matrix of walnut kernels. Feature extraction was performed using a variable space shrinkage method. The initial variable space consisted of all wavelength variables in the walnut kernel calibration spectral matrix. Based on the contribution of each wavelength variable to the classification of walnut inner seed coat color during the modeling process, the variable space was iteratively shrunk. In each iteration, the importance evaluation index of each wavelength variable was calculated, and wavelength variables were retained or removed according to their importance, gradually removing wavelength variables with small classification contributions or high redundancy from the variable space. After multiple iterations, a set of feature wavelength variables that significantly contribute to the classification of walnut inner seed coat color was obtained. ,in To determine the number of characteristic wavelengths obtained through screening, For the first One characteristic wavelength;
[0083] The characteristic wavelength variable sets obtained in steps 2.4 and 2.3 are used to correct the spectral matrix of walnut kernels. Extract the spectral variables at the corresponding characteristic wavelengths. Constructing the corrected characteristic spectral matrix of walnut kernels ;
[0084] Step 2.5, take the characteristic spectral matrix obtained in step 2.4. Color category value of walnut inner seed coat To establish a correlation, the Extreme Gradient Boosting (XGBoost) method was used to build a classification and detection model for seed coat color within walnut seeds. The model form is as follows: , among which The category value represents the color of the inner seed coat of walnuts, with light yellow samples denoted as 0 and brown and dark brown samples denoted as 1; the model established after training is denoted as... ;
[0085] Step 3: Prediction of the inner seed coat and kernel color of unknown intact walnut samples;
[0086] Step 3.1, for For each intact walnut sample to be tested, near-infrared spectra were collected sequentially under the same conditions as in step 1.2, and the spectral matrix was obtained. ;
[0087] Step 3.2, adjust the spectral matrix according to step 1.7. Preprocessing was performed to obtain the complete spectral matrix of shelled walnuts. ;
[0088] Step 3.3: Using the one-dimensional convolutional neural network correction model established in steps 1.9 to 1.22, the spectral matrix is... The spectra of each intact shelled walnut sample were calibrated to obtain the walnut kernel calibrated spectral matrix of the sample to be tested. ;
[0089] Step 3.4, based on the set of characteristic wavelength variables determined in Step 2.3 From the walnut kernel calibration spectral matrix in step 2.3, extract the spectral variables at the corresponding characteristic wavelengths to construct the characteristic spectral matrix of the sample to be tested, and substitute it into the XGBoost classification prediction model established in step 2.5. In the middle, we get This method predicts the color category of the inner seed coat of a complete, shelled walnut sample, thereby enabling rapid and non-destructive detection of the color of the inner seed coat of a complete walnut.
[0090] The above specific embodiments are used to explain and illustrate the present invention, but not to limit the present invention. Any modifications and changes made to the present invention within the spirit and scope of the claims shall fall within the protection scope of the present invention.
Claims
1. A non-destructive detection method for the inner seed coat color of walnuts based on neural network fine-tuning correction, characterized in that, The steps of this method are as follows: Step 1: Establishment of a spectral correction model based on neural network fine-tuning; Step 1.1: Select whole, intact walnut samples that are uniform in size, free from mold and mechanical damage. indivual; Step 1.2, regarding the above Near-infrared spectroscopy was performed on each intact walnut sample with its shell intact. The spectral acquisition method was diffuse transmission, and the environmental conditions were 25 ℃ and 40% relative humidity. Step 1.3, after completing the spectral acquisition, the above... One complete walnut sample with its shell intact was cracked open to obtain the corresponding walnut kernel and shell. The color of the inner seed coat of the walnut kernel was graded using a colorimetric card, and the walnut samples were divided into two categories based on the color of the inner seed coat: walnut samples with a pale yellow inner seed coat were classified into one category, and the number of samples in this category was denoted as [number missing]. The category label is assigned a value of 0; walnut samples with brown or dark brown inner seed coats are classified into another category, and the number of such samples is denoted as [missing information]. The category label is assigned a value of 1; where, ; Step 1.4, from the above Selected from walnut samples These samples were used as modeling samples for spectral correction, and these were extracted. The near-infrared spectra of complete shelled walnuts corresponding to each sample were used to construct a complete shelled walnut spectral matrix, denoted as [missing information]. ,in , The number of wavelength points; Step 1.5, obtain the information described in Step 1.
4. The walnut kernels corresponding to each walnut sample were crushed separately to obtain... We collected walnut kernel powder samples; then, we collected near-infrared spectra of each sample to construct a walnut kernel spectral matrix, denoted as walnut kernel powder powder. ,in , The number of wavelength points; Step 1.6, select from Step 1.4 The walnut shells corresponding to each walnut sample were then crushed to obtain... A sample of walnut shell powder; for Near-infrared spectra were collected from 10 walnut shell powder samples sequentially, and a walnut shell spectral matrix was constructed, denoted as [missing information]. ,in , The number of wavelength points; Step 1.7: Since the near-infrared raw spectrum contains information about the sample's own chemical composition, it may also be affected by noise, baseline drift, and light scattering. Therefore, the spectral matrix of the complete shelled walnut is analyzed separately. Walnut kernel spectral matrix and walnut shell spectral matrix Spectral preprocessing is performed, including smoothing and denoising, baseline correction, and normalization. The preprocessed spectral matrices of the complete shelled walnut, the kernel, and the shell are denoted as follows: , and ; Step 1.8: Since the near-infrared spectrum of a whole shelled walnut contains mixed information from both the shell and the kernel, the shell information can interfere with the detection of the inner seed coat color. Therefore, a one-dimensional neural network spectral correction model is constructed. First, the spectral features of the kernel are learned through pre-training. Then, the nonlinear mapping relationship between the spectrum of a whole shelled walnut and the kernel spectrum is learned through residual correction. In the fine-tuning stage, the shell spectrum is introduced as an auxiliary constraint sample. The joint loss function is adjusted by dynamically calculating the Pearson correlation coefficient between the corrected kernel spectrum and the corresponding shell spectrum, thereby correcting the interference from the shell. Step 1.9: Construct a one-dimensional neural network adapted to the one-dimensional sequence features of near-infrared spectra, which sequentially includes an input layer, a one-dimensional convolutional layer, a batch normalization layer, an activation function layer, a feature extraction layer, a reconstruction layer, and an output layer. The input layer is used to receive a single near-infrared spectral sample, wherein the number of neurons corresponds to the wavelength of the near-infrared spectrum of a single sample. The quantity is consistent, and the input dimension is The system uses 2-4 one-dimensional convolutional layers with kernel sizes of 3-7 and strides of 1, employing the same padding method. The number of kernels is configured from 64 to 128 to 256 to 128. Multiple convolutional operations are used to extract absorption peaks, troughs, and local variation features from the spectrum. Each one-dimensional convolutional layer is followed by a batch normalization layer to standardize the features output by the convolutional layers, eliminate internal covariate bias, accelerate network training convergence, and improve the model's generalization ability. The calculation formula is as follows: ,in, These are the feature values output by the convolutional layer; This represents the mean of the current batch of samples; This represents the variance of the current batch of samples; It is a stability constant used to prevent the denominator from being zero; These are the normalized feature values; Activation function layer: After the batch normalization layer, an activation function layer is connected, using the ReLU activation function, expressed as follows: This is used to introduce nonlinear mapping capabilities into the network, fitting the complex nonlinear relationship between the complete walnut spectrum and the walnut kernel spectrum; Feature extraction layer: After convolutional feature extraction, a feature extraction layer is set to fuse global spectral information. The feature extraction layer includes a global average pooling layer and a fully connected layer. Let the output feature obtained after the last one-dimensional convolution be: ,in For the number of channels, Given the feature length for each channel, the output after global average pooling is expressed as: ,in, For the first The output values of each channel after global average pooling are combined to obtain a one-dimensional feature vector. Reconstruction layer: 1-2 fully connected layers are set, with the number of neurons decreasing in the order of 512→L, used to map the fused global features back to a feature space consistent with the original spectral dimensions; Output layer: The number of neurons is equal to the number of wavelength points. Consistent, output dimension is A linear activation function is used to ensure that the output spectral values are continuous, which is used to output the walnut kernel-corrected spectrum in the output layer. ; Step 1.10, define the input-output mapping relationship of the one-dimensional neural network: Let the input be a single preprocessed complete walnut spectrum sample. ,in , The absorbance values of the sample at different wavelengths are given; the output spectrum of the one-dimensional neural network for this sample is given. ,in This represents the walnut kernel correction spectrum output by the neural network. For a one-dimensional neural network, the set of all trainable parameters is given. Indicates parameters For a one-dimensional neural network nonlinear mapping function; Step 1.11: Pre-train the one-dimensional neural network to enable it to learn the intrinsic spectral structure features of walnut kernels in advance. Using the walnut kernel spectrum itself as the network input and target output, establish a spectral self-reconstruction mapping relationship: ,in For the input of a single walnut kernel spectral sample, This represents the walnut kernel correction spectrum output by the neural network. This is the set of network parameters for the pre-training phase. Step 1.12, pre-training data partitioning, dividing the pre-processed walnut kernel spectral matrix The pre-training data is divided into training and testing sets in a 7:3 ratio for iterative optimization of network parameters and control of pre-training convergence. Step 1.13: Set the loss function and training parameters for the pre-training stage to complete network pre-training. The mean squared error is used as the loss function during pre-training to measure the difference between the neural network's output spectrum and the actual walnut kernel spectrum. Its expression is: ,in Indicates the network output spectrum at the th The value at each wavelength point, The true walnut kernel spectrum is shown in the first... The value of each wavelength point; Step 1.14: Minimize the pre-training loss function using the gradient descent algorithm, and adjust the network parameters. Iterative updates are performed to allow the neural network to fully learn the core features of the walnut kernel spectrum, such as its intrinsic structure, absorption peak distribution, and spectral trends. After pre-training, the optimal network parameters are saved. ; Step 1.15: Fine-tune the one-dimensional neural network based on the pre-trained parameters to establish a correction model from the complete walnut spectrum to the corrected walnut kernel spectrum, and save the network parameters after pre-training. The preprocessed complete shelled walnut spectral matrix was used as the initial parameter for fine-tuning training. As the input dataset for fine-tuning, the corresponding preprocessed walnut kernel spectral matrix Output dataset as the target for fine-tuning; Step 1.16, fine-tune the data partitioning, The corresponding dataset is divided into a 7:3 ratio for fine-tuning the training and testing sets, which are used for iterative optimization of network parameters and fine-tuning convergence control. Step 1.17, Fine-tuning the mapping relationship: Using the spectrum of a complete shelled walnut as network input and the spectrum of the walnut kernel as a reference, establish a nonlinear mapping relationship from the complete walnut spectrum to the walnut kernel spectrum: ,in This is the complete walnut spectrum after preprocessing. The corrected spectrum of walnut kernels is obtained after network correction. This is the set of fine-tuned network parameters, derived from the initial parameters. Obtained through iterative updates; Step 1.18, during the fine-tuning training process, the one-dimensional neural network processes each input complete walnut spectral sample. The process involves sequential operations such as convolution, batch normalization, activation, feature extraction, and feature reconstruction, through a nonlinear mapping function. Output walnut kernel calibrated spectrum Network parameters Continuous iterative optimization during training improves the output. Constantly approaching the true spectrum of walnut kernels ; Step 1.19: The fine-tuning training phase does not involve blind end-to-end fitting, but introduces a shell interference residual correction mechanism and physical feature auxiliary constraints to improve the network's ability to suppress walnut shell interference. Interference Residual Definition: The walnut shell interference information contained in the complete walnut spectrum is defined as the shell interference residual, denoted as . , ; A one-dimensional convolutional neural network is specifically designed to learn the mapping relationship between the complete walnut spectrum and the shell interference residual, expressed as: ,in This is the complete walnut spectrum after preprocessing. These are the network parameters during the fine-tuning process; Residual correction calculation: The network specifically learns the nonlinear "interference residual" caused by the shell in the spectrum of a whole walnut. During the fine-tuning forward propagation, the predicted shell interference residual is subtracted from the spectrum of a whole walnut with shell to dynamically reconstruct the corrected spectrum of the walnut kernel. The expression is as follows: ; Step 1.20: Construct the joint loss function for the fine-tuning stage. To ensure that the corrected equivalent spectrum of the walnut kernel is close to the spectrum of the real walnut kernel while retaining the spectral features related to the color of the walnut kernel, which is beneficial for subsequent kernel color detection, a multi-dimensional joint loss function is constructed, the expression of which is: ,in For the joint loss function, Corrected spectrum in the Each wavelength point value, For the true walnut kernel spectrum in the first The value of each wavelength point; The cross-entropy loss is used to incorporate walnut kernel color category information during the neural network fine-tuning stage, thereby enhancing the correlation between the calibration spectrum and walnut kernel color. ,in This is a label indicating the true color of walnuts. The class probabilities predicted by the model; , , For the loss weight coefficients, satisfying ,in The mean squared error loss weight is preferably set between 0.5 and 0.
7. This is the weight for the first-order difference error loss, preferably set to 0.2-0.
3. The preferred value for the cross-entropy loss weight is 0.1-0.2, which can be flexibly adjusted according to actual detection needs. Step 1.21: Introduce walnut shell spectroscopy as an auxiliary constraint to enhance the network's ability to suppress shell information. The preprocessed walnut shell spectral matrix... As auxiliary constraint samples, the fine-tuning training process is introduced, and the corrected spectrum of the walnut kernel output is calculated after each iteration update of the network parameters. Corresponding walnut shell spectrum The Pearson correlation coefficient was used to measure the feature similarity between the equivalent spectrum of the walnut kernel and the spectrum of the walnut shell during the iteration process. A similarity threshold of 0.1-0.2 was set. When the similarity exceeded the threshold, a corresponding weighted penalty was applied to the joint loss function so that the loss value increased with the increase of similarity. This dynamic weighted penalty method can guide the network to reduce the interference of shell features through parameter adjustment and ensure that the corrected spectrum retains only the intrinsic features of the walnut kernel. During network training, gradients are calculated and network parameters are iteratively updated using only the training set. Meanwhile, after each training epoch, the generalization performance of the network model is evaluated using the test set. When the test set loss reaches its minimum and no longer decreases significantly, an early stopping mechanism is triggered, and the network parameters that perform best on the test set at this time are saved as the optimal network parameters. Step 1.22: After fine-tuning, save the final optimal network parameters. A one-dimensional neural network correction model was obtained, which has the ability to eliminate interference from the walnut shell and converts the complete shelled walnut spectrum into the corrected walnut kernel spectrum. Step 2: Establishing a classification model for the color of the inner seed coat of walnuts; Step 2.1, in Of the walnut samples, after removing those already selected in step 1.4 After selecting one sample, a certain number of walnut samples are then chosen as classification modeling samples for the inner seed coat color of walnuts, totaling [number missing]. One, and extract the The near-infrared spectra of complete shelled walnuts corresponding to each sample; the near-infrared spectra are preprocessed according to step 1.7 to obtain the preprocessed spectral data matrix, denoted as . , ; Step 2.2: Using the one-dimensional convolutional neural network correction model established in steps 1.9 to 1.22, the spectral matrix is... The spectra of each intact shelled walnut sample were calibrated to obtain... The calibrated spectral matrix of walnut kernels for each sample is denoted as . ; Step 2.3, calibrate the spectral matrix of walnut kernels. Feature extraction was performed using a variable space shrinkage method. All wavelength variables in the walnut kernel calibration spectral matrix were used as the initial variable space. Based on the contribution of each wavelength variable to the classification of the inner seed coat color of the walnut during the modeling process, the variable space was iteratively shrunk. In each iteration, the importance evaluation index of each wavelength variable was calculated, and wavelength variables were retained or removed according to their importance, so that wavelength variables with small contribution to classification or high redundancy were gradually removed from the variable space. After multiple iterations, a set of characteristic wavelength variables that significantly contribute to the classification of walnut inner seed coat color was obtained: ,in To determine the number of characteristic wavelengths obtained through screening, For the first One characteristic wavelength; The characteristic wavelength variable sets obtained in steps 2.4 and 2.3 are used to correct the spectral matrix of walnut kernels. Extract the spectral variables at the corresponding characteristic wavelengths. Constructing the corrected characteristic spectral matrix of walnut kernels ; Step 2.5, take the characteristic spectral matrix obtained in step 2.
4. Color category value of walnut inner seed coat To establish a correlation, the Extreme Gradient Boosting (XGBoost) method was used to build a classification and detection model for seed coat color within walnut seeds. The model form is as follows: , among which The category value is the color of the inner seed coat of the walnut. The light yellow color sample is recorded as 0, and the brown and dark brown samples are recorded as 1. The model built after training is denoted as ; Step 3: Prediction of the inner seed coat and kernel color of unknown intact walnut samples; Step 3.1, for For each intact walnut sample to be tested, near-infrared spectra were collected sequentially under the same conditions as in step 1.2, and the spectral matrix was obtained. ; Step 3.2, adjust the spectral matrix according to step 1.
7. Preprocessing was performed to obtain the complete spectral matrix of shelled walnuts. ; Step 3.3: Using the one-dimensional convolutional neural network correction model established in steps 1.9 to 1.22, the spectral matrix is... The spectra of each intact shelled walnut sample were calibrated to obtain the walnut kernel calibrated spectral matrix of the sample to be tested. ; Step 3.4, based on the set of characteristic wavelength variables determined in Step 2.3 From the walnut kernel calibration spectral matrix in step 2.3, extract the spectral variables at the corresponding characteristic wavelengths to construct the characteristic spectral matrix of the sample to be tested, and substitute it into the XGBoost classification prediction model established in step 2.
5. In the middle, we get This method predicts the color category of the inner seed coat of a complete, shelled walnut sample, thereby enabling rapid and non-destructive detection of the color of the inner seed coat of a complete walnut.