## 4 Proposed Method
### Focal Modulation Network  
The original backbone of YOLOv8 builds upon its predecessors by incorporating advanced architectural designs such as convolutional layers for hierarchical feature extraction, residual blocks to enhance gradient flow, bottleneck layers for computational efficiency, and CSPNet to balance computational load and improve performance. One of the critical components in this backbone is the Spatial Pyramid Pooling Fast (SPPF) module, which captures multi-scale information by pooling features at multiple scales. We found that in tasks such as student classroom behavior detection, there are a variety of scenarios with varying sample sizes of different student behaviors as well as more complex classroom environments, which often lead to less effective detection models. Many researchers consider introducing self-attention mechanisms [40] to alleviate this problem in such situations. Self-attention mechanisms are widely used in visual tasks, but their computational complexity is high, especially when dealing with high-resolution inputs. Therefore, we decided to introduce the Focal Modulation technique [41], a relatively lightweight network structure, as a direct replacement for the traditional SPFF module to further limit the complexity of the model, thus guaranteeing the real-time performance of our detector and ensuring that it can be applied to real classroom environments.The Focal Modulation is mainly a multilevel feature fusion mechanism that is incorporated into the module to learn both coarse-grained spatial information and fine-grained feature information in the classroom environment, and acquiring student behavior information from far and near, thus improving the model performance, as shown in Figure 2. Focal Modulation can also increase the focus on hard-to-detect targets (behaviors with small sample sizes in the dataset) and achieve focus on difficult samples, i.e., special behaviors, thus improving the detection accuracy of the model. Traditional self-attention mechanisms aggregate contextual information by computing the similarity between query tokens and their surrounding tokens, with a computational complexity of quadratic order. Focal modulation, however, redefines this process by first aggregating contextual information at each query position and then modulating based on the aggregated context. Specifically, the process of self-attention can usually be expressed as follows:  
\[y_{i}=M_{1}(T_{1}(x_{i},X),X)\]  
Figure 1: The overall structure of our model. where \(M_{1}\) represents the aggregation operation performed on the attention score matrix between the query and its targets, and \(T_{1}\) is the interaction between the query and targets. In contrast, the process of focal modulation is expressed as follows:  
\[y_{i}=T_{2}(M_{2}(i,X),x_{i}) \tag{4}\]  
In this case, \(M_{2}\) is the operation of aggregating the context at each position, and \(T_{2}\) is the interaction between the query and the aggregated features. Specifically, as shown in Figure 3 and Algorithm 1, focal modulation uses a set of deep convolutional implementations to encode short- to long-range visual contexts at different granularities, selectively aggregates the contextual features of each marker according to its content, and fuses the aggregated features into the query, greatly simplifying the computational process compared to traditional self-attention modules. The specific computation of focus modulation is shown below:  
\[y_{i}=q(x_{i})\odot h\left(\sum_{\ell=1}^{L+1}g_{i}^{\dagger\ell}\cdot z_{i}^ {\dagger\ell}\right) \tag{5}\]  
where \(g_{i}^{\dagger\ell}\) and \(z_{i}^{\dagger\ell}\) are the gating values and visual features, and \(q(x_{i})\) is a query projection function. Figure 3: The main difference between Self Attention (SA) and Focal Modulation lies in the way contextual information is processed.