A Lightweight End-Side LSTM-Based Flood Forecasting Method Based on ONNX

By deploying a lightweight LSTM flood prediction model on edge devices and performing local rolling inference, the problem of flood prediction relying on cloud deployment in existing technologies is solved, and real-time and reliable flood forecasting is achieved.

CN122332842APending Publication Date: 2026-07-03WUHAN DASHUIYUN TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
WUHAN DASHUIYUN TECH CO LTD
Filing Date
2026-06-05
Publication Date
2026-07-03

AI Technical Summary

Technical Problem

Existing flood prediction models rely on cloud deployment, which leads to problems such as data transmission delays, high operation and maintenance costs, and network instability causing prediction service failures. Furthermore, the separation of monitoring and forecasting tasks prevents data from being processed in a closed loop.

Method used

A lightweight LSTM flood prediction model is constructed and converted to ONNX format. It is then deployed on edge devices for local rolling inference. Combined with data preprocessing and real-time compensation mechanisms, a closed loop integrating measurement and forecasting is formed.

Benefits of technology

It improves the timeliness and reliability of flood forecasting, reduces operation and maintenance costs, adapts to complex network environments, and enables real-time and continuous flood forecasting.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122332842A_ABST
    Figure CN122332842A_ABST
Patent Text Reader

Abstract

This invention provides a lightweight, edge-side LSTM-based integrated flood forecasting method based on ONNX. It acquires flow data and processes missing and outlier values, performs sliding window sampling and standardization, and constructs and trains an LSTM flood forecasting model based on the processed sample data. The trained LSTM flood forecasting model is then converted into an ONNX model and optimized through computational graph optimization, constant folding, quantization optimization, and hardware adaptation optimization to obtain a lightweight flood forecasting model. This lightweight flood forecasting model is then deployed on edge devices to perform local rolling inference on real-time collected flow monitoring data and output flood forecast results. This invention enables closed-loop operation of data acquisition, local inference, and forecast output on the edge, reducing model size, memory usage, and power consumption, and improving the real-time performance and reliability of flood forecasting in remote areas and scenarios with weak networks.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of hydrological forecasting and end-side intelligent computing technology, specifically to an end-side lightweight LSTM-based flood forecasting method based on ONNX. Background Technology

[0002] Floods are characterized by their high frequency and destructiveness, making timely and accurate flood forecasting a crucial foundation for disaster prevention and mitigation. Current mainstream flood forecasting models primarily include physical mechanism-based models and data-driven models. Physical mechanism-based models involve complex parameter calibration, high computational overhead, and demanding hardware computing power; while data-driven models, although possessing strong nonlinear fitting capabilities, typically have a large number of parameters and high computational complexity, also relying on high-performance hardware environments.

[0003] In terms of deployment, existing flood forecasting models mostly adopt a centralized cloud deployment model, which typically involves multiple stages such as data collection, cloud transmission, cloud computing, and result distribution. This model has the following problems: First, data transmission and cloud queuing computing introduce significant delays, making it difficult to meet the real-time forecasting needs of scenarios with high confluence speeds, such as small and medium-sized river basins. Second, the construction of cloud server clusters, link maintenance, and the storage and transmission of massive amounts of hydrological data all increase operation and maintenance costs. Third, in remote mountainous areas or areas with weak networks, data transmission interruptions can cause forecasting services to fail, affecting the continuity and reliability of flood warnings.

[0004] While existing studies on end-side flood forecasting have verified that end-side equipment possesses a certain computing power, they typically separate monitoring and forecasting tasks, relying on cross-device communication for data transmission. In extreme situations such as network outages or power failures, problems easily arise where monitoring data cannot be uploaded and forecast results cannot be distributed, making it difficult to achieve a truly integrated closed-loop operation of monitoring and forecasting.

[0005] Therefore, there is an urgent need for a flood forecasting method that can balance forecasting accuracy, operational efficiency, and end-side adaptability, so as to achieve closed-loop processing of data acquisition, local inference, and forecast output, and improve the timeliness and reliability of flood forecasting in complex application environments. Summary of the Invention

[0006] The purpose of this invention is to provide a lightweight LSTM-based flood forecasting method based on ONNX, which solves the problems of separation of monitoring and forecasting tasks, reliance on cross-device communication, difficulty in end-side deployment, and high operating costs in the prior art.

[0007] To achieve the above objectives, the present invention adopts the following technical solution: acquiring and preprocessing flow monitoring data to construct sample data for flood prediction; constructing and training an LSTM flood prediction model based on the sample data; converting the trained LSTM flood prediction model into an ONNX model and performing lightweight processing to obtain a lightweight flood prediction model; deploying the lightweight flood prediction model on an edge device to perform local rolling inference on the real-time collected flow monitoring data and output flood prediction results.

[0008] Furthermore, the preprocessing includes: processing missing and outlier values ​​in the collected traffic data; using linear interpolation to supplement missing or outlier values ​​when the continuous length corresponding to a missing or outlier value is less than 3 time steps, and directly discarding them when it exceeds 3 time steps; and using a fixed-length sliding window method, taking traffic data from 5 consecutive time steps as input and the traffic flow at the next time step as the prediction target to generate training samples.

[0009] Furthermore, the preprocessing also includes standardizing the traffic data using the standard deviation standardization method, and following the processing method of standardizing the training set separately and reusing the standardized parameters of the training set for the test set.

[0010] Furthermore, the LSTM flood prediction model adopts a 2-layer LSTM stacked architecture, with 256 LSTM hidden layer neurons and 512 feedforward network hidden layer neurons, and introduces a fully connected feedforward neural network and the ReLU activation function.

[0011] Furthermore, the construction and training of the LSTM flood prediction model includes: using the mean absolute error as the loss function, setting the initial learning rate to 1e-4, adjusting the learning rate using a cosine annealing strategy, setting an early stopping mechanism, and setting a maximum training step of 300 steps.

[0012] Furthermore, the local rolling inference adopts a real-time data supplementation strategy: the traffic predicted at the current moment is added to the end of the input window, and the old data at the front of the window is removed to form a new window for prediction at the next moment; the number of inference steps is set within the preset maximum inference step size range.

[0013] Furthermore, the step of converting the trained LSTM flood prediction model into an ONNX model includes converting the PyTorch format LSTM flood prediction model into the ONNX standard format to achieve cross-platform deployment compatibility.

[0014] Furthermore, the lightweighting process includes: performing computation graph optimization based on ONNX Runtime, constant folding, quantization optimization to convert FP32 to FP16, and hardware adaptation optimization for edge CPUs; the rate of change in model prediction accuracy after lightweighting is less than 0.002%.

[0015] Furthermore, the end-side device is a monitoring workstation, adapted to x86 and ARM architectures, and supports multiple monitoring frequency scenarios; the local rolling inference includes: collecting river flow data through flow monitoring equipment, performing preprocessing, model inference, and prediction output locally on the end-side device, forming an integrated monitoring and reporting closed loop.

[0016] Furthermore, during the edge-side inference stage, if data gaps or anomalies occur, the valid data prior to the aforementioned gap or anomaly time is used as input to infer the flow rate at the corresponding time.

[0017] Compared with the prior art, the present invention has the following beneficial effects:

[0018] (1) By processing missing and outlier values ​​in the flow data and combining sliding window sampling, YeoJohnson transformation and standard deviation standardization, this invention can improve the quality of input data and the stability of sample time series, thereby providing a reliable data foundation for flood prediction.

[0019] (2) By constructing a lightweight LSTM flood prediction model and combining Dropout, cosine annealing learning rate scheduling and early stopping mechanism, this invention can fully explore the temporal dependency relationship of the flow sequence, thereby improving the accuracy and stability of flood prediction at multiple consecutive times.

[0020] (3) By converting the trained model into the ONNX standard format and performing computation graph optimization, constant folding, quantization optimization and hardware adaptation optimization, this invention can significantly reduce the model size, executable file size, memory usage and power consumption while basically maintaining the prediction accuracy.

[0021] (4) By performing local rolling inference and anomaly compensation processing on the end-side device, the present invention can form an integrated measurement and forecasting closed loop, thereby enhancing the real-time performance and reliability of flood forecasting in weak network, network outage and remote scenarios. Attached Figure Description

[0022] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the following description of the embodiments are briefly explained. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0023] Figure 1 This is a flowchart illustrating an ONNX-based lightweight LSTM-based flood forecasting method for end-side monitoring and reporting in an embodiment of the present invention.

[0024] Figure 2 This is a schematic diagram of the rolling forecast calculation process of the flood prediction model in an embodiment of the present invention;

[0025] Figure 3 This is a schematic diagram of the flood prediction model structure based on LSTM in an embodiment of the present invention. Detailed Implementation

[0026] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described below with reference to the accompanying drawings and specific embodiments. It should be understood that the following embodiments are only for explaining the invention and are not intended to limit the scope of protection of the invention.

[0027] Please see Figures 1 to 3 This invention provides a lightweight end-side LSTM-based flood forecasting method based on ONNX.

[0028] First, traffic monitoring data is acquired and preprocessed to construct sample data for flood prediction.

[0029] Flow data can be derived from continuous measured flow sequences at river monitoring sections. To ensure data availability, missing and outlier values ​​are first processed in the collected flow data. When the continuous length corresponding to a missing or outlier value is less than three time steps, linear interpolation is used to fill the gap; when the continuous length is greater than or equal to three time steps, the corresponding data segment is directly removed. This method reduces the impact of short-term data loss on sample continuity and avoids interference from large segments of outlier data on model training. When temporary gaps or outliers occur during the online inference phase on the endpoint, valid data from before that moment can be used to estimate the current input to maintain continuous prediction.

[0030] After basic cleaning, a fixed-length sliding window method is used to construct the sample set. Using flow data from five consecutive time points as input and the flow value from the next time point as the supervised output, the sample set is generated by sliding the window time-by-time. The expression is:

[0031]

[0032]

[0033]

[0034] In the formula, Let be the flow rate at time t. The input to the model at time t, This is the output of the model at time t. Represents the training sample set, This indicates the total length of the flow sequence.

[0035] After adopting the above sample construction method, the window slides along the time axis moment by moment, thereby transforming the original flow time series into a large number of supervised samples suitable for training time series prediction models. Since flood processes have obvious temporal correlations, flow information from five consecutive moments can provide basic context for prediction at the next moment.

[0036] The data was then standardized by using Yeo Johnson transformation and standard deviation standardization to convert the original traffic data into approximately normally distributed data with a mean of 0 and a variance of 1, in order to reduce the adverse effects of skewed distribution and numerical fluctuations on model training.

[0037] The statistics of the training set are calculated as follows:

[0038]

[0039] In the formula, Q represents the original flow data, and q represents the approximately normally distributed data of Q after Yeo Johnson transformation. It is a real number.

[0040]

[0041]

[0042]

[0043]

[0044] In the formula, The average traffic of the training set. To train the standard deviation of the flow, The length of the training set data. For standardized training data, This is the standardized test data.

[0045] The training set calculates the mean and standard deviation separately, while the test set directly reuses the statistical parameters of the training set, thereby avoiding the leakage of test information into the training phase and improving the objectivity of the evaluation results.

[0046] After obtaining standardized samples, an LSTM flood prediction model is constructed and trained based on the sample data.

[0047] The LSTM flood prediction model employs a two-layer stacked LSTM structure to enhance its ability to model long-term dependency features of hydrological time series. The model uses 256 neurons in the hidden layer of the LSTM, followed by a feedforward network with 512 neurons in its hidden layer. A Dropout layer is added to the network to reduce the risk of overfitting. The Dropout processing can be represented as follows:

[0048]

[0049] In the formula, Features after random discarding These are the input features for the Dropout layer. is a 0~1 mask matrix whose elements follow a Bernoulli distribution.

[0050] The gating units and state update process in an LSTM network can be represented as follows:

[0051] Forgotten Gate:

[0052]

[0053] Input Gate:

[0054]

[0055] Candidate cell status:

[0056]

[0057] Cell status update:

[0058]

[0059] Output gate:

[0060]

[0061] Hidden status update:

[0062]

[0063] in, Output for the forget gate. For input gate output, Candidate cell state, The current cell state, For output gate output, Currently in a hidden state. Input for the current time, h t-1 and C t-1 These represent the hidden state and the cell state from the previous moment, respectively. , , , For learnable weights, , , , For learnable bias, It is the Sigmoid activation function. The hyperbolic tangent activation function is used. This is an element-wise multiplication operation.

[0064] The output of the second-layer LSTM is fed forward to obtain the prediction result, which can be expressed as:

[0065]

[0066] In the formula, For the model prediction results, For activation function, This represents the final hidden state of the second LSTM layer. and represents the learnable weights and bias vectors of the feedforward network.

[0067] During the model training phase, the mean absolute error is used as the loss function, expressed as:

[0068]

[0069] in, For model training loss, For model training batch size, For the model prediction results, These are the actual measurement results.

[0070] The initial learning rate is set to 1e-4, and a cosine annealing strategy is used to dynamically adjust the learning rate, the expression of which is:

[0071]

[0072] in, Let be the learning rate at step t. To minimize the learning rate, The initial maximum learning rate, This represents the current number of training steps for the model. This represents the maximum number of training steps for the model.

[0073] The maximum number of training steps is set to 300, and an early stopping mechanism is implemented. Training is terminated when the validation set metrics no longer improve after several consecutive training epochs. This network structure and training strategy balances flood sequence modeling capability, training stability, and model generalization performance.

[0074] After completing the model training, the trained LSTM flood prediction model is converted into an ONNX model and then lightweighted to obtain a lightweight flood prediction model.

[0075] The trained PyTorch LSTM flood prediction model was converted to the ONNX standard format to improve its deployability across different hardware and software environments. Subsequently, multi-level lightweighting was performed on the model based on the ONNX Runtime.

[0076] Lightweight processing includes the following: optimizing the computation graph to eliminate redundant nodes and merge related operators, reducing the number of operator calls and graph execution overhead during the inference phase; performing constant folding, pre-compiling constant expressions and caching results to reduce redundant computation; implementing quantization optimization, converting FP32 floating-point precision to a lower precision format and using FP16 quantization to achieve model size compression and reduced memory usage; and simultaneously performing hardware adaptation optimization for edge CPU instruction sets to improve local computing efficiency under x86 and ARM architectures.

[0077] After obtaining the lightweight flood prediction model, the model is deployed on the end-side device to perform local rolling inference on the real-time collected flow monitoring data and output the flood prediction results.

[0078] The end-side equipment can be a monitoring workstation, compatible with both x86 and ARM hardware architectures. River flow data can be collected by the flow monitoring equipment using spatiotemporal image velocimetry and then sent to the monitoring workstation.

[0079] The monitoring workstation locally completes data cleaning, window construction, standardization, model inference, and prediction output, thus forming an integrated closed loop of "data acquisition - local preprocessing - model inference - prediction output".

[0080] Local rolling inference employs a real-time data replenishment strategy. The maximum inference step size of the model is set to S. max Given an initial inference window:

[0081]

[0082] After inputting the model into the current window, the predicted flow rate for the next time step can be obtained:

[0083]

[0084] Update the input window after completing the current step prediction:

[0085]

[0086]

[0087] Where step represents the number of reasoning steps. The model predicts the first Flow rate at any moment The model number is represented by the first... Input at any time This represents the maximum inference step size.

[0088] In this rolling forecasting process, the current forecast result is added to the end of the window, while old data at the front of the window is removed, thus forming the model input for the next time step. If new measured flow data is available at the current time, the measured data is used to update the window first; if there are gaps or anomalies, they are supplemented with previous valid data and model inference results to maintain continuous forecasting. This mechanism is suitable for the need for short-term, continuous, and real-time flow forecasting in rapid confluence scenarios in small and medium-sized watersheds.

[0089] In other embodiments, without departing from the core concept of this invention, equivalent adjustments can be made to the number of LSTM network layers, the number of hidden units, the quantization accuracy, and the edge adaptation strategy. In scenarios with stronger edge resource constraints and relatively lower accuracy requirements, INT8 quantization can be used instead of FP16 quantization to further reduce model storage and computational resource consumption. All of the above adjustments do not change the core ideas of this invention regarding the integrated edge-side monitoring and reporting closed loop and lightweight model deployment.

[0090] In summary, by processing missing and outlier values ​​in flow data, and combining this with sliding window sampling and standard deviation standardization, we can improve the quality of input data and enhance the learnability of sample sequences, thereby solving the problems of high data noise and insufficient sample stability in existing end-side flood prediction.

[0091] By constructing a two-layer LSTM flood prediction model and combining it with Dropout, mean absolute error loss, cosine annealing learning rate scheduling, and early stopping mechanism, the long-term dependencies of the flow sequence can be fully captured and the training stability can be improved, thereby solving the problem of insufficient accuracy and generalization ability of existing flood prediction models in edge scenarios.

[0092] By converting the trained model to the ONNX standard format and performing computation graph optimization, constant folding, quantization optimization, and hardware adaptation optimization, the model size, memory usage, and power consumption can be reduced while maintaining prediction accuracy. This solves the problem that deep learning flood prediction models are difficult to adapt to edge resource constraints.

[0093] By deploying lightweight models on edge devices such as monitoring workstations and performing local inference, a closed loop of monitoring and reporting can be formed, encompassing "data acquisition - local preprocessing - model inference - prediction output," thereby solving the problems of existing technologies relying on cloud transmission and cross-device communication, and being susceptible to network environment influences.

[0094] By introducing real-time data supplementation and rolling update mechanisms during the edge-side inference process, continuous forecasting capabilities can be maintained in scenarios with data gaps, anomalies, or weak networks, thereby improving the real-time performance, stability, and engineering adaptability of flood forecasting services.

[0095] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. An ONNX-based end-side lightweight LSTM forecasting integrated flood prediction method, characterized in that, include: Acquire and preprocess flow monitoring data to construct sample data for flood prediction; An LSTM flood prediction model is constructed and trained based on the sample data; the trained LSTM flood prediction model is converted into an ONNX model and lightweighted to obtain a lightweight flood prediction model; the lightweight flood prediction model is deployed on the edge device to perform local rolling inference on the real-time collected flow monitoring data and output the flood prediction results.

2. The method according to claim 1, characterized in that, The preprocessing includes: processing missing and outlier values ​​in the collected traffic data; using linear interpolation to supplement missing or outlier values ​​when the continuous length corresponding to a missing or outlier value is less than 3 time steps, and directly discarding them when it exceeds 3 time steps; and using a fixed-length sliding window method, taking traffic data from 5 consecutive time steps as input and the traffic flow at the next time step as the prediction target to generate training samples.

3. The method according to claim 2, characterized in that, The preprocessing also includes standardizing the traffic data using Yeo Johnson transformation and standard deviation normalization, following the principle of standardizing the training set separately and reusing the standardized parameters of the training set for the test set.

4. The method according to claim 1, characterized in that, The LSTM flood prediction model adopts a 2-layer LSTM stacked architecture, with 256 neurons in the LSTM hidden layer and 512 neurons in the feedforward network hidden layer, and introduces a fully connected feedforward neural network and the ReLU activation function.

5. The method according to claim 4, characterized in that, The construction and training of the LSTM flood prediction model includes: using the mean absolute error as the loss function, setting the initial learning rate to 1e-4, adjusting the learning rate using a cosine annealing strategy, setting an early stopping mechanism, and setting a maximum training step of 300 steps.

6. The method according to claim 1, characterized in that, The local rolling inference adopts a real-time data supplementation strategy: the traffic predicted at the current moment is added to the end of the input window, and the old data at the front of the window is removed to form a new window for prediction at the next moment; The number of inference steps for the local rolling inference is set within a preset maximum inference step size range.

7. The method according to claim 1, characterized in that, The step of converting the trained LSTM flood prediction model into an ONNX model includes converting the PyTorch format LSTM flood prediction model into the ONNX standard format to achieve cross-platform deployment compatibility.

8. The method according to claim 7, characterized in that, The lightweighting process includes: performing computation graph optimization based on ONNX Runtime, constant folding, quantization optimization to convert FP32 to FP16, and hardware adaptation optimization for edge CPUs; the model prediction accuracy change rate after lightweighting is less than 0.002%.

9. The method according to claim 1, characterized in that, The end-side device is a monitoring workstation, adapted to x86 and ARM architectures, and supports multiple monitoring frequency scenarios; the local rolling inference includes: collecting river flow data through flow monitoring equipment, performing preprocessing, model inference, and prediction output locally on the end-side device, forming an integrated monitoring and reporting closed loop.

10. The method according to claim 1, characterized in that, During the edge-side inference phase, if data gaps or anomalies occur, the input window is supplemented with valid data prior to the aforementioned gaps or anomalies, and the corresponding flow rate is calculated based on the model inference results.