Abstract:Accurate monitoring and timely intervention of dairy cows' prepartum behavior are of great value for safeguarding the health of dairy cows, enhancing reproductive efficiency, and improving breeding productivity. However, prepartum behaviors such as tail warping and pelvic relaxation are characterized by small target sizes and overlapping features; they are also highly susceptible to interference from environmental factors, which often leads to misrecognition. To achieve rapid and accurate identification of dairy cows' prepartum behavior in complex barn environment, a prepartum behavior recognition method was proposed based on improved YOLO v8n. Firstly, an optimized HGNet V2 model was integrated to enhance the model's target recognition performance in complex barn scenarios. Secondly, a lightweight efficient channel attention (ECA) module was introduced after the C2f module in the model's head section. Finally, the MPDIoU Loss function was adopted to replace the CIoU loss function. Experimental results showed that compared with the baseline YOLO v8n model, the improved model achieved a mean average precision (mAP@ 0.5) of 92.9% for the recognition of the four prepartum behaviors-representing an increase of 1.6 percentage points. Specifically, the average precision (AP) for tail warping and pelvic relaxation behaviors was increased by 5.6 and 1.7 percentage points, respectively. When compared with other mainstream detection models, the improved model's mAP@ 0.5 was enhanced by 9.6, 10.5, 10.9, 6.5, 3.0, 2.8, 1.0, 1.0 and 1.1 percentage points, respectively. In conclusion, the model constructed exhibited strong robustness, enabling accurate identification of dairy cows' prepartum behaviors under dynamic and complex breeding environments as well as all-weather conditions.