## 3 Methods
### Feature Pyramid Structure  
Different camera angles in the classrooms and the distances between students and the camera can lead to different size of students in the top and bottom rows of the classroom in the same image frame, so how to represent and deal with multi-scale features effectively is a difficult problem in classroom behavior detection. Figure 3(a) Feature Pyramid Network (FPN) proposes a top-down approach that combines multi-scale features for prediction using composite feature layers with more semantic information. In line with this idea, Figure 3(b) PANet continues to add a bottom-up path aggregation network on top of FPN, taking into account both the semantic information of the top layer and the location information of the bottom layer. The YOLOv5 framework integrates multi-scale features with the FPN+PAN structure, but due to the different resolution of input features, the contribution of the FPN+PAN structure to the fusion output features is often uneven and the features between different scales cannot be fully exploited. Therefore, a simple and efficient weighted bidirectional feature pyramid network (BiFPN) has been introduced to the neck of the YOLOv5 framework to improve the detection accuracy. The fusion steps are as follows:  
Figure 4: FPN, PAN, and BiFPN structures.  
Figure 3: The network structure of the algorithm in this paper.  
1. First remove those nodes that have only one input edge, because if a node has only one input edge without feature fusion, its contribution to a feature network that incorporates different feature information is usually weak. Therefore, BiFPN eliminates the intermediate nodes of P3 and P7 in PANet, which leads to a simplified bidirectional network. 2. Add a jump connection between input nodes to output nodes at the same scale because they are on the same layer and can incorporate more features and enhance feature representation without adding too much computational overhead. 3. Combine each bidirectional (top-down and bottom-up) path considered as a feature network layer so that it can be repeatedly stacked to achieve higher level feature fusion. The structure of the BIFPN in this paper is shown in Figure 5.  
BiFPN uses the fast normalization method for weighted feature fusion, in which the fast normalization directly divides the weight by the weighted sum of all values for normalization, and the value of each normalization weight is also between 0 and 1, in order to increase the speed of calculation, the formula is as follows:  
\[O=\sum_{i}\frac{\omega_{i}}{\in+\sum_{j}\omega_{j}}\cdot l_{i} \tag{1}\]  
In the formula, \(\omega_{i}\) represents the learnable weight, which is obtained by the network training, and \(I_{i}\) represents the input feature. The weights \(\omega_{i}\geq 0\) are ensured by using a ReLu activation function after each \(\omega_{i}\), and the value of the output weights is controlled between 0 and 1 by regularization. Finally, BiFPN integrates bidirectional cross-scale connection and fast normalization fusion. Taking node P6 in Figure 6 as an example, the two feature fusion processes formed are as follows:  
\[P_{6}^{nd}=Conv\Bigg{(}\frac{w_{1}\cdot P_{6}^{nn}+w_{2}\cdot Resize(P_{7}^{ nn})}{w_{1}+w_{2}+\in}\Bigg{)}\]  
Figure 5: BiFPN feature fusion structure in this paper.  
Figure 6: BiFPN feature fusion process.  
In the formula, \(P_{6}^{td}\) represents the top-down intermediate feature layer, \(P_{6}^{out}\) represents the bottom-up intermediate special layer, Conv represents the convolution operation, and Resize represents the up-sampling or down-sampling operation. Based on the above advantages, BiFPN is introduced to improve the feature pyramid structure, enhance multi-scale feature fusion, and improve model detection accuracy.