Abstract:Abstract: Body mass growth of gestating sows is an important indicator of their health status and reproductive performance. Computer vision-based contactless pig body mass measurement methods can effectively reduce stress and have become a hot topic in recent years. However, most current computer vision-based contactless pig mass measurement methods require data acquisition and mass measurement calculation under specific ideal experimental environments and lack application in usual breeding environments. In this paper, an Intelligent Mass Measurement Model for Gestating Sows (IMMM-GS) based on deep learning is proposed based on video image data under usual farming by using instance segmentation and keypoint detection algorithms in computer vision technology. The model includes three main sub-algorithms to solve the typical occlusion problem in the normal environment, the first is the pig instance segmentation algorithm based on Mask R-CNN, the second is the pig keypoint detection algorithm based on Keypoint R-CNN, and the last is the pig mass measurement algorithm based on modified ResNet. The instance segmentation algorithm is used to segment the pigs from the image to reduce the influence of the image background on the mass measurement, and the keypoint detection algorithm is used to eliminate incomplete pigs to ensure that there are no incomplete pigs in the dataset. In this paper, video data and mass data of 48 gestating sows for six months are used for dataset construction and experimental analysis. The datasets were collected at a commercial pig farm in Guangzhou City, Guangdong Province, China in 2022. A camera was deployed to the slide rail to get real-time video data of the pigs, and the test pigs were weighed every five days. The IMMM-GS model used the PyTorch deep learning framework, MMDetection framework, and MMPose framework. The experiment was carried out on the Ubuntu18.04 system with a CPU of Intel Core i7-9700 and a GPU (graphics processing units) of NVIDIA A30 whose memory was 24 GB. The root mean square error of the model on the test set was 3.01 kg, which was 2.14 kg and 7.86 kg lower compared to the model with ConvNeXt and ResNet as the backbone network. And the mean absolute percentage error was 2.02%, which was 2.10% and 4.75% lower than the model with ConvNeXt and ResNet as the backbone network. The model constructed in this paper also monitored the mass of ten gestating sows for three months with an image size of 2 688×1 520, the average measurement speed per image was 0.684 s and the root mean square error between the estimated mass and the actual mass was 3.24 kg and the computational speed and accuracy met the demand of real-time computing. Therefore, the author thought that the IMMM-GS model could provide data support for estimating the reproductive performance such as the mass growth pattern of sows during gestation, the developmental status of gestating sows, and estimating the expected farrowing period and litter size in real-time using the standing video for a long time, and has broad application prospects.