Abstract:
Farrowing onset time in sows is essential for piglet survival in commercial pig production. Its accurate prediction can contribute to timely parturition supervision and dystocia prevention. Existing methods rely largely on contact or invasive sensors that compromise animal welfare. Whereas non-contact vision can provide only stage-level behavioral alarms rather than continuous, quantitative prediction of the onset time. It is required for reliable temperature extraction from the low-resolution thermal infrared images commonly available on farms. In this study, a non-contact and welfare-friendly framework was developed to extract body-surface temperature from low-resolution thermal infrared images and then predict the farrowing onset time of late-gestation sows. Thermal infrared images were acquired at one frame per minute from 20 primiparous Large White sows during late gestation on a commercial farm in Guangdong, China. 5 000 images with 144 000 frames were annotated for the head, udder, and rump. A two-stage cascaded model was proposed for the sow onset of farrowing prediction model (SOFP). Firstly, a lightweight instance segmentation network was constructed on You Only Look Once version 8, termed weighted feature fusion-YOLOv8 (WFF-YOLOv8). The input was matched to the native image resolution, where the backbone downsampling ratio was reduced to prune redundant detections and neck branches. Feature concatenation was replaced with a weighted feature fusion module; Regional temperatures from the predicted masks were reduced into univariate series by principal component analysis (PCA). Secondly, a time-series prediction model was selected to output the continuous onset time from 6-hour windows. The model also incorporated convolutional extraction, long short-term memory (LSTM) networks, and a temporal pattern attention mechanism. Finally, 16 sows were used for four-fold cross-validation, where four were held out as an independent test set. The results showed that the WFF-YOLOv8 model achieved a mean Average Precision at an intersection-over-union threshold of 0.5 (mAP@0.5) of 98.6%, with a precision of 96.3% and a recall of 98.4%, thereby exceeding the YOLOv8n-seg baseline by 2.7 percentage points (95.9%). Only 2.08 million parameters were contained, occupying 4.5 MB. Moreover, 2.6 ms per frame was required to outperform mainstream segmentation models—including the larger YOLOv8s-seg and YOLOv8m-seg, YOLOv9c-seg, YOLO11n-seg and YOLO12n-seg—while having the fewest parameters. Ablation experiments confirmed that the input-and-downsampling adaptation, the pruned 2Head and Lean-Neck structures, and the weighted feature fusion module each contributed to the accuracy gain and acted complementarily. Cohort analysis of the 20 sows revealed that there was a coherent thermal pattern: although individual baseline temperatures varied considerably (33.91–36.51 ℃), all sows maintained a plateau from 96 to 24 h before farrowing, after which the mean temperature rose by about 0.40 ℃ above each sow’s baseline within the final 24 h (95% confidence interval 0.26–0.55 ℃), while the net within-interval rise accelerated to roughly 1.28 ℃ (95% confidence interval 0.98–1.59 ℃), about three to ten times the increased in earlier intervals; Trend decomposition revealed that a two-phase, gentle-then-accelerated rise was found with moderate individual variation in the time of acceleration. On the independent test set, the time-series prediction model was markedly more accurate, as farrowing approached: the mean absolute error (MAE) was 569.63 and 508.64 min, respectively, in the 24-18 h and 18-12 h windows, fell to 61.04 min in the 12-6 h window, and reached only 3.54 min in the final 6 h, where the root mean square error (RMSE) was 4.91 min and the coefficient of determination was 0.99. This sharp accuracy gain coincided with the accelerated temperature rise, indicating the farrowing thermal variations. The SOFP was used to reliably extract key-part body temperature from low-resolution thermal infrared images. The correlation between temperature dynamics and farrowing was captured to accurately predict the onset time within 6 h before parturition. Therefore, the findings can provide a non-contact, welfare-friendly and readily deployable pathway for continuous farrowing monitoring and early warning in commercial pig production. Environmental and behavioral cues can be integrated to reduce farrowing risk for piglet survival and efficiency over parities, breeds, and farms.