Non-optical activity water quality parameter inversion method based on hyperspectral image
Through the combination of machine learning feature engineering and deep learning models, the high-dimensional nonlinear feature extraction of hyperspectral data and generalization ability in small sample scenarios are solved, and high-precision non-optical active water quality parameter inversion and pollution source positioning are achieved, improving the efficiency and accuracy of water quality monitoring.
Patent Information
- Application Number
- CN202510779248.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-12
- Publication Date
- 2025-07-11
- Estimated Expiration
- 2045-06-12
AI Technical Summary
The prior art is difficult to effectively capture the high-dimensional nonlinear features of hyperspectral data of non-optical active water quality parameters, and the generalization ability of deep learning models in small sample scenarios is weak, resulting in high inversion errors in low concentration intervals, and it is impossible to realize the sub-cell positioning of pollution sources and the dynamic analysis of pollution diffusion paths.
Using machine learning feature engineering module, DM-ViT training module and visual inversion module, through random forest, XGBoost and PCA feature extraction, combined with DM data augmentation and ViT feature extraction, an empty spectrum collaborative feature extraction network is constructed, a diffusion model and dynamic weighted loss function are designed, and dynamic optimization decoding of multimodal features is realized.
The inversion accuracy of non-optical active water quality parameters is improved, and the sub-cell spatial distribution prediction of total nitrogen and total phosphorus concentrations is realized, which improves the model's sensitivity and generalization ability to low-concentration parameters, and provides high-precision dynamic monitoring of water pollution.
Smart Images

Figure CN120293873A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical fields of machine learning algorithms and computer vision, and particularly relates to a method for retrieving non - optically active water quality parameters based on hyperspectral images. Background Technique
[0002] The hyperspectral inversion of non - optically active water quality parameters is to retrieve the concentration spatial distribution of non - optically active parameters such as total nitrogen (TN) and total phosphorus (TP) in water bodies through the continuous spectral information of hyperspectral remote sensing images, combined with deep learning techniques. This technology models through the mapping relationship between spectral features and water quality parameters, providing large - scale and high - frequency dynamic monitoring capabilities for agricultural engineering and water quality monitoring, and has important application values in agricultural production, environmental supervision and ecological protection. Traditional water quality monitoring methods rely on laboratory analysis of discrete sampling points and are difficult to capture the spatial heterogeneity of pollution diffusion. Hyperspectral inversion technology, through spatio - spectral fusion and data - driven modeling, has achieved the leap from point - like monitoring to area - like prediction.
[0003] The main challenges in the inversion of non - optically active water quality parameters lie in the extraction of high - dimensional non - linear features of hyperspectral data and the sensitive modeling of low - concentration parameters. Existing methods mainly have two limitations: First, traditional empirical models have insufficient utilization of spectral features and are difficult to capture cross - band non - linear correlations; Second, the generalization ability of a single deep learning model in small - sample scenarios is weak, resulting in high inversion errors in low - concentration intervals. In addition, traditional point - like monitoring methods are limited by spatial resolution, unable to achieve sub - pixel - level positioning of pollution sources, and difficult to analyze the dynamic evolution of pollution diffusion paths. Therefore, how to design a spatio - spectral collaborative feature extraction network, construct a data augmentation method that conforms to physical mechanisms, and achieve dynamic optimization decoding of multi - modal features, and then ultimately improve the inversion accuracy has become the key task of non - optically active water quality parameters. Summary of the Invention
[0004] Aiming at the existing technical defects in the background technique, the present invention proposes a method for retrieving non - optically active water quality parameters based on hyperspectral images, which specifically includes the following steps: In the first aspect, the present invention provides a method for retrieving non - optically active water quality parameters based on hyperspectral images, including: Step S1, collecting hyperspectral images and a dataset of synchronously measured water quality parameters; Step S2, constructing an inversion model for non - optically active water quality parameters based on hyperspectral images to implement the method for retrieving non - optically active water quality parameters. The model includes: a machine learning feature engineering module, a DM - ViT training module, and a visualization inversion module; the specific inversion process is as follows: Step S21, generating a principal component projection vector using the machine learning feature engineering module , and the process is as follows: Step S211: Use the random forest feature selection module to extract features from the input hyperspectral image and output a band-sensitive subset. ; Step S212: Use the XGBoost feature importance analysis module to calculate the gain weights for and output a weighted importance sequence. ; Step S213: Use the PCA feature dimensionality reduction module to perform orthogonalization on and generate a principal component projection vector. ; Step S22: Use the DM-ViT training module to output the water quality parameter inversion result. , and the process is as follows: Step S221: Use the DM data augmentation module to generate multi-scale augmented spectral features from the original input samples and generate a spectral feature augmented training set. ; Step S222: Use the ViT feature extraction module to extract features, perform feature mapping, and perform global average pooling on the spectral feature augmented training set, and output the water quality parameter inversion result. ; Step S23: Use the visualization inversion module to process the water quality parameter inversion result and output the spatial distribution maps of nitrogen and phosphorus concentrations in the target water area. ; Step S3: Input the samples in the dataset into the water quality parameter inversion model, calculate the total loss function value, perform backpropagation, and optimize the model weights through the AdamW optimizer and the dynamic learning rate strategy. After training for multiple rounds, obtain the final water quality parameter inversion model. Step S4: Based on the trained water quality parameter inversion model, input the hyperspectral image to be processed and output the spatial distribution maps of nitrogen and phosphorus concentrations in the target water area.
[0005] Preferably, in step S211, the specific process of the random forest feature selection module outputting the band-sensitive subset is as follows: Step Sa1: Reconstruct the original hyperspectral image data matrix into a spatial-spectral joint feature tensor , and generate an input feature matrix through window mean sampling and normalization processing , , and the formula is as follows:
[0006]
[0007]
[0008] Among them, is a function used to perform dimensional reconstruction on the original hyperspectral image data matrix ; is the window mean sampling operation, which is used to calculate the mean value of each band for the reconstructed is the standardization processing operation, is the mean value of each band, is the standard deviation of each band; Step Sa2, construct a random forest regression model containing 100 decision trees, and calculate the band weights through the feature importance ranking function as follows:
[0009] Among them, is the feature importance score of band b, which is the band weight, is the total number of decision trees. Here = 100, is the true value, is the predicted value of the th tree, is the predicted value after permutation of band b, is the mean square error between the predicted value and the true value; Step Sa3, select the band indices arranged in descending order of feature importance scores to generate a band sensitive subset , satisfying the following formula:
[0010]
[0011] Among them, is the sorting function, which sorts and returns the sorted index values. is the feature index arranged in descending order of importance, which is used to organize the band numbers, is the band.
[0012] Preferably, in the step S212, the specific process of the XGBoost feature importance analysis module outputting the weighted importance sequence is as follows: Step Sb1, perform standardization processing on the input band sensitive subset to generate a normalized feature matrix with zero mean and unit variance, and the calculation formula is:
[0013] Among them, is a subset of sensitive wavelength bands, is the mean of the subset of sensitive wavelength bands, is the standard deviation of the subset of sensitive wavelength bands; Step Sb2, construct an XGBoost regression model, which uses an objective function with regularization terms The defined formula is:
[0014] Among them, is the L1 regularization term, = 0.1 is the L1 regularization coefficient, is the L2 regularization term, = 1.0 is the L2 regularization coefficient, n = 100 represents the number of samples, is the true value of the th sample, is the predicted value of the th sample; Step Sb3, calculate the feature gain weight vector The formula for the feature gain weight of its k-th dimensional component is:
[0015] Among them, is the feature weight based on information gain of the th, is the total number of decision trees, is the index of the decision tree, and its value range is from 1 to , is the information gain brought by the wavelength band in the th tree, is the index of the feature, and its value range is from 1 to , is the information gain brought by the th feature in the th tree; Step Sb4, generate a weighted importance sequence whose elements are arranged in descending order according to and satisfy the following formula:
[0016] Among them, is the original wavelength band number, is the feature index.
[0017] Preferably, in the step S213, the specific process of the PCA feature dimensionality reduction module generating the principal component projection vector is as follows: Step Sc1, process the input weighted importance sequence to obtain an empty spectral fusion feature matrix , then perform normalization and covariance matrix decomposition to obtain the eigenvalue decomposition result, which is the eigenvalue and eigenvector of matrix . Select the corresponding eigenvectors from the eigenvalue decomposition result to generate a principal component basis vector matrix , satisfying the following formula:
[0018]
[0019] where, is the transpose of matrix, is the covariance matrix, is the normalized empty spectral fusion feature matrix, is the number of principal components with cumulative variance ≥ 99%, is to perform eigenvalue decomposition operation on the covariance matrix to obtain the eigenvalue decomposition result, is the principal component basis vector matrix; Step Sc2, calculate the band weight tensor of each principal component, and screen the top 30 sensitive bands of each principal component through absolute value sorting. The specific formula is as follows:
[0020] where, is the principal component basis vector matrix, is the th principal component in the principal component basis vector matrix corresponding to the th band, is the sorting function, for the th principal component, obtain the indices sorted from largest to smallest by weight absolute value through the function, and then take the top 30 indices. The bands corresponding to these indices are the sensitive bands under this principal component; Step Sc3, generate a principal component projection vector
[0021] where, is to take the th index value in the set, is the index variable, is the main component projection vector element in
[0022] Preferably, in step S221, the DM data enhancement module generates a spectral feature enhanced training set The process is as follows: Step Sd1, initialize the diffusion noise scheduling parameter, define the total diffusion time step = 1000, generate a linear noise scheduling sequence The specific formula is as follows:
[0023] In the formula is a function used to generate a specified -4 number of linearly equally spaced numerical sequences between the two endpoint values specified from 10 to 0.02; And calculate the cumulative attenuation coefficient The specific formula is as follows:
[0024] Among them, is the result of multiplying from time step 1 to time step continuously; Step Sd2, construct a U-Net type diffusion model with time embedding, the model input is the spectral feature vector and the time step , output the noise prediction vector , where the time embedding layer generates a time encoding vector with a dimension of 256; Step Sd3, perform forward diffusion noise addition training, inject the noise with a random time step into the original spectral sample to generate a noisy spectral feature The specific formula is as follows:
[0025] And minimize the predicted noise error as the goal, and use the AdamW optimizer for model training. The specific formula is as follows:
[0026] Among them, is the original spectral sample, is the injected noise, is the predicted noise model, is the time step; Step Sd4, from Gaussian noise Start from this and generate reverse diffusion samples through reverse iterative calculation. The specific formula is as follows:
[0027] Among them, is the initial noise-added spectral feature, is the random perturbation term, is the set of generated enhanced spectral feature vectors, is the spectral feature obtained through reverse iterative calculation; Step Sd5: Weightedly fuse the original training set and the enhanced sample set to form the spectral feature enhanced training set , and the specific formula is as follows:
[0028] Among them, =0.3 is the enhancement factor, = is the set of generated enhanced spectral feature vectors.
[0029] Preferably, in the step S222, the process of the ViT feature extraction module outputting the water quality parameter inversion result is as follows: Step Se1: Reconstruct the input spectral feature vector into a three-dimensional tensor , where is the spatial window size, is the number of spectral bands; Step Se2: Construct a network structure containing a dual Transformer encoder, and each layer of the encoder executes the following formula;
[0030]
[0031]
[0032]
[0033]
[0034]
[0035] Among them, is the encoder layer index, is the output of the previous layer of the encoder, is the layer normalization operation, is the output of the previous layer Perform layer normalization operation, is the multi-head attention mechanism, is to as the input, and the value calculated through the multi-head attention mechanism, is to randomly set the output of some neurons to 0 to prevent overfitting, is to apply the Dropout operation, and then combine it with the result after residual connection, is to the result of performing layer normalization operation again, is the activation function, is the fully connected layer, is to first apply the activation function, and then the value calculated through the fully connected layer, is to apply operation, and then combine it with the result after residual connection as the output of the current encoder; Step Se3, design a dynamic weighted loss function, construct a piecewise weighted mean square error loss function , and its expression is:
[0036] In the formula is the number of training samples, is the true value of the th sample, is the th sample's predicted value, is the weight function, is the mean square error, regularization coefficient = 0.01, is the weight matrix the square of the L2 norm; Among them, the weight function satisfies the following formula:
[0037] Among them, is the water quality parameter concentration, regularization coefficient = 0.01; Step Se4, adopt an adaptive learning rate training strategy, initialize the learning rate with the Nadam optimizer = 0.001, and define the learning rate dynamic decay rule: when the validation loss has not improved for 10 epochs, the learning rate is updated to = 0.1 , the minimum learning rate is limited to = 0.0001; Step Se5, multi-scale feature fusion prediction. Perform global average pooling on the encoder output, and after mapping through Dropout and the fully connected layer, output the inversion result of the total nitrogen concentration .
[0038] Preferably, in the step S23, the visualization inversion module outputs the spatial distribution maps of nitrogen and phosphorus concentrations in the target water area The process is as follows: Step Sf1, generate a hyperspectral image dynamic mask, read the input hyperspectral image , and construct a dynamic mask matrix based on the band threshold condition , satisfying the following formula:
[0039] Among them, = 270 is the number of spectral bands, is the spatial coordinate index, is the row index of the spatial coordinate, is the column index of the spatial coordinate; Step Sf2, pixel-level normalization and prediction: For the pixel points satisfying = 1, extract the spectral vector , and then normalize it through the pre-trained MinMaxScaler normalizer. The formula is as follows:
[0040] In the formula is the spectral vector processed by the MinMaxScaler normalizer, is the pre-trained MinMaxScaler normalizer object, is the normalization conversion function of the MinMaxScaler normalizer, is the original spectral vector transpose; and input it into the ViT inversion model to predict the nitrogen and phosphorus concentration values , the formula is as follows:
[0041] Step Sf3, reconstruct the spatial distribution map, map the prediction result to the original image spatial dimension, and generate a concentration matrix , the rule is:
[0042] In the formula Indicates that concentration prediction is not performed at this location or there is no valid data; Step Sf4, update the output parameters according to the input image metadata meta, and write to the single-band raster file , and use the row-column traversal algorithm to fill in the predicted values pixel by pixel to generate the spatial distribution maps of nitrogen and phosphorus concentrations in the target water area ; Step Sf5, distributed storage management: construct a hierarchical output directory structure, and use the recursive directory creation function based on the input file path to ensure data storage integrity, and output the spatial distribution maps of nitrogen and phosphorus concentrations in the target water area .
[0043] Preferably, in the above step S3, the process of calculating the total loss function value L of the model is as follows: In the regression prediction stage of the ViT feature extraction module, the weighted mean square error of the full sample and the regularization loss are jointly optimized, and its total loss is calculated as follows:
[0044] Among them, is the concentration-sensitive weight function, and the defined regular formula is:
[0045] In the formula = 0.01 is the regularization strength coefficient, which acts on the sum of the squares of the L2 norms of all the trainable parameter sets of the model , is the number of samples in the training batch, and are respectively the true concentration value and the model predicted value of the th sample.
[0046] In a second aspect, the present invention proposes a computer-readable storage medium storing a computer program, characterized in that when the computer program is executed by a processor, it implements the above-mentioned method for inverting non-optical active water quality parameters based on hyperspectral images.
[0047] Compared with the prior art, the present invention proposes a method for inverting non-optical active water quality parameters based on hyperspectral images, and the present invention has the following beneficial effects: Compared with the prior art, the present invention proposes a method for retrieving non-optical active water quality parameters based on hyperspectral images. This method generates robust spectral features through diffusion-enhanced spatio-spectral joint coding, and realizes high-precision parameter retrieval based on the ViT collaborative decoding architecture. At the same time, a concentration-sensitive weighted learning mechanism is introduced to improve the sensitivity and generalization ability of the model to low-concentration parameters. Specifically, first, a diffusion model based on U-Net and a time embedding mechanism are designed. Through forward diffusion noise injection and reverse denoising, enhanced samples that conform to spectral physical laws are generated, and a spatio-spectral joint feature space is constructed to solve the problems of insufficient spectral feature diversity and distribution deviation in small-sample scenarios. At the same time, a Transformer encoder and a global pooling decoding module are developed. The multi-head self-attention mechanism is used to extract cross-band spectral correlation features, and combined with a pixel-level inversion algorithm with dynamic mask constraints, the sub-pixel-level spatial distribution prediction of total nitrogen and total phosphorus concentrations is realized. On this basis, a piecewise weighted loss function is constructed to drive the model to preferentially learn the spectral response patterns in key concentration intervals, significantly improving the inversion accuracy of low-concentration water quality parameters and providing high-precision and high-robustness technical support for the dynamic monitoring of water body pollution. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] Figure 1 is the overall flowchart of the present invention; Figure 2 is the framework diagram of the inversion model of the present invention; Figure 3 is the structural diagram of the DM-ViT training system of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0049] Next, the technical solutions in the embodiments of the present application will be further clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. It should be noted that the described embodiments are only a part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative efforts belong to the scope of protection of the present application.
[0050] In order to make the invention purpose, technical solutions and advantages of the present application clearer, the embodiments of the present application will be further described in detail below with reference to the accompanying drawings of the specification: In order to better understand the above-mentioned purpose, features and advantages of the present invention, the advantages of the present invention will be further illustrated by comparing with embodiments through the accompanying drawings and specific embodiments.
[0051] The present invention proposes a method for retrieving non-optical active water quality parameters based on hyperspectral images. The flowchart of this method is as Figure 1 shown. The steps of this method will be described in detail below: Step S1, collect hyperspectral images and a dataset of synchronously measured water quality parameters; Step S2, construct an inversion model for non - optically active water quality parameters based on hyperspectral images to realize the inversion method for non - optically active water quality parameters. The model includes: a machine learning feature engineering module, a DM - ViT training module, and a visualization inversion module. The specific inversion process is as follows: Step S21, generate a principal component projection vector using the machine learning feature engineering module , the process is as follows: Step S211, use the random forest feature selection module to extract features from the input hyperspectral image and output a band - sensitive subset ; Specifically, in step S211, the specific process of the random forest feature selection module outputting the band - sensitive subset is as follows: Step Sa1, reconstruct the original hyperspectral image data matrix into a spatial - spectral joint feature tensor , and generate an input feature matrix through window mean sampling and normalization processing , , the formula is as follows:
[0052]
[0053]
[0054] Among them, is a function used to reconstruct the dimension of the original hyperspectral image data matrix , is the window mean sampling operation, used to calculate the mean of each band for the reconstructed , is the normalization processing operation, used to adjust the data to a unified scale, is the mean of each band, is the standard deviation of each band; Step Sa2, construct a random forest regression model containing 100 decision trees, and calculate the band weights through the feature importance ranking function , the formula is as follows:
[0055] Among them, is the feature importance score of band b, that is, the band weight, used to measure the importance of each band in the model, is the total number of decision trees, here = 100, is the true value, is the Predicted value of the tree, is the predicted value after replacement of band b, is the mean square error between the predicted value and the true value; Step Sa3, select the band indices sorted in descending order of feature importance scores to generate a band-sensitive subset , satisfying the following formula:
[0056]
[0057] Among them, is a sorting function that sorts and returns the sorted index values for achieving descending order, is the feature index sorted in descending order of importance, is used to organize the band numbers, is the band.
[0058] Step S212, use the XGBoost feature importance analysis module to calculate the gain weights for and output the weighted importance sequence ; Specifically, in the step S22, the specific process of the XGBoost feature importance analysis module outputting the weighted importance sequence includes: Step Sb1, perform standardization processing on the input band-sensitive subset to generate a normalized feature matrix with zero mean and unit variance , which is used to eliminate the differences in numerical scales between different features. The calculation formula is:
[0059] Among them, is the sensitive band subset, is the mean of the sensitive band subset, is the standard deviation of the sensitive band subset; Step Sb2, construct an XGBoost regression model, and the definition formula of its objective function with a regularization term is:
[0060] Among them, is the L1 regularization term, =0.1 is the L1 regularization coefficient, is the L2 regularization term, =1.0 is the L2 regularization coefficient, n = 100 represents the number of samples, is the The true value of a sample, is the predicted value of the th sample; Step Sb3, calculate the feature gain weight vector
[0061] where, is the th feature weight based on information gain, which is used to measure the information gain weight of each feature in all decision trees, is the total number of decision trees, is the index of the decision tree, and its value range is from 1 to , is the th information gain brought by the band in the th tree, is the index of the feature, and its value range is from 1 to is the th information gain brought by the th feature in the th tree; Step Sb4, generate a weighted importance sequence whose elements are arranged in descending order and satisfy the following formula:
[0062] where, is the original band number, is the feature index.
[0063] Step S213, use the PCA feature dimensionality reduction module to orthogonalize and generate the principal component projection vector ; Specifically, in the step S23, the specific process of the PCA feature dimensionality reduction module generating the principal component projection vector is as follows: Step Sc1, process the input weighted importance sequence to obtain the empty spectrum fusion feature matrix , then perform standardization and covariance matrix decomposition to obtain the eigenvalue decomposition result, that is, the eigenvalues and eigenvectors of the matrix . Select the corresponding eigenvectors from the eigenvalue decomposition result to generate the principal component basis vector matrix , which satisfies the following formula:
[0064]
[0065] Among them, is the transpose of the matrix, is the covariance matrix, is the empty-spectrum fusion feature matrix after standardization, is the number of principal components with cumulative variance ≥ 99%, is to perform eigenvalue decomposition operation on the covariance matrix to obtain the eigenvalue decomposition result, is the principal component basis vector matrix; Step Sc2, calculate the band weight tensor of each principal component , and screen the first 30 sensitive bands of each principal component through absolute value sorting. The specific formula is as follows:
[0066] Among them, is the principal component basis vector matrix, is the principal component basis vector matrix in the th band corresponding to the is the sorting function, is for the th principal component, and through the function to obtain the indexes sorted from largest to smallest by the absolute value of the weight, and then take the first 30 indexes. The bands corresponding to these indexes are the sensitive bands under this principal component; Step Sc3, generate the principal component projection vector , the elements of which are the set of sensitive bands compensated by the original band numbers. The specific formula is as follows:
[0067] Among them, is to take the th index value in the set, is the index variable, is the element in the principal component projection vector .
[0068] Step S22, use the DM-ViT training module to output the water quality parameter inversion result , the process is as follows: Step S221, use the DM data augmentation module to generate multi-scale enhanced spectral features from the original input samples to generate a spectral feature enhanced training set ; Specifically, in step S24, the DM data enhancement module generates a spectral feature enhanced training set The process is as follows: Step Sd1, initialize the diffusion noise scheduling parameters, define the total diffusion time steps = 1000, and generate a linear noise scheduling sequence The specific formula is as follows:
[0069] In the formula is a function used to generate a specified -4 number of linearly equally spaced numerical sequences between the two endpoint values specified by 10 and 0.02; And calculate the cumulative attenuation coefficient The specific formula is as follows:
[0070] Among them, is the result of multiplying from time step 1 to time step in succession; Step Sd2, construct a U-Net type diffusion model with time embedding. The model input is the spectral feature vector and the time step , and the output is the noise prediction vector , where the time embedding layer generates a time encoding vector with a dimension of 256; Step Sd3, perform forward diffusion noise addition training. Inject the noise of a random time step into the original spectral sample to generate a noise-added spectral feature . The specific formula is as follows:
[0071] And with minimizing the predicted noise error as the goal, use the AdamW optimizer for model training. The specific formula is as follows:
[0072] Among them, is the original spectral sample, is the injected noise, is the predicted noise model, is the time step; Step Sd4, starting from the Gaussian noise , generate reverse diffusion samples through reverse iterative calculation. The specific formula is as follows:
[0073] Among them, is the initial noise-added spectral feature, is the random perturbation term, is the set of generated enhanced spectral feature vectors, is the spectral feature obtained through inverse iterative calculation; Step Sd5, the original training set and the enhanced sample set are weighted and fused to form the spectral feature enhanced training set , and the specific formula is as follows:
[0074] Among them, =0.3 is the enhancement factor, is the set of generated enhanced spectral feature vectors.
[0075] Step S222, using the ViT feature extraction module, perform feature extraction, feature mapping, and global average pooling on the spectral feature enhanced training set, and output the water quality parameter inversion result ; Specifically, in the step S25, the process of the ViT feature extraction module outputting the water quality parameter inversion result is as follows: Step Se1, reconstruct the input spectral feature vector into a three-dimensional tensor , where is the spatial window size, is the number of spectral bands; Step Se2, construct a network structure containing dual Transformer encoders, and each encoder executes the following formula;
[0076]
[0077]
[0078]
[0079]
[0080]
[0081] Among them, is the encoder layer index, is the output of the previous layer encoder, is the layer normalization operation, To perform layer normalization on the output of the previous layer and perform layer normalization operation, which is the multi-head attention mechanism, To use as the input, and calculate the value obtained through the multi-head attention mechanism ; To randomly set the output of some neurons to 0 to prevent overfitting, To apply the Dropout operation to and then add it to the result after performing the residual connection (addition) with ; To perform layer normalization on again, and the result is the activation function, which is the fully connected layer, First, apply the activation function to and then calculate the value obtained through the fully connected layer; To apply the operation to and then add it to the result after performing the residual connection with as the output of the current encoder; Step Se3, design a dynamic weighted loss function, and construct a piecewise weighted mean square error loss function , and its expression is:
[0082] In the formula, is the number of training samples, is the true value of the th sample, is the predicted value of the th sample, is the weight function, is the mean square error, and the regularization coefficient = 0.01, is the square of the L2 norm of the weight matrix ; Among them, the weight function satisfies the following formula:
[0083] Among them, is the concentration of water quality parameters, and the regularization coefficient = 0.01; Step Se4, adopt an adaptive learning rate training strategy, and initialize the learning rate with the Nadam optimizer = 0.001, and define the dynamic decay rule of the learning rate: when the validation loss has not improved for 10 epochs, the learning rate is updated to = 0.1 , and the minimum learning rate is limited to = 0.0001; Step Se5, multi-scale feature fusion prediction. Perform global average pooling on the encoder output, and after mapping through Dropout and the fully connected layer, output the inversion result of the total nitrogen concentration .
[0084] Step S23, use the visualization inversion module to process the inversion result of the water quality parameters and output the spatial distribution maps of nitrogen and phosphorus concentrations in the target water area ; Specifically, in the said step S23, the process of the visualization inversion module outputting the spatial distribution maps of nitrogen and phosphorus concentrations in the target water area is as follows: Step Sf1, generate a dynamic mask for the hyperspectral image, read the input hyperspectral image , and construct a dynamic mask matrix based on the band threshold condition , satisfying the following formula:
[0085] where = 270 is the number of spectral bands, is the spatial coordinate index, is the row index of the spatial coordinate, is the column index of the spatial coordinate; Step Sf2, pixel-level normalization and prediction: for the pixel points satisfying , extract the spectral vector , and then normalize it through the pre-trained MinMaxScaler normalizer. The formula is as follows:
[0086] In the formula is the spectral vector processed by the MinMaxScaler normalizer, is the pre-trained MinMaxScaler normalizer object, is the normalization conversion function of the MinMaxScaler normalizer, is the original spectral vector transpose; and input it into the ViT inversion model to predict the nitrogen and phosphorus concentration values , the formula is as follows:
[0087] Step Sf3, reconstruct the spatial distribution map, map the prediction results to the original image spatial dimension, and generate a concentration matrix , and the rule is:
[0088] In the formula indicates that no concentration prediction is performed at this position or there is no valid data; Step Sf4, update the output parameters according to the input image metadata meta, and write into a single-band raster file O , and use the row-column traversal algorithm to fill in the predicted values pixel by pixel to generate the spatial distribution maps of nitrogen and phosphorus concentrations in the target water area ; Step Sf5, distributed storage management: construct a hierarchical output directory structure, and use the recursive directory creation function based on the input file path to ensure the integrity of data storage, and output the spatial distribution maps of nitrogen and phosphorus concentrations in the target water area .
[0089] Step S3, input the samples in the dataset into the water quality parameter inversion model, calculate the total loss function value, perform backpropagation, and optimize the model weights through the AdamW optimizer and the dynamic learning rate strategy. After multiple rounds of training, the final water quality parameter inversion model is obtained; Specifically, in the regression prediction stage of the ViT feature extraction module, the weighted mean square error and the regularization loss of all samples are jointly optimized, and its total loss is calculated as follows:
[0090] where is the concentration sensitivity weight function, and the defined rule formula is:
[0091] In the formula =0.01 is the regularization strength coefficient, which acts on the sum of the squares of the L2 norms of all trainable parameter sets of the model, is the number of samples in the training batch, and are respectively the true concentration value and the model prediction value of the th sample.
[0092] Step S4, based on the trained water quality parameter inversion model, input the hyperspectral image to be processed, and output the spatial distribution maps of nitrogen and phosphorus concentrations in the target water area.
[0093] The present invention constructs a high - spectral remote - sensing dataset of unmanned aerial vehicles (UAVs), and uses the water - quality monitoring data and diffusion - enhanced samples of Chitian Reservoir for model training; constructs a water - quality inversion model based on spectral - spatial fusion, including a machine - learning feature - engineering module, a DM - ViT training module, and a visualization inversion module in the model; inputs the sample data of the dataset into the model, performs feature engineering, diffusion enhancement, and spectral - feature fusion, conducts backpropagation through a weighted loss function and a Nadam optimizer, combines a learning - rate dynamic - decay strategy to optimize network parameters, and finally obtains an enhanced water - quality inversion model after training; based on the trained model, inputs the hyperspectral remote - sensing image, and outputs the total nitrogen and total phosphorus concentration distribution maps with sub - 100 - meter accuracy and the pollution - hot - spot location results. The present invention combines UAV hyperspectral imaging and deep - learning techniques, significantly improves the generalization ability of small - sample scenarios based on data enhancement of the diffusion model, realizes co - modeling of spectral - spatial features through the ViT network, innovatively introduces a dynamic weighted - loss mechanism to effectively optimize the prediction accuracy of low - concentration parameters, and improves the efficiency and accuracy of the inversion task of non - optically - active water - quality parameters.
[0094] Although the preferred embodiments of the present application have been described, those skilled in the art can make additional changes and modifications once they learn the basic creative concept. Therefore, the appended claims are intended to be construed to include the preferred embodiments as well as all changes and modifications falling within the scope of the present application.
[0095] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalent technologies, the present application is also intended to include these changes and modifications.
Claims
1. A method for retrieving non - optically active water quality parameters based on hyperspectral images, characterized in that, Including: Step S1: Collect hyperspectral images and synchronous measured water quality parameters to construct a dataset; Step S2: Construct an inversion model for non-optical active water quality parameters based on hyperspectral images to achieve the inversion of non-optical active water quality parameters. The model includes: a machine learning feature engineering module, a DM-ViT training module, and a visualization inversion module. The specific inversion process is as follows: Step S21, generating a principal component projection vector using a machine learning feature engineering module , The process is as follows: Step S211, use the random forest feature selection module to extract features from the input hyperspectral image and output a band-sensitive subset ; Step S212, using the XGBoost feature importance analysis module, for perform gain weight calculation and output the weighted importance sequence ; Step S213, using the PCA feature dimensionality reduction module, for perform an orthogonality processing to generate the principal component projection vector ; Step S22, using the DM-ViT training module to output the water quality parameter inversion result , the process is as follows: Step S221: Use the DM data augmentation module to generate multi-scale augmented spectral features from the original input samples, and generate an augmented training set of spectral features. ; Step S222: Use the ViT feature extraction module to perform feature extraction, feature mapping, and global average pooling on the spectrogram feature enhanced training set, and output the water quality parameter inversion result ; Step S23: Use the visualization inversion module to process the inversion results of water quality parameters and output the spatial distribution maps of nitrogen and phosphorus concentrations in the target water area ; Step S3: Input the samples in the dataset into the water quality parameter inversion model, calculate the total loss function value, perform backpropagation, and optimize the model weights through the AdamW optimizer and the dynamic learning rate strategy. After multiple rounds of training, the final water quality parameter inversion model is obtained; Step S4: Based on the trained water quality parameter inversion model, input the hyperspectral image to be processed, and output the spatial distribution maps of nitrogen and phosphorus concentrations in the target water area.
2. The non-optical active water quality parameter inversion method based on hyperspectral images according to claim 1, wherein, In the step S211, the specific process of the random forest feature selection module outputting the band-sensitive subset is as follows: Step Sa1, reconstruct the original hyperspectral image data matrix into a spatio-spectral joint feature tensor , and generate an input feature matrix through window mean sampling and normalization processing , the formula is as follows: ; ; ; Among them, is a function used to perform dimensional reconstruction on the original hyperspectral image data matrix ; is the window mean sampling operation used to calculate the mean of each band for the reconstructed ; is the mean of each band, and is the standard deviation of each band. Step Sa2, construct a random forest regression model containing 100 decision trees, and calculate the band weights through the feature importance ranking function as follows: ; Among them, is the feature importance score of band b, that is, the band weight, is the total number of decision trees. Here , is the true value, is the th tree prediction value, is the prediction value after the replacement of band b, is the mean square error between the prediction value and the true value; Step Sa3, select the band indices arranged in descending order of feature importance scores to generate a band-sensitive subset , and satisfy the following formula: ; ; Among them, is a sorting function that sorts and returns the sorted index values. is the feature index sorted in descending order of importance. is used to organize the band numbers. is the band.
3. The non-optical active water quality parameter inversion method based on hyperspectral images according to claim 1, wherein In the step S212, the XGBoost feature importance analysis module outputs a weighted importance sequence The specific process includes: Step Sb1, perform normalization on the input band-sensitive subset to generate a normalized feature matrix with zero mean and unit variance , and the calculation formula is as follows: ; Among them, is a subset of sensitive wavelength bands, is the mean value of the subset of sensitive wavelength bands, is the standard deviation of the subset of sensitive wavelength bands; Step Sb2, construct an XGBoost regression model, which uses an objective function with a regularization term The defining formula of which is: ; Among them, is the L1 regularization term, = 0.1 is the L1 regularization coefficient, is the L2 regularization term, = 1.0 is the L2 regularization coefficient, n = 100 represents the number of samples, is the true value of the th sample, is the predicted value of the th sample; Step Sb3, calculate the feature gain weight vector , and the formula for the feature gain weight of its k-th dimensional component is: ; where, is the th feature weight based on information gain, is the total number of decision trees, is the index of the decision tree, ranging from 1 to , is the th information gain brought by band in the th tree, is the index of the feature, ranging from 1 to is the th information gain brought by the th feature in the Step Sb4, generate a weighted importance sequence , whose elements are arranged in descending order and satisfy the following formula: ; Among them, is the original band number, is the feature index.
4. The non-optical activity water quality parameter inversion method based on hyperspectral images according to claim 1, wherein In the step S213, the PCA feature dimensionality reduction module generates a principal component projection vector The specific process is as follows: Step Sc1, process the input weighted importance sequence to obtain an empty spectral fusion feature matrix . Then perform standardization and covariance matrix decomposition to obtain the eigenvalue decomposition result, which is the eigenvalues and eigenvectors of matrix . Select the corresponding eigenvectors from the eigenvalue decomposition result to generate a principal component basis vector matrix , satisfying the following equation: ; ; wherein, is the transpose of the matrix, is the covariance matrix, is the empty-spectrum fusion feature matrix after standardization, is the number of principal components with cumulative variance ≥ 99%, is to perform an eigenvalue decomposition operation on the covariance matrix to obtain the eigenvalue decomposition result, which is the principal component basis vector matrix; Step Sc2, calculate the band weight tensor of each principal component , screen the first 30 sensitive bands of each principal component by sorting in absolute value, and the specific formula is as follows: ; Among them, is the principal component basis vector matrix, is the principal component basis vector matrix in the th principal component corresponding to the th band, is the sorting function, for the th principal component, through the function to obtain the indexes sorted in descending order of the absolute value of the weights, and then take the first 30 indexes. The bands corresponding to these indexes are the sensitive bands under this principal component; Step Sc3, generate the principal component projection vector , whose elements are the set of sensitive bands after compensating the original band numbers, and the specific formula is as follows: ; Among them, is to take the -th index value in the set, is the index variable, and is an element in the principal component projection vector.
5. The non-optical active water quality parameter inversion method based on hyperspectral images according to claim 1, wherein In the step S221, the DM data enhancement module generates a spectral feature enhanced training set The process is as follows: Step Sd1, initialize the diffusion noise scheduling parameters and define the total diffusion time steps , generate a linear noise scheduling sequence , and the specific formula is as follows: ; In the formula is a function used to generate a specified -4 number of linearly equally spaced numerical sequences between the two endpoint values specified by 10 and 0.02; And calculate the cumulative attenuation coefficient , and the specific formula is as follows: ; Among them, is the result of successive multiplication of from time step 1 to time step . Step Sd2: Construct a U-Net type diffusion model with time embedding. The input of the model is the spectral feature vector and the time step , and output the noise prediction vector . Among them, the time embedding layer generates a time encoding vector with a dimension of 256; Step Sd3, perform forward diffusion denoising training on the original spectral samples with random time steps to inject noise and generate noisy spectral features . The specific formula is as follows: ; and minimize the prediction noise error As the goal, the AdamW optimizer is used for model training, and the specific formula is as follows: ; Among them, is the original spectral sample, is the injected noise, is the predicted noise model, is the time step; Step Sd4, starting from Gaussian noise generate reverse diffusion samples through reverse iterative calculation. The specific formula is as follows: ; Among them, is the initial noisy spectral feature, is the random perturbation term, is the set of generated enhanced spectral feature vectors, is the spectral feature obtained by inverse iterative calculation; Step Sd5, take the original training set and the augmented sample set to perform weighted fusion to form a spectrogram feature augmented training set . The specific formula is as follows: ; Among them, = 0.3 is the enhancement factor, is to generate an enhanced spectral feature vector set.
6. The non-optical activity water quality parameter inversion method based on hyperspectral images according to claim 1, wherein, In the step S222, the ViT feature extraction module outputs the inversion result of water quality parameters The process is as follows: Step Se1, reconstruct the input spectral feature vector into a three-dimensional tensor , where is the spatial window size, is the number of spectral bands; Step Se2: Construct a network structure containing a dual Transformer encoder, and each layer of the encoder executes the following formula; ; ; ; ; ; ; Among them, is the encoder layer index, is the output of the previous encoder layer, is the layer normalization operation, is to perform the layer normalization operation on the output of the previous layer is the multi-head attention mechanism, is to use as the input, and the value calculated through the multi-head attention mechanism, is to randomly set the outputs of some neurons to 0 to prevent overfitting, is to apply the Dropout operation to and then the result after residual connection with is to perform the layer normalization operation again on is the activation function, is the fully connected layer, is to first apply the activation function to and then the value calculated through the fully connected layer, is to apply the operation to and then the result after residual connection with is used as the output of the current encoder; Step Se3, design the dynamic weighted loss function, and construct the piecewise weighted mean square error loss function , and its expression is: ; where is the number of training samples, is the true value of the -th sample, is the predicted value of the -th sample, is the weight function, is the mean squared error, the regularization coefficient , is the weight matrix squared L2 norm; Among them, the weight function satisfies the following formula: ; Among them, is the concentration of water quality parameters, and the regularization coefficient ; Step Se4, adopt an adaptive learning rate training strategy, and initialize the learning rate with the Nadam optimizer = 0.001, and define the dynamic decay rule of the learning rate: when the validation loss has not improved for 10 epochs, the learning rate is updated to = 0.1 , and the minimum learning rate is limited to = 0.0001; Step Se5, multi-scale feature fusion prediction: perform global average pooling on the encoder output, and after mapping through Dropout and the fully connected layer, output the inversion result of the total nitrogen concentration .
7. The non-optical active water quality parameter inversion method based on hyperspectral images according to claim 1, characterized in that In the step S23, the visualization inversion module outputs the spatial distribution maps of nitrogen and phosphorus concentrations in the target water area. The process is as follows: Step Sf1, generate a hyperspectral image dynamic mask, and read the input hyperspectral image , construct a dynamic mask matrix based on the band threshold condition , which satisfies the following formula: ; Among them, = 270 is the number of spectral bands, is the spatial coordinate index, is the row index of the spatial coordinate, is the column index of the spatial coordinate; Step Sf2, perform pixel-level normalization and prediction. For the pixel points that satisfy = 1, extract the spectral vector , and then normalize it through the pre-trained MinMaxScaler normalizer. The formula is as follows: ; In the formula is the spectral vector processed by the MinMaxScaler normalizer, is the pre-trained MinMaxScaler normalizer object, is the normalization conversion function of the MinMaxScaler normalizer, is the original spectral vector is the transpose of; And input the ViT inversion model Predict the nitrogen and phosphorus concentration values , and the formula is as follows: ; Step Sf3, reconstruct the spatial distribution map, map the prediction result to the spatial dimension of the original image, and generate a concentration matrix , the rule is: ; In the formula denotes when (i,j) = 0, the pixel points do not perform concentration prediction or have no valid data; Step Sf4, update the output parameters according to the input image metadata meta, and write it into a single-band raster file , and use the row-column traversal algorithm to fill the predicted values pixel by pixel to generate the spatial distribution maps of nitrogen and phosphorus concentrations in the target water area ; Step Sf5: Perform distributed storage management, construct a hierarchical output directory structure, recursively create a directory function based on the input file path to ensure data storage integrity, and output the spatial distribution maps of nitrogen and phosphorus concentrations in the target water area .
8. The non-optical active water quality parameter inversion method based on hyperspectral images according to claim 1, wherein In the said Step S3, the process of calculating the total loss function value L of the model is as follows: In the regression prediction stage of the ViT feature extraction module, the weighted mean squared error of the full sample and the regularization loss are jointly optimized, and the total loss is calculated as follows: ; Among them, is a concentration-sensitive weight function, and the defining formula is: ; where = 0.01 is the regularization strength coefficient, acting on the sum of the squares of the L2 norms of all trainable parameter sets of the model , is the number of training batch samples and are the true concentration value and the model prediction value of the 9. The present invention provides a computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Water quality inversion method based on feature adaptive operation and machine learning fusion
CN115561176A
Path tracking control method based on digital-intelligent dual-drive sea wave inversion observation
CN117111600A
Inversion method of nitrogen content of apple canopy leaves based on hyperspectrum
CN117933084A
Latent low-rank projection learning based unsupervised feature extraction method for hyperspectral image
WO2022001159A1
Cited By
Aircraft tail smoke multi-component analysis method and system for spectral imaging on miniature chip
CN120931625A
Intelligent water quality treatment method and device
CN121147677A
Spectral aliasing decoupling and concentration inversion method under cross influence of multi-source environmental factors
CN121384844A
River water ecological environment dynamic monitoring method based on satellite remote sensing and AI
CN121723125A