← Projects
ML/Data2025

Pig Weight Estimation

CV pipeline combining YOLO detection, SAM segmentation, and ResNet regression to estimate live pig weight from smartphone images — built during an internship at Animalia. Data collection app deployed to production and actively used by pig producers across Norway.

Illustration of capturing a pig image from above at a maximum 15° angle

The goal of this project was to reduce the need for manual pig weighing by estimating live weight directly from smartphone images. Traditional weighing is labor-intensive, time-consuming, and can cause unnecessary stress for both farmers and animals. By leveraging computer vision and machine learning, we aimed to create a practical tool that could estimate pig weight directly inside the pen using equipment farmers already own: a mobile phone.

The project ran over 8 weeks as part of my work at Animalia, during which I designed and implemented the complete system end-to-end: data collection workflows, mobile application, ML pipeline, and ONNX/Triton deployment infrastructure.

Impact

  • Reduces the need for manual pig weighing
  • Minimizes stress for both animals and farmers
  • Enables weight estimation using only a smartphone
  • Established a continuous data collection workflow for future model improvements

Machine Learning Pipeline

The system processes overhead images of pigs through a multi-stage computer vision pipeline:

  • YOLO Object Detection identifies the pig and crops the image to the relevant region.
  • Segment Anything Model (SAM) removes the background and extracts the pig's body.
  • PCA-based alignment standardizes the pig's orientation.
  • A lightweight neural network classifies whether the pig is facing upward or downward and rotates the image into a consistent pose.
  • A ResNet regression model predicts the pig's live weight from the processed image.

The entire pipeline was designed for deployment on NVIDIA Triton Inference Server using ONNX models, making it easy to replace individual models without redesigning the full system.

Computer Vision Pipeline

The figures below illustrate the preprocessing pipeline used before weight estimation. Starting from a smartphone image captured in the pen, the system detects the pig, removes the background, standardizes its orientation, and produces a consistent input for the regression model.

Original smartphone photo of a pig in the pen1 / 4

Original Image

A smartphone photo captured directly in the pen — the raw input to the system.

The model does not predict weight directly from the raw image. Instead, the image passes through several preprocessing stages designed to isolate the pig, standardize orientation, and reduce irrelevant variation before reaching the regression model.

The Apps

Two separate apps support the system, and it helps to keep them distinct. One is a data-collection app used to gather labeled training data for Animalia; the other is the weight-estimation app that actually runs the pipeline and returns a predicted weight.

App screen for uploading a pig photo for weight estimation1 / 3

Weight Estimation App — Upload

In the weight-estimation app, the user photographs or uploads an image of a pig. On upload, the image is run through the computer vision pipeline and an estimated live weight is returned within seconds.

Mobile Data Collection Platform

A major challenge was obtaining high-quality training data. To address this, I developed a mobile application that allows farmers and Animalia staff to:

  • Upload pig images directly from a smartphone
  • Register weight measurements
  • Store and manage collected data
  • Track uploaded images and associated metadata

The data collection application was deployed within Animalia and remains in active use today, continuously collecting labeled training data from Norwegian pig producers.

Results

  • Successfully deployed a complete inference pipeline on NVIDIA Triton
  • Established a production data collection workflow
  • Collected training data from commercial pig farms across Norway
  • Demonstrated that live pig weight can be estimated from ordinary smartphone images with promising accuracy

The weight estimation pipeline is not yet accurate enough for production. However, data collection is ongoing, and the system was built as a modular, maintainable foundation that can be improved and deployed once enough labeled data has been gathered.

Impact & Recognition

The project was featured by both Animalia and Ingris as part of their digitalization initiatives in the Norwegian livestock industry.

Key Contributions

  • Designed and implemented an end-to-end computer vision pipeline: YOLO detection → SAM segmentation → PCA alignment → ResNet regression.
  • Developed a mobile data collection app deployed to production and actively used by pig producers across Norway to gather labeled training data for Animalia.
  • Built a modular ONNX/Triton inference server architecture — swap any model stage without redesigning the pipeline.
  • Established a scalable training data workflow directly with commercial pig farms.
  • Project featured in national industry press (svin.no, Animalia.no).

Stack

PythonPyTorchTensorFlowYOLOSegment Anything Model (SAM)ResNetONNXNVIDIA Triton Inference ServerComputer VisionDeep LearningMobile Application Development