# Real-Time Pipeline Leak Detection: A Hybrid Deep Learning Approach Using Acoustic Emission Signals
## 2 Proposed Methodology
### CNN and LSTM Hybrid Structure
#### 2.3.2 Long Short-Term Memory  
LSTM is a type of RNN, specifically designed to handle and process long-time sequence information. The LSTM architecture for the proposed model is described below in Table 1. Unlike traditional RNNs, LSTM can handle long-term dependencies more effectively by incorporating a gate mechanism and cell state [34]. The network consists of three key gates: the forget gate, input gate, and output gate, which are responsible for controlling the flow of information through the network. These gates work together to manage memory retention, input updates, and output generation, enabling LSTMs to effectively capture long-term dependencies in sequential data. Figure 5 provides a visual representation of this architecture, illustrating how these gates interact to regulate the information flow across different time steps.  
Figure 5: LSTM architecture for the proposed model.  
The forget gate controls which information from the previous cell state should be discarded or retained. It evaluates the importance of past information using a sigmoid activation function and is mathematically expressed as:  
\[f_{t}=\sigma\ \left(w_{f}\cdot\left[\ h_{t-1}\,\ x_{t}\right]+b_{f}\right) \tag{7}\]  
where \(w_{f}\) is the weight matrix, \(b_{f}\) is the bias vector, \(h_{t-1}\) is the output of the previous unit, and \(x_{t}\) is the current input.  
The input gate controls which new information is added to the cell state, computed as:  
\[i_{t}=\sigma\ \left(w_{i}\cdot\left[\ h_{t-1}\,\ x_{t}\right]+b_{i}\right) \tag{8}\]  
\[C_{t}=tanh\ \left(w_{g}\cdot\left[\ h_{t-1}\,\ x_{t}\right]+b_{g}\right) \tag{9}\]  
Here, \(w_{i}\) and \(w_{g}\) are weight matrices, \(b_{i}\) and \(b_{i}\) are bias vectors, and \(C_{t}\) represents the candidate cell state.  
The cell state combines the previous cell state information with the new one. The cell state is updated using:  
\[C_{t}=f_{t}\cdot C_{t-1}+i_{t}\cdot C_{t} \tag{10}\]  
\[C_{t}=f_{t}\cdot C_{t-1}+i_{t}\cdot C_{t} \tag{11}\]  
where \(C_{t-1}\) is the previous cell state and \(\cdot\) denotes element-wise multiplication.  
Output gates determine the next hidden state, and from the cell state, which information should be output, where the output gate is given by:  
\[h_{t}=o_{t}\cdot tanh\ (C_{t}) \tag{12}\]  
where \(w_{0}\) and \(b_{0}\) are the weight matrix and bias vector. The hidden state \(h_{t}\) is the output of the LSTM unit.  
The CNN-LSTM model processes AE-CWT images through a hybrid architecture that combines spatial feature extraction and temporal pattern recognition. The workflow begins with the CNN component, where the input images are passed through three convolutional layers to extract spatial features. The first convolutional layer applies 32 filters of size 3 \(\times\) 3, followed by a 2 \(\times\) 2 max-pooling layer, reducing the feature map size from 654 \(\times\) 873 to 327 \(\times\) 436. In the second convolutional layer, 64 filters of size 3 \(\times\) 3 are applied, and another 2 \(\times\) 2 max-pooling layer further reduces the feature map to 162 \(\times\) 217. The third convolutional layer employs 128 filters of size 3 \(\times\) 3, followed by a final 2 \(\times\) 2 max-pooling layer, which compresses the output to 80 \(\times\) 107. The resulting 3D feature map is then flattened into a 1D vector of size 1,095,680 and passed into an LSTM layer with 64 units. The LSTM layer captures temporal dependencies within the sequential data using a tanh activation function, enabling the model to recognize time-dependent patterns essential for detecting pipeline faults effectively.  
This hybrid CNN-LSTM architecture combines the spatial feature extraction capabilities of the CNN with the temporal sequence modeling strengths of the LSTM. This synergy allows the model to capture intricate spatial patterns while maintaining an understanding of time-dependent relationships, making it highly effective for pipeline fault detection and diagnosis.