# Fault Diagnosis Algorithm of Beam Pumping Unit Based on Transfer Learning and DenseNet Model
## 3 Dynamometer Classification Model Based on the Transfer Learning Method
### Training Results and Discussion
#### 3.3.2 Comparative Experiments of Different Depth Convolutional Network Models  
To further verify the recognition effect of the model, experiments were conducted under the same conditions to compare the classification effects of ResNet, Xception, and MobileNet, three deep convolutional network models with 15 kinds of indicator diagrams. The analysis effect of neural networks on data features in machine learning is often directly related to the number of network layers. Deep networks can describe data features well, but the difficulty of training increases with the depth of the network. The ResNet model applies the residual block structure shown in Figure 12, which effectively solves the problem of gradient disappearance in deep networks and effectively solves the problem of degradation in deep neural networks [20]. The structure shown in Figure 12 is a three-layer residual structure, and the number of residual block layers is self-designed according to the task situation. According to the above structure, the residual structure output for any layer depth \(L\) can be expressed as Equation (9):  
\[Y_{L}=x_{l}+\sum_{i=l}^{L-l}F(x_{i},W_{i}) \tag{9}\]  
where:  
\(Y_{L}\)--the output of the residual block;  
\(x_{l}\)--input feature vector for the lth layer;  
\(F(x_{i},W_{i})\)--the mapping function that needs to be learned;  
\(W_{i}\)--the projection matrix. The basic model is established according to the ResNet structure. After pretraining on ImageNet, the convolutional layer is used as the feature extraction structure, and the bottom layer of the residual model is added to a fully connected layer as a classifier. The dropout function is added to the fully connected layer, as shown in Equation (5). The established residual model is trained, and the initial learning rate is 0.01. The loss function is the same as Equation (7), and the learning rate decreases with the increase of training time. Figure 12: ResNet structure. In this paper, the TensorFlow machine learning development platform is used to train the transfer learning model based on the ResNet model, and the indicator diagram classification experiment is carried out. The experimental environment is the NVIDIA Tesla T4 computing platform. The model is tested while the training set is trained, and the output of the training set and test set are recorded as shown in Figure 12(a),b, respectively, and the test results are shown in Figure 12(c). The recognition accuracy of the test set is 95.3%, the output loss of the test set is 0.618, and the single training time of the model is 8.021 s.  
In Figure 12(a),b, the abscissa represents the number of training times, the ordinate represents the training accuracy and output error of the model, respectively, and the two curves represent the training set and test set data, respectively. The experimental results show that the transfer learning model based on the ResNet model can basically complete the indicator diagram classification task. As can be seen from Figure 12(a), the accuracy of the model increases rapidly in the early stage of training. Compared with the classic deep learning model, the transfer learning model has a faster growth rate in the early stage of training; after about 40 times of training, the model accuracy enters a gentle growth range, and then the training set accuracy gradually stabilizes at 1. It can be seen from Figure 12(b) that the data loss trend of the training set is opposite to the accuracy rate. In the early stage of training, both the training set and the test set have a high degree of data loss, but it quickly drops to a normal level, and then the data loss decreases steadily until the trend is flat, entering the lower data loss range. In the flat interval, the data loss of the test set fluctuates less, but it is always larger than the training  
Figure 12: Transfer learning model training results based on ResNet model. set, indicating that there is a certain deviation between the model and the actual situation.