Online nondestructive detection method, device and equipment for chemical components of flue-cured tobacco and storage medium
By combining feature wavelength screening and multi-branch deep neural networks, the problems of model overfitting and gradient conflict in the detection of chemical components in flue-cured tobacco are solved, enabling fast, online, and non-destructive multi-component prediction, and improving detection accuracy and interpretability.
Patent Information
- Application Number
- CN202610941276.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-28
- Publication Date
- 2026-11-06
AI Technical Summary
Existing technologies for detecting chemical components in flue-cured tobacco suffer from problems such as high spectral dimensionality, strong inter-band collinearity leading to model overfitting, gradient conflicts caused by traditional hard parameter sharing multi-task networks, and insufficient model interpretability.
By employing a branch network structure with characteristic wavelength screening and gradient isolation, multiple chemical component prediction values are simultaneously output through a single hyperspectral scan. Feature extraction and dedicated regression prediction are performed using a multi-branch deep neural network, and the parameters of each task output module are independent, thus solving the problems of negative transfer and gradient conflict.
It enables rapid, online, and non-destructive detection of chemical components in flue-cured tobacco, reduces spectral redundancy and the risk of model overfitting, and improves prediction accuracy and model interpretability.
Smart Images

Figure CN123045997A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of tobacco chemical component detection technology, and in particular to an online non-destructive detection method, apparatus, equipment and storage medium for flue-cured tobacco chemical components. Background Technology
[0002] The intrinsic quality and industrial usability of flue-cured tobacco are closely related to its key chemical components, such as total alkaloids, total nitrogen, reducing sugars, total sugars, potassium, chlorine, and starch. Rapidly obtaining information on the content of these chemical components is crucial for quality control and process optimization during stages such as tobacco leaf acquisition, grading, re-drying, and formulation design.
[0003] Hyperspectral imaging and near-infrared spectroscopy, enabling non-destructive testing, have become an important alternative to traditional wet chemical methods. These techniques acquire continuous reflectance spectra of samples in the visible, near-infrared, and short-wave near-infrared bands, and indirectly reflect the content of various chemical components in the sample by utilizing the overtone and combination frequency absorption information of chemical bonds such as CH, OH, and NH in the spectra. Existing hyperspectral-based methods for detecting tobacco chemical components mainly include: chemometric methods such as partial least squares regression, machine learning methods such as support vector regression, and ordinary deep neural networks or multi-task deep neural networks with hard parameter sharing.
[0004] However, the above-mentioned detection technologies still have the following technical problems in practical applications: First, after fusing visible-near-infrared and short-wave near-infrared spectra, the spectral dimension is high and the collinearity between bands is strong, making the model prone to overfitting under limited sample conditions.
[0005] Second, the spectral response mechanisms of the seven chemical components differ significantly. Traditional multi-task networks with shared hard parameters compress the prediction tasks of all components into the same implicit representation, leading to negative transfer and gradient conflicts between different tasks, and a decrease in the prediction accuracy of some indicators.
[0006] Third, traditional end-to-end deep networks lack explicit screening mechanisms for effective feature wavelengths, resulting in insufficient model interpretability and hindering the deployment of industrial testing equipment. Summary of the Invention
[0007] To address the aforementioned technical issues, this application provides an online non-destructive testing method, apparatus, equipment, and storage medium for the chemical components of flue-cured tobacco. This method enables rapid non-destructive testing by simultaneously outputting predicted values of multiple chemical components in a single hyperspectral scan. Furthermore, it utilizes a branch network structure with characteristic wavelength filtering and gradient isolation to resolve the negative transfer and gradient conflict issues in multi-task learning.
[0008] Firstly, this application provides an online non-destructive testing method for the chemical components of flue-cured tobacco, including: Acquire hyperspectral images of flue-cured tobacco samples; The hyperspectral image is processed to obtain the original average spectrum, and the original average spectrum is preprocessed to obtain the preprocessed spectrum. The preprocessed spectrum is subjected to characteristic wavelength screening to obtain key spectral feature vectors; The key spectral feature vectors are input into a pre-trained multi-branch deep neural network, which outputs predicted values of various chemical components in the flue-cured tobacco sample. The multi-branch deep neural network includes a shared feature extraction module and a task output module. The shared feature extraction module is used to extract general spectral features from the key spectral feature vector. The task output module is used to perform specific regression prediction based on the general spectral features. The parameters of each task output module are independent of each other.
[0009] Furthermore, the processing of the hyperspectral image includes: performing dark-white correction, region of interest extraction, and average spectral processing on the hyperspectral image.
[0010] Furthermore, the preprocessing of the original average spectrum includes smoothing, standard normal variable transformation correction, second derivative enhancement, and / or Z-score normalization.
[0011] Furthermore, the step of screening characteristic wavelengths in the preprocessed spectrum includes: iteratively calculating the orthogonal projection residual of the candidate wavelength vector on the selected wavelength subspace, and selecting the wavelength that maximizes the residual norm to add to the selected wavelength set, until a preset number of characteristic wavelengths is reached.
[0012] Furthermore, the step of iteratively calculating the orthogonal projection residual of the candidate wavelength vector onto the selected wavelength subspace includes the following formula: ; in, For candidate wavelength vectors, This is a matrix consisting of the spectral values of all wavelengths in the selected wavelength set across all samples. for The transpose of the matrix, Here is the regularization constant. It is the identity matrix. Candidate wavelength vector The orthogonal projection residual vector on the selected wavelength subspace.
[0013] Furthermore, the chemical components include: total alkaloids, total nitrogen, reducing sugars, total sugars, potassium, chlorine, and starch; the number of task output modules corresponds to each of the chemical components.
[0014] Furthermore, the multi-branch deep neural network also includes an auxiliary task output module for outputting a predicted sugar-alkali ratio, wherein the sugar-alkali ratio is the ratio of total sugar to total alkaloids.
[0015] Secondly, this application also provides an online non-destructive testing device for the chemical components of flue-cured tobacco, applicable to the method described in any of the above-mentioned embodiments, the device comprising: The hyperspectral imaging unit is used to acquire hyperspectral images of flue-cured tobacco samples; A spectral processing unit is used to process the hyperspectral image to obtain the original average spectrum, and to preprocess the original average spectrum to obtain the preprocessed spectrum. The feature filtering unit is used to filter the preprocessed spectrum by feature wavelengths and generate key spectral feature vectors. A multi-branch deep neural network unit is used to receive the key spectral feature vector and output the predicted values of multiple chemical components in the flue-cured tobacco sample. The multi-branch deep neural network module includes a shared feature extraction unit and multiple task output units. The shared feature extraction unit is used to extract general spectral features from the key spectral feature vector. Each task output unit is used to perform specific regression prediction based on the general spectral features, and the parameters of each task output unit are independent of each other.
[0016] Thirdly, this application also provides an electronic device, comprising: a memory for storing a computer program; and a processor for calling and executing the computer program to implement the method described in the first aspect above.
[0017] Fourthly, this application also provides a computer storage medium that stores a program or instructions that cause a computer to perform the method described in the first aspect above.
[0018] The technical solution provided in this application has the following advantages compared with the prior art: The online non-destructive testing method for chemical components of flue-cured tobacco provided in this application obtains the original average spectrum by processing the hyperspectral image and performing preprocessing; and obtains key spectral feature vectors by screening the feature wavelengths of the preprocessed spectrum, thereby reducing spectral redundancy and the risk of model overfitting; by adopting a multi-branch deep neural network including a shared feature extraction module and multiple task output modules, and with the parameters of each task output module being independent of each other, gradient isolation is achieved during backpropagation, solving the problems of negative transfer and gradient conflict in traditional hard parameter shared multi-task networks.
[0019] Meanwhile, the online non-destructive testing method for chemical components of flue-cured tobacco provided in this application embodiment can simultaneously output predicted values of multiple chemical components with just one hyperspectral scan, realizing rapid, online, and non-destructive testing of chemical components of flue-cured tobacco. Attached Figure Description
[0020] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0021] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the accompanying drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, those skilled in the art can obtain other drawings based on these drawings without any creative effort.
[0022] Figure 1 A schematic flowchart of the online non-destructive testing method for chemical components of flue-cured tobacco provided in the embodiments of this application; Figure 2 A schematic diagram of the overall process of the online non-destructive testing method for chemical components of flue-cured tobacco provided in the embodiments of this application; Figure 3 A schematic diagram of the screening characteristic wavelengths provided in an embodiment of this application; Figure 4 This is a schematic diagram of the structure of a multi-branch deep neural network provided in an embodiment of this application; Figure 5 A schematic diagram of the structure of the online non-destructive testing device for the chemical components of flue-cured tobacco provided in the embodiments of this application; Figure 6 This is a schematic diagram of the hardware structure of the electronic device provided in the embodiments of this application. Detailed Implementation
[0023] To better understand the above-mentioned objectives, features, and advantages of this application, the solution of this application will be further described below. It should be noted that, unless otherwise specified, the embodiments and features described in these embodiments can be combined with each other.
[0024] Many specific details are set forth in the following description in order to provide a full understanding of this application, but this application may also be implemented in other ways different from those described herein; obviously, the embodiments in the specification are only some embodiments of this application, and not all embodiments.
[0025] The online non-destructive testing method, apparatus, equipment, and storage medium for the chemical components of flue-cured tobacco provided in this application will be described exemplarily below with reference to the accompanying drawings. Figure 1This is a schematic flowchart of the online non-destructive testing method for the chemical components of flue-cured tobacco provided in the embodiments of this application. Figure 2 This is a schematic diagram of the overall process of the online non-destructive testing method for the chemical components of flue-cured tobacco provided in the embodiments of this application. Figure 3 This is a schematic diagram of the screening characteristic wavelength provided in an embodiment of this application. Figure 4 This is a schematic diagram of the structure of a multi-branch deep neural network provided in an embodiment of this application.
[0026] First refer to Figure 1 and Figure 2 The online non-destructive testing method 100 for the chemical components of flue-cured tobacco includes the following steps: S101. Acquire hyperspectral images of flue-cured tobacco samples.
[0027] Specifically, samples of flue-cured tobacco from different origins, grades, and maturity levels can be collected (e.g., 2454 samples). After removing the midribs from the collected samples, they are cut into leaves of uniform size (e.g., 5cm x 5cm) to ensure that the sample surface is flat and consistent.
[0028] The processed sample is placed on the transport platform of a closed hyperspectral acquisition system. The hyperspectral acquisition system may include: a visible-near-infrared sensor, a short-wave near-infrared sensor, a halogen light source array (symmetrically arranged on both sides of the transport platform to provide stable and uniform illumination), a transport mechanism (used to move the sample through the imaging area at a uniform speed), and acquisition control software.
[0029] Start the acquisition system and set the scanning parameters: the exposure time can be adaptively adjusted according to the sample reflectance, the conveyor belt speed is 5-10 mm / s, and the spectral resolution is 5-10 nm. As the sample moves to the imaging area with the conveyor belt, the hyperspectral camera scans the sample surface line by line, simultaneously acquiring continuous reflectance spectral images of the sample in the visible to short-wave near-infrared bands. Multiple wavelength channels are acquired to obtain the original hyperspectral image.
[0030] S102. Process the hyperspectral image to obtain the original average spectrum, and preprocess the original average spectrum to obtain the preprocessed spectrum.
[0031] Specifically, the original hyperspectral image acquired in step S101 can be processed, for example, by performing dark-white correction to eliminate the effects of dark current and light source inhomogeneity. Then, the region of interest is extracted from the corrected image, and the spectral values of all pixels within the region are arithmetically averaged to obtain the original average spectrum, as shown below: R raw .
[0032] After obtaining the original average spectrum, it can be preprocessed again, for example, by performing smoothing (such as SG filtering), standard normal transformation correction, second derivative enhancement, and normalization. Smoothing suppresses high-frequency random noise, standard normal transformation eliminates baseline drift caused by scattering, second derivative enhancement enhances spectral details and weak absorption peaks, and normalization eliminates dimensional differences. Through these preprocessing steps, the preprocessed spectrum is obtained.
[0033] For example, processing the hyperspectral image may include: performing dark-white correction, region of interest extraction, and average spectral processing on the hyperspectral image.
[0034] Specifically, the original hyperspectral image undergoes dark-to-white correction, and a white reference image is acquired simultaneously. R white and dark reference image R dark Reflectivity correction is performed according to the following formula: ; in, R c The corrected reflectance image is obtained by correcting the dark current, light source inhomogeneity, and instrument response drift to eliminate the effects of dark current, light source inhomogeneity, and instrument response drift on subsequent modeling.
[0035] The corrected hyperspectral image undergoes background segmentation to remove non-smokestonymic leaf areas, midribs, edge shadows, and anomalous noise regions. Preferably, a pseudo-RGB image can be synthesized using characteristic bands and then converted to [the correct image format]. HSV Color space, based on hue H saturation S and brightness V Threshold for obtaining effective tissue mask of tobacco leaves M For the first i The first sample and the first j Wavelength λ j ,like ROI The number of effective pixels is N i Then the average spectrum of the sample can be expressed as: ; in, x ij For the first i The sample in the first j Average spectral value at each wavelength j Average spectral value at each wavelength, N i For the first i The total number of valid pixels in the region of interest for each sample Mi For the first i One sample ROI The boundaries or range, p For each specific pixel traversed within this range, Rc ( p,λ j ) represents the wavelength of pixel p in the corrected image. λ j The reflectance value at point ∑p∈Mi is the summation of all pixels within the region of interest.
[0036] Let the original average spectral matrix be denoted as Where n is the number of samples and m is the number of effective spectral channels. In practical applications, characteristic wavelengths can be optimized first for the entire spectrum, and a specified number of channels can be retained for subsequent fusion analysis.
[0037] Furthermore, the preprocessing of the original average spectrum may include: smoothing the original average spectrum, standard normal variable transformation correction, second derivative enhancement processing, and / or Z-score normalization processing.
[0038] To eliminate the effects of noise, scattering, and dimensional differences, the following preprocessing operations can be performed on the raw average spectrum: (1) Savitzky-Golay (SG Filtering and smoothing: To suppress high-frequency random noise and preserve spectral peak characteristics, smoothing is performed using... SG Filtering is used for smoothing. For example, the sliding window length is set to 15, and the polynomial fitting order is 3. Its calculation form can be expressed as: ; in, x sGij For the smoothed first i The sample in the first j Spectral values at each wavelength C l The convolution coefficients are obtained by fitting local polynomials. x i, j+1 The first in the original spectrum i The sample in the first j+1 Spectral values at each wavelength This is to sum the wavelengths within the window.
[0039] (2) Standard normal variable transformation SNV To eliminate baseline drift effects such as changes in optical path length caused by particle size inhomogeneity and surface scattering, the smoothed spectral samples were centered and scaled. The calculation formula is as follows: ; In the formula, x SNV,ij for go through SNV After transformation i The sample in the first j Spectral values at each wavelength mean ( xSGi ) is the first i The mean of the spectra of each sample. std ( xSGi ) is the first i Standard deviation of the spectrum of each sample ε A minimal constant introduced to prevent the denominator from being zero.
[0040] (3) Second derivative enhancement processing: After completing SG filtering smoothing and standard normal variable transformation ( SNV Building upon this, second-derivative (SD) processing can be further employed to enhance spectral detail. Second-derivative preprocessing enhances spectral curvature and weak absorption peak information. The resulting negative value is the normal mathematical result of the derivative spectrum; this method does not truncate or take its absolute value, but directly uses it in subsequent standardization, feature selection, and neural network modeling. SG Derivative filtering is implemented efficiently, and its second derivative calculation formula is as follows: ; In the formula, x SDij After processing the second derivative, the th i The sample in the first j Spectral values at each wavelength x SNV (λ) is the spectral function after SNV transformation, where λ is the wavelength. j This is the j-th wavelength point.
[0041] This step effectively reduces broad background and residual baseline drift, and significantly highlights overlapping absorption peaks.
[0042] From the perspective of the physicochemical mechanism of material response, the second derivative treatment has a differentiated enhancement effect on different types of components: on the one hand, for organic components containing overtone and combination frequency absorption information of CH, OH, and NH bonds, such as sugars, starches, and nitrogen-containing compounds, the second derivative can significantly improve the distinguishability of weak absorption peaks; on the other hand, for inorganic ions such as potassium and chlorine that do not have direct absorption peaks in the near-infrared region, the second derivative helps to keenly capture indirect spectral variations caused by changes in hydrated ion state, changes in the cellular microenvironment, and perturbations of the organic skeleton, thereby ensuring that this key information can be effectively captured by subsequent prediction models.
[0043] (4) Z-score standardization: To eliminate the influence of differences in the dimensions of different variables and to make the spectral features and chemical labels comparable in numerical scale, Z-score standardization was performed on the input feature matrix X and the chemical label matrix Y in this embodiment. Specifically, the mean and standard deviation σ of each dimension were calculated only based on the training set samples. Xj The standardized model input is obtained using the following formula: ; in, z ij For the standardized first i The sample in the first j Spectral values at each wavelength x ij For the first i The sample in the first j Average spectral value at each wavelength, μ Xj For the first j The mean of all samples at each wavelength. σ Xj For the first j The standard deviation of all samples at each wavelength.
[0044] Similarly, for the t-th chemical component label, calculate its mean. μ Yt and standard deviation σ Yt The standardized label is obtained using the following formula: ; in, Let be the standardized label value of the i-th sample for the t-th chemical component. y it The first in the original chemical label i The sample in the first t Measured values of various chemical components μ Yt For the first t The mean of the chemical components in all samples, σ Yt For the first t The standard deviation of a chemical component across all samples.
[0045] S103. The preprocessed spectrum is subjected to characteristic wavelength screening to obtain key spectral feature vectors.
[0046] Specifically, in this step, the Successive Projections Algorithm (SPA) can be used to screen the characteristic wavelengths of the preprocessed spectrum, selecting a subset of characteristic wavelengths with low collinearity and high representativeness from the entire band.
[0047] SPA is a forward feature selection method that selects the wavelength combination with the least redundancy and the most information by analyzing the projection relationship between wavelengths.
[0048] In some embodiments, the step of screening characteristic wavelengths in the preprocessed spectrum includes: iteratively calculating the orthogonal projection residual of the candidate wavelength vector on the selected wavelength subspace, and selecting the wavelength that maximizes the residual norm to add to the selected wavelength set, until a preset number of characteristic wavelengths is reached.
[0049] Specifically, the orthogonal projection residuals of candidate wavelengths onto the selected wavelength subspace are calculated iteratively. Each time, the wavelength with the largest residual is added to the set until the preset number of wavelengths is reached. Through SPA (Spectral Spatial Analysis) filtering, the original 445 wavelength channels can be compressed into 80 feature wavelengths, forming a key spectral feature vector. This step reduces collinearity among variables and the dimensionality of the model input, suppressing the risk of overfitting under small sample conditions.
[0050] For example, SPA uses wavelengths with larger projection norms as the initial starting point, and denoted as SS for the selected wavelength set. In the k-th iteration, the candidate wavelength vectors are... x j Calculate its orthogonal projection residuals on the selected subspace, including the following formula: ; in, For candidate wavelength vectors, This is a matrix consisting of the spectral values of all wavelengths in the selected wavelength set across all samples. for The transpose of the matrix, Here is the regularization constant. It is the identity matrix. Candidate wavelength vector The orthogonal projection residual vector on the selected wavelength subspace.
[0051] Simultaneously select a residual norm that makes the residual norm The largest wavelength is added to set S. This process is repeated until the preset number of characteristic wavelengths is reached.
[0052] SPA can compress the original high-dimensional fusion spectrum to a low number of representative wavelengths; or perform SPA screening for each target component and then take the union to achieve joint extraction of multi-component features. Figure 3 This is a schematic diagram illustrating the screening characteristic wavelengths provided in an embodiment of this application. (See diagram below.) Figure 3 As shown, after SPA iterative screening, 80 characteristic wavelengths were finally selected from the original 445 full-band wavelength channels (marked with asterisks in the figure). From Figure 3 As can be seen, the selected characteristic wavelengths are discretely distributed in the range of 400-2500nm, mainly concentrated in the band regions with clear chemical responses, such as 400-800nm, 900-1100nm, 1100-1350nm, 1350-1500nm and 1500-1700nm. These correspond to the indirect spectral responses of components such as flue-cured tobacco color and pigment information, overtone and combination frequency absorption of CH, OH and NH groups, sugar and starch content, moisture and nitrogen-containing compounds, and plant alkaloids. Unselected wavelengths (spectral curves represented by solid lines in the figure) are eliminated, thus achieving effective dimensionality reduction and feature optimization of spectral data.
[0053] S104. Input the key spectral feature vector into a pre-trained multi-branch deep neural network and output the predicted values of various chemical components in the flue-cured tobacco sample. The multi-branch deep neural network includes a shared feature extraction module and a task output module. The shared feature extraction module is used to extract general spectral features from the key spectral feature vector. The task output module is used to perform specific regression prediction based on the general spectral features. The parameters of each task output module are independent of each other.
[0054] Specifically, the key spectral feature vectors obtained in step S103 are input into a pre-trained multi-branch deep neural network ( Branch-DNN The multi-branch deep neural network of this application includes a shared base and a task output module. Figure 4 This is a schematic diagram of the structure of a multi-branch deep neural network provided in an embodiment of this application. (Refer to...) Figure 4 The shared base can be constructed by stacking two fully connected layers, Linear(80,512) and Linear(512,256), with each layer followed by BatchNorm1d, GELU activation function, and Dropout(0.5) to extract general spectral features from the input 80-dimensional key spectral feature vector. Multiple task output modules are set up in parallel, corresponding to seven main tasks (total alkaloids, total nitrogen, reducing sugar, total sugar, potassium, chlorine, and starch) and an auxiliary task (sugar-alkaloid ratio). The structure of each module is as follows: Linear (256,128)→ BatchNorm1d → GELU → Dropout→ Linear (128,1), the parameters of each module are independent of each other; during the backpropagation process, the shared base receives the joint gradient of the loss functions of all tasks to extract common information, and each task output module only receives the local gradient of its own corresponding loss function to avoid gradient conflict, thereby achieving gradient isolation and effectively solving the negative transfer problem in traditional hard parameter shared multi-task networks.
[0055] For example, the chemical components may include: total alkaloids, total nitrogen, reducing sugars, total sugars, potassium, chlorine, and starch; the number of task output modules corresponds to each of the chemical components.
[0056] Specifically, each task output module is responsible for predicting the content of one chemical component. The parameters of each module are independent and do not interfere with each other, so that each task output module can perform dedicated learning and fine-tuning for the spectral response characteristics of its corresponding chemical component. This avoids negative migration and gradient conflicts caused by differences in response mechanisms between different chemical components, thereby improving the balance of prediction accuracy for each chemical component.
[0057] In some embodiments, the multi-branch deep neural network may further include: an auxiliary task output module for outputting a predicted sugar-alkali ratio, wherein the sugar-alkali ratio is the ratio of total sugar to total alkali.
[0058] Specifically, the multi-branch deep neural network may further include an auxiliary task output module for outputting the predicted sugar-alkali ratio, which is the ratio of total sugar to total alkaloids. The auxiliary task output module is configured in parallel with the seven main task output modules, sharing the same network structure (Linear(256,128)→BatchNorm1d→GELU→Dropout→Linear(128,1)). Its input is the common spectral features extracted from a shared base, and its output is the predicted sugar-alkali ratio. During the training phase, the loss function of the auxiliary task for the sugar-alkali ratio is jointly optimized with the loss functions of the seven main tasks using a weighted average. This allows the network to learn the stoichiometric constraints between total sugar and total alkaloids while simultaneously learning the predictions of each chemical component. This auxiliary supervision mechanism enhances the model's ability to perceive the intrinsic relationship between sugars and nitrogen-containing compounds, thereby improving the stability and accuracy of the predictions for total sugar and total alkaloids.
[0059] For example, let the input vector after SPA filtering be... , d To filter the number of wavelengths. A network sharing base can be represented as... This is used to learn the nonlinear spectral manifold common to seven chemical components and the sugar-base ratio. Specifically, the multi-branch deep neural network structure may include: Linear (d,512) BatchNorm1d (512) GELU , Dropout , Linear (512,256) BatchNorm1d (256) GELU , Dropout In lightweight deployment, it can also be adopted. Linea r(d,256) and Linear Shared dock (256,128). BatchNorm1d Used to stabilize mini-batch training distributions. GELU Used to provide smooth nonlinear mapping, Dropout and weight decay together suppress small-sample overfitting.
[0060] Shared features h Input seven parallel task headers respectively F t (h;θ t ) Each task header corresponds to a chemical component, plus an auxiliary task header for the sugar-base ratio. The output format is: ; in, For the first t Predicted values of various chemical components, F t For the mapping function of the output module of the t-th task, For the first t Each task header has its own unique weight parameters, and these parameters are completely independent of each other, with no parameter sharing.
[0061] Each task head can include Linear(256,128), BatchNorm1d(128), GELU, Dropout, and Linear(128,1), with lightweight versions using Linear(128,64) and Linear(64,1). The eight task heads correspond to total alkaloids, total nitrogen, reducing sugars, total sugars, potassium, chlorine, starch, and sugar-alkaloid ratio, respectively. Compared to traditional hard-parameter-shared DNNs, this structure only shares a general spectral representation at the bottom layer, while the top-level parameters are independent of each other, allowing for dedicated fine-tuning of tasks with different response mechanisms, such as sugars, nitrogenous compounds, inorganic salts, and starch.
[0062] The optimization objective of this branch structure is composed of the multi-task reconstruction error and the regularization term. The total loss function... L An equal-weight strategy can be used to jointly optimize the seven independent tasks, and its mathematical expression is as follows: ; in, These are the weighting coefficients. To sum over seven independent tasks, and Let be the actual physicochemical value and the network predicted value of the i-th sample for the t-th chemical component, respectively. This is the weight decay regularization term, used to constrain the complexity of the entire network parameter space and further suppress the risk of overfitting under small sample conditions.
[0063] Among them, the t The mean square error of each task ( Mean Squared Error (MSE) ) can be defined as: ; In the formula, n This represents the number of samples in a mini-batch.
[0064] The auxiliary loss function for consistency of the sugar-base ratio can be expressed as: ; in, The sugar-base ratio is the auxiliary loss function value. MSE Let be the mean square error function. To predict total sugar, To predict total alkaloids, S For true total sugar, A This represents the true total plant alkaloids. A regularization constant used to prevent division by zero anomalies.
[0065] During the backpropagation phase, this topology achieves physical gradient isolation. Shared base parameters. Receive the joint gradient of all task loss propagation ( ), thereby fully extracting the nonlinear spectral manifold shared by multiple components; and the t-th task header parameter Only local gradients of the corresponding chemical components are received. This mechanism, while utilizing common information, effectively blocks gradient conflicts between different response mechanisms (such as strongly absorbed sugars and weakly responsive inorganic salts), thus mitigating the negative migration effect.
[0066] During the training phase, the network described above can be implemented using PyTorch, with the Adam optimizer used to update the parameters. The initial learning rate is preferably 5×10⁻⁶. -4 The preferred weight decay is 1×10. -3 Cosine annealing learning rate scheduling is used to gradually reduce the learning rate to 10. -6Batch size can be set to 16 or 32, and the number of training rounds can be set to 500 to 1500. An early stopping strategy can be used to save the model weights with the optimal training loss. To avoid sample leakage from different parts of the same tobacco leaf, a stratified training / testing partitioning method by year or leaf number can be adopted. Evaluation metrics include RMSE, MAE, and coefficient of determination R. 2 RPD and the industrially acceptable prediction ratio under different relative error thresholds.
[0067] After training, the optimal model weights, standardized parameters, SPA characteristic wavelength index, predicted values, true values, absolute error, relative error, and scatter plot are saved. In practical applications, the tobacco sample only needs to undergo one hyperspectral scan to generate model input following the same process of dark white correction, ROI averaging, preprocessing, SPA wavelength selection, and standardization. Branch-DNN The system simultaneously outputs the content of seven chemical components. This process can be deployed in scenarios such as tobacco leaf purchasing and grading, re-drying processing, formula quality control, and rapid laboratory screening, and can also be transferred to other non-destructive testing tasks for multiple components of agricultural products.
[0068] The online non-destructive testing method for flue-cured tobacco chemical components provided in this application is illustrated below using specific experimental data. Table 1 compares the prediction accuracy of the original Branch-DNN and the Branch-DNN with sugar-alkali ratio-assisted supervision within different relative error ranges for total alkaloids; Tables 2 and 3 compare the performance of the Branch-DNN with sugar-alkali ratio-assisted supervision and the PLSR model.
[0069] Table 1:
[0070] Table 2:
[0071] Table 3:
[0072] The comparative experimental data above show that Branch-DNN with sugar-alkali ratio-assisted supervision outperforms the original Branch-DNN and the classic PLSR model in terms of prediction accuracy of total alkaloids and overall prediction performance of each chemical component, thus verifying the effectiveness of the online non-destructive detection method for flue-cured tobacco chemical components provided in the embodiments of this application.
[0073] In summary, the online non-destructive testing method for chemical components of flue-cured tobacco provided in this application reduces spectral redundancy and model overfitting by processing the hyperspectral image to obtain the original average spectrum and performing preprocessing; and by selecting key spectral feature vectors from the preprocessed spectrum using feature wavelengths. By employing a multi-branch deep neural network including a shared feature extraction module and multiple task output modules, with the parameters of each task output module being independent, gradient isolation is achieved during backpropagation, solving the problems of negative transfer and gradient conflict in traditional hard parameter shared multi-task networks.
[0074] Meanwhile, the online non-destructive testing method for chemical components of flue-cured tobacco provided in this application embodiment can simultaneously output predicted values of multiple chemical components with just one hyperspectral scan, realizing rapid, online, and non-destructive testing of chemical components of flue-cured tobacco.
[0075] Based on the same inventive concept, this application also provides an online non-destructive testing device 200 for the chemical components of flue-cured tobacco. Figure 5 This is a schematic diagram of the online non-destructive testing device for the chemical components of flue-cured tobacco provided in an embodiment of this application. Figure 5 As shown, the device includes 200 comprising: The hyperspectral imaging unit 201 is used to acquire hyperspectral images of flue-cured tobacco samples; The spectral processing unit 202 is used to process the hyperspectral image to obtain the original average spectrum, and to preprocess the original average spectrum to obtain the preprocessed spectrum. The feature filtering unit 203 is used to filter the preprocessed spectrum by feature wavelengths and generate key spectral feature vectors. A multi-branch deep neural network unit 204 is used to receive the key spectral feature vector and output the predicted values of multiple chemical components in the flue-cured tobacco sample. The multi-branch deep neural network module includes a shared feature extraction unit and multiple task output units. The shared feature extraction unit is used to extract general spectral features from the key spectral feature vector. Each task output unit is used to perform specific regression prediction based on the general spectral features, and the parameters of each task output unit are independent of each other.
[0076] The online non-destructive testing device for flue-cured tobacco chemical components provided in the above embodiments can perform the online non-destructive testing methods for flue-cured tobacco chemical components provided in the above embodiments, and has the same or corresponding beneficial effects, which will not be described in detail here.
[0077] This application also provides an electronic device, such as a terminal or a server. The server can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms. The terminal can be a smartphone, tablet computer, laptop computer, desktop computer, etc., but is not limited to these.
[0078] Example diagrams of the hardware structure block diagrams of the electronic devices provided in this application are shown below. Figure 6 As shown, it may include: Processor 1, communication interface 2, memory 3, and communication bus 4; The processor 1, communication interface 2, and memory 3 communicate with each other via communication bus 4. Optionally, communication interface 2 can be an interface of a communication module, such as the interface of a GSM module; Processor 1 may be a central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of this application.
[0079] The memory 3 may include high-speed RAM, and may also include non-volatile memory, such as at least one disk storage device. Specifically, the processor 1 is used to execute the computer program stored in the memory 3 to perform the online non-destructive testing method for the chemical components of flue-cured tobacco described in any of the above embodiments.
[0080] This application also provides a computer storage medium storing a computer program. When executed by a processor, the computer program can implement the online non-destructive testing method for the chemical components of flue-cured tobacco described in any of the embodiments above. It should be understood that in this embodiment, the computer storage medium can be located at at least one of multiple network servers in a computer network. Optionally, in this embodiment, the storage medium can include, but is not limited to, various media capable of storing program code, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard drive, magnetic disk, or optical disk. It should be noted that the order of the embodiments described above is merely descriptive and does not represent the superiority or inferiority of the embodiments.
[0081] In the description of this specification, references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this application. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of those different embodiments or examples.
[0082] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this application, "a plurality of" means two or more, unless otherwise explicitly specified.
[0083] In this application, unless otherwise stated, directional terms such as "up" and "down" are generally used in relation to the direction shown in the accompanying drawings, or in relation to the vertical, perpendicular, or gravitational direction; similarly, for ease of understanding and description, "left" and "right" are generally used in relation to the left and right shown in the accompanying drawings; "inner" and "outer" refer to the inner and outer contours of each component itself, but the above directional terms are not intended to limit this application.
[0084] The above description is merely an exemplary embodiment of this application, but the scope of protection of this application is not limited thereto. Any person skilled in the art can easily conceive of various variations or substitutions within the technical scope described in this application, and these should all be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A method for online non-destructive testing of chemical components in flue-cured tobacco, characterized in that, include: Acquire hyperspectral images of flue-cured tobacco samples; The hyperspectral image is processed to obtain the original average spectrum, and the original average spectrum is preprocessed to obtain the preprocessed spectrum. The preprocessed spectrum is subjected to characteristic wavelength screening to obtain key spectral feature vectors; The key spectral feature vectors are input into a pre-trained multi-branch deep neural network, which outputs predicted values of various chemical components in the flue-cured tobacco sample. The multi-branch deep neural network includes a shared feature extraction module and a task output module. The shared feature extraction module is used to extract general spectral features from the key spectral feature vector. The task output module is used to perform specific regression prediction based on the general spectral features. The parameters of each task output module are independent of each other.
2. The method according to claim 1, characterized in that, The processing of the hyperspectral image includes: The hyperspectral image is subjected to darkening correction, region of interest extraction, and average spectral processing.
3. The method according to claim 1, characterized in that, The preprocessing of the original average spectrum includes: The original average spectrum is smoothed, corrected by standard normal variable transformation, enhanced by second derivative, and / or normalized by Z-score.
4. The method according to claim 1, characterized in that, The step of screening the preprocessed spectrum for characteristic wavelengths includes: The orthogonal projection residuals of candidate wavelength vectors onto the selected wavelength subspace are calculated iteratively, and the wavelengths that maximize the residual norm are added to the selected wavelength set until the preset number of characteristic wavelengths is reached.
5. The method according to claim 4, characterized in that, The step of iteratively calculating the orthogonal projection residual of the candidate wavelength vector onto the selected wavelength subspace includes the following formula: ; in, For candidate wavelength vectors, This is a matrix consisting of the spectral values of all wavelengths in the selected wavelength set across all samples. for The transpose of the matrix, Here is the regularization constant. It is the identity matrix. Candidate wavelength vector The orthogonal projection residual vector on the selected wavelength subspace.
6. The method according to claim 1, characterized in that, The chemical components include: total alkaloids, total nitrogen, reducing sugars, total sugars, potassium, chlorine, and starch; the number of task output modules corresponds to each of the chemical components.
7. The method according to claim 1, characterized in that, The multi-branch deep neural network also includes: An auxiliary task output module is used to output the predicted sugar-alkali ratio, which is the ratio of total sugar to total alkali.
8. An online non-destructive testing device for the chemical components of flue-cured tobacco, applicable to the method of any one of claims 1 to 7, the device comprising: The hyperspectral imaging unit is used to acquire hyperspectral images of flue-cured tobacco samples; A spectral processing unit is used to process the hyperspectral image to obtain the original average spectrum, and to preprocess the original average spectrum to obtain the preprocessed spectrum. The feature filtering unit is used to filter the preprocessed spectrum by feature wavelengths and generate key spectral feature vectors. A multi-branch deep neural network unit is used to receive the key spectral feature vector and output the predicted values of multiple chemical components in the flue-cured tobacco sample. The multi-branch deep neural network module includes a shared feature extraction unit and multiple task output units. The shared feature extraction unit is used to extract general spectral features from the key spectral feature vector. Each task output unit is used to perform specific regression prediction based on the general spectral features, and the parameters of each task output unit are independent of each other.
9. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor for invoking and executing the computer program to implement the method as described in any one of claims 1 to 7.
10. A computer storage medium, characterized in that, The computer storage medium stores a program or instructions that cause the computer to perform the method as described in any one of claims 1 to 7.
