Abstract:
Accurate prediction of farrowing onset helps schedule supervision and assistance in commercial pig production. Sensors attached to sows may interfere with normal activity, while existing vision methods primarily provide behavioral alerts rather than continuous estimates of time remaining until farrowing. Low spatial resolution further complicates the separation of adjacent body regions and the extraction of their temperatures from thermal images. This study developed a sow onset of farrowing prediction (SOFP) model combining instance segmentation with time series prediction for noncontact monitoring. Thermal images were collected once per minute from 20 primiparous Large White sows on a commercial farm in Guangdong, China. After image deduplication, 50 images per sow were randomly selected from each of five consecutive 24 h intervals during the 120 h before farrowing. The resulting
5000 images were annotated for the head, udder, and rump and divided into training, validation, and test sets at a ratio of 7:2:1. The first stage used a lightweight instance segmentation model, weighted feature fusion YOLOv8 (WFF-YOLOv8), developed from YOLOv8n-seg. Its input resolution matched the original thermal images of 160 × 120 pixels, and the backbone downsampling factor was reduced from 32 to 8. A prediction head operating at two scales (2Head) and a simplified neck (Lean-Neck) reduced redundant branches. A weighted feature fusion (WFF) module assigned attention weights at individual spatial locations to integrate features from different network levels. Predicted masks were mapped to the corresponding temperature matrices to extract regional body surface temperatures. Temperature series spanning the 120 h before farrowing were resampled at 5 min intervals, yielding
1441 sampling points per sow. Principal component analysis reduced the regional temperature measurements to a univariate representation. Sliding windows containing 73 points, spanning 6 h, advanced by one sampling point, generating
27380 samples across the 20 sows. Each window was labeled with the time remaining from its final sampling point to farrowing onset, identified from visible-light video as the birth of the first piglet. The second stage used a time series prediction (TSP) model combining convolutional feature extraction, long short-term memory, and temporal pattern attention. Data from 16 sows were used for TSP training and fourfold cross-validation, while the remaining four sows were reserved for testing. Temperature analysis and prediction evaluation covered the final 96 h, comprising four complete 24 h intervals with sufficient historical input for every prediction. WFF-YOLOv8 achieved a mean average precision of 98.6% at an intersection over union threshold of 0.5, exceeding YOLOv8n-seg under its default configuration by 2.7 percentage points. The corresponding precision and recall were 96.3% and 98.4%, respectively. The model contained 2.08 million parameters and had a file size of 4.5 MB. Mean absolute errors for TSP, averaged across the four test sows, were 569.63 and 508.64 min at 24 to 18 and 18 to 12 h before farrowing, respectively. These errors decreased to 61.04 min at 12 to 6 h and 3.54 min during the final 6 h. The corresponding average root mean square error during the final 6 h was 4.91 min. Temperature trends in the test sows showed gradual warming followed by a faster increase, with individual differences in transition timing. Prediction errors declined around this transition, indicating a temporal association between warming patterns and improved predictions. SOFP combined automated temperature extraction with continuous prediction of time remaining until farrowing, with the greatest accuracy observed during the final 6 h. The model provides a method for noncontact farrowing monitoring, although larger cohorts and validation across different farms are needed to assess its suitability for practical deployment.