# Insulators and Defect Detection Based on the Improved Focal Loss Function
## 4 Results and Discussion
### Comparison of Weighting Factors  
Different values of \(\alpha\) and \(\gamma\) in the Focal loss function will have a greater impact on the model training process, resulting in differences in detection performance. Table 5 shows the influence of the YOLOv5 model on the accuracy and recall of insulators and their defects detection under different \(\alpha\) values. Table 6 shows the influence of the YOLOv5 model on the accuracy and recall of insulators and their defects detection under different \(\gamma\) values. It can be seen from the experimental results that when \(\alpha\) is set to 0.5, mAP reaches 98%, which is better than the 0.25 value suggested by the literature. When \(\gamma\) is set to 1.1, mAP reaches 97.7%, which is also better than the value of 2.0 suggested by the literature. Through the analysis of the data set samples, the results of the experiment can be improved to a certain extent by setting the values of \(\alpha\) and \(\gamma\) reasonably. \begin{table}
\begin{tabular}{c c c c c c c} \hline \hline
**Pretrained Weights** & **Focal Loss** & **Insulator Precision/\%** & **Insulator Recall/\%** & **Defect Precision/\%** & **Defect Recall/\%** & **mAP/\%** \\ \hline  & & 94.2 & 87.1 & 92.5 & 85 & 92.6 \\  & ✓ & 81.2 & 62.1 & 89.7 & 73.1 & 79.2 \\ ✓ & ✓ & 90.1 & 95.6 & 98.8 & 93 & 97.1 \\ \hline \hline \end{tabular}
\end{table} 
Table 4: Comparison of transfer learning results. \begin{table}
\begin{tabular}{c c c c c c} \hline \hline
**The Number of the \(\alpha\)** & **Insulator Precision/\%** & **Insulator Recall/\%** & **Defect Precision/\%** & **Defect Recall/\%** & **mAP/\%** \\ \hline
0.15 & 91.5 & 95.5 & 97.7 & 91.9 & 97.5 \\
0.25 & 90.1 & 95.6 & 98.8 & 93 & 97.1 \\
0.35 & 92.3 & 96.5 & 98.9 & 92.5 & 97.8 \\
0.5 & 94.3 & 95.4 & 99.1 & 92.4 & 98 \\
0.8 & 91.7 & 96.1 &However, each time the value is taken, new training of the model is required. A good weight value can be obtained through a large number of comparative experiments, which requires a lot of hard and soft resources and time. Figure 6 records the changing trends of \(\alpha\) and \(\gamma\) during the training process (where \(\alpha\) and \(\gamma\) are the mean values in each round of training). It can be seen from Figure 6a that the value range of \(\alpha\) in this paper is calculated to be stable from 0.447 to 0.449 according to the number of positive and negative samples. It is close to the \(\alpha\) value of 0.5 for the optimal effect in Table 5. Prove the validity of the dynamic \(\alpha\) value. The value of \(\gamma\) in Figure 6b shows a trend of gradual decay. The network recognition effect is poor in the early stage, and the gap between the prediction and the true value is large, so the value of \(\gamma\) is large. In the later stage, with the emphasis on difficult samples, the network recognition effect is good, and the prediction effect is good. The gap between the prediction and the true value is small, and there are few difficult samples, so the \(\gamma\) value is small. The decay of the \(\gamma\) value reflects the process of difficult samples from more to less, which proves the effectiveness of the Focal loss algorithm with dynamic weights. Table 7 shows the comparison results between the method of dynamically changing weights proposed in this paper and the best results of multiple empirical values of Focal loss. It can be seen from Table 7 that the overall mAP value of the YOLOv5 model using the dynamic weight calculation method is higher than that of the empirical method. \begin{table}
\begin{tabular}{c c c c c c} \hline \hline
**The Number** & **Insulator** & **Insulator** & **Defect** & **Defect** & **mAP/\%** & **Time/h** \\
**of the \(\gamma\)** & **Precision/\%** & **Recall/\%** & **Precision/\%** & **Recall/\%** & **mAP/\%** \\ \hline \(1.1\) & 92.7 & 95.3 & 98.8 & 93 & 97.7 \\ \(1.5\) & 92.3 & 95.2 & 98.3 & 91.3 & 97.3 \\ \(2.0\) & 90.1 & 95.6 & 98.8 & 93 & 97.1 \\ \(2.5\) & 91.1 & 94.9 & 98.7 & 89 & 96.3 \\ \(3.0\) & 92.3 & 95 & 98.2 & 89 & 97.1 \\ \hline \hline \end{tabular}
\end{table}