An intelligent detection method for urban inland river sewage
The wastewater index quantitative detection model constructed by near-infrared spectroscopy and convolutional neural networks solves the problems of time-consuming and inaccurate chemical metrology methods in urban river water quality testing, and achieves rapid and accurate water quality testing.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- FUZHOU UNIV
- Filing Date
- 2023-04-28
- Publication Date
- 2026-04-17
AI Technical Summary
In existing technologies, chemometric methods for testing water quality in urban rivers are time-consuming and yield inaccurate results.
A quantitative detection model for wastewater indicators was constructed using near-infrared spectroscopy combined with convolutional neural networks. The model was trained and tested using training and testing sets. The model was then used to detect the water quality of urban rivers, and its accuracy and reliability were verified by chemometrics.
It enables rapid and accurate detection of urban river water quality, reducing time and labor costs.
Smart Images

Figure CN116625972B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of wastewater detection technology, specifically to an intelligent detection method for wastewater in urban rivers. Background Technology
[0002] Chemical oxygen demand (COD) refers to the mass concentration of oxygen corresponding to the dichromate consumed by dissolved substances and suspended solids in a water sample under certain conditions after oxidation treatment with K2Cr2O7. It is an important parameter for evaluating water quality, especially in assessing the degree of organic pollution in water bodies.
[0003] The amount of dissolved oxygen consumed by microorganisms in decomposing biodegradable organic matter in water is called biochemical oxygen demand (BOD). It is a comprehensive indicator reflecting the content of organic pollutants in water and also the biodegradability of organic matter in wastewater. For wastewater treatment plants using biological methods, BOD can predict the water treatment effect and plays a more important indicative role in adjusting water treatment processes. Therefore, the demand for accurate BOD detection is increasing.
[0004] Near-infrared spectroscopy (NIR), as a non-destructive analytical method, is characterized by its speed, non-destructive nature, and lack of pollution. Based on NIR spectroscopy, traditional chemometric methods have been established for the quantitative analysis of pollutants in wastewater. However, the spectra obtained by traditional chemometric methods have thousands of characteristic wavelengths, which poses challenges to chemometric methods and leads to problems such as "dimensional explosion." Summary of the Invention
[0005] The purpose of this invention is to provide an intelligent detection method for urban inland river sewage, which is beneficial to improving the speed and accuracy of urban inland river water quality detection.
[0006] To achieve the above objectives, the technical solution adopted by the present invention is: an intelligent detection method for urban inland river sewage, comprising the following steps:
[0007] 1) Prepare standard wastewater samples to obtain multiple wastewater samples with different indicators and different indicator data;
[0008] 2) Near-infrared spectral data of all sewage samples were collected using a near-infrared spectrometer and preprocessed to form a near-infrared spectral dataset, which was then divided into a training set and a test set.
[0009] 3) Construct a quantitative detection model for wastewater indicators based on convolutional neural networks. Train and test the quantitative detection model for wastewater indicators using training and testing sets to obtain a well-trained quantitative detection model for wastewater indicators.
[0010] 4) Collect actual water samples and divide them into two parts. One part is used to obtain key indicator data through chemometrics, and the other part is used to predict key indicator data through the established wastewater index quantitative detection model. The accuracy and reliability of the established model are verified by comparison. If the accuracy and reliability of the model do not meet the requirements, return to step 3) and retrain the model.
[0011] 5) The obtained wastewater index quantitative detection model is used to detect the water quality of the urban inland river to be tested.
[0012] Further, in step 1), the prepared wastewater samples include COD and BOD samples with different concentration gradients, with a concentration range of 1-1000 mg / L; when the concentration range is 1-100 mg / L, the concentration interval is 1 mg / L; when the concentration range is 100-1000 mg / L, the concentration interval is 10 mg / L.
[0013] Furthermore, the COD sample preparation method is as follows: potassium hydrogen phthalate of known purity is dissolved in deionized water to obtain a stock solution; then the prepared stock solution is diluted with deionized water to prepare 190 COD solution samples of different concentrations; after preparation, each COD solution sample is stored in a test tube and labeled with its concentration.
[0014] The method for preparing the BOD samples is as follows: glucose and glutamic acid of known purity are dissolved in deionized water to obtain a stock solution; then the prepared stock solution is diluted with deionized water to prepare 190 BOD solution samples of different concentrations; after preparation, each BOD solution sample is stored in a test tube and labeled with its concentration.
[0015] Furthermore, in step 2), for each concentration of COD sample, the upper, middle and lower liquid layers are taken, and the spectra are collected three times for each layer, resulting in 1710 spectral data; for each concentration of BOD sample, the four liquid layers are taken from top to bottom, and the spectra are collected four times for each layer, resulting in 3040 spectral data.
[0016] Further, in step 2), the collected near-infrared spectral data are normalized and subjected to multivariate dispersion correction to extract characteristic spectral peak information of the wastewater samples and construct a near-infrared spectral dataset; the calculation formula for multivariate dispersion correction is as follows:
[0017]
[0018] In the formula, A represents an n×p dimensional calibration spectral data matrix, n is the number of calibration samples, and p is the number of wavelength points used for spectral acquisition. i It is a 1×p-dimensional matrix, representing the spectral vector of the i-th sample. The m represents the average spectral vector obtained by averaging the original near-infrared spectra of all samples at various wavelengths. i and b i The near-infrared spectra A of each sample are represented respectively. i With average spectrum The relative offset coefficients and translations obtained after performing univariate linear regression.
[0019] Furthermore, in step 3), a neural network model with an Inception structure is used to construct a quantitative detection model for wastewater indicators, in order to extract spectral features and perform regression prediction. The model enhances the feature receptive field of the neural network through the Inception module and reduces the model complexity. The neural network model consists of three convolutional layers, an Inception module, a BN regularization mechanism, a ReLU activation function, a connection layer, a maxpooling layer, a flatten layer, a fully connected layer, and an output layer. The ability to extract features is improved by using convolutional kernels of different sizes (1*1, 3*3, and 5*5) in parallel, and the model structure is simplified and the amount of computation is reduced.
[0020] Furthermore, in step 3), during the training and testing of the model, the prediction results of the wastewater index quantitative detection model are evaluated using R2, MAE, and RMSE indicators.
[0021] The formula for calculating MAE is:
[0022]
[0023] Where y represents the true value. This represents the predicted value, where n represents the number of values.
[0024] The formula for calculating RMSE is:
[0025]
[0026] Where N represents the number of values, y t Represents the true value. R represents the predicted value; 2 The coefficient of determination is used to determine how much of the fluctuation of the response y can be described by the fluctuation of x, that is, how much of the variation of the characterizing variable y can be explained by the controllable independent variable X.
[0027] R 2 The calculation formula is:
[0028]
[0029] Among them, SS res SS represents the sum of squared residuals. tot SS represents the total sum of squares. reg R represents the regression sum of squares; 2 The value range of R is 0-1. 2 The closer a value is to 1, the higher the degree to which the independent variable explains the dependent variable.
[0030] Compared with the prior art, the present invention has the following beneficial effects: it provides an intelligent detection method for urban inland river sewage, which solves the problems of long time consumption and inaccurate results of chemical metrology methods for urban inland river water quality detection. Under the premise of ensuring detection accuracy and reliability, it realizes rapid determination of inland river sewage quality, which greatly saves time and labor costs. Attached Figure Description
[0031] Figure 1 This is a flowchart illustrating the method implementation of an embodiment of the present invention;
[0032] Figure 2 This is the raw BOD spectral dataset collected in this embodiment of the invention;
[0033] Figure 3 This is the preprocessed BOD spectral dataset in this embodiment of the invention;
[0034] Figure 4 This is the raw COD spectral dataset collected in this embodiment of the invention;
[0035] Figure 5 This is the preprocessed COD spectral dataset in this embodiment of the invention;
[0036] Figure 6 This is a curve showing the fitting of the predicted value and the true value after model training in an embodiment of the present invention. Detailed Implementation
[0037] The present invention will be further described below with reference to the accompanying drawings and embodiments.
[0038] It should be noted that the following detailed descriptions are exemplary and intended to provide further explanation of this application. Unless otherwise specified, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application pertains.
[0039] It should be noted that the terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit the exemplary embodiments according to this application. As used herein, the singular form is intended to include the plural form as well, unless the context clearly indicates otherwise. Furthermore, it should be understood that when the terms "comprising" and / or "including" are used in this specification, they indicate the presence of features, steps, operations, devices, components, and / or combinations thereof.
[0040] like Figure 1 As shown, this embodiment provides a method for intelligent detection of sewage in urban rivers, including the following steps:
[0041] 1) Prepare standard wastewater samples to obtain multiple wastewater samples with different indicators and different indicator data.
[0042] 2) Near-infrared spectral data of all sewage samples were collected using a near-infrared spectrometer and preprocessed to form a near-infrared spectral dataset, which was then divided into a training set and a test set.
[0043] 3) Construct a quantitative detection model for wastewater indicators based on convolutional neural networks. Train and test the quantitative detection model for wastewater indicators using training and testing sets to obtain a well-trained quantitative detection model for wastewater indicators.
[0044] 4) Collect actual water samples and divide them into two parts. One part is used to obtain key indicator data through chemometrics, and the other part is used to predict key indicator data through the established wastewater index quantitative detection model. The accuracy and reliability of the established model are verified by comparison. If the accuracy and reliability of the model do not meet the requirements, return to step 3) to retrain the model.
[0045] 5) The obtained wastewater index quantitative detection model is used to detect the water quality of the urban inland river to be tested.
[0046] In step 1), the prepared wastewater samples include COD and BOD samples with different concentration gradients, with a concentration range of 1-1000 mg / L; when the concentration range is 1-100 mg / L, the concentration interval is 1 mg / L; when the concentration range is 100-1000 mg / L, the concentration interval is 10 mg / L.
[0047] The COD sample preparation method is as follows: potassium hydrogen phthalate (KHC8O4H4) of known purity is dissolved in deionized water to obtain a stock solution; then the prepared stock solution is diluted with deionized water to prepare 190 COD solution samples of different concentrations; after preparation, each COD solution sample is stored in a test tube and the concentration is labeled.
[0048] The method for preparing BOD samples is as follows: glucose (C6H12O6) and glutamic acid (HOOC-CH2-CH2-CHNH2-COOH) of known purity are dissolved in deionized water to obtain a stock solution; then the prepared stock solution is diluted with deionized water to prepare 190 BOD solution samples of different concentrations; after preparation, each BOD solution sample is stored in a test tube and labeled with its concentration.
[0049] In this embodiment, for each COD concentration sample, the upper, middle, and lower liquid layers were taken, and spectra were collected three times for each layer, resulting in 1710 spectral data points. Of these, 1197 spectral data points were used as the training set samples, with a concentration range of 1-1000 mg / L, a mean of 297.34 mg / L, and a standard deviation of 313.29 mg / L; 513 spectral data points were used as the prediction set samples, with a concentration range of 1-1000 mg / L, a mean of 266.09 mg / L, and a standard deviation of 297.86 mg / L.
[0050] For each BOD concentration sample, four liquid layers were taken from top to bottom, and four spectra were collected for each layer, resulting in 3040 spectral data points. Of these, 2128 spectral data points were used as the training set, with a concentration range of 1-1000 mg / L, a mean of 297.34 mg / L, and a standard deviation of 313.29 mg / L; 912 spectral data points were used as the prediction set, with a concentration range of 1-1000 mg / L, a mean of 266.09 mg / L, and a standard deviation of 297.86 mg / L.
[0051] In this embodiment, a Fourier transform near-infrared spectrometer (ANTANRIS II FT-NIR) was used to acquire near-infrared spectral information in the band of 700-2500 nm. The gain was set to 8, the number of scans was 32, the background was selected as air, and the resolution was 8 cm⁻¹. -1 The experiment was conducted in a dry environment at room temperature of 25 degrees Celsius.
[0052] Before use, a spectrometer must be calibrated by acquiring the background spectrum. The background spectrum is the spectrum recorded on the spectrometer's array in the absence of a light source, and subtracting the background spectrum is crucial for reducing the influence of ambient light.
[0053] The spectrum was acquired in transmission mode, with air as a reference, and a resolution of 8 cm⁻¹. -1 The spectra of each sample are in the range of 4000-10000 cm⁻¹ -1 The scan was performed within a certain range, with 32 scans. At a depth of 7000 cm... -1There is a strong absorption peak nearby, which is the first-order absorption frequency of the OH stretching vibration in pure water. To avoid the influence of the saturation peak, pay attention to the 7127-6985 cm⁻¹ range when modeling. -1 Spectral information of the signal.
[0054] The raw BOD and COD spectra collected in this embodiment are as follows: Figure 2 , 4 As shown.
[0055] In step 2), the specific method for preprocessing the near-infrared spectral data is as follows:
[0056] The collected near-infrared spectral data were normalized and subjected to multivariate dispersion correction (MSC) processing to extract characteristic spectral peak information of wastewater samples and construct a near-infrared spectral dataset.
[0057] The main purposes of normalization are: first, to transform data into decimals between (0, 1) and (1, 1). Mapping data to the range of 0 to 1 makes processing more convenient and faster. Second, to transform dimensional expressions into dimensionless expressions, facilitating comparison and weighting of indicators with different units or magnitudes. This embodiment uses the Min-MaxNormalization method, and its calculation formula is as follows:
[0058]
[0059] Multivariate dispersion correction can eliminate noise in near-infrared diffuse reflectance spectra caused by specular reflection and inhomogeneity of the sample, as well as baseline drift and spectral non-repeatability. The calculation formula for multivariate dispersion correction is as follows:
[0060]
[0061] In the formula, A represents an n×p dimensional calibration spectral data matrix, n is the number of calibration samples, and p is the number of wavelength points used for spectral acquisition. i It is a 1×p-dimensional matrix, representing the spectral vector of the i-th sample. The m represents the average spectral vector obtained by averaging the original near-infrared spectra of all samples at various wavelengths. i and b i The near-infrared spectra A of each sample are represented respectively. i With average spectrum The relative offset coefficients and translations obtained after performing univariate linear regression.
[0062] In this embodiment, the preprocessed BOD and COD spectra are as follows: Figure 3 , 5 As shown.
[0063] In step 3), a neural network model with an Inception structure is used to construct a quantitative detection model for wastewater indicators, in order to extract spectral features and perform regression prediction. The model enhances the feature receptive field of the neural network through the Inception module and reduces the model complexity. The neural network model consists of three convolutional layers, an Inception module, a BN regularization mechanism, a ReLU activation function, a connection layer, a maxpooling layer, a flatten layer, a fully connected layer, and an output layer. The ability to extract features is improved by using convolutional kernels of different sizes such as 1*1, 3*3, and 5*5 in parallel, and the model structure is simplified and the amount of computation is reduced.
[0064] During the training and testing of the model, the prediction results of the quantitative detection model for wastewater indicators are evaluated using R2, MAE, and RMSE metrics. The formula for calculating MAE is:
[0065]
[0066] Where y represents the true value. This represents the predicted value, and n represents the number of values.
[0067] The formula for calculating RMSE is:
[0068]
[0069] Where N represents the number of values, y t Represents the true value. R represents the predicted value; 2 The coefficient of determination is used to determine what percentage of the fluctuations in the response y can be described by the fluctuations in x, that is, what percentage of the variation in the characterizing variable y can be explained by the controlled independent variable X.
[0070] R 2 The calculation formula is:
[0071]
[0072] Among them, SS res SS represents the sum of squared residuals. tot SS represents the total sum of squares. reg R represents the regression sum of squares; 2 The value range of R is 0-1. 2 The closer a value is to 1, the higher the degree to which the independent variable explains the dependent variable.
[0073] In this embodiment, a quantitative detection model for wastewater indicators is established based on regression analysis using a convolutional neural network combined with the Inception module. The main steps are as follows:
[0074] Step 1: Divide the obtained spectral dataset into a test set and a training set using the SPXY algorithm. The SPXY algorithm is an improvement over the KS algorithm. The SPXY algorithm takes into account both the x variable and the y variable, and its formula is as follows:
[0075]
[0076] where N is the total number of samples, d<0OO0030>is the distance in the x direction of the sample, d y is the distance in the y direction of the sample. The SPXY algorithm combines the distances in the x and y directions through regularization, enabling a more comprehensive evaluation and division of the NIR dataset. <000OO226>Step 2: Perform spectral feature selection using successive projections algorithm (SPA) to reduce feature redundancy. The brief steps of this algorithm are as follows:
[0078] Denote the initial iteration vector as x k(0) , the number of variables to be extracted as N, and the spectral matrix as J columns.
[0079] 1. Randomly select 1 column (the j-th column) of the spectral matrix and assign the j-th column of the modeling set to x j [[ID=ZZ3]]and denote it as x k(0) .
[0080] 2. Denote the set of positions of the unselected column vectors as s:
[0081]
[0082] 3. Calculate the projections of x j ]>onto the remaining column vectors respectively:
[0083]
[0084] 4. Extract the spectral wavelength of the maximum projection vector:
[0085] k(n) = arg(max(|P(x j )|), j ∈ s <000OO246>5. Let x i = p x , j ∈ s
[0087] 6. n = n + 1. If n < N, then calculate iteratively according to formula (1).
[0088] Step 3: Input the divided training set into the improved convolutional neural network for training.
[0089] Step 4: Calculate the loss value through forward propagation.
[0090] Step 5: Adjust the hyperparameters of the convolution using the loss value. This is done by using the `optimizer.step()` and `scheduler.step()` functions in PyTorch for rolling optimization and iterative weight updates. `optimizer.step()` updates the network parameters based on the gradient information from backpropagation to reduce the loss value; `scheduler.step()`...
[0091] The optimizer's learning rate is updated in epochs.
[0092] Step Six: Calculate RMSE, MAE, and R 2 Use indicators to determine whether the requirements are met. If the requirements are met or the predicted training period is reached, stop training. If not, repeat steps three through five.
[0093] Step 7: Use the trained model to perform regression prediction on the divided test set to determine its reliability and accuracy.
[0094] The fitting curves between the predicted and actual values after model training are as follows: Figure 6 As shown.
[0095] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention in any other way. Any person skilled in the art may make changes or modifications to the above-disclosed technical content to create equivalent embodiments. However, any simple modifications, equivalent changes, and modifications made to the above embodiments based on the technical essence of the present invention without departing from the scope of the present invention shall still fall within the protection scope of the present invention.
Claims
1. A method for intelligent detection of sewage in urban inland rivers, characterized in that, Includes the following steps: 1) Prepare standard wastewater samples to obtain multiple wastewater samples with different indicators and different indicator data; 2) Near-infrared spectral data of all sewage samples were collected using a near-infrared spectrometer and preprocessed to form a near-infrared spectral dataset, which was then divided into a training set and a test set. 3) Construct a quantitative detection model for wastewater indicators based on convolutional neural networks. Train and test the quantitative detection model for wastewater indicators using training and testing sets to obtain a well-trained quantitative detection model for wastewater indicators. 4) Collect actual water samples and divide them into two parts. One part is used to obtain key indicator data through chemometrics, and the other part is used to predict key indicator data through the established wastewater index quantitative detection model. The accuracy and reliability of the established model are verified by comparison. If the accuracy and reliability of the model do not meet the requirements, return to step 3) and retrain the model. 5) The obtained quantitative detection model for wastewater indicators was used to detect the water quality of the urban inland river to be tested; In step 1), the prepared wastewater samples include COD and BOD samples with different concentration gradients, with a concentration range of 1-1000 mg / L; when the concentration range is 1-100 mg / L, the concentration interval is 1 mg / L; when the concentration range is 100-1000 mg / L, the concentration interval is 10 mg / L. In step 2), the collected near-infrared spectral data are normalized and subjected to multivariate dispersion correction to extract the characteristic spectral peak information of the sewage samples and construct a near-infrared spectral dataset. In step 3), a neural network model with an Inception structure is used to construct a quantitative detection model for wastewater indicators, in order to extract spectral features and perform regression prediction. The model enhances the feature receptive field of the neural network through the Inception module and reduces the model complexity. The neural network model consists of three convolutional layers, an Inception module, a BN regularization mechanism, a ReLU activation function, a connection layer, a maxpooling layer, a flatten layer, a fully connected layer, and an output layer. The ability to extract features is improved by using convolutional kernels of different sizes (1*1, 3*3, and 5*5) in parallel, and the model structure is simplified and the amount of computation is reduced.
2. The intelligent detection method for urban inland river sewage according to claim 1, characterized in that, The method for preparing the COD samples is as follows: potassium hydrogen phthalate of known purity is dissolved in deionized water to obtain a stock solution; then the prepared stock solution is diluted with deionized water to prepare 190 COD solution samples of different concentrations. After preparation, each COD solution sample was stored in a test tube and its concentration was labeled. The method for preparing the BOD samples is as follows: glucose and glutamic acid of known purity are dissolved in deionized water to obtain a stock solution; then the prepared stock solution is diluted with deionized water to prepare 190 BOD solution samples of different concentrations. After preparation, each BOD solution sample was stored in a test tube and its concentration was labeled.
3. The intelligent detection method for urban inland river sewage according to claim 1, characterized in that, In step 2), for each concentration of COD sample, the upper, middle and lower liquid layers were taken, and the spectra were collected three times for each layer, resulting in 1710 spectral data; for each concentration of BOD sample, the four liquid layers were taken from top to bottom, and the spectra were collected four times for each layer, resulting in 3040 spectral data.
4. The intelligent detection method for urban inland river sewage according to claim 1, characterized in that, In step 2), the calculation formula for multivariate dispersion correction is as follows: In the formula, A represents an n×p dimensional calibration spectral data matrix, n is the number of calibration samples, and p is the number of wavelength points used for spectral acquisition. It is a 1×p-dimensional matrix, representing the spectral vector of the i-th sample. This represents the average spectral vector obtained by averaging the original near-infrared spectra of all samples at various wavelengths. and The near-infrared spectra of each sample are shown below. With average spectrum The relative offset coefficients and translations obtained after performing univariate linear regression.
5. The intelligent detection method for urban inland river sewage according to claim 1, characterized in that, In step 3), during the training and testing of the model, the prediction results of the wastewater index quantitative detection model are evaluated using R2, MAE, and RMSE indicators. The formula for calculating MAE is: Where y represents the true value. This represents the predicted value, where n represents the number of values. The formula for calculating RMSE is: Where N represents the number of values, Represents the actual value. Indicates the predicted value; The coefficient of determination is used to reflect how much of the fluctuation of y can be described by the fluctuation of x, that is, how much of the variation of the variable y can be explained by the controllable independent variable X. R 2 The calculation formula is: in, Represents the sum of squared residuals. Represents the total sum of squares. Represents the sum of squares of regression; The value range is 0-1. The closer a value is to 1, the higher the degree to which the independent variable explains the dependent variable.
Citation Information
Patent Citations
Near infrared spectrum analysis method based on one-dimensional convolutional neural network
CN107478598A
Near infrared spectrum wavelength selection method based on convolutional neural network
CN113686810A