Deep learning-based modeling of CO2 corrosion rate prediction in oil and gas pipelines
Published Online: Mar 19, 2025
Received: Nov 06, 2024
Accepted: Feb 04, 2025
DOI: https://doi.org/10.2478/amns-2025-0415
Keywords
© 2025 Jian Cui et al., published by Sciendo
This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.
Oil and gas pipeline is an important facility for oil and gas transportation, which carries the heavy responsibility of national economic development. Pipelines will have corrosion problems in long-term operation, and if they are not effectively protected, they will have a serious impact on the safety and operation of pipelines [1–3]. Carbon dioxide corrosion refers to the oil and gas pipeline containing a certain concentration of carbon dioxide and water corrosion. Some natural gas, especially condensate, often contains high concentrations of carbon dioxide. Carbon dioxide dissolved in the extraction water or condensate to generate bicarbonate ions, carbonate ions ions, so that the steel electrochemical corrosion [4–7]. Carbon dioxide corrosion belongs to hydrogen depolarization corrosion, often more serious than the same pH value of the strong acid corrosion. Its corrosion is controlled by the rate of depolarization reaction, but also with the corrosion products on the metal surface to form a film and the stability of the film, so the prediction of CO2 corrosion rate in oil and gas pipelines is of great significance [8–11].
The corrosion of oil and gas pipelines containing CO2 is mostly generated in the pipeline as well as water-soluble carbonic acid occurs in a typical electrochemical process, in the electrochemical effect, the pipeline occurs thinning, perforation and other manifestations. Therefore, when predicting the corrosion rate of oil and gas pipelines, the accuracy of the remaining life prediction should be guaranteed as much as possible [12–14]. The corrosion study of CO2-containing oil and gas pipelines should not be analyzed only at the qualitative level, but should be further analyzed quantitatively, based on a comprehensive form of corrosion rate prediction model, to predict the corrosion rate of CO2-containing gas wells, to determine the time of pipe replacement and renewal of pipe, etc., in order to ensure the long-term stable and economic production of oil and gas [15–18].
A CO2 corrosion model was constructed in the literature [19] to predict the corrosion rate of steel in oil and gas production and transportation systems. Based on experimental data, it was pointed out that the model covers different scenarios such as deoxygenated CO2 corrosion, aerated CO2 corrosion, etc., and the characteristics of the model and the connection between the different scenarios were outlined. Literature [20] presented a practical implementation of a robust integrated learning model for predicting corrosion rates within oil and gas pipelines, and the learning model was verified to have excellent performance through a series of studies. Literature [21] explored different prediction models used to assess the co-corrosion of carbon steel in the oil and gas industry. The differences between these models are explained, with the largest differences being in the “prediction of the effect of protective corrosion film” and “the effect of oil wetting on co-corrosion”. Literature [22] created a model for predicting internal pitting corrosion in oil and gas pipelines, which was able to predict the growth of pitting corrosion, including other internal pits not included in the model, based on readily available operating parameters by taking into account the statistical properties of pitting corrosion, and identified errors in the predictions, which were demonstrated based on data from multiple operating pipelines. Literature [23] constructed a neural network-based corrosion rate prediction model for oil and gas pipelines, and applied the LM back propagation algorithm to optimize the training of this model in order to improve its prediction accuracy. The model was also validated using MATLAB, and it was found that the prediction accuracy of the model was very high and could accurately predict the corrosion rate of the pipeline through the evaluation of industrial datasets.
In this study, in order to study the corrosion rate of CO2 in oil and gas pipelines, deep learning is used as the basic tool, and deep confidence networks, generative adversarial networks, and the Transformer model are studied in detail. Combined with the mechanism of corrosion rate of oil and gas pipelines, corrosion factors are selected, and in order to meet the needs of model training, this paper expands the collected corrosion data, and extracts the main features of corrosion rate through correlation analysis and principal component analysis. Finally, this paper uses the Adam algorithm to optimize the DBN model, proposes a corrosion rate prediction model based on the improved DBN model, and tests the prediction effect of the model to compare the prediction performance of different models.
Simply put, deep learning algorithms are an enhanced version of traditional machine learning methods. If traditional machine learning algorithms can be viewed as a one-layer neural network, deep learning algorithms can be viewed as a multi-layer neural network. Thus, deep learning algorithms are a relative concept, a subset of machine learning algorithms.
Deep learning algorithms extract features from traditional machine learning algorithms and incorporate them into the model training process. That is, the input data is fed directly into the model, and the feature extraction is carried out through the deep learning model internally before training, so that the main step of manually extracting features can be eliminated and the training process of the model can be simplified. Since deep learning models incorporate the feature extraction method into the model, this also increases the complexity of the model. It is due to this complexity that deep learning models learn deeper features. What’s more, deep learning models can save a lot of labor by extracting various features through their own learning. In recent years, with the continuous development of deep learning algorithms, deep learning models have been widely used in applications such as images, speech, text, and so on. With the full utilization of computer hardware resources, the advantages of deep learning models are becoming more and more prominent.
Deep Confidence Network Model (DBN) was first proposed in 2006, the basic constituent unit of DBN network is RBM, there are
In Eq.
Due to the independence between the layers, the joint probability distribution of (
Because of the feature of unconnected layers, the activation probability of
The purpose of RBM training and learning is to find the value of parameter
In the recent development of neural networks and deep learning, the RBM model has played a significant role, and it is the foundation for deep confidence networks and deep Boltzmann machines. In addition, it can be used as a generative and discriminative model in a variety of domains, such as classification, dimensionality reduction, topic modeling, and so on.
The first layer of a DBN network is the visible layer V, which is used to receive raw data signals and then transmit the signals to the hidden layer H for feature extraction, which usually consists of a number of layers with different numbers of neurons, depending on the size of the data. During unsupervised training, V and H1 constitute the first RBM, and H1 and H2 constitute the second RBM. Neurons in the layers are connected together, but there is no connection between the layers. The data information from the previous RBM’s hidden layer is acquired by the hidden layer of each RBM, and several better and more abstract features are extracted from it. Finally, the feature data is transmitted to the third part of the DBN, the output layer, where the number of neurons is usually given according to the training task, and in case of a classification task, the number of neurons is the number of classifications.
There are multiple RBMs in the traditional DBN, and its learning process is divided into unsupervised training and backward fine-tuning. First, each RBM is trained according to the unsupervised greedy training method. In this process, the weights are updated using the contrast gradient algorithm. The hidden layer of the current RBM is treated as the visible layer of the next RBM, and then trained with the same steps until the last layer of the RBM is trained.Second, the network is extended into a forward neural network, where all neurons are locally optimized and the weights of the whole network are adjusted using the BP algorithm. The input data travels through the entire DBN network layer by layer, with each layer obtaining more high-level functionality than the previous layers. In two ways, deep learning has substantial advantages over traditional neural network learning methods. One benefit of each layer is that it greatly improves training efficiency, while the other is that they avoid the risk of traditional neural networks falling into local minima in an unsupervised learning environment.
In 2014, Generative Adversarial Networks (GAN) was proposed. GAN is one of the most widely used applications in adversarial learning. The structure of GAN consists of a generator and a discriminator. Random noise can be input into the generator to get a pseudo sample, and real samples together into the discriminator, the discriminator by judging the input samples and generator to form a game training, the discriminator’s goal is to accurately distinguish between the input samples and the generator’s goal is to make the pseudo samples as far as possible with the real samples to form the same distribution, and repeated training of the two networks to form a dynamic Nash equilibrium. Training the discriminator results in a greater discriminative loss, while training the generator results in a smaller loss, so the objective function of the GAN is defined as:
Fixing the generator network
Where
Here, JS stands for the Jensen-Shannon distance, which is used to evaluate the gap between the two distributions, and its property compared to the KL distance is that it is non-negative, so in order to minimize the loss of the generator, in this paper, we only need to minimize the value of JS to achieve the lowest value of the loss –log4. And the minimum value of JS indicates that the distributions of the two are exactly the same, and so finding the best generator is actually is the way to find the minimum JS value. After many rounds of iteration, according to the theoretical derivation, the quality of the final sample should be infinitely close to the real sample, which makes it difficult for the discriminator to distinguish the generated sample from the real sample.
Transformer model is a deep neural network coupled with a self-attention mechanism and parallelized processing data proposed by the Google team in 2017. Transformer is a deep learning model based on self-attention. Transformer model consists of an encoder and a decoder, where the encoder is used to encode the input sequence and the The decoder is used to generate the output sequence, which was initially used in the field of Natural Language Processing (NLP).The Transformer network uses a self-attention mechanism to process the sequence information as a whole, avoiding recursive transfer between information and allowing attention to local information with strong correlation.
The self-attention mechanism allows the model to focus on different locations in the input sequence during encoding and decoding, thus capturing long-distance dependencies in the sequence. It performs a weighted summation of the sequence by computing the attentional weights between the query, keys, and values to obtain a representation of each position.
In the Transformer model, each encoder and decoder layer consists of a multi-head attention mechanism and a feed-forward neural network. The multi-head attention mechanism allows the model to pay attention in different representation subspaces, thus capturing semantic information at different levels and from different perspectives.The Transformer model has achieved remarkable success in text processing tasks, especially in machine translation tasks. It is capable of modeling the input sequence globally and has good parallel computing performance. The mathematical representation of the self-attention mechanism is shown below:
Transformer’s encoder and decoder achieve global modeling by stacking multiple self-attention layers and feedforward neural network layers. The encoder is used to encode the input sequence and the decoder is used to generate the output sequence. In addition to BERT, the Transformer model has spawned many other variants and improvements, such as XLNet, an improved version of BERT, and Transformer-xl, which enhances Transformer’s ability to model long-term dependencies.These models have made significant progress in the field of natural language processing and have become benchmark models for many tasks.
CO2 often exists in the form of associated gas in oil and gas, and its corrosion type mainly includes localized corrosion and uniform corrosion. Localized corrosion, including pitting, surface corrosion and flow-induced localized corrosion, etc., this type of corrosion can easily lead to oil casing puncture, but also the main form of damage and failure of oil casing. Localized corrosion is mainly generated with the CO2 corrosive environment in the surface of the casing corrosion product film generated in close contact with the corrosive medium flow rate and the composition of the casing material will also affect the occurrence of localized corrosion. The CO2 localized corrosion of the oil casing has been the focus of the corrosion field, but the current research on localized corrosion is still insufficient, and can not make accurate judgment and prediction of the localized corrosion rate. When CO2 in the form of uniform corrosion exists, all or most of the area of the exposed part of the oil casing is uniformly damaged by corrosion, which leads to a reduction in the strength of the tubing and the thickness of the tubing wall, and it is easy to fall out of the well accident. Uniform corrosion is mainly controlled by the corrosion product film formed on the surface of the casing, but also by the corrosive environment CO2 partial pressure, temperature, corrosive medium flow rate, corrosive medium pH value and alloying elements in the pipe.
CO2 corrosive effect is mainly through CO2 dissolved in aqueous solution after the formation of carbonic acid and caused by galvanic corrosion. When the steel surface encounters aqueous solution containing CO2, the surface will easily generate corrosion product film or deposit a layer of scale, when the film or scale is more dense, like a physical barrier to inhibit the continuous corrosion behavior of steel. However, when this layer of film or scale for the structure is not dense, this layer of metal under the scale will form an oxygen-deficient area, it is easy to form an oxygen-rich area with the surrounding oxygen-concentrated electrode, oxygen-deficient area of steel due to the oxygen deficiency potential is more negative and anodic iron dissolution occurs, the formation of a small anode, and finally with the rear outside of the large cathode area to form a corrosive battery of a small anode and a large cathode, to promote corrosion of the corrosion product film or the corrosive effect of the steel under the rear.
About CO2 corrosion mechanism and law gradually tends to mature, generally believe that the reaction of its corrosion process as follows:
First, CO2 dissolved in aqueous solution to form carbonic acid:
H2CO3 in aqueous solution undergoes a two-step ionization:
Steel undergoes galvanic corrosion in H2CO3 solution:
Its total corrosion reaction is:
During the corrosion process, intermediate product
Due to the differences in experimental setup conditions, in addition, the lack of effective experimental validation regarding
In the process of oil and gas extraction of various types of corrosive associated gases,
The electrochemical reaction of iron in an aqueous solution of
HS corrosive environment with the difference in environmental conditions may both accelerate the corrosive effect of steel, but also inhibit the corrosion of steel. In the acidic medium solution, HS promotes accelerated cathodic reaction precipitation of hydrogen atoms and anodic iron dissolution rate, thus the corrosion rate rises accordingly, while when the HS concentration content in the medium solution is less than 0.44×10−3
Regarding the corrosive effect at low
The corrosion intermediate product
In general, DBN can be categorized into two phases for training: unsupervised layer-by-layer pre-training and supervised backward fine-tuning process. Default values for all network weights are set at the beginning, followed by the implementation of pre-training for each independent and mutually exclusive part, i.e., each layer of the RBMs, to ensure that it maps various attributes in the input samples into different dimensions and maintains as much as possible the correlation between them. Since the sample features may be distributed across multiple potential states, a BP network is ultimately used to complete the DBN’s global correction of the entire system until a specified maximum number of cycles is satisfied or until a certain range of error rates is allowed to be tolerated.
Neural network contains very many parameters which will affect the training of the model as well as the final output, and the optimizer is mainly used to update and calculate these parameters, so choosing the right optimizer is necessary for neural network. When we train the model, we have to set the size of the learning rate, and the learning rate itself is difficult to adjust, and for many neural network optimizers, some small changes in the learning rate will make the model have different performance, if the learning rate is not set appropriately, it may seriously affect the final results of the model.
The most common method of parameter gradient update algorithm currently applied in DBN is SGD (Stochastic Gradient Descent), which is used to update the gradient formula:
Where t represents the number of iterations counter,
In Adam’s algorithm, the value of ||
The modified first-order and second-order variable update formula is:
The parameter update formula is:
Compared with the Adam optimization algorithm to record the first-order variables of the gradient, the optimized Adam-DBN algorithm uses the traditional momentum method in the computation of the first-order variables and retains only the momentum factor
Based on the analysis of the corrosion mechanism of oil and gas pipelines, temperature, pH, pressure and other factors will affect the corrosion rate of pipeline CO2, in which the wall shear is deeply affected by the temperature, pressure, medium and flow rate, the corrosion product film will play a protective role on the pipe wall to slow down the corrosion, but the corrosion product film is subject to a number of factors, such as temperature and pH, and so on, therefore, in the construction of the corrosion rate of CO2 Therefore, when constructing the input indexes of CO2 corrosion rate prediction model, the factors with eigenvalue greater than 1 and cumulative contribution rate above 85% are considered.
Due to the complex environment of oil and natural pipelines, it is more difficult to collect data, due to the small number of samples, resulting in the corrosion prediction based on deep learning is not comprehensive enough, so through the collection of existing data for data expansion data in order to be used for the training of deep learning algorithms, a total of 75 sets of data were collected in this paper, and 75 sets of the sample set of the oil and gas pipelines were expanded through Matlab, which was divided into 60 The training samples are divided into 60 training samples and 15 samples to be predicted, and the original corrosion remaining life training samples are expanded to 1000 by using double cubic interpolation and inverse distance-weighted interpolation, in order to obtain sufficient and reasonable data sets to be applied to the prediction of the remaining corrosion life of buried pipelines, and 978 groups of corrosion data are obtained by eliminating some invalid data.
Based on the acquired data, the corrosion factors are sorted out and their importance is determined. If there is a strong correlation between the factors, the dimension will be reduced. If there is no strong correlation between the factors, then these results can be used directly for prediction. According to the size of the absolute value of the correlation coefficient to identify the degree of correlation of different corrosion factors, 0 ~ 0.3 indicates a weak correlation, 0.3 ~ 0.5 is a low correlation, and 0.5 or more is judged to have a significant correlation.
The corrosion factor correlation analysis results are shown in Table 1, corrosion factors G1~G9 are temperature, pH, pressure, medium, flow rate, material selection, water content, carbonic acid concentration and CO2 concentration, respectively. The correlation coefficient of carbonic acid concentration (G8) and CO2 concentration (G9) is 0.715 which is greater than the absolute value of correlation coefficient r of 0.5, the correlation relationship is more significant. The correlations of the other corrosion factors are not very obvious, or even very weak. In other words, the correlation degree of corrosion factors is relatively low from the overall situation. Considering the carbonic acid concentration (G8) and CO2 concentration (G9), the correlation between the two corrosion factors is relatively high, and the principal component analysis is chosen to extract the main components of the pipeline corrosion factors.
Analysis of corrosion factor correlation analysis
| Evaluation factor | G1 | G2 | G3 | G4 | G5 | G6 | G7 | G8 | G9 |
|---|---|---|---|---|---|---|---|---|---|
| G1 | 1 | ||||||||
| G2 | 0.231 | 1 | |||||||
| G3 | -0.181 | 0.215 | 1 | ||||||
| G4 | 0.123 | 0.231 | 0.345 | 1 | |||||
| G5 | 0.253 | 0.325 | 0.456 | 0.122 | 1 | ||||
| G6 | 0.189 | 0.123 | 0.485 | 0.213 | 0.213 | 1 | |||
| G7 | 0.231 | 0.321 | 0.012 | 0.005 | 0.322 | 0.214 | 1 | ||
| G8 | 0.321 | 0.231 | 0.030 | 0.023 | 0.125 | 0.216 | 0.038 | 1 | |
| G9 | 0.073 | 0.062 | -0.031 | 0.082 | 0.123 | 0.133 | 0.052 | 0.715 | 1 |
The corrosion sample data were standardized, and the principal component analysis was used for corrosion factor feature screening, and the variables were selected according to the cumulative contribution rate of more than 85% when extracting the main corrosion features.
The results of principal component analysis are shown in Fig. 1, (a) and (b) are the eigenvalues of principal component analysis, the contribution rate of principal component analysis and the cumulative contribution rate, respectively. It can be seen that the cumulative contribution rate of the first eight principal components is as high as 92%, more than 85%, in accordance with the general principle of selection in order to ensure the integrity of the corrosion structure, it is necessary to use the first eight principal components as the model input indicators. With the original corrosion characteristics data just 1 dimension difference, each corrosion factor except G8 and G9 have a strong correlation, the rest of the factors are weakly correlated, comprehensive consideration of the selection of the eigenvalue is greater than 1 and the cumulative contribution rate of 85% or more, and ultimately, in order to ensure the completeness of the corrosion dataset, do not remove the last corrosion factor.

Main component analysis results
According to the selected corrosion pipeline sample data and 9 principal components of the normalization process as the output of the whole system, the data obtained as input data randomly divided into the training set and test set, the data obtained according to the proportion of the randomly divided into two groups, 782 groups of data for model training, the remaining 196 groups for prediction, the input of the trained model for prediction, and comparison with the actual value to detect the effect of model prediction is shown in Figure 2. The CO2 corrosion rate prediction results can be seen in Fig. 2, from the comparison between the predicted corrosion rate and the actual corrosion rate, it can be seen that the predicted value is very close to the real value, and the maximum value of the relative error of CO2 corrosion rate is not more than 3%, which is small and the prediction effect is good.

Prediction of CO2 corrosion rate
In order to compare the prediction performance of this paper’s model more intuitively, it is compared with the previously mentioned traditional DBN model, Generative Adversarial Network (GAN), and Transformer model, and the relative errors of the prediction results of the different models are shown in Fig. 3, which shows that the improved DBN model in this paper has the best prediction effect, with the relative error stabilized between 1.3 and 2.8%, and the highest error compared to the The maximum error is reduced by 1.3% compared with the traditional DBN model. Compared to other models, the prediction effect of this paper’s model still has a significant advantage, which indicates that the prediction effect of this paper based on improved DBN is better.

Relative error of prediction of different models
In order to further verify the prediction effect of the constructed model, this paper will choose three indicators to compare the prediction results of different models, namely, the mean absolute error (MAE), the mean absolute percentage error (MAPE) and the root mean square error (RMSE). Comparison of model prediction performance is shown in Table 2, which shows that the MAE, MAPE and RMSE of the improved model in this paper are 0.035, 1.893% and 0.039 respectively, which are smaller than the other three groups of models. The effectiveness of the improved DBN model in this paper is further verified, and it performs better in predicting the CO2 corrosion rate in pipelines.
Model predictability can be compared
| Index | DBN | GAN | Transformer | Ours |
|---|---|---|---|---|
| MAE | 0.925 | 0.121 | 0.212 | 0.035 |
| MAPE(%) | 3.480 | 4.486 | 5.872 | 1.893 |
| RESE | 0.0985 | 0.135 | 0.321 | 0.039 |
In this paper, on the basis of deep learning, the DBN model is improved by using Adam algorithm, and the corrosion rate prediction model based on the improved DBN model is constructed, and the performance of different prediction models is analyzed through experiments. The findings of this paper are as follows: In order to meet the data requirements of the prediction model, this paper expands and characterizes the collected corrosion data, among which, the correlation coefficient of carbonic acid concentration (G8) and CO2 concentration (G9) is 0.715 greater than the absolute value of the correlation coefficient r of 0.5, the correlation is more significant, while the correlation of the other corrosion factors is not very obvious, or even more so, it is very weak. From the contribution rate of principal component analysis and the cumulative contribution rate, the cumulative contribution rate of the first eight principal components is as high as 92%, and the overall consideration is that in addition to the strong correlation between G8 and G9, the correlation with the rest of the factors is weaker, so in order to ensure the completeness of the corrosion dataset, the final nine corrosion factors are still used for analysis. The maximum value of the relative error of the CO2 corrosion rate prediction model based on the improved DBN model in this paper does not exceed 3%, and the relative error is stable between 1.3 and 2.8%, with the highest error reduced by 1.3% compared with the traditional DBN model. In addition, the MAE, MAPE and RMSE of the improved model in this paper are 0.035, 1.893% and 0.039, respectively, which are still the best prediction results compared with the traditional DBN model, GAN and Transformer model, and further validate the practical effect of the corrosion rate prediction model in this paper.
