# Broiler Behavior Detection and Tracking Method Based on Lightweight Transformer
## 2 Materials and Methods
### Rat-Detr  
RT-DETR provides a robust framework, as illustrated in Figure 5. Its backbone network employs a convolutional neural network (CNN) to extract outputs from three scale layers, specifically S3, S4, and S5, with S5 serving as the input for the Transformer encoder AIFI. The mathematical procedures are detailed in Equations (1) and (2). Notably, S3, S4, and S5 convert multi-scale features into image feature sequences through the cross-scale feature fusion module (CCFM), with the corresponding mathematical process presented in Equation (3). Subsequently, a fixed number of image features are selected as the initial object queries for the decoder via the IoU-aware query selector. Ultimately, the decoder within the auxiliary prediction header iteratively optimizes the object queries to produce bounding boxes and confidence scores. This approach transforms the detection task into an unordered sequence output, significantly mitigating the influence of variations in size, shape, and texture among target individuals on the model's detection performance. Therefore, adopting RT-DETR as the benchmark model for broiler behavior detection is a viable strategy.  
\[Q=K=V=Flatten(S_{5}) \tag{1}\]  
\[F_{5}=Reshape(Attn(Q,K,V)) \tag{2}\]  
\[Output=CCFM(\{S_{3},S_{4},F_{5}\}) \tag{3}\]  
where Attn denotes multi-head self-attention and Reshape refers to restoring the feature shape to that of S5, which is the inverse operation of Flatten.  
However, RT-DETR still faces several challenges in broiler behavior detection, including the following:  
1. Compared to other lightweight detection models, the Transformer requires the storage of large-scale key-value pairs due to its fully connected attention mechanism. This  
Figure 5: RT-DETR network structure.  
\begin{table}
\begin{tabular}{c c c c c} \hline \hline
**Dataset** & **Lying Instance** & **Feed Instance** & **Stand Instance** &
\begin{tabular}{c} **Drink** \\ **Instance** \\ \end{tabular} \\ \hline Validation set & 12,604 & 5334 & 5839 & 2307 \\ Test set A & 12,627 & 5464 & 5709 & 2208 \\ Test set B & 2586 & 641 & 1177 & 122 \\ \hline \hline \end{tabular}
\end{table}
Table 3: Instance distribution per dataset.  
requirement can lead to memory limitations and slow detection speeds, particularly given the restricted computing resources available at actual breeding sites.
2. The single-neck feature structure of RT-DETR often results in the loss of contextual semantic information. Chickens possess similar appearance characteristics and tend to congregate, which poses significant challenges for distinguishing individual behaviors. This is especially problematic during detection and tracking, where mutual occlusion between individuals can easily result in target loss.
3. The varying shooting equipment utilized by different breeding institutions and researchers leads to significant discrepancies in the acquired images. Additionally, slight variations in shooting angles and heights can cause substantial changes in the image background. Consequently, the model must demonstrate strong generalization capabilities to effectively manage variable scenes and target features.