# Fault Diagnosis Algorithm of Beam Pumping Unit Based on Transfer Learning and DenseNet Model
## 2 Fault Diagnosis Model and Application Method
### Fault Diagnosis Model  
#### 2.2.1 Convolutional Neural Network and Transfer Learning  
The convolutional neural network is one of the classic algorithms of deep learning, that is, a kind of feedforward neural network that includes convolutional computation and has deep structure. The convolutional neural network is constructed by imitating biological visual perception, and its convolution layer can describe the image features with a small amount of computation, which enables it to have a stable operation effect and means it does not need to carry out additional feature engineering features [14]. A convolutional neural network consists of an input layer, a hidden layer, and an output layer. After the data are filtered, the input layer preprocesses the filtered data and converts all data into a unified format, the preprocessed images are input to the convolutional layer and pooling layer for feature extraction and computational analysis, and the images to be classified are converted into feature images. Through full connection layer matching, the final output is reached the target value. The main execution flow is shown in Figure 4[15]. The input  
Figure 2: Theoretical indicator diagram under static load. layer of the convolutional neural network can receive arrays from one to four dimensions depending on the structure. Before input of the learning data into the hidden layer, the data should be normalized to improve the accuracy and efficiency of the algorithm. The hidden layer of a convolutional neural network algorithm usually consists of three structures: convolutional layer, pooling layer, and fully connected layer. We identify the two-dimensional convolution function of the image as Equation (1) [16]:  
\[S=X\times W= \sum_{i,j=1}^{m\times n}x_{\mathrm{ij}}\times w_{\mathrm{ij}} \tag{1}\]  
where:  
\(S\)--characteristic coefficient;  
\(X\)--input matrix;  
\(W\)--convolution kernel matrix;  
\((i,j)\)--the position of the variable in the feature matrix;  
\((m,n)\)--the position of the convolution kernel element. The convolutional layer contains multiple convolution kernels, which are similar to neurons in a feedforward neural network. The parameters of the convolution layer include the size, step size, and filling method of the convolution kernel. These three factors jointly determine the size of the output feature graph of the convolutional layer. The convolutional layer contains an excitation function to help it express complex features. After feature  
Figure 4: Diagram of convolutional neural network image recognition process. Figure 3: Example of Dynamometer Fault Types. extraction in the convolutional layer, feature selection and filtering are carried out in the convolutional layer. Through the preset pooling function, the result of a single point in the feature map is replaced by its neighboring area feature map statistics. The pooling function is expressed as Equation (2) [17,18]:  
\[A(i,j)=\left[\Sigma_{x=1}^{f}\Sigma_{y=1}^{f}A_{k}^{l}(s_{0}i+x,s_{0}j+y)^{p} \right]^{\frac{1}{p}} \tag{2}\]  
where:  
\(s_{0}\)--step length;  
\(A\)--output value;  
\(f\)--size of pooling layer;  
\(p\)--optional coefficient, when \(p=1\), the value of \(A(i,j)\) is denoted as \(L_{1}(A)\), called mean pooling; when \(p=\infty\), the value of \(A(i,j)\) is denoted as \(L_{\infty}(A)\), called maximum pooling;  
\(\mu\)--the random parameter is determined by the actual operation;  
\(k\) value--calculated channel position;  
\(l\)--calculate channel position. The fully connected layer of the convolutional neural network is located at the end of the hidden layer of the convolutional neural network, which expands the feature graph into a vector and transmits it to the next layer through the activation function. The fully connected layer performs a nonlinear combination of the extracted features and uses the extracted high-order features for learning.