# Fault Diagnosis Algorithm of Beam Pumping Unit Based on Transfer Learning and DenseNet Model
## 3 Dynamometer Classification Model Based on the Transfer Learning Method  
### Data Preprocessing  
Data preprocessing includes image size definition, sample labeling, sample training, batch classification, and sample normalization. The purpose of data preprocessing is to make the sample format consistent for easy calculation, while removing redundant information to reduce the amount of calculation  
A total of 5053 sets of fault diagnosis data were collected in a well area in Daqing Oilfield, including 37 types of data including normal, plunger up bump, plunger down bump, insufficient fluid supply, pump leakage, broken rod, and gas effect. The production data are filtered according to the data type, and the types with less than 10 groups of production data of the same type are classified as the other, and there are 15 main fault types in actual production. After cleaning up the defective data (such as lost data, unexplained data, obvious errors, etc.), the remaining 3502 groups of valid data were classified and stored. Labels were assigned to 15 fault types, and their indexes and quantities are shown in Table 1.  
The indicator diagram was drawn according to the data, and all JPG images were unified into 600 \(\times\) 400 pixels with the same coordinate system. Of these, 20% were randomly selected as test set data and the remaining 80% as training set. After segmentation, the sequence of indicator diagram data is fully disordered, and the training data set is packaged. The indicator diagram data are normalized, as shown in Equation (3):  
\[\hat{x_{i}}=\frac{x_{i}-225}{127.5} \tag{3}\]  
\begin{table}
\begin{tabular}{c c c} \hline \hline
**Fault Type** & **Index** & **Number** \\ \hline Plunger up bump & 0 & 126 \\ \hline Plunger down bump & 1 & 119 \\ \hline Insufficient fluid supply & 2 & 332 \\ \hline Double valve loss & 3 & 178 \\ \hline Fixed valve loss & 4 & 91 \\ \hline Broken rod & 5 & 325 \\ \hline Normal operating conditions & 6 & 565 \\ \hline Gas effect & 7 & 444 \\ \hline Pump leakage & 8 & 375 \\ \hline Plunger come out & 9 & 134 \\ \hline Swimming valve loss & 10 & 275 \\ \hline Sand effect & 11 & 110 \\ \hline Heavy oil effect & 12 & 73 \\ \hline Wax effect & 13 & 226 \\ \hline Pump and eject & 14 & 89 \\ \hline \hline \end{tabular}
\end{table}
Table 1: Label index assignment result.  
where:  
\(\tilde{x_{i}}\)--Represents the pixel value of \(i\) th pixel of the sample after normalization;  
\(x_{i}\)--The \(i\) th pixel value of the sample, the purpose is to classify all pixels as \([-1,1]\).  
According to the statistical results of the number of each fault type in Table 1, the data amount of each type generated in actual production is not uniform, which does not meet the requirement of data amount equality in traditional machine learning. At the same time, the amount of data generated in actual production is often limited, and it needs to be accumulated for a period of time to meet the requirements of machine learning. Therefore, according to the characteristics of actual oil well production data, the transfer learning method is used to establish the recognition model.