Inversion method of non-optically active water quality parameters based on hyperspectral images

Through the hyperspectral image inversion method, combined with machine learning and deep learning technology, the high-precision and sub-cell positioning problems of non-optical active water quality parameters are solved, and efficient dynamic monitoring of water quality parameters and precise positioning of pollution sources are achieved.

CN120293873BActive Publication Date: 2025-08-12SANYA SCI & EDUCATION INNOVATION PARK WUHAN UNIV OF TECH +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510779248.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-06-12
Publication Date
2025-08-12
Estimated Expiration
2045-06-12

AI Technical Summary

Technical Problem

The prior art is difficult to effectively capture the spatial heterogeneity of pollution diffusion, and cannot achieve high-precision, sub-cell-level positioning and dynamic monitoring of non-optical active water quality parameters. The traditional method has insufficient generalization ability in small sample scenarios.

Method used

Using a non-optical active water quality parameter inversion method based on hyperspectral images, the machine learning feature engineering module, DM-ViT training module and visual inversion module are combined with random forest, XGBoost and PCA feature extraction, and the spectral features are enhanced by diffusion models, a ViT collaborative decoding architecture is constructed, and the concentration-sensitive weighted learning mechanism is introduced to achieve high-precision inversion.

Benefits of technology

The inversion accuracy and robustness of non-optical active water quality parameters are improved, and the sub-cell spatial distribution prediction of total nitrogen and total phosphorus concentrations is achieved, and the efficiency and accuracy of pollution monitoring are improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120293873B_ABST
    Figure CN120293873B_ABST
Patent Text Reader

Abstract

The present invention belongs to the technical field of agricultural hyperspectral image classification, and discloses a method for inverting non-optically active water quality parameters based on hyperspectral images. The present invention comprises: a data preprocessing module, a spectral-spatial feature fusion module, a multi-algorithm collaborative inversion module, and a visualization output module; the collected hyperspectral images are input into the system, feature learning is performed by integrating the Transformer architecture and the Diffusion data generation technology, and parameter optimization is performed by combining machine learning algorithms such as random forest and XGBoost, and a high-precision water quality inversion model is obtained after iterative training; the hyperspectral remote sensing image to be analyzed is input, and a spatial distribution map of non-optically active water quality parameters is output to realize intelligent inversion of water quality parameters. The present invention mines spectral feature associations based on the self-attention mechanism of deep learning, enhances data representation capabilities through a diffusion model, and utilizes multi-algorithm collaborative optimization to improve the model generalization performance, thereby improving the efficiency of large-scale water area monitoring and the accuracy of parameter inversion.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of machine learning algorithms and computer vision technology, and specifically relates to a method for inverting non-optically active water quality parameters based on hyperspectral images. Background Art

[0002] Hyperspectral inversion of non-optically active water quality parameters uses continuous spectral information from hyperspectral remote sensing images combined with deep learning techniques to invert the spatial distribution of non-optically active parameters such as total nitrogen (TN) and total phosphorus (TP) in water bodies. This technology, by modeling the mapping relationship between spectral features and water quality parameters, provides large-scale, high-frequency dynamic monitoring capabilities for agricultural engineering and water quality monitoring, and has important application value in agricultural production, environmental regulation, and ecological protection. Traditional water quality monitoring methods rely on laboratory analysis at discrete sampling points, making it difficult to capture the spatial heterogeneity of pollution diffusion. Hyperspectral inversion technology, through spatial-spectral fusion and data-driven modeling, has achieved a leap from point-based monitoring to surface-based prediction.

[0003] The main challenges in inverting non-optically active water quality parameters lie in the extraction of high-dimensional nonlinear features from hyperspectral data and the modeling of low-concentration parameter sensitivity. Existing methods have two main limitations: first, traditional empirical models make insufficient use of spectral features, making it difficult to capture nonlinear correlations across bands; second, single deep learning models have weak generalization capabilities in small sample scenarios, resulting in high inversion errors in low-concentration intervals. In addition, traditional point monitoring methods are limited by spatial resolution and cannot achieve sub-pixel-level positioning of pollution sources, and it is difficult to analyze the dynamic evolution of pollution diffusion paths. Therefore, how to design a spatial-spectral collaborative feature extraction network, construct a data enhancement method that conforms to physical mechanisms, and realize dynamic optimization decoding of multimodal features, and ultimately achieve improved inversion accuracy, has become a key task for non-optically active water quality parameters. Summary of the Invention

[0004] In view of the existing technical defects in the background technology, the present invention proposes a method for inverting non-optically active water quality parameters based on hyperspectral images, which specifically includes the following steps:

[0005] In a first aspect, the present invention provides a method for inverting non-optically active water quality parameters based on hyperspectral images, comprising:

[0006] Step S1, collecting hyperspectral images and synchronously measured water quality parameter datasets;

[0007] Step S2: constructing a non-optically active water quality parameter inversion model based on hyperspectral images to implement a non-optically active water quality parameter inversion method. 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:

[0008] Step S21, using the machine learning feature engineering module to generate the principal component projection vector , the process is as follows:

[0009] Step S211: Use the random forest feature selection module to extract features from the input hyperspectral image and output the band sensitive subset ;

[0010] Step S212: Using XGBoost feature importance analysis module, Perform gain weight calculation and output weighted importance sequence ;

[0011] Step S213, using PCA feature dimensionality reduction module, Perform orthogonal processing to generate the principal component projection vector ;

[0012] Step S22: Output the water quality parameter inversion results using the DM-ViT training module , the process is as follows:

[0013] Step S221: Using the DM data enhancement module, the original input samples are used to generate multi-scale enhanced spectral features and generate a spectral feature enhancement training set. ;

[0014] Step S222: Use the ViT feature extraction module to perform feature extraction, feature mapping and global average pooling on the spectral feature enhancement training set, and output the water quality parameter inversion result. ;

[0015] Step S23: Use the visualization inversion module to process the water quality parameter inversion results and output the nitrogen and phosphorus concentration spatial distribution map of the target water area. ;

[0016] In step S3, the samples in the data set are input into the water quality parameter inversion model, the total loss function value is calculated, back propagation is performed, the model weights are optimized using the AdamW optimizer and the dynamic learning rate strategy, and the final water quality parameter inversion model is obtained after multiple rounds of training;

[0017] Step S4: Based on the trained water quality parameter inversion model, the hyperspectral image to be processed is input and the spatial distribution map of nitrogen and phosphorus concentrations in the target water area is output.

[0018] Preferably, in step S211, the random forest feature selection module outputs the band sensitive subset The specific process is as follows:

[0019] Step Sa1: convert the original hyperspectral image data matrix Reconstructed into a joint spatial-spectral feature tensor , generate the input feature matrix through window mean sampling and standardization , , the formula is as follows:

[0020]

[0021]

[0022]

[0023] in, Is a function used to convert the original hyperspectral image data matrix Perform dimension reconstruction, It is a window mean sampling operation used to reconstruct Calculate the mean of each band, To standardize processing operations, is the mean value of each band, is the standard deviation of each band;

[0024] Step Sa2: Build a random forest regression model containing 100 decision trees and use the feature importance ranking function Calculate the band weight using the following formula:

[0025]

[0026] in, is the feature importance score of band b, that is, the band weight, is the total number of decision trees, where =100, is the true value, For the The predicted value of each tree, is the predicted value after band b is replaced, is the mean square error between the predicted value and the true value;

[0027] Step Sa3: Select the band indexes in descending order of feature importance scores to generate the band sensitive subset , satisfying the following formula:

[0028]

[0029]

[0030] in, is the sorting function, Sorting is performed and the index value after sorting is returned. are feature indices in descending order of importance, Used to organize the band numbers, For the band.

[0031] Preferably, in step S212, the XGBoost feature importance analysis module outputs a weighted importance sequence The specific process includes:

[0032] Step Sb1, sensitive subset of input band Perform standardization to generate a normalized feature matrix with zero mean and unit variance , the calculation formula is:

[0033]

[0034] in, is a subset of sensitive bands, is the mean of the sensitive band subset, is the standard deviation of the sensitive band subset;

[0035] Step Sb2: Build an XGBoost regression model using an objective function with a regularization term. The definition formula is:

[0036]

[0037] in, 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, For the The true value of the sample, For the The predicted value of samples;

[0038] Step Sb3, calculate the feature gain weight vector , the formula of the feature gain weight of the k-th dimension component is:

[0039]

[0040] in, For the feature weights based on information gain, is the total number of decision trees, The index of the decision tree, ranging from 1 to , For the Tree mid-band The information gain brought by The index of the feature, ranging from 1 to , For the The first tree Information gain brought by features;

[0041] Step Sb4, generate weighted importance sequence , whose elements are Arrange in descending order and satisfy the following formula:

[0042]

[0043] in, is the original band number, is the feature index.

[0044] Preferably, in step S213, the PCA feature dimensionality reduction module generates the principal component projection vector The specific process is as follows:

[0045] Step Sc1, input weighted importance sequence Processing is performed to obtain the spatial-spectral fusion feature matrix , then perform standardization and covariance matrix decomposition to obtain the eigenvalue decomposition result, which is the matrix The eigenvalues and eigenvectors of , select the corresponding Eigenvectors generate the principal component basis vector matrix , satisfying the following formula:

[0046]

[0047]

[0048] in, for The transpose of the matrix, is the covariance matrix, is the normalized spatial-spectral fusion feature matrix, is the number of principal components with cumulative variance ≥ 99%, is the covariance matrix Perform eigenvalue decomposition operation to obtain the eigenvalue decomposition result. is the principal component basis vector matrix;

[0049] Step Sc2, calculate the band weight tensor of each principal component , the top 30 sensitive bands of each principal component are screened by absolute value sorting. The specific formula is as follows:

[0050]

[0051] in, is the principal component basis vector matrix, is the principal component basis vector matrix Middle The principal component corresponding to bands, is the sorting function, For the principal components, through The function obtains the indexes sorted from large to small by the absolute value of the weight, and then takes the first 30 indexes. The bands corresponding to these indexes are the sensitive bands under the principal component.

[0052] Step Sc3, generate principal component projection vector , whose elements are the sensitive band sets after the original band numbers are compensated. The specific formula is as follows:

[0053]

[0054] in, To obtain The first in the collection index values, is the index variable, Principal component projection vector Elements in .

[0055] Preferably, in step S221, the DM data enhancement module generates a spectral feature enhancement training set The process is as follows:

[0056] Step Sd1, initialize the diffusion noise scheduling parameters and define the total diffusion time step =1000, generate linear noise scheduling sequence , the specific formula is as follows:

[0057]

[0058] In the formula is a function used to -4 to 0.02, generate the specified A linear sequence of equally spaced values of a quantity;

[0059] And calculate the cumulative attenuation coefficient , the specific formula is as follows:

[0060]

[0061] in, From time step 1 to time step ,right The result of performing a series of multiplications;

[0062] Step Sd2: Construct a U-Net diffusion model with time embedding, and the model input is the spectral feature vector With time step , output noise prediction vector , where the time embedding layer generates a time encoding vector of dimension 256;

[0063] Step Sd3, perform forward diffusion noise training to the original spectrum sample Take random time steps Noise Injection, generating noise-added spectral features , the specific formula is as follows:

[0064]

[0065] And minimize the prediction noise error As the goal, AdamW optimizer is used for model training. The specific formula is as follows:

[0066]

[0067] in, is the original spectrum sample, is the injected noise, To predict the noise model, is the time step;

[0068] Step Sd4, from Gaussian noise Starting from, through reverse iterative calculation, the reverse diffusion sample is generated. The specific formula is as follows:

[0069]

[0070] in, is the initial noise spectrum feature, is a random disturbance term, To generate a set of enhanced spectral feature vectors, is the spectral feature obtained by reverse iterative calculation;

[0071] Step Sd5, the original training set With enhanced sample set Perform weighted fusion to form a spectral feature enhanced training set , the specific formula is as follows:

[0072]

[0073] in, =0.3 is the enhancement factor, = To generate a set of enhanced spectral feature vectors.

[0074] Preferably, in step S222, the ViT feature extraction module outputs the water quality parameter inversion result The process is as follows:

[0075] Step Se1: Input spectral feature vector Reconstructed into a 3D tensor ,in, is the spatial window size, is the number of spectral bands;

[0076] Step Se2: construct a network structure containing dual Transformer encoders. Each layer of encoders executes the following formula;

[0077]

[0078]

[0079]

[0080]

[0081]

[0082]

[0083] in, is the encoder level index, is the output of the previous encoder, is the layer normalization operation, is the output of the previous layer Perform layer normalization operation, It is a multi-head attention mechanism. For the general As input, the value calculated by the multi-head attention mechanism, To randomly set the output of some neurons to 0 to prevent overfitting, For Apply Dropout operation and then The result after residual connection, For The result of layer normalization operation again is, is the activation function, is the fully connected layer, First application Activation function, and then the value calculated by the fully connected layer, For application Operation, then The result after residual connection is used as the output of the current encoder;

[0084] Step Se3, design a dynamic weighted loss function and construct a piecewise weighted mean square error loss function , whose expression is:

[0085]

[0086] In the formula is the number of training samples, For the The true value of the sample, For the The predicted value of the sample, is the weight function, is the mean square error, regularization coefficient =0.01, is the weight matrix The square of the L2 norm of ;

[0087] Among them, the weight function The formula is as follows:

[0088]

[0089] in, is the concentration of water quality parameters, regularization coefficient =0.01;

[0090] Step Se4, using the adaptive learning rate training strategy, the Nadam optimizer initializes the learning rate = 0.001, and define the dynamic decay rule of learning rate: when the validation loss does not improve for 10 epochs, the learning rate is updated to =0.1 , the minimum learning rate is limited to =0.0001;

[0091] Step Se5, multi-scale feature fusion prediction, global average pooling of the encoder output, after Dropout and full connection layer mapping, output the total nitrogen concentration inversion result .

[0092] Preferably, in step S23, the visualization inversion module outputs the spatial distribution map of nitrogen and phosphorus concentrations in the target waters. The process is as follows:

[0093] Step Sf1: Generate a dynamic mask for the hyperspectral image and read the input hyperspectral image , construct a dynamic mask matrix based on the band threshold condition , satisfying the following formula:

[0094]

[0095] in, =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;

[0096] Step Sf2, pixel-level normalization and prediction: =1 pixel point, extract the spectrum vector , and then normalized by the pre-trained MinMaxScaler normalizer, the formula is as follows:

[0097]

[0098] In the formula is the spectral vector processed by the MinMaxScaler normalizer, is a pre-trained MinMaxScaler normalizer object, is the normalization transfer function of the MinMaxScaler normalizer, is the original spectrum vector The transpose of

[0099] And input ViT inversion model Predicted nitrogen and phosphorus concentrations , the formula is as follows:

[0100]

[0101] Step Sf3, reconstruct the spatial distribution map, map the prediction results to the original image space dimension, and generate the concentration matrix , the rules are:

[0102]

[0103] In the formula Indicates that no concentration prediction is made for this location or there is no valid data;

[0104] Step Sf4, update the output parameters according to the input image metadata meta Writing a single-band raster file , and use the row-column traversal algorithm to fill the predicted value pixel by pixel to generate the spatial distribution map of nitrogen and phosphorus concentrations in the target waters ;

[0105] Step Sf5, distributed storage management: build a hierarchical output directory structure, recursively create directory functions based on the input file path to ensure data storage integrity, and output the spatial distribution map of nitrogen and phosphorus concentrations in the target water area .

[0106] Preferably, in step S3, the process of calculating the total loss function value L of the model is as follows:

[0107] In the regression prediction stage of the ViT feature extraction module, the weighted mean square error and regularization loss of all samples are jointly optimized, and the total loss The calculation is as follows:

[0108]

[0109] in, is the concentration-sensitive weight function, and the formula for defining the rule is:

[0110]

[0111] In the formula =0.01 is the regularization strength coefficient, which acts on the entire set of trainable parameters of the model The L2 norm sum of squares, is the number of training batch samples, and Respectively The actual concentration value of each sample and the model predicted value.

[0112] 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-optically active water quality parameters based on hyperspectral images.

[0113] Compared with the prior art, the present invention proposes a method for inverting non-optically active water quality parameters based on hyperspectral images. The present invention has the following beneficial effects:

[0114] Compared with the existing technology, the present invention proposes a non-optically active water quality parameter inversion method based on hyperspectral images. The method generates robust spectral features through diffusion-enhanced spatial-spectral joint encoding, and realizes high-precision parameter inversion based on the ViT collaborative decoding architecture. At the same time, a concentration-sensitive weighted learning mechanism is introduced to improve the model's sensitivity and generalization ability to low-concentration parameters. Specifically, a diffusion model and time embedding mechanism based on U-Net are first designed, and enhanced samples that conform to the laws of spectral physics are generated through forward diffusion noise injection and reverse denoising. A spatial-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, and a multi-head self-attention mechanism is used to extract cross-band spectral correlation features. Combined with a pixel-level inversion algorithm with dynamic mask constraints, 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 pattern of the key concentration range, significantly improving the inversion accuracy of low-concentration water quality parameters, and providing high-precision and high-robustness technical support for dynamic monitoring of water pollution. BRIEF DESCRIPTION OF THE DRAWINGS

[0115] Figure 1 It is the overall flow chart of the present invention;

[0116] Figure 2 It is the framework diagram of the inversion model of the present invention;

[0117] Figure 3 This is a diagram of the DM-ViT training system architecture of the present invention. DETAILED DESCRIPTION

[0118] The following will be combined with the drawings in the embodiments of this application to further clearly and completely describe the technical solutions in the embodiments of this application. It should be noted that the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without making any creative work shall fall within the scope of protection of this application.

[0119] In order to make the invention objectives, technical solutions and advantages of this application clearer, the embodiments of this application are further described in detail in conjunction with the drawings in the specification: In order to more clearly understand the above-mentioned objectives, features and advantages of the present invention, the advantages of the present invention will be further illustrated by comparing the embodiments in conjunction with the drawings and specific implementation methods.

[0120] The present invention proposes a method for inverting non-optically active water quality parameters based on hyperspectral images. The flow chart of the method is as follows: Figure 1 As shown, the steps of this method are described in detail below:

[0121] Step S1, collecting hyperspectral images and synchronously measured water quality parameter datasets;

[0122] Step S2: constructing a non-optically active water quality parameter inversion model based on hyperspectral images to implement a non-optically active water quality parameter inversion method. 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:

[0123] Step S21, using the machine learning feature engineering module to generate the principal component projection vector , the process is as follows:

[0124] Step S211: Use the random forest feature selection module to extract features from the input hyperspectral image and output the band sensitive subset ;

[0125] Specifically, in step S211, the random forest feature selection module outputs the band sensitive subset The specific process is as follows:

[0126] Step Sa1: convert the original hyperspectral image data matrix Reconstructed into a joint spatial-spectral feature tensor , generate the input feature matrix through window mean sampling and standardization , , the formula is as follows:

[0127]

[0128]

[0129]

[0130] in, Is a function used to convert the original hyperspectral image data matrix Perform dimension reconstruction, It is a window mean sampling operation used to reconstruct Calculate the mean of each band, It is a standardization operation used to adjust the data to a uniform scale. is the mean value of each band, is the standard deviation of each band;

[0131] Step Sa2: Build a random forest regression model containing 100 decision trees and use the feature importance ranking function Calculate the band weight using the following formula:

[0132]

[0133] in, is the feature importance score of band b, that is, the band weight, which is used to measure the importance of each band in the model. is the total number of decision trees, where =100, is the true value, For the The predicted value of each tree, is the predicted value after band b is replaced, is the mean square error between the predicted value and the true value;

[0134] Step Sa3: Select the band indexes in descending order of feature importance scores to generate the band sensitive subset , satisfying the following formula:

[0135]

[0136]

[0137] in, is the sorting function, Sorting is performed and the index value after sorting is returned, which is used to achieve descending order. are feature indices in descending order of importance, Used to organize the band numbers, For the band.

[0138] Step S212: Using XGBoost feature importance analysis module, Perform gain weight calculation and output weighted importance sequence ;

[0139] Specifically, in step S22, the XGBoost feature importance analysis module outputs a weighted importance sequence The specific process includes:

[0140] Step Sb1, sensitive subset of input band Perform standardization 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:

[0141]

[0142] in, is a subset of sensitive bands, is the mean of the sensitive band subset, is the standard deviation of the sensitive band subset;

[0143] Step Sb2: Build an XGBoost regression model using an objective function with a regularization term. The definition formula is:

[0144]

[0145] in, 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, For the The true value of the sample, For the The predicted value of samples;

[0146] Step Sb3, calculate the feature gain weight vector , the formula of the feature gain weight of the k-th dimension component is:

[0147]

[0148] in, For the A feature weight based on information gain is used to measure the information gain weight of each feature in all decision trees. is the total number of decision trees, The index of the decision tree, ranging from 1 to , For the Tree mid-band The information gain brought by The index of the feature, ranging from 1 to , For the The first tree Information gain brought by features;

[0149] Step Sb4, generate weighted importance sequence , whose elements are Arrange in descending order and satisfy the following formula:

[0150]

[0151] in, is the original band number, is the feature index.

[0152] Step S213, using PCA feature dimensionality reduction module, Perform orthogonal processing to generate the principal component projection vector ;

[0153] Specifically, in step S23, the PCA feature dimension reduction module generates the principal component projection vector The specific process is as follows:

[0154] Step Sc1, input weighted importance sequence Processing is performed to obtain the spatial-spectral fusion feature matrix , then perform standardization and covariance matrix decomposition to obtain the eigenvalue decomposition result, which is the matrix The eigenvalues and eigenvectors of , select the corresponding Eigenvectors generate the principal component basis vector matrix , satisfying the following formula:

[0155]

[0156]

[0157] in, for The transpose of the matrix, is the covariance matrix, is the normalized spatial-spectral fusion feature matrix, is the number of principal components with cumulative variance ≥ 99%, is the covariance matrix Perform eigenvalue decomposition operation to obtain the eigenvalue decomposition result. is the principal component basis vector matrix;

[0158] Step Sc2, calculate the band weight tensor of each principal component , the top 30 sensitive bands of each principal component are screened by absolute value sorting. The specific formula is as follows:

[0159]

[0160] in, is the principal component basis vector matrix, is the principal component basis vector matrix Middle The principal component corresponding to bands, is the sorting function, For the principal components, through The function obtains the indexes sorted from large to small by the absolute value of the weight, and then takes the first 30 indexes. The bands corresponding to these indexes are the sensitive bands under the principal component.

[0161] Step Sc3, generate principal component projection vector , whose elements are the sensitive band sets after the original band numbers are compensated. The specific formula is as follows:

[0162]

[0163] in, To obtain The first in the collection index values, is the index variable, Principal component projection vector Elements in .

[0164] Step S22: Output the water quality parameter inversion results using the DM-ViT training module , the process is as follows:

[0165] Step S221: Using the DM data enhancement module, the original input samples are used to generate multi-scale enhanced spectral features and generate a spectral feature enhancement training set. ;

[0166] Specifically, in step S24, the DM data enhancement module generates a spectral feature enhancement training set The process is as follows:

[0167] Step Sd1, initialize the diffusion noise scheduling parameters and define the total diffusion time step =1000, generate linear noise scheduling sequence , the specific formula is as follows:

[0168]

[0169] In the formula is a function used to -4 to 0.02, generate the specified A linear sequence of equally spaced values of a quantity;

[0170] And calculate the cumulative attenuation coefficient , the specific formula is as follows:

[0171]

[0172] in, From time step 1 to time step ,right The result of performing a series of multiplications;

[0173] Step Sd2: Construct a U-Net diffusion model with time embedding, and the model input is the spectral feature vector With time step , output noise prediction vector , where the time embedding layer generates a time encoding vector of dimension 256;

[0174] Step Sd3, perform forward diffusion noise training to the original spectrum sample Take random time steps Noise Injection, generating noise-added spectral features , the specific formula is as follows:

[0175]

[0176] And minimize the prediction noise error As the goal, AdamW optimizer is used for model training. The specific formula is as follows:

[0177]

[0178] in, is the original spectrum sample, is the injected noise, To predict the noise model, is the time step;

[0179] Step Sd4, from Gaussian noise Starting from, through reverse iterative calculation, the reverse diffusion sample is generated. The specific formula is as follows:

[0180]

[0181] in, is the initial noise spectrum feature, is a random disturbance term, To generate a set of enhanced spectral feature vectors, is the spectral feature obtained by reverse iterative calculation;

[0182] Step Sd5, the original training set With enhanced sample set Perform weighted fusion to form a spectral feature enhanced training set , the specific formula is as follows:

[0183]

[0184] in, =0.3 is the enhancement factor, To generate a set of enhanced spectral feature vectors.

[0185] Step S222: Use the ViT feature extraction module to perform feature extraction, feature mapping and global average pooling on the spectral feature enhancement training set, and output the water quality parameter inversion result. ;

[0186] Specifically, in step S25, the ViT feature extraction module outputs the water quality parameter inversion result The process is as follows:

[0187] Step Se1: Input spectral feature vector Reconstructed into a 3D tensor ,in, is the spatial window size, is the number of spectral bands;

[0188] Step Se2: construct a network structure containing dual Transformer encoders. Each layer of encoders executes the following formula;

[0189]

[0190]

[0191]

[0192]

[0193]

[0194]

[0195] in, is the encoder level index, is the output of the previous encoder, is the layer normalization operation, is the output of the previous layer Perform layer normalization operation, It is a multi-head attention mechanism. For the general As input, through the multi-head attention mechanism The calculated value, To randomly set the output of some neurons to 0 to prevent overfitting, For Apply Dropout operation and then The result after residual connection (addition) is For The result of layer normalization operation again is, is the activation function, is the fully connected layer, First application Activation function, and then the value calculated by the fully connected layer, For application Operation, then The result after residual connection is used as the output of the current encoder;

[0196] Step Se3, design a dynamic weighted loss function and construct a piecewise weighted mean square error loss function , whose expression is:

[0197]

[0198] In the formula is the number of training samples, For the The true value of the sample, For the The predicted value of the sample, is the weight function, is the mean square error, regularization coefficient =0.01, is the weight matrix The square of the L2 norm of ;

[0199] Among them, the weight function The formula is as follows:

[0200]

[0201] in, is the concentration of water quality parameters, regularization coefficient =0.01;

[0202] Step Se4, using the adaptive learning rate training strategy, the Nadam optimizer initializes the learning rate = 0.001, and define the dynamic decay rule of learning rate: when the validation loss does not improve for 10 epochs, the learning rate is updated to =0.1 , the minimum learning rate is limited to =0.0001;

[0203] Step Se5, multi-scale feature fusion prediction, global average pooling of the encoder output, after Dropout and full connection layer mapping, output the total nitrogen concentration inversion result .

[0204] Step S23: Use the visualization inversion module to process the water quality parameter inversion results and output the nitrogen and phosphorus concentration spatial distribution map of the target water area. ;

[0205] Specifically, in step S23, the visualization inversion module outputs the spatial distribution map of nitrogen and phosphorus concentrations in the target water area. The process is as follows:

[0206] Step Sf1: Generate a dynamic mask for the hyperspectral image and read the input hyperspectral image , construct a dynamic mask matrix based on the band threshold condition , satisfying the following formula:

[0207]

[0208] in, =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;

[0209] Step Sf2, pixel-level normalization and prediction: Pixel points, extract the spectrum vector , and then normalized by the pre-trained MinMaxScaler normalizer, the formula is as follows:

[0210]

[0211] In the formula is the spectral vector processed by the MinMaxScaler normalizer, is a pre-trained MinMaxScaler normalizer object, is the normalization transfer function of the MinMaxScaler normalizer, is the original spectrum vector The transpose of

[0212] And input ViT inversion model Predicted nitrogen and phosphorus concentrations , the formula is as follows:

[0213]

[0214] Step Sf3, reconstruct the spatial distribution map, map the prediction results to the original image space dimension, and generate the concentration matrix , the rules are:

[0215]

[0216] In the formula Indicates that no concentration prediction is made for this location or there is no valid data;

[0217] Step Sf4, update the output parameters according to the input image metadata meta Writing a single-band raster file O, and use the row-column traversal algorithm to fill the predicted value pixel by pixel to generate the spatial distribution map of nitrogen and phosphorus concentrations in the target waters ;

[0218] Step Sf5, distributed storage management: build a hierarchical output directory structure, recursively create directory functions based on the input file path to ensure data storage integrity, and output the spatial distribution map of nitrogen and phosphorus concentrations in the target water area .

[0219] In step S3, the samples in the data set are input into the water quality parameter inversion model, the total loss function value is calculated, back propagation is performed, the model weights are optimized using the AdamW optimizer and the dynamic learning rate strategy, and the final water quality parameter inversion model is obtained after multiple rounds of training;

[0220] Specifically, in the regression prediction stage of the ViT feature extraction module, the weighted mean square error of all samples and the regularization loss are jointly optimized, and the total loss is The calculation is as follows:

[0221]

[0222] in, is the concentration-sensitive weight function, and the formula for defining the rule is:

[0223]

[0224] In the formula =0.01 is the regularization strength coefficient, which acts on the entire set of trainable parameters of the model The L2 norm sum of squares, is the number of training batch samples, and Respectively The actual concentration value of each sample and the model predicted value.

[0225] Step S4: Based on the trained water quality parameter inversion model, the hyperspectral image to be processed is input and the spatial distribution map of nitrogen and phosphorus concentrations in the target water area is output.

[0226] The present invention constructs a UAV hyperspectral remote sensing dataset and uses Chitian Reservoir water quality monitoring data and diffusion enhancement samples for model training; constructs a water quality inversion model based on spatial-spectral fusion, the model machine learning feature engineering module, DM-ViT training module and visualization inversion module; inputs sample data of the dataset into the model, performs feature engineering, diffusion enhancement and spectral feature fusion, performs backpropagation through a weighted loss function and a Nadam optimizer, optimizes network parameters in combination with a learning rate dynamic decay strategy, and obtains the final enhanced water quality inversion model after training; based on the trained model, inputs hyperspectral remote sensing images, and outputs sub-hundred-meter precision total nitrogen and total phosphorus concentration distribution maps and pollution hotspot location results. By integrating UAV hyperspectral imaging and deep learning technology, the present invention significantly improves the generalization ability of small sample scenarios based on data enhancement of the diffusion model, realizes collaborative modeling of spectral-spatial features through the ViT network, and innovatively introduces a dynamic weighted loss mechanism to effectively optimize the prediction accuracy of low-concentration parameters, thereby improving the efficiency and accuracy of the non-optically active water quality parameter inversion task.

[0227] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present application.

[0228] Obviously, those skilled in the art may make various changes and modifications to this application without departing from the spirit and scope of this application. Thus, if these modifications and variations of this application fall within the scope of the claims of this application and their equivalents, this application is intended to include these modifications and variations.

Claims

1. A method for inverting non-optically active water quality parameters based on hyperspectral images, characterized in that: include: Step S1, collect hyperspectral images and synchronously measured water quality parameters to construct a data set; Step S2: construct a non-optically active water quality parameter inversion model based on hyperspectral images to achieve inversion of 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, using the machine learning feature engineering module to generate the principal component projection vector The process is as follows: Step S211: Use the random forest feature selection module to extract features from the input hyperspectral image and output the band sensitive subset ; Step S212: Using XGBoost feature importance analysis module, Perform gain weight calculation and output weighted importance sequence ; Step S213, using PCA feature dimensionality reduction module, Perform orthogonal processing to generate the principal component projection vector ; Step S22: Output the water quality parameter inversion results using the DM-ViT training module , the process is as follows: Step S221: Using the DM data enhancement module, the original input samples are used to generate multi-scale enhanced spectral features and generate a spectral feature enhancement training set. ; Step S222: Use the ViT feature extraction module to perform feature extraction, feature mapping and global average pooling on the spectral feature enhancement training set, and output the water quality parameter inversion result. ; Step S23: Use the visualization inversion module to process the water quality parameter inversion results and output the nitrogen and phosphorus concentration spatial distribution map of the target water area. ; In step S3, the samples in the data set are input into the water quality parameter inversion model, the total loss function value is calculated, back propagation is performed, the model weights are optimized using the AdamW optimizer and the dynamic learning rate strategy, and the final water quality parameter inversion model is obtained after multiple rounds of training; In step S23, the visualization inversion module outputs the spatial distribution map of nitrogen and phosphorus concentrations in the target water area. The process is as follows: Step Sf1: Generate a dynamic mask for the hyperspectral image and read the input hyperspectral image , construct a dynamic mask matrix based on the band threshold condition ; Step Sf2, pixel-level normalization and prediction, for Pixel points, extract the spectrum vector , and then normalized by the pre-trained MinMaxScaler normalizer; Step Sf3, reconstruct the spatial distribution map, map the prediction results to the original image space dimension, and generate the concentration matrix ; Step Sf4, update the output parameters according to the input image metadata meta Y Writing a single-band raster file O , and use the row-column traversal algorithm to fill the predicted value pixel by pixel to generate the spatial distribution map of nitrogen and phosphorus concentrations in the target waters ; Step Sf5: Perform distributed storage management, build a hierarchical output directory structure, recursively create directory functions based on the input file path to ensure data storage integrity, and output the spatial distribution map of nitrogen and phosphorus concentrations in the target water area. ; Step S4: Based on the trained water quality parameter inversion model, the hyperspectral image to be processed is input and the spatial distribution map of nitrogen and phosphorus concentrations in the target water area is output.

2. The method for inverting non-optically active water quality parameters based on hyperspectral images according to claim 1, characterized in that: In step S211, the random forest feature selection module outputs the band sensitive subset The specific process is as follows: Step Sa1: convert the original hyperspectral image data matrix Reconstructed into a joint spatial-spectral feature tensor , generate the input feature matrix through window mean sampling and standardization , the formula is as follows: ; in, Is a function used to convert the original hyperspectral image data matrix Perform dimension reconstruction, It is a window mean sampling operation used to reconstruct Calculate the mean of each band, To standardize processing operations, is the mean value of each band, is the standard deviation of each band; Step Sa2: Build a random forest regression model containing 100 decision trees and use the feature importance ranking function Calculate the band weight, the formula is as follows: ; in, is the feature importance score of band b, that is, the band weight, T is the total number of decision trees, where , is the true value, For the t The predicted value of each tree, is the predicted value after band b is replaced, is the mean square error between the predicted value and the true value; Step Sa3: Select the band indexes in descending order of feature importance scores to generate the band sensitive subset , satisfying the following formula: ; in, is the sorting function, Sorting is performed and the index value after sorting is returned. are feature indices in descending order of importance, Used to organize the band numbers, For the band.

3. The method for inverting non-optically active water quality parameters based on hyperspectral images according to claim 1, characterized in that: In step S212, the XGBoost feature importance analysis module outputs a weighted importance sequence The specific process includes: Step Sb1, sensitive subset of input band Perform standardization to generate a normalized feature matrix with zero mean and unit variance , the calculation formula is: ; in, is a subset of sensitive bands, is the mean of the sensitive band subset, is the standard deviation of the sensitive band subset; Step Sb2: Build an XGBoost regression model using an objective function with a regularization term. The definition formula is: ; in, for Regularization term, for Regularization coefficient, for Regularization term, for Regularization coefficient, n=100 represents the number of samples, For the The true value of each sample, i.e. the concentration of water quality parameters, For the The predicted value of samples; Step Sb3, calculate the feature gain weight vector , the formula of the feature gain weight of the k-th dimension component is: ; in, For the feature weights based on information gain, is the total number of decision trees, The index of the decision tree, ranging from 1 to T , For the Tree mid-band The information gain brought by The index of the feature, ranging from 1 to , For the The first tree Information gain brought by features; Step Sb4, generate weighted importance sequence , whose elements are Arrange in descending order and satisfy the following formula: ; in, is the original band number, is the feature index.

4. The method for inverting non-optically active water quality parameters based on hyperspectral images according to claim 1, characterized in that: In step S213, the PCA feature dimension reduction module generates the principal component projection vector The specific process is as follows: Step Sc1, input weighted importance sequence Processing is performed to obtain the spatial-spectral fusion feature matrix , then perform standardization and covariance matrix decomposition to obtain the eigenvalue decomposition result, which is the matrix The eigenvalues and eigenvectors of , select the corresponding Eigenvectors generate the principal component basis vector matrix , satisfying the following formula: ; in, for The transpose of the matrix, is the covariance matrix, is the normalized spatial-spectral fusion feature matrix, k is the number of principal components with cumulative variance ≥ 99%, is the covariance matrix Perform eigenvalue decomposition operation to obtain the eigenvalue decomposition result. is the principal component basis vector matrix; Step Sc2, calculate the band weight tensor of each principal component , the top 30 sensitive bands of each principal component are screened by absolute value sorting. The specific formula is as follows: ; in, is the principal component basis vector matrix, is the principal component basis vector matrix Middle The principal component corresponding to bands, is the sorting function, For the principal components, through The function obtains the indexes sorted from large to small by the absolute value of the weight, and then takes the first 30 indexes. The bands corresponding to these indexes are the sensitive bands under the principal component. Step Sc3, generate principal component projection vector , whose elements are the sensitive band sets after the original band numbers are compensated. The specific formula is as follows: ; in, To obtain The first in the collection index values, is the index variable, Principal component projection vector Elements in .

5. The method for inverting non-optically active water quality parameters based on hyperspectral images according to claim 1, characterized in that: In step S221, the DM data enhancement module generates a spectral feature enhancement training set The process is as follows: Step Sd1, initialize the diffusion noise scheduling parameters and define the total diffusion time step , generating a linear noise scheduling sequence , the specific formula is as follows: ; In the formula is a function used in arrive Between the two specified endpoint values, generate the specified A linear sequence of equally spaced values of a quantity; And calculate the cumulative attenuation coefficient , the specific formula is as follows: ; in, From time step 1 to time step ,right The result of performing a continuous multiplication; Step Sd2: Construct a U-Net diffusion model with time embedding, and the model input is the spectral feature vector With time step , output noise prediction vector , where the time embedding layer generates a time encoding vector of dimension 256; Step Sd3, perform forward diffusion noise training to the original spectrum sample Take random time steps Noise Injection, generating noise-added spectral features , the specific formula is as follows: ; And minimize the prediction noise error As the goal, AdamW optimizer is used for model training. The specific formula is as follows: ; in, is the original spectrum sample, is the injected noise, To predict the noise model, is the time step; Step Sd4, from Gaussian noise Starting from, through reverse iterative calculation, the reverse diffusion sample is generated. The specific formula is as follows: ; in, is the initial noise spectrum feature, is a random disturbance term, To generate a set of enhanced spectral feature vectors, is the spectral feature obtained by reverse iterative calculation; Step Sd5, the original training set With enhanced sample set Perform weighted fusion to form a spectral feature enhanced training set , the specific formula is as follows: ; in, is the enhancement factor, To generate a set of enhanced spectral feature vectors.

6. The method for inverting non-optically active water quality parameters based on hyperspectral images according to claim 1, characterized in that: In step S222, the ViT feature extraction module outputs the water quality parameter inversion result. The process is as follows: Step Se1: Input spectral feature vector Reconstructed into a 3D tensor ,in, is the spatial window size, is the number of spectral bands; Step Se2: construct a network structure containing dual Transformer encoders. Each layer of encoders executes the following formula; ; in, l is the encoder level index, is the output of the previous encoder, is the layer normalization operation, is the output of the previous layer Perform layer normalization operation, It is a multi-head attention mechanism. For the general As input, the value calculated by the multi-head attention mechanism, To randomly set the output of some neurons to 0 to prevent overfitting, For application Operation, then The result after residual connection, For The result of layer normalization operation again is, is the activation function, is the fully connected layer, First application Activation function, and then the value calculated by the fully connected layer, For application Operation, then The result after residual connection is used 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 , whose expression is: ; In the formula is the number of training samples, For the The true value of each sample, i.e. the concentration of water quality parameters, For the The predicted value of the sample, is the weight function, is the mean square error, regularization coefficient , is the weight matrix of The square of the norm; Among them, the weight function The formula is as follows: ; in, For the The true value of the sample, that is, the concentration of water quality parameters, regularization coefficient ; Step Se4, using the adaptive learning rate training strategy, the Nadam optimizer initializes the learning rate , and define the dynamic attenuation rule of learning rate: when the validation loss does not improve for 10 epochs, the learning rate is updated to , the minimum learning rate is limited to ; Step Se5, multi-scale feature fusion prediction, global average pooling of the encoder output, after Dropout and full connection layer mapping, output the total nitrogen concentration inversion result .

7. The method for inverting non-optically active water quality parameters based on hyperspectral images according to claim 1, characterized in that: In step S23, the visualization inversion module outputs the spatial distribution map of nitrogen and phosphorus concentrations in the target water area. The process is as follows: Step Sf1: Generate a dynamic mask for the hyperspectral image and read the input hyperspectral image , construct a dynamic mask matrix based on the band threshold condition , satisfying the following formula: ; in, 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 Pixel points, extract the spectrum vector , and then normalized by the pre-trained MinMaxScaler normalizer, the formula is as follows: ; In the formula is the spectral vector processed by the MinMaxScaler normalizer, is a pre-trained MinMaxScaler normalizer object, is the normalization transfer function of the MinMaxScaler normalizer, is the original spectrum vector The transpose of And input ViT inversion model Predicted nitrogen and phosphorus concentrations , the formula is as follows: ; Step Sf3, reconstruct the spatial distribution map, map the prediction results to the original image space dimension, and generate the concentration matrix , the rules are: ; In the formula express The pixel point at this time does not perform concentration prediction or has no valid data; Step Sf4, update the output parameters according to the input image metadata meta Y Writing a single-band raster file O , and use the row-column traversal algorithm to fill the predicted value pixel by pixel to generate the spatial distribution map of nitrogen and phosphorus concentrations in the target waters ; Step Sf5: Perform distributed storage management, build a hierarchical output directory structure, recursively create directory functions based on the input file path to ensure data storage integrity, and output the spatial distribution map of nitrogen and phosphorus concentrations in the target water area. .

8. The method for inverting non-optically active water quality parameters based on hyperspectral images according to claim 1, characterized in that: In step S3, the total loss function value of the model is calculated The process is as follows: In the regression prediction stage of the ViT feature extraction module, the weighted mean square error and regularization loss of all samples are jointly optimized, and the total loss The calculation is as follows: ; in, is the concentration-sensitive weight function, and the formula for defining the rule is: ; In the formula is the regularization strength coefficient, which acts on the set of all trainable parameters of the model of norm sum of squares, is the number of training batch samples, and Respectively The actual concentration value of each sample and the model predicted value.

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, the method according to any one of claims 1 to 8 is implemented.

Citation Information

Patent Citations

  • 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