## 4 Proposed Method
### Dyhead Module  
After the backbone and neck structure further refine these features by aggregating information from different scales, the head of YOLOv8 is where the final detection occurs. It processes the aggregated features from the neck to predict bounding boxes and class probabilities. To enhance this process, we use a dynamic head module to unify the attention mechanisms, as shown in Figure 4. The dynamic head [42] combines multiple attention mechanisms at the feature level, spatial location, and output channel. This enables scale-awareness, spatial-awareness, and task-awareness, making the model particularly effective in dealing with complex student behaviors in a classroom setting. The dynamic head module enhances the robustness of student behavior detection, and its design allows for high-performance target detection with relatively low computational resources. Even with limited computational resources, it still provides satisfactory results, aligning with our goal of a lightweight model.  
Figure 4: This image shows the execution flow of the three attention modules of Dyhead; it is worth noting that we can stack more than one Dyhead module to achieve better results, but this often leads to performance loss.  
To be more specific, given a feature map \(\mathcal{F}\in\mathbb{R}^{L\times S\times C}\), the broad definition of attention can be described as follows:  
\[W(\mathcal{F})=\pi(\mathcal{F})\cdot\mathcal{F} \tag{6}\]  
One optimal solution is to adopt global attention, but the attention function at all scales will lead to excessive computational overhead and is not practical due to high-dimensional problems. Instead, we convert the attention function into a series of cascaded attentions, each focusing only on one scale:  
\[W(\mathcal{F})=\pi_{\text{C}}(\pi_{\text{S}}(\pi_{L}(\mathcal{F})\cdot \mathcal{F})\cdot\mathcal{F})\cdot\mathcal{F} \tag{7}\]  
Scale-aware Attention \(\pi_{L}\): We first introduce scale-aware attention based on the importance of different scales:  
\[\pi_{L}(\mathcal{F})=\sigma\bigg{(}f\bigg{(}\frac{1}{SC}\sum_{S,C}\mathcal{F} \bigg{)}\bigg{)}\cdot\mathcal{F} \tag{8}\]  
where \(f(\cdot)\) is a linear function, using a \(1\times 1\) convolution, and \(\sigma(x)\) is a hard-sigmoid activation function.  
Spatial-aware Attention \(\pi_{\text{S}}\): Next, we introduce spatial-aware attention to focus on different spatial positions of the feature map. Considering the high dimensionality \(S\), we decompose it as follows: first, use convolution to learn the feature transformation, and then aggregate across scales:  
\[\pi_{S}(\mathcal{F})\cdot\mathcal{F}=\frac{1}{L}\sum_{k=1}^{L}w_{i,j,k}\cdot \mathcal{F}(l;p_{k}+\Delta k;c)\cdot\Delta m_{k} \tag{9}\]  
where \(K\) is the sampling depth, and by using position shifts \((p_{k}+\Delta k)\) and importance factors \(\Delta m_{k}\), the attention mechanism can adaptively focus on regions with high discriminative power.  
Task-aware Attention \(\pi_{\text{C}}\): Finally, we introduce task-aware attention to enhance the learning of task-specific characteristics. It can dynamically open channels to help distinguish different tasks:  
\[\pi_{\text{C}}(\mathcal{F})\cdot\mathcal{F}=\text{max}(\alpha_{1}^{1}( \mathcal{F})\cdot\mathcal{F}_{1}+\beta_{1}^{1}(\mathcal{F}),\alpha_{2}^{1}( \mathcal{F})\cdot\mathcal{F}_{\text{C}}+\beta_{2}^{1}(\mathcal{F})) \tag{10}\]  
where \(\{\alpha_{1}^{1},\alpha_{2}^{1},\beta_{1}^{1},\beta_{2}^{1}\}^{T}=\theta( \mathcal{F})\) are hyperparameters for parameterizing \(\mathcal{F}\). \(\text{max}(\cdot)\) is similar to DyReLU.