Evaluation of Deep Learning Instance Segmentation Models for Pig Precision Livestock Farming


  • Jan-Hendrik Witte Carl von Ossietzky University of Oldenburg image/svg+xml
  • Johann Gerberding Carl von Ossietzky University of Oldenburg image/svg+xml
  • Christian Melching Carl von Ossietzky University of Oldenburg image/svg+xml
  • Jorge Marx Gómez Carl von Ossietzky University of Oldenburg image/svg+xml




Precision Livestock Farming, Instance Segmentation, Computer Vision, Deep Learning, Pig


In this paper, the deep learning instance segmentation architectures DetectoRS, SOLOv2, DETR and Mask R-CNN were applied to data from the field of Pig Precision Livestock Farming to investigate whether these models can address the specific challenges of this domain. For this purpose, we created a custom dataset consisting of 731 images with high heterogeneity and high-quality segmentation masks. For evaluation, the standard metric for benchmarking instance segmentation models in computer vision, the mean average precision, was used. The results show that all tested models can be applied to the considered domain in terms of prediction accuracy. With a mAP of 0.848, DetectoRS achieves the best results on the test set, but is also the largest model with the greatest hardware requirements. It turns out that increasing model complexity and size does not have a large impact on prediction accuracy for instance segmentation of pigs. DETR, SOLOv2, and Mask R-CNN achieve similar results to DetectoRS with a parameter count almost three times smaller. Visual evaluation of predictions shows quality differences in terms of accuracy of segmentation masks. DetectoRS generates the best masks overall, while DETR has advantages in correctly segmenting the tail region. However, it can be observed that each of the tested models has problems in assigning segmentation masks correctly once a pig is overlapped. The results demonstrate the potential of deep learning instance segmentation models in Pig Precision Livestock Farming and lay the foundation for future research in this area.


Download data is not yet available.


Statisitsches Bundesamt (Destatis), Betriebe: Deutschland, Jahre, Tierarten. [Online]. Available: https://www-genesis.destatis.de/genesis/online, Code: 41311-0003 (accessed: Feb. 17 2021).

Statisitsches Bundesamt (Destatis), Gehaltene Tiere: Deutschland, Jahre, Tierarten. [Online]. Available: https://www-genesis.destatis.de/genesis/online, Code: 41311-0001 (accessed: Feb. 17 2021).

D. Berckmans, “Precision livestock farming technologies for welfare management in intensive livestock systems,” Revue scientifique et technique (International Office of Epizootics), vol. 33, no. 1, pp. 189–196, 2014, doi: 10.20506/rst.33.1.2273.

R. B. D'Eath et al., “Automatic early warning of tail biting in pigs: 3D cameras can detect lowered tail posture before an outbreak,” PloS one, vol. 13, no. 4, e0194524, 2018, doi: 10.1371/journal.pone.0194524.

J. Cowton, I. Kyriazakis, T. Plötz, and J. Bacardit, “A Combined Deep Learning GRU-Autoencoder for the Early Detection of Respiratory Disease in Pigs Using Multiple Environmental Sensors,” Sensors (Basel, Switzerland), vol. 18, no. 8, p. 2521, 2018, doi: 10.3390/s18082521.

C. Chen et al., “Recognition of aggressive episodes of pigs based on convolutional neural network and long short-term memory,” Computers and Electronics in Agriculture, vol. 169, p. 105166, 2020, doi: 10.1016/j.compag.2019.105166.

C. Chijioke Ojukwu, Y. Feng, G. Jia, H. Zhao, and H. Ta, “Development of a computer vision system to detect inactivity in group-housed pigs,” International Journal of Agricultural and Biological Engineering, vol. 13, no. 1, pp. 42–46, 2020, doi: 10.25165/j.ijabe.20201301.5030.

S. Zhang, J. Yang, and B. Schiele, “Occluded Pedestrian Detection Through Guided Attention in CNNs,” in 2018 IEEE/CVF Conference on Computer Vision and Pattern Recognition: CVPR 2018 : proceedings : 18-22 June 2018, Salt Lake City, Utah, Salt Lake City, UT, 2018, pp. 6995–7003, doi: 10.1109/CVPR.2018.00731

K. He, G. Gkioxari, P. Dollár, and R. Girshick, “Mask R-CNN,” Mar. 2017. Accessed: May 28 2020. [Online]. Available: http://arxiv.org/pdf/1703.06870v3

Y. Cang, H. He, and Y. Qiao, “An Intelligent Pig Weights Estimate Method Based on Deep Learning in Sow Stall Environments,” IEEE Access, vol. 7, no. 99, pp. 164867–164875, 2019, doi: 10.1109/ACCESS.2019.2953099.

A. Nasirahmadi et al., “Deep Learning and Machine Vision Approaches for Posture Detection of Individual Pigs,” Sensors (Basel, Switzerland), vol. 19, no. 17, 2019, doi: 10.3390/s19173738.

J. Sa, Y. Choi, H. Lee, Y. Chung, D. Park, and J. Cho, “Fast Pig Detection with a Top-View Camera under Various Illumination Conditions,” Symmetry, vol. 11, no. 2, p. 266, 2019, doi: 10.3390/sym11020266.

S. Küster, M. Kardel, S. Ammer, J. Brünger, R. Koch, and I. Traulsen, “Usage of computer vision analysis for automatic detection of activity changes in sows during final gestation,” Computers and Electronics in Agriculture, vol. 169, p. 105177, 2020, doi: 10.1016/j.compag.2019.105177.

S. Schukat and H. Heise, “Indikatoren für die Früherkennung von Schwanzbeißen bei Schweinen – eine Metaanalyse,” (in de) Berichte über Landwirtschaft - Zeitschrift für Agrarpolitik und Landwirtschaft, vol. 11, no, 22, 2019, doi: 10.12767/BUEL.V97I3.249.

S. Tu et al., “Instance Segmentation Based on Mask Scoring R-CNN for Group-housed Pigs,” in 2020 International Conference on Computer Engineering and Application: ICCEA 2020 : 27-29 March 2020, Guangzhou, China : proceedings, Guangzhou, China, 2020, pp. 458–462, doi: 10.1109/ICCEA50009.2020.00105

B. Li, L. Liu, M. Shen, Y. Sun, and M. Lu, “Group-housed pig detection in video surveillance of overhead views using multi-feature template matching,” Biosystems Engineering, vol. 181, pp. 28–39, 2019, doi: 10.1016/j.biosystemseng.2019.02.018.

A. Nasirahmadi, S. A. Edwards, S. M. Matheson, and B. Sturm, “Using automated image analysis in pig behavioural research: Assessment of the influence of enrichment substrate provision on lying behaviour,” Applied Animal Behaviour Science, vol. 196, pp. 30–35, 2017, doi: 10.1016/j.applanim.2017.06.015.

S. Lee, H. Ahn, J. Seo, Y. Chung, D. Park, and S. Pan, “Practical Monitoring of Undergrown Pigs for IoT-Based Large-Scale Smart Farm,” IEEE Access, vol. 7, pp. 173796–173810, 2019, doi: 10.1109/ACCESS.2019.2955761.

J. Kim et al., “Depth-Based Detection of Standing-Pigs in Moving Noise Environments,” Sensors (Basel, Switzerland), vol. 17, no. 12, 2017, doi: 10.3390/s17122757.

K. Jun, S. J. Kim, and H. W. Ji, “Estimating pig weights from images without constraint on posture and illumination,” Computers and Electronics in Agriculture, vol. 153, pp. 169–176, 2018, doi: 10.1016/j.compag.2018.08.006.

A. Nasirahmadi, O. Hensel, S. A. Edwards, and B. Sturm, “Automatic detection of mounting behaviours among pigs using image analysis,” Computers and Electronics in Agriculture, vol. 124, pp. 295–302, 2016, doi: 10.1016/j.compag.2016.04.022.

W. Huang, W. Zhu, C. Ma, Y. Guo, and C. Chen, “Identification of group-housed pigs based on Gabor and Local Binary Pattern features,” Biosystems Engineering, vol. 166, pp. 90–100, 2018, doi: 10.1016/j.biosystemseng.2017.11.007.

J. Seo, J. Sa, Y. Choi, Y. Chung, D. Park, and H. Kim, “A YOLO-based Separation of Touching-Pigs for Smart Pig Farm Applications,” in 2019 21st International Conference on Advanced Communication Technology (ICACT), 2019, pp. 395–401, doi: 10.23919/ICACT.2019.8701968.

D. Li, Y. Chen, K. Zhang, and Z. Li, “Mounting Behaviour Recognition for Pigs Based on Deep Learning,” Sensors (Basel, Switzerland), vol. 19, no. 22, 2019, doi: 10.3390/s19224924.

Z. Huang, L. Huang, Y. Gong, C. Huang, and X. Wang, “Mask Scoring R-CNN,” Mar. 2019. [Online]. Available: https://arxiv.org/pdf/1903.00241

T.-Y. Lin et al., “Microsoft COCO: Common Objects in Context,” May. 2014. [Online]. Available: https://arxiv.org/pdf/1405.0312

R. Padilla, W. L. Passos, T. L. B. Dias, S. L. Netto, and E. A. B. da Silva, “A Comparative Analysis of Object Detection Metrics with a Companion Open-Source Toolkit,” Electronics, vol. 10, no. 3, p. 279, 2021, doi: 10.3390/electronics10030279.

M. A. Rahman and Y. Wang, “Optimizing Intersection-Over-Union in Deep Neural Networks for Image Segmentation,” in ISVC, 2016, doi: 10.1007/978-3-319-50835-1_22

M. Thoma, “A Survey of Semantic Segmentation,” Feb. 2016. [Online]. Available: https://arxiv.org/pdf/1602.06541

T. Norton, C. Chen, M. L. V. Larsen, and D. Berckmans, “Review: Precision livestock farming: building 'digital representations' to bring the animals closer to the farmer,” animal, vol. 13, no. 12, pp. 3009–3017, 2019, doi: 10.1017/S175173111900199X.

S. Qiao, L.-C. Chen, and A. Yuille, “DetectoRS: Detecting Objects with Recursive Feature Pyramid and Switchable Atrous Convolution,” Jun. 2020. [Online]. Available: https://arxiv.org/pdf/2006.02334

X. Wang, T. Kong, C. Shen, Y. Jiang, and L. Li, “SOLO: Segmenting Objects by Locations,” Dec. 2019. [Online]. Available: https://arxiv.org/pdf/1912.04488

X. Wang, R. Zhang, T. Kong, L. Li, and C. Shen, “SOLOv2: Dynamic and Fast Instance Segmentation,” Mar. 2020. [Online]. Available: https://arxiv.org/pdf/2003.10152

N. Carion, F. Massa, G. Synnaeve, N. Usunier, A. Kirillov, and S. Zagoruyko, “End-to-End Object Detection with Transformers,” May. 2020. Accessed: May 28 2020. [Online]. Available: http://arxiv.org/pdf/2005.12872v2

A. Vaswani et al., “Attention Is All You Need,” Jun. 2017. [Online]. Available: https://arxiv.org/pdf/1706.03762

Kentaro Wada, labelme: Image Polygonal Annotation with Python.

E. T. Psota, M. Mittek, L. C. Pérez, T. Schmidt, and B. Mote, “Multi-Pig Part Detection and Association with a Fully-Convolutional Network,” Sensors (Basel, Switzerland), vol. 19, no. 4, p. 852, 2019, doi: 10.3390/s19040852.

K. Chen et al., “MMDetection: Open MMLab Detection Toolbox and Benchmark,” arXiv preprint arXiv:1906.07155, 2019.

Z. Tian, H. Chen, X. Wang, Y. Liu, and C. Shen, AdelaiDet: A Toolbox for Instance-level Recognition Tasks.