# Object Detection Related to Irregular Behaviors of Substation Personnel Based on Improved YOLOv4
## 3 Improved YOLOv4 Lightweight Detection Model
### Improved YOLOv4 Model  
The implementation of YOLOv4 has high requirements in terms of computing performance and memory space. In order to improve the detection speed to meet the real-time requirements of practical engineering, an improved YOLOv4 lightweight model is proposed, the structure of which is shown in Figure 6. The particular principle is described in detail as follows.  
Figure 5: Structural diagram of the ECA module.  
Figure 6: Structure of the improved YOLOv4 lightweight network.  
(1) Feature extraction network: the CSPDarknet53 feature extraction network in YOLOv4 was replaced by the MobileNetV3 lightweight convolutional neural network, and the input size required by the initial MobileNetV3 was reshaped from 224 \(\times\) 224 to 416 \(\times\) 416. As shown in Figure 6, the original three scale features were increased to four scales; the features after bneck3, bneck6 and bneck3 modules were used as feature 1, feature 2, feature 3, and feature 4, respectively, where the number of the bneck represents the amount of modules. Moreover, SENet was only used in the second bneck3 module, the last two bencks in the bneck6 module, and the last bneck3 module. Then, the size of features 1, 2, 3, and 4 in the improved YOLOv4 model was reshaped to 104 \(\times\) 104, 52 \(\times\) 52, 26 \(\times\) 26, and 13 \(\times\) 13 and used for feature fusion and enhancement of the SPP and PANet networks.  
(2) ECA-SPP and ECA-PANet: in order to further improve detection accuracy, the ECA attention mechanism was added behind the extracted four scale features; DSC was used to replace the 3 \(\times\) 3 standard convolution in SPP and PANet and the ECA attention mechanism was embedded in SPP and PANet to improve accuracy. The resulting networks were named ECA-SPP and ECA-PANet, as shown in Figure 6. The details are as follows: (i) the CBR \(\times\) 3 in front of and behind the SPP in Figure 3 was replaced with a CDC module; (ii) the ECA attention mechanism was added behind the max-pooling with four kinds of pooling kernel sizes (1 \(\times\) 1, 5 \(\times\) 5, 9 \(\times\) 9, 13 \(\times\) 13) in SPP; (iii) the CBR \(\times\) 5 in PANet of YOLOv4 in Figure 3 was replaced with an MFC module; (iv) the ECA attention mechanism was added behind each upsampling and downsampling.  
(3) Prediction network: The scales of the output feature maps of ECA-SPP and ECA-PANet were input to the prediction network (YOLOHead), where the CBR modules were replaced by DSC to further reduce the computation of the model. Then, the fused features of the three scales were reshaped to 52 \(\times\) 52 \(\times\) 33, 26 \(\times\) 26 \(\times\) 33, and 13 \(\times\) 13 \(\times\) 33, where the third dimension, 33, can be split into 3 \(\times\) (6 + 5); 3 represents the anchors assigned to each scale feature map, 6 represents the total number of categories in the irregular behavior dataset of substation personnel, and 5 can be divided into \(1+1+1+1+1\), which represent, respectively, the abscissa and ordinate of the center point, height, and width of the prediction box and the confidence degree.