Abstract:The problem of lameness in pigs presents significant challenges to the production and management of pig farms, making accurate detection of pig lameness crucial. Currently, pig farms primarily rely on manual observation and recording, which is inefficient, time-consuming, and prone to subjective judgment errors. In light of this, a method for detecting pig lameness based on key points and walking characteristics was proposed. Firstly, key point information for pigs was defined and determined, including critical parts such as the legs, knees, and back. Based on these key points, an improved YOLO v8n-pose model was employed for detection. This model built upon the original YOLO v8n-pose by introducing a bidirectional feature pyramid network (BiFPN) at the neck for multi-scale feature fusion and incorporating a RepGhost network into the backbone to reduce the parameter count and computational complexity of the feature extraction network. Then using the coordinates of the detected key points, walking characteristics such as stride length, knee bending degree, and back curvature were calculated. These features were inputed into a K-nearest neighbors (KNN) algorithm to classify pigs as lame or non-lame. Experimental results showed that the improved YOLO v8n-pose model achieved a mean average precision (mAP) of 92.4%, which was 4.2 percentage points higher than the detection accuracy of the original YOLO v8n-pose model. Compared with other key point detection models (HRNet-w32, Lite-HRNet, ResNet50, ViPNAS, and Hourglass), the mAP was improved by 10.2, 11.6, 14.2, 11.8 and 12.5 percentage points, respectively. The KNN algorithm achieved a detection accuracy of 81.7% on the pig lameness test set, which was 1.5, 11.3 and 6.5 percentage points higher than that of the BP algorithm, Decision Tree algorithm, and SVM algorithm, respectively. These results demonstrated that the proposed method for detecting pig lameness was feasible and can provide technical support for pig farm detection.