A water quality prediction method based on invariance-specificity decoupling and dynamic adaptive fusion
The water quality prediction method, which integrates invariance-specificity decoupling and dynamic adaptive fusion, solves the spatial and temporal lag problems of water quality monitoring in existing technologies, achieves high-precision prediction and interpretability analysis of water quality parameters, and improves the stability and adaptability of the model.
Patent Information
- Application Number
- CN202611131312.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-29
- Publication Date
- 2026-11-17
- Estimated Expiration
- 2046-07-29
AI Technical Summary
Existing water quality monitoring methods are difficult to capture the distribution characteristics and real-time changes of pollutants in water bodies in terms of space and time. Furthermore, traditional and deep learning methods lack predictive stability under environmental disturbances, and cross-modal fusion strategies lack adaptability and are difficult to adapt to the ecodynamic characteristics of different water quality indicators.
A water quality prediction method based on invariance-specific decoupling and dynamic adaptive fusion is adopted. By extracting modal features from multimodal datasets, decoupling and separating them and adaptive weighted fusion, combined with SHAP analysis, high-precision prediction and interpretable analysis of water quality parameters are achieved.
It significantly improves the prediction accuracy and robustness of water quality parameters, enhances the model's generalization ability under different hydrological scenarios through dynamic adaptive fusion capability, and provides multi-dimensional interpretability analysis, thereby enhancing the model's credibility and acceptability.
Smart Images

Figure CN122654989B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of computer vision and environmental monitoring technology, specifically to a water quality prediction method based on invariance-specific decoupling and dynamic adaptive fusion. Background Technology
[0002] With the rapid development of industrialization and urbanization, water pollution has become increasingly serious. Chlorophyll a (Chl-a) and chemical oxygen demand (COD) are core indicators of aquatic ecosystem health and water quality management. Their accurate and real-time monitoring is crucial for early warning, precise pollution control and sustainable water resource management.
[0003] Traditional monitoring methods rely on on-site sampling and laboratory analysis, such as spectrophotometry for Chl-a and dichromate titration for COD. While these methods offer reliable accuracy for individual samples, their inherent limitations are equally apparent: spatially, discrete sampling cannot capture the spatial distribution characteristics of heterogeneous pollutants in large water bodies; temporally, the sampling and laboratory analysis cycles are long, resulting in monitoring results that lag significantly behind real-time water quality changes, making it difficult to meet rapid response requirements; and economically and technically, traditional methods are costly, labor-intensive, and susceptible to subjective interference from operators, making them difficult to deploy continuously in large-scale, long-term monitoring.
[0004] In recent years, deep learning technology has been widely used in the field of water quality assessment, but existing methods still have many bottlenecks. Convolutional Neural Network (CNN)-based methods are highly sensitive to environmental disturbances such as cloud cover and changes in illumination, resulting in insufficient prediction stability; Long Short-Term Memory (LSTM)-based methods rely solely on time-series data, lacking visual information support and making it difficult to capture rapidly changing events such as sudden algal blooms; traditional machine learning models such as Random Forest (RF) and Extreme Gradient Boosting (XGBoost) treat features as static inputs and cannot adapt to the dynamic changes in signal importance across different concentration ranges.
[0005] Multimodal learning has become an important development direction in the field of water quality monitoring, as it compensates for the insufficient information of a single modality by fusing image information with water quality parameter information. However, existing cross-modal fusion strategies are generally too simplistic, typically just directly concatenating or weighting the features of each modality, lacking dynamic adaptation to modal-specific features. The fusion model struggles to adaptively adjust the modal contribution based on the distribution of sample features, limiting its generalization ability across different hydrological scenarios. Furthermore, existing methods rarely employ ablation experiments for mechanistic analysis, and the functional contributions of each module remain unclear, hindering further optimization of the model architecture.
[0006] A more fundamental problem lies in the fact that existing frameworks typically handle cross-modal interactions across all prediction targets in a uniform manner, neglecting the fundamentally different ecodynamic characteristics exhibited by different water quality indicators in aquatic systems: chemical oxygen demand (COD), as a comprehensive indicator of the degree of organic pollution, shows relatively stable changes and high ecological stability; while chlorophyll a concentration is highly variable in time and space due to the interaction of multiple factors such as light, temperature, and nutrients. These structural differences between indicators determine that cross-modal signals exhibit different patterns at the feature expression level. A uniform fusion approach is insufficient to adapt to the characteristics of different indicators, necessitating the design of differentiated feature processing strategies.
[0007] Therefore, there is an urgent need for a multimodal fusion method that can explicitly separate cross-modal shared information from modal-specific information and adaptively adjust modal weights according to the sample feature distribution, so as to achieve high-precision and robust synchronous prediction of COD and Chl-a. Summary of the Invention
[0008] To overcome the shortcomings of existing technologies, the present invention aims to provide a water quality prediction method based on invariance-specific decoupling and dynamic adaptive fusion. This method can achieve high-precision prediction and interpretable analysis of water quality parameters by extracting modal features, decoupling and separating, adaptively weighting and fusing, and interacting across modalities from RGB images of the water surface and water quality parameters.
[0009] To achieve the objective of this invention, the following solution is adopted: The water quality prediction method based on invariance-specific decoupling and dynamic adaptive fusion includes the following steps: S1: Collect a multi-time, multi-modal dataset containing RGB image data of the water surface and water quality parameter data from multiple geographical monitoring stations; S2: Preprocess the multimodal dataset to obtain a training set, a validation set, and a test set; S3: Construct an invariant-specific decoupled multimodal model, use the model to extract modal features from the RGB images of the water surface and water quality parameters in the training set, then decouple and separate the shared features and unique features of each modal feature, and then perform adaptive weighted fusion and cross-modal interaction on all decoupled features to output the predicted value of water quality parameters. S4: Construct a multi-objective joint loss function based on the predicted and actual values of the water quality parameters, optimize and train the model, and dynamically save the optimal model through the validation set; S5: Based on the optimal model, predict the test set to obtain the final prediction results of chlorophyll a concentration and chemical oxygen demand, and output multi-dimensional interpretability analysis results in combination with SHAP analysis.
[0010] Furthermore, in step S1, the multimodal dataset covers water surface images collected by fixed RGB cameras at multiple representative monitoring stations in the target watershed, including various lighting scenarios, collected at multiple time periods every day, and finally constructs a multimodal dataset containing multiple valid paired samples.
[0011] Further, in step S2, the preprocessing includes: S2.1: Divide the preprocessed multimodal dataset into training set, validation set and test set by stratified sampling in a ratio of 8:1:1; S2.2: Perform Z-score standardization on all water quality input features in the training set, and apply the calculated mean and standard deviation to the validation set and the test set for standardization, respectively; S2.3: Apply logarithmic transformation to the predicted target values of chemical oxygen demand and chlorophyll a; S2.4: Implement data augmentation strategies on the images in the training set, including random horizontal flipping, brightness and contrast adjustment, and Gaussian blur; S2.5: Perform resampling with replacement on the low-frequency layers in the training set.
[0012] Further, in step S3, the modal feature extraction includes: Feature extraction was performed on the RGB image of the water surface using the ViT-B / 16 model pre-trained on the ImageNet-1k dataset. The 768-dimensional features output by ViT were mapped to 128 dimensions through a linear projection layer to obtain the initial features of the image. Feature extraction is performed on the water quality parameters, and the 8-dimensional parameter vector after Z-score standardization is directly used as the initial features of the water quality parameters.
[0013] Furthermore, in step S3, the decoupling and separation are achieved through an invariant encoder and a specific encoder. The invariant encoder is used to extract cross-modal shared features, and the specific encoder is used to retain modality-specific features. The initial image features are input into the invariant encoder and the specific encoder, respectively, to obtain image invariant features and image specific features; The initial features of the water quality parameters are input into the invariant encoder and the specific encoder, respectively, to obtain the invariant features of the water quality parameters and the specific features of the water quality parameters. Both the invariant encoder and the specific encoder adopt a two-layer multilayer perceptron structure with 128 hidden units, ReLU activation function, and 128-dimensional output. The invariant encoder and the specific encoder use independent parameters.
[0014] Further, in step S3, the adaptive weighted fusion includes: The norm of the sum of invariant and specific features for each modality is calculated separately. The weight of each modality is determined according to the proportion of the norm of each modality to the total norm. The sum of invariant and specific features of each modality is weighted using the weight of each modality. The weighted modal features are then concatenated to obtain a fused feature. The fused feature is then input into the prediction head after cross-modal interaction, and the predicted value of the water quality parameter is output.
[0015] Further, in step S4, the multi-objective joint loss function includes the main task prediction loss, invariance alignment loss, and orthogonality loss; the main task prediction loss uses mean squared error, the optimizer is Adam, and the learning rate scheduler uses cosine annealing. Specific steps include: S4.1: Start the cosine annealing learning rate scheduler so that the learning rate during training changes periodically between the preset maximum and minimum values according to the cosine function. S4.2: The invariant-specific decoupled multimodal model is trained using the training set, and the learning rate scheduler dynamically adjusts the current learning rate synchronously during the training process; S4.3: At the end of each epoch, evaluate the model performance on the validation set, monitor the coefficient of determination metric on the validation set, and save the best-performing model parameters as the optimal model.
[0016] Further, in step S5, the specific steps for predicting the test set based on the optimal model include: S5.1: Obtain the preprocessed test set data and input it into the optimal model, wherein the input variables are the RGB image of the water surface and the 8-dimensional water quality parameter vector, and the output variables are the prediction results of chemical oxygen demand and chlorophyll a; S5.2: Use the optimal model to make predictions, calculate and record the model's performance metrics on the test set, including the coefficient of determination R², root mean square error RMSE, and mean absolute error MAE. S5.3: Generate a comparison chart of the predicted results and the true values on the test set, as well as a residual chart, for visualization analysis.
[0017] Furthermore, in step S5, the specific steps of the SHAP analysis include: S5.4: Fix the features of the water surface RGB image to their mean on the training set, so that the subsequent SHAP analysis focuses on the independent contribution of each water quality parameter to the prediction; use SHAP to generate a feature importance analysis map to quantify the contribution of each water quality parameter to the prediction. S5.5: Randomly select a preset number of samples from the training set, replace the features of the RGB images of the water surface with the mean, and thus construct the SHAP background dataset; generate an interpretability analysis report, including dynamic modal weight distribution analysis and ablation experiment results, to intuitively display the decision basis of the model; S5.6: Based on the background dataset, calculate the SHAP value of each water quality parameter for the test set samples, identify the features that contribute the most to the prediction of chemical oxygen demand and chlorophyll a according to the SHAP value, and generate feature importance ranking and SHAP value distribution map.
[0018] Furthermore, in step S5, the specific steps of SHAP feature importance analysis include: By fixing the mean features of image modalities, the contribution of water quality parameters to prediction is focused. The SHAP background dataset is sampled from the training set, containing 30 randomly selected samples to ensure representative feature distribution. SHAP values for each feature are calculated for the test set samples, identifying the features that contribute most to COD and Chl-a predictions, generating feature importance rankings and SHAP value distribution maps, thereby enhancing the model's interpretability and reliability.
[0019] Furthermore, in step S5, the multi-dimensional interpretability analysis results also include dynamic modal weight distribution analysis and ablation experiment results; The dynamic modal weight distribution analysis shows the weight distribution of the water surface RGB image and the water quality parameters in different concentration ranges; The ablation experiment quantifies the contribution of each operation to the prediction performance by removing the decoupling and separation operations of the shared features and unique features, as well as the cross-modal interaction operations.
[0020] Compared with the prior art, the beneficial effects of the present invention are as follows: 1. This invention significantly improves the prediction accuracy and robustness of water quality parameters. By constructing an invariant-specific decoupled multimodal model, this invention extracts modal features from both the RGB image of the water surface and the water quality parameters. It then explicitly decouples and separates shared and unique features among the modal features, overcoming the shortcomings of traditional single-modal methods (insufficient information) and existing simple stitching fusion strategies (difficulty in capturing cross-modal complementary information). Through adaptive weighted fusion and cross-modal interaction, the model can fully utilize the synergistic complementary relationship between the visual information of the image modality and the numerical information of the water quality parameter modality, maintaining stable prediction performance under varying water surface illumination and different hydrological scenarios. Experimental results show that the present invention achieves a determination coefficient R² of 0.846 and a root mean square error of 0.411 mg / L for predicting chemical oxygen demand, and a determination coefficient R² of 0.746 and a root mean square error of 1.813 μg / L for predicting chlorophyll a. Compared with the single-modal method, the R² is improved by 0.040~0.104 and the root mean square error is reduced by 7.0%~25.0%, which is significantly better than the existing baseline model.
[0021] 2. This invention possesses dynamic adaptive fusion capabilities. By adaptively weighting and fusing all decoupled features, this invention dynamically determines modal contribution weights based on the norm ratio of each modal feature vector. This achieves adaptive modal importance adjustment for samples without introducing additional learnable parameters, avoiding the overfitting risk of learning-based gating mechanisms on medium-sized datasets. For the relatively stable chemical oxygen demand (COD), the model automatically achieves balanced fusion of image and water quality parameters; for the highly variable chlorophyll a, the model automatically prioritizes image modal weights to capture visual signals such as algal color changes and surface textures, enhancing the model's robustness and generalization ability under different concentration scenarios.
[0022] 3. This invention provides multi-dimensional interpretability analysis. While outputting the final prediction results, this invention combines SHAP analysis to quantify and rank the importance of water quality parameter characteristics, and outputs dynamic modal weight distribution analysis and ablation experiment results. This intuitively demonstrates the model's decision-making basis and the contribution of each functional component, overcoming the lack of interpretability in existing deep learning water quality prediction models. It enhances the model's credibility and acceptability in practical monitoring applications, and provides data support for subsequent lightweight model deployment and key feature selection. Attached Figure Description
[0023] Figure 1 This is a flowchart of the water quality prediction method based on invariance-specific decoupling and dynamic adaptive fusion in an embodiment of the present invention; Figure 2 This is a schematic diagram of the architecture of the invariance-specific decoupling multimodal framework in an embodiment of the present invention; Figure 3This is a comparison chart and residual chart of the predicted and actual values of COD and Chl-a in an embodiment of the present invention; Figure 4 This is a comparison chart of prediction performance for different modal configurations in embodiments of the present invention; Figure 5 This is a comparison chart of the ablation performance of the core components in the embodiments of the present invention; Figure 6 This is a dynamic modal weight distribution diagram in an embodiment of the present invention; Figure 7 This is a feature importance analysis diagram based on SHAP in an embodiment of the present invention. Detailed Implementation
[0024] The present invention will now be further described in conjunction with the accompanying drawings and specific embodiments. It should be noted that, without conflict, the various embodiments or technical features described below can be arbitrarily combined to form new embodiments.
[0025] like Figure 1-7 As shown, this invention provides a water quality prediction method based on invariance-specific decoupling and dynamic adaptive fusion. This method improves the prediction accuracy of water quality parameters under different environmental conditions by integrating an invariance-specific decoupling architecture, a dynamic modal weight adaptive strategy, and a Transformer interaction layer. It is suitable for the simultaneous accurate prediction and interpretability analysis of chlorophyll a (Chl-a) and chemical oxygen demand (COD).
[0026] like Figure 1 As shown in the figure, the water quality prediction method based on invariance-specific decoupling and dynamic adaptive fusion according to an embodiment of the present invention includes the following steps: S1: Collect a multi-time, multi-modal dataset containing RGB image data of the water surface and water quality parameter data from multiple geographical monitoring stations.
[0027] S2: Preprocess the multimodal dataset to obtain the training set, validation set, and test set.
[0028] S3: Construct an invariant-specific decoupled multimodal model. Use the model to extract modal features from the RGB images of the water surface and water quality parameters in the training set. Then, decouple and separate the shared features and unique features of each modal feature. Finally, perform adaptive weighted fusion and cross-modal interaction on all decoupled features to output the predicted value of the water quality parameters.
[0029] S4: Construct a multi-objective joint loss function based on the predicted and actual values of the water quality parameters, optimize and train the model, and dynamically save the optimal model through a validation set.
[0030] S5: Based on the optimal model, predict the test set to obtain the final prediction results of chlorophyll a concentration and / or chemical oxygen demand, and output multi-dimensional interpretability analysis results in combination with SHAP analysis.
[0031] The following is a more detailed description of the water quality prediction method based on invariance-specific decoupling and dynamic adaptive fusion according to embodiments of the present invention.
[0032] The specific details of the water quality prediction method based on invariance-specific decoupling and dynamic adaptive fusion according to embodiments of the present invention are as follows: A multi-time-period, multi-modal dataset containing RGB image data of the water surface and water quality parameters was collected from multiple geographical monitoring stations. The multi-modal dataset was preprocessed, including Z-score normalization, logarithmic transformation, data augmentation, and oversampling balancing, and stratified sampling was performed according to a preset ratio. An invariant-specific decoupled multi-modal model was constructed, and cross-modal feature representation and fusion were optimized through a modal feature extraction module, an invariant-specific representation decoupling module, and a dynamic fusion prediction module. A multi-objective joint loss function was designed, and a dynamic modal weight adaptive strategy and a Transformer interaction layer were used to optimize and train the model. The optimal weights were dynamically saved through a validation set. Based on the trained model, chlorophyll a concentration and chemical oxygen demand were predicted simultaneously, and multi-dimensional interpretability analysis results were output using SHAP analysis.
[0033] In this embodiment, the multi-time-period, multi-modal dataset containing water surface RGB image data and water quality parameter data collected through multiple geographical monitoring stations in step S1 is as follows: The collected data comes from monitoring stations in different geographical locations and at different times, ensuring that the data covers samples under various environmental conditions.
[0034] Specifically, acquiring multimodal data includes: The target watershed was selected as the study area. This region has a subtropical monsoon climate with an annual rainfall of 1800 mm and a rich hydrological network. Based on the principles of representative coverage of the watershed, priority for hydrologically sensitive areas, and diversity of spatiotemporal sampling, fixed RGB camera equipment was deployed at multiple representative monitoring stations in the main sub-watersheds.
[0035] A strategy of timed data collection at 8:00, 12:00, and 16:00 daily was adopted to capture the daily variation patterns of water quality. Water surface images were acquired using fixed Hikvision DS-2DE2Q140MY-TIGL2 RGB cameras deployed at each site, supporting a maximum resolution of 2560×1440 pixels at 25fps; image acquisition and water quality sampling were synchronized instantaneously.
[0036] Nine core water quality indicators were measured using corresponding standard methods: Chemical oxygen demand (COD, dichromate method, GB 11892-89), chlorophyll a (Chl-a, fluorescence method, HJ 897-2017), ammonia nitrogen (NH3-N, Nessler's reagent spectrophotometric method, HJ 536-2009), total phosphorus (TP, ammonium molybdate spectrophotometric method, GB 11893-89), pH (glass electrode method, GB / T 6920-86), dissolved oxygen (DO, fluorescence quenching method, GB / T 11913-89), conductivity (Cond, four-wire electrode method, GB / T 6908-2018), turbidity (Turb, 90-degree scattering method, GB / T 13200-91), and water temperature (Temp, resistance temperature method, GB / T 13195-91).
[0037] After data preprocessing and removal of invalid data, a multimodal dataset containing 1949 valid paired samples was finally constructed. COD and Chl-a were selected as dual prediction targets: for COD prediction, the input features included seven core water quality indicators (pH, DO, Cond, Temp, Turb, TP, NH3-N) plus Chl-a; for Chl-a prediction, the input features included the same seven core water quality indicators plus COD.
[0038] In this embodiment, the preprocessing of the collected multimodal data in step S2 includes the following specific steps: S2.1: The effective samples are divided into training set, validation set and test set in a ratio of 8:1:1. This division is performed by stratified sampling based on COD and Chl-a concentrations (each indicator is divided into 5 intervals according to the 0-20%, 20%-40%, 40%-60%, 60%-80%, and 80%-100% quantiles) to maintain the representativeness of the distribution of different concentration ranges.
[0039] S2.2: All water quality input features are standardized using Z-scores. The mean and standard deviation are calculated only from the training set and then applied to the validation and test sets. The standardization formula is: in, and These are the mean and standard deviation of the corresponding features in the training set, respectively.
[0040] S2.3: Apply a logarithmic transformation to the two predicted targets to mitigate the right-skewed distribution: S2.4: Perform data augmentation on the training set images (random horizontal flip, ±20% brightness / contrast adjustment, Gaussian blur with a probability of 0.3) to enhance generalization ability, while retaining the original images during the validation and testing phases.
[0041] S2.5: Resample the low-frequency layers (layers with a sample ratio of <8% in a single metric layer) in the training set with replacement, and resample each low-frequency layer to 10% of the training set size.
[0042] In this embodiment, the construction of the invariant-specific decoupled multimodal model in step S3 includes initializing the ViT-B / 16 pre-trained weights, adding an invariant encoder and a specific encoder, and defining the loss function, optimizer, and learning rate scheduler.
[0043] Specifically, step S3 involves constructing an invariant-specific decoupled multimodal model suitable for water quality parameter prediction, such as... Figure 2 The diagram illustrates the architecture of an invariant-specific decoupling multimodal framework, which integrates three core functionalities: feature extraction, invariant-specific decoupling, and dynamic fusion with Transformer interaction. The specific steps include: S3.1: Image modality feature extraction uses ViT-B / 16 (Vision Transformer Base model, 16×16 patch size), pre-trained on the ImageNet-1k dataset, as the feature extractor. Its global self-attention mechanism can capture non-locally distributed cues in water surface images more effectively than CNN encoders with local receptive fields. The 768-dimensional output of ViT is projected onto a 128-dimensional feature space through a linear layer. The image feature extraction formula is: in, The feature matrix output by the image branch. For the feature extraction process of the pre-trained ViT-B / 16 model, The input is the water surface image tensor. For linear projection layers, Batch size; S3.2: Water quality parameter modal feature extraction directly inputs the Z-score-normalized 8-dimensional parameter vector to form a structured feature matrix: This process preserves the numerical semantic information of water quality parameters while eliminating the interference of dimensional differences on model training.
[0044] S3.3: The invariance-specificity characterization decoupling module separates cross-modal shared information and modality-specific information through a dual-encoder structure. Both the invariance encoder and the specificity encoder adopt a two-layer multilayer perceptron (MLP) structure with 128 hidden units, ReLU activation function, and 128-dimensional output.
[0045] S3.4: The invariant encoder extracts cross-modal shared features that reflect the inherent properties of water bodies, enhancing the generalization ability across watersheds and monitoring scenarios; the specific encoder retains modal-specific features, such as visual details like water surface texture in image modalities and numerical patterns of water quality parameter modalities, to prevent the loss of unique modal information during the fusion process.
[0046] The invariant encoder and the specific encoder employ identical two-layer MLP structures, containing linear layers, ReLU activation functions, linear layers, and ReLU activation functions, with a 128-dimensional output. The inputs to both encoders are also identical; that is, the same modal features are fed into both encoders simultaneously. Functional differentiation does not depend on architectural or input differences, but rather on the independent trainable parameter sets possessed by each encoder. During training, different loss functions provide different gradient signals, driving the parameters to converge in different directions, ultimately learning different feature maps.
[0047] During training, a multi-objective joint loss function is used to ensure functional differentiation. Specifically, the invariant alignment loss forces the invariant feature outputs of two modalities to be as similar as possible, compelling the invariant encoder to extract only cross-modal shared information; the orthogonality loss minimizes the correlation between invariant and specific features within the same modality, forcing the specific encoder to capture modality-specific information not covered by the invariant encoder; and the main task loss ensures that all features are useful for the final prediction. These three factors work together to form a closed-loop constraint, achieving decoupling.
[0048] S3.5: The model is trained using the mean squared error (MSE) loss function and the Adam optimizer, while the learning rate is dynamically adjusted using the cosine annealing learning rate scheduler (Cosine AnnealingLR).
[0049] Specifically, the forward propagation process of the invariance-specificity decoupled multimodal model can be described as follows: Input: RGB image tensor of the water surface and water quality parameter vector .
[0050] Processing flow: The water surface image is processed by extracting 768-dimensional CLS token features using a pre-trained ViT-B / 16 model, and then mapped to 128-dimensional image features via a linear projection layer. .
[0051] The water quality parameter vector is standardized by Z-score to form an 8-dimensional feature matrix. .
[0052] Image features Inputting the invariant encoder and the specific encoder respectively, we obtain and .
[0053] Water quality parameter characteristics Inputting the invariant encoder and the specific encoder respectively, we obtain and .
[0054] Calculating dynamic mode weights based on L2 norm and .
[0055] The weighted two-modal features are concatenated into a fused feature matrix. .
[0056] The predicted values of COD or Chl-a are output through a 2-layer MLP prediction head.
[0057] Output: Predicted values for COD or Chl-a .
[0058] In this embodiment, regarding the invariant encoder module: According to the present invention, the invariant encoder is implemented by the following structure: in, As modal feature input, and For the weights of the fully connected layer, and For bias terms, The input dimensions are 128 for the image and 8 for the water quality parameters.
[0059] According to the present invention, the operation path of the invariant encoder is as follows: Input: Feature vectors from the modality feature extraction module, where the image modality is... The water quality parameter mode is .
[0060] Processing flow: The input features are mapped to 128 dimensions through the first fully connected layer.
[0061] Applying the ReLU activation function increases the nonlinear expressive power.
[0062] The 128-dimensional output is maintained through a second fully connected layer.
[0063] The ReLU activation function is applied to generate the final invariant feature representation.
[0064] Output: Cross-modal shared features This reflects the inherent properties of the water body.
[0065] In this embodiment, regarding the specific encoder module: According to the present invention, the specific encoder and the invariant encoder have the same network structure, but their parameters are trained independently: in, , , , These are independent parameters for specific encoders.
[0066] According to the present invention, the operation path of the specific encoder is as follows: Input: Feature vectors from the modality feature extraction module, the same input received by the invariant encoder.
[0067] Processing flow: The input features are mapped to 128 dimensions through the first fully connected layer.
[0068] Applying the ReLU activation function increases the nonlinear expressive power.
[0069] The 128-dimensional output is maintained through a second fully connected layer.
[0070] The ReLU activation function is applied to generate the final specific feature representation.
[0071] Output: Modality-specific features It preserves the visual texture details of image modalities or the numerical patterns of water quality parameter modalities.
[0072] In this embodiment, the calculation of dynamic modal weights is detailed as follows: According to the present invention, the dynamic mode weights are calculated using the following mathematical formula: in, For image modal weights, and These are the invariant and specific features of water surface images, respectively. and These represent the invariant and specific characteristics of water quality parameters, respectively, and the modal weights of water quality parameters. .
[0073] Step S3 is used to decouple the extracted initial features. The image modal feature extraction module encodes the RGB image of the water surface using the ViT model to obtain the initial image features FImg; the water quality parameters are standardized to obtain the initial water quality parameter features FWQP. In step S3, the initial image features are input into the invariant encoder and the specific encoder respectively to obtain the image invariant feature FImg-inv and the image specific feature FImg-spe; the initial water quality parameter features are input into the invariant encoder and the specific encoder respectively to obtain the water quality parameter invariant feature FWQP-inv and the water quality parameter specific feature FWQP-spe.
[0074] Step S3 performs secondary encoding and decoupling based on existing modal features. Its input is the modal representation extracted in the previous step, and its output is the separated invariant and specific features. The purpose of this step is to explicitly separate cross-modal shared information from modal-specific information, providing structured feature input for subsequent adaptive weighted fusion.
[0075] The L2 norm-based weight calculation is adopted because the L2 norm of the modality combination feature vector quantifies its representational energy for a given sample, providing parameter-free and sample-adaptive weights, thus avoiding the risk of overfitting in learning-based gating mechanisms on medium-sized datasets.
[0076] In this embodiment, the feature matrix is fused for construction and prediction, as detailed below: The method for constructing the fused feature matrix is as follows: The fused feature matrix is segmented into four tokens and fed into a single-layer Transformer encoder, whose self-attention mechanism models the non-linear dependencies between cross-modal features. Then, the predicted values of the target variable are output through a two-layer MLP prediction head. in, This refers to the cross-modal feature interaction process of the Transformer encoder. It is a two-layer MLP prediction head.
[0077] In this embodiment, the model initialization, loss function, and optimizer settings are defined as follows: The model uses mean squared error (MSE) as the loss function, and the Adam optimizer updates the parameters with an initial learning rate of 1e. -4 The weight decays to 1e -4 The period length T_max of the cosine annealing learning rate scheduler is set to the total number of training epochs.
[0078] In this embodiment, the model training process in step S4 includes the following specific steps: S4.1: The invariant-specific decoupled multimodal model is trained using the training set data, with mean squared error (MSE) as the loss function, and all module parameters are optimized simultaneously through backpropagation.
[0079] S4.2: At the end of each epoch, evaluate the model performance on the validation set, monitor the R² metric on the validation set, and save the parameters of the best-performing model.
[0080] S4.3: During training, the learning rate is dynamically adjusted using a learning rate scheduler (CosineAnnealingLR). The learning rate update formula is as follows: in, This represents the current iteration number. The period length effectively avoids local optima.
[0081] In this embodiment, step S5, which involves using the trained optimal model to predict the test set and evaluating the model's performance and interpretability through multi-dimensional metrics, includes the following specific steps: S5.1: Use an independent test set (10% of the total data, n=195) that has never been used for any training or parameter tuning to perform the final evaluation of the trained model.
[0082] S5.2: Model performance is quantified using three metrics: coefficient of determination (R²), root mean square error (RMSE), and mean absolute error (MAE), calculated as follows: in, For the first The true value of each sample For predicted values, The mean of the true values. This represents the number of test samples.
[0083] S5.3: Generate a comparison chart of predicted and actual values, as well as a residual chart, for visual analysis, such as... Figure 3 As shown.
[0084] S5.4: Conduct modal configuration comparison experiments and ablation experiments to evaluate the contributions of each mode and component, such as... Figure 4 and Figure 5 As shown.
[0085] S5.5: Analyze the distribution of dynamic modal weights in different concentration groups, such as Figure 6 As shown.
[0086] S5.6: Use SHAP to generate a feature importance analysis plot to quantify the contribution of each water quality parameter to the prediction, such as... Figure 7 As shown.
[0087] In this embodiment, as Figure 3 As shown, the comparison plots and residual plots of COD and Chl-a predicted values with the actual values demonstrate the model's prediction performance on the test set. For COD prediction, the fusion modal model achieved excellent performance on the independent test set, with an R² of 0.846, an RMSE of 0.411 mg / L, and a MAE of 0.289 mg / L. The predicted values are generally closely distributed around the 1:1 reference line, and the 95% confidence interval remains narrow across the entire concentration range, indicating a high consistency between the model's predictions and the actual values. The COD residuals are mainly randomly distributed around the zero line, ranging from approximately -2.0 to 1.0 mg / L, and no significant systematic bias was observed under different concentration gradients, indicating that the model effectively avoids overfitting to specific concentration ranges. For Chl-a prediction, the fusion modal model achieved an R² of 0.746, an RMSE of 1.813 μg / L, and a MAE of 0.769 μg / L. The residuals also did not exhibit a clear directional pattern, ranging from approximately -20.0 to 0.0 μg / L. Although the residual fluctuation range was relatively large, reflecting the high natural variability of Chl-a itself, the model did not show any sustained overestimation or underestimation throughout the entire concentration range, verifying the stability and reliability of the model's predictions.
[0088] In this embodiment, as Figure 4 As shown in the comparison chart of prediction performance for different modal configurations, the fusion model demonstrates the significant advantages of the single-modal model over the single-modal model. For COD prediction, the baseline models with only image mode and only water quality parameter mode achieved R² performances of 0.810 (RMSE=0.457 mg / L) and 0.726 (RMSE=0.548 mg / L), respectively; for Chl-a prediction, the corresponding R² performances were 0.706 (RMSE=1.949 μg / L) and 0.658 (RMSE=2.104 μg / L), respectively. In contrast, the fusion model improved the average R² of 0.040 over the image mode alone and 0.104 over the water quality parameter mode alone on both COD and Chl-a tasks, while reducing RMSE by approximately 7.0%–25.0% and MAE by approximately 6.8%–22.8%. This performance improvement demonstrates a clear complementarity between the two modes: water quality parameters can effectively constrain changes in organic pollution, while image features can capture visual information that is difficult to reflect with numerical parameters.
[0089] In this embodiment, the performance comparison table of different baseline models (Table 1) shows the performance comparison results of the method of the present invention with various baseline models, as detailed below: Table 1 Performance Comparison of Different Baseline Models Model enter COD R² COD RMSE (mg / L) COD MAE (mg / L) Chl-a R² Chl-a RMSE (μg / L) Chl-a MAE (μg / L) LightGBM Water quality parameters only 0.738 0.536 0.343 0.638 2.164 0.966 WQP-MLP Water quality parameters only 0.517 0.727 0.46 0.525 2.479 1.075 Image-Only-ViT Image only 0.806 0.461 0.312 0.621 2.216 0.819 ResNet50-Concat Image + water quality parameters 0.827 0.435 0.309 0.559 2.388 0.83 ViT-Simple-Concat Image + water quality parameters 0.844 0.413 0.289 0.535 2.452 0.866 Method of the present invention Image + water quality parameters 0.846 0.411 0.289 0.746 1.813 0.769 In the baseline traditional tabular models, LightGBM and WQP-MLP significantly outperformed the method of this invention on both prediction tasks (ΔR² ≥ +0.108 for both COD and Chl-a tasks), indicating that relying solely on water quality parameters is insufficient to fully characterize the complex features of organic pollution and algal changes. Furthermore, the method of this invention outperforms ResNet50-Concat and ViT-Simple-Concat in both COD and Chl-a predictions. The performance improvement over ViT-Simple-Concat is particularly significant on the Chl-a task (ΔR² = +0.211). Since this baseline model shares the same ViT backbone network and Transformer structure as the method of this invention, lacking only decoupling design, the results further validate the important value of the "invariance-specificity" architecture for predicting highly heterogeneous and highly variable indicators.
[0090] In this embodiment, as Figure 5 As shown in the comparison chart of the ablation experimental performance of the core components, the invariant encoder, the specific encoder, and the Transformer fusion layer further reveal the functional roles of the three core components. For COD prediction, the complete model achieved the best performance (R²=0.846, RMSE=0.411 mg / L, MAE=0.289 mg / L). When the specific encoder was removed, R² decreased to 0.816 (relative decrease of 3.5%), and RMSE increased by 9.2%; when the Transformer fusion layer was removed, R² further decreased to 0.807 (relative decrease of 4.6%), and RMSE increased by 12.0%. In contrast, removing the invariant encoder had a smaller impact on COD prediction, with R² remaining around 0.844. For Chl-a prediction, the complete model achieved R... 2The performance was 0.746. Notably, removing the invariant encoder actually improved the model performance to R² = 0.765, indicating that cross-modal shared features may have introduced some redundant noise into Chl-a prediction. Meanwhile, removing the specific encoder and the Transformer fusion layer reduced R² to 0.731 and 0.711, respectively. It should be noted that the ViT-Simple-Concat baseline model completely removed the decoupling structure from this invention but retained the same ViT backbone and Transformer modules. Its Chl-a prediction R² was only 0.535, far lower than the 0.746 of the complete model, further demonstrating the crucial role of the specific encoder in constructing modality-specific representations and improving Chl-a prediction performance.
[0091] In this embodiment, as Figure 6 As shown, the dynamic modal weight distribution plot illustrates the normalized weight distribution of the image modality and the water quality parameter modality across different concentration ranges. For COD prediction (low concentration range 0.02–1.71 mg / L, medium concentration range 1.71–3.94 mg / L, high concentration range 3.94–9.49 mg / L), the weights of the two modalities remain relatively balanced across each concentration group, indicating that both image information and water quality parameters make stable contributions to COD prediction. This balance is consistent with the relatively stable organic pollution variation pattern of COD. For Chl-a prediction (low concentration range 0.02–1.75 μg / L, medium concentration range 1.75–7.31 μg / L, high concentration range 7.31–48.30 μg / L), the weight of the image modality is significantly higher than that of the water quality parameter modality in all concentration ranges, and its weight further increases in the high concentration group. This indicates that Chl-a has a stronger correlation with visual features such as algal color changes and surface algal bloom textures. The results above demonstrate that this model can adaptively enhance more discriminative modal information based on different indicators and concentration scenarios, thereby improving the model's generalization ability and prediction robustness.
[0092] In this embodiment, as Figure 7As shown in the SHAP-based feature importance analysis diagram, the contribution of different water quality parameters to COD and Chl-a prediction results is illustrated. For COD prediction, turbidity (Turb) and conductivity (Cond) exhibit the most significant impact, with the widest distribution of SHAP values. Higher turbidity typically corresponds to a positive increase in COD prediction values, consistent with turbidity's role as an indirect characterization indicator of suspended organic matter. For Chl-a prediction, turbidity is also the most critical influencing factor, with the largest SHAP value coverage, and an increase in turbidity is significantly positively correlated with an increase in Chl-a prediction values. Furthermore, conductivity and COD themselves also contribute to Chl-a prediction, while the impact of total phosphorus (TP) and ammonia nitrogen (NH3-N) is relatively limited. SHAP analysis results indicate that in practical deployments, retaining key inputs such as Turb, Cond, pH, DO, and RGB images can achieve relatively reliable prediction performance, thereby reducing laboratory testing costs and lowering the barrier to system application.
[0093] The water quality prediction method based on invariance-specific decoupling and dynamic adaptive fusion in this invention has the following advantages: 1. This invention achieves high-precision water quality parameter prediction. Through an invariance-specificity decoupling architecture and a dynamic modal weight adaptive strategy, the fusion model achieves an R² of 0.846 and an RMSE of 0.411 mg / L for COD and an R² of 0.746 and an RMSE of 1.813 μg / L for Chl-a. Compared to single-modal methods, this represents an improvement of 0.040-0.104 in R² and a reduction of 7.0-25.0% in RMSE. This invention outperforms multimodal baseline models such as ResNet50-Concat and ViT-Simple-Concat in both COD and Chl-a predictions, with a particularly significant performance improvement over ViT-Simple-Concat on the Chl-a task (ΔR). 2 =+0.211), since the baseline model shares the same ViT backbone network and Transformer structure as the method of this invention, only lacking decoupling design, the results further verify the important value of the "invariance-specificity" architecture for predicting highly heterogeneous and highly variable indicators.
[0094] 2. This invention possesses dynamic adaptive fusion capabilities. The L2-norm-based dynamic modal weighting strategy can adaptively adjust modal importance according to the sample feature distribution, achieving balanced cross-modal fusion for COD and automatically prioritizing the image modality for Chl-a, enhancing the model's robustness across different concentration scenarios. For COD prediction, the weights of the two modalities remain relatively balanced across all concentration groups, indicating that both image information and water quality parameters make stable contributions to COD prediction, consistent with the relatively stable organic pollution variation pattern of COD. For Chl-a prediction, the image modality has a significantly higher weight than the water quality parameter modality in all concentration ranges, and its weight further increases in high-concentration groups, indicating a stronger correlation between Chl-a and visual features such as algal color changes and surface algal bloom textures.
[0095] 3. This invention possesses good interpretability. By quantifying the contribution of each feature through SHAP analysis, turbidity and conductivity are identified as key roles in cross-modal anchoring features, providing a basis for feature simplification and reducing laboratory measurement costs and deployment barriers. For COD prediction, turbidity and conductivity exhibit the most significant impact; higher turbidity typically corresponds to a positive increase in predicted COD values, consistent with turbidity's role as an indirect characterization indicator of suspended organic matter. For Chl-a prediction, turbidity is also the most critical influencing factor; increased turbidity is significantly positively correlated with increased Chl-a predicted values. Conductivity and COD themselves also contribute to Chl-a prediction, while the effects of total phosphorus and ammonia nitrogen are relatively limited.
[0096] 4. This invention possesses excellent generalization ability. The nonlinear dependencies between cross-modal features are modeled using the Transformer self-attention mechanism. Ablation experiments verify the necessity of each component, ensuring stable model performance under different hydrological environments. For COD prediction, removing the specific encoder reduces R² to 0.816 (a relative decrease of 3.5%), while increasing RMSE by 9.2%; removing the Transformer fusion layer reduces R² to 0.807 (a relative decrease of 4.6%), while increasing RMSE by 12.0%, indicating that removing the invariant encoder has little impact on COD prediction. For Chl-a prediction, removing the invariant encoder actually improves performance to R²=0.765, suggesting that cross-modal shared features may introduce some redundant noise to highly variable indicators; removing the specific encoder and the Transformer fusion layer reduces R² to 0.731 and 0.711 respectively, further demonstrating the crucial role of the specific encoder in constructing modality-specific representations.
[0097] The above is a detailed description of the preferred embodiments of the present invention. However, the present invention is not limited to the embodiments described. Those skilled in the art can make various equivalent modifications or substitutions without departing from the spirit of the present invention. All such equivalent modifications or substitutions are included within the scope defined by the claims of this application.
Claims
1. A water quality prediction method based on invariance-specific decoupling and dynamic adaptive fusion, characterized in that, Includes the following steps: S1: Collect a multi-time, multi-modal dataset containing RGB image data of the water surface and water quality parameter data from multiple geographical monitoring stations; S2: Preprocess the multimodal dataset to obtain a training set, a validation set, and a test set; S3: Construct an invariant-specific decoupled multimodal model, use the model to extract modal features from the RGB images of the water surface and water quality parameters in the training set, then decouple and separate the shared features and unique features of each modal feature, and then perform adaptive weighted fusion and cross-modal interaction on all decoupled features to output the predicted value of water quality parameters. The modality feature extraction includes: Feature extraction was performed on the RGB image of the water surface using the ViT-B / 16 model pre-trained on the ImageNet-1k dataset. The 768-dimensional features output by ViT were mapped to 128 dimensions through a linear projection layer to obtain the initial features of the image. Feature extraction is performed on the water quality parameters, and the 8-dimensional parameter vector after Z-score normalization is directly used as the initial feature of the water quality parameters; The decoupling separation is achieved through an invariant encoder and a specific encoder. The invariant encoder is used to extract cross-modal shared features, and the specific encoder is used to retain modality-specific features. The initial image features are input into the invariant encoder and the specific encoder, respectively, to obtain image invariant features and image specific features; The initial features of the water quality parameters are input into the invariant encoder and the specific encoder, respectively, to obtain the invariant features of the water quality parameters and the specific features of the water quality parameters. Both the invariant encoder and the specific encoder adopt a two-layer multilayer perceptron structure with 128 hidden units, ReLU activation function, and 128-dimensional output. The invariant encoder and the specific encoder use independent parameters. The adaptive weighted fusion includes: The norm of the sum of invariant and specific features for each modality is calculated separately. The weight of each modality is determined according to the proportion of the norm of each modality to the total norm. The sum of invariant and specific features of each modality is weighted using the weight of each modality. The weighted modal features are then concatenated to obtain a fused feature. The fused feature is then input into the prediction head after cross-modal interaction, and the predicted value of the water quality parameter is output. S4: Construct a multi-objective joint loss function based on the predicted and actual values of the water quality parameters, optimize and train the model, and dynamically save the optimal model through the validation set; S5: Based on the optimal model, predict the test set to obtain the final prediction results of chlorophyll a concentration and chemical oxygen demand, and output multi-dimensional interpretability analysis results in combination with SHAP analysis.
2. The water quality prediction method based on invariance-specificity decoupling and dynamic adaptive fusion according to claim 1, characterized in that, In step S1, the multimodal dataset covers water surface images collected by fixed RGB cameras at multiple representative monitoring stations in the target watershed, including various lighting scenarios, collected at multiple time periods every day, and finally constructs a multimodal dataset containing multiple valid paired samples.
3. The water quality prediction method based on invariance-specificity decoupling and dynamic adaptive fusion according to claim 1, characterized in that, In step S2, the preprocessing includes: S2.1: Divide the preprocessed multimodal dataset into training set, validation set and test set by stratified sampling in a ratio of 8:1:1; S2.2: Perform Z-score standardization on all water quality input features in the training set, and apply the calculated mean and standard deviation to the validation set and the test set for standardization, respectively; S2.3: Apply logarithmic transformation to the predicted target values of chemical oxygen demand and chlorophyll a; S2.4: Implement data augmentation strategies on the images in the training set, including random horizontal flipping, brightness and contrast adjustment, and Gaussian blur; S2.5: Perform resampling with replacement on the low-frequency layers in the training set.
4. The water quality prediction method based on invariance-specificity decoupling and dynamic adaptive fusion according to claim 1, characterized in that, In step S4, the multi-objective joint loss function includes the main task prediction loss, invariance alignment loss, and orthogonality loss; the main task prediction loss uses mean squared error, the optimizer is Adam, and the learning rate scheduler uses cosine annealing. Specific steps include: S4.1: Start the cosine annealing learning rate scheduler so that the learning rate during training changes periodically between the preset maximum and minimum values according to the cosine function. S4.2: The invariant-specific decoupled multimodal model is trained using the training set, and the learning rate scheduler dynamically adjusts the current learning rate synchronously during the training process; S4.3: At the end of each epoch, evaluate the model performance on the validation set, monitor the coefficient of determination metric on the validation set, and save the best-performing model parameters as the optimal model.
5. The water quality prediction method based on invariance-specificity decoupling and dynamic adaptive fusion according to claim 1, characterized in that, In step S5, the specific steps for predicting the test set based on the optimal model include: S5.1: Obtain the preprocessed test set data and input it into the optimal model, wherein the input variables are the RGB image of the water surface and the 8-dimensional water quality parameter vector, and the output variables are the prediction results of chemical oxygen demand and chlorophyll a; S5.2: Use the optimal model to make predictions, calculate and record the model's performance metrics on the test set, including the coefficient of determination, root mean square error, and mean absolute error; S5.3: Generate a comparison chart of the predicted results and the true values on the test set, as well as a residual chart, for visualization analysis.
6. The water quality prediction method based on invariance-specificity decoupling and dynamic adaptive fusion according to claim 5, characterized in that, In step S5, the specific steps of the SHAP analysis include: S5.4: Fix the features of the water surface RGB image to their mean on the training set, so that the subsequent SHAP analysis focuses on the independent contribution of each water quality parameter to the prediction. S5.5: Randomly select a preset number of samples from the training set, and replace the features of the RGB images of the water surface with the mean value to construct the SHAP background dataset; S5.6: Based on the background dataset, calculate the SHAP value of each water quality parameter for the test set samples, identify the features that contribute the most to the prediction of chemical oxygen demand and chlorophyll a according to the SHAP value, and generate feature importance ranking and SHAP value distribution map.
7. The water quality prediction method based on invariance-specificity decoupling and dynamic adaptive fusion according to claim 1, characterized in that, In step S5, the results of the multi-dimensional interpretability analysis also include dynamic modal weight distribution analysis and ablation experiment results; The dynamic modal weight distribution analysis shows the weight distribution of the water surface RGB image and the water quality parameters in different concentration ranges; The ablation experiment quantifies the contribution of each operation to the prediction performance by removing the decoupling and separation operations of the shared features and unique features, as well as the cross-modal interaction operations.
Citation Information
Patent Citations
Multi-working-condition industrial process quality index prediction method
CN120672191A
Water quality multi-parameter prediction method and system based on image recognition
CN121767743A
