# 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.1 Training Results Based on Transfer Learning  
This paper uses the TensorFlow machine learning development platform to conduct a DenseNet model-based transfer learning model indicator diagram classification experiment. The experimental environment is the NVIDIA Tesla T4 computing platform. The indicator diagram graph features are mainly composed of contour information, so this paper adopts global average pooling. The model was tested during the training set and test set, and Figure 6 records the output results of the training set and test set, respectively. The recognition accuracy of the test set is 96.9%, the output loss of the test set is 0.401, and the single training time of the model is 5.032 s.  
The training results of the densely connected model using the global pooling layer classifier are shown in Figure 6. Figure 6a shows the development trend of the accuracy rate. Initially, the accuracy rate increased rapidly, but the upward trend quickly flattened and stabilized within the range of 80% to 90%; after 140 times of training, the dense connection model was thawed and fine-tuned, the accuracy rate had increased significantly, and the accuracy rate of the training set had stabilized above 99%  
Figure 6b shows the data loss curve, the trend of which is basically the same as the accuracy curve. The data loss is relatively large at the beginning of training, but it will quickly drop to a stable range, and then the data loss will drop significantly after the model is thawed and fine-tuned. The pretraining set curve in Figure 6a is lower than the validation set curve, because the dropout layer randomly selects the parameters to freeze during the training process, and the curve appears after fine-tuning. The cross-training set accuracy improves rapidly. The data loss curve in Figure 5(b) shows that the data loss of the validation set during training is unstable, showing a downward trend but fluctuating greatly, which affects the final accuracy. There were 747 indicator diagrams randomly selected which contain all the types of working conditions that were tested for classification. The results are shown in Figure 5(c). It can be seen from Figure 5(c) that the model performs well under various types of working conditions and can meet the actual requirements, and various working conditions can achieve a high recognition rate. To verify the classification effect of the dense connection model on the indicator diagram, the classification effects of the fully connected layer classifier and the global pooling classifier were compared under the same experimental conditions. The recognition accuracy of the test set is 96.9%, the output loss of the test set is 0.371, and the single training time of the model is 7.038 s  
The model training results of the densely connected model using the fully connected layer classifier are shown in Figure 7. It can be seen from Figure 6(a),b that the initial accuracy rate increases rapidly, and the loss function decreases rapidly, indicating that the transfer learning model can quickly adapt to new tasks. The accuracy of the dense connection model based on the full connection layer increased with the increase of training time, and the model was thawed by fine-tuning after the increasing trend was flat, and the model accuracy increased as a whole. After 100 times of training, the accuracy curve of the training set basically tends to be flat and can be maintained above 98%; the curve of the validation set and the curve of the training set have a similar growth trend, and there is a curve crossing phenomenon, indicating that the neural network is not appear to be overfitting. Figure 6: Densely connected model applying global pooling layer classifier. After training, pictures containing all types of working conditions are randomly selected from the test set, for a total of 747 pictures, and are classified and tested to obtain Figure 6(c). In Figure 6(c), the ordinate is the real label, and the abscissa is the classification result.