Knowledge Hub · Digitalization and phenomics

AI & Computer Vision in Animal Breeding

From big data and machine learning to deep learning and high-throughput phenotyping, how artificial intelligence is reshaping the way we measure animals and make breeding decisions.

★ Self-paced⏱ ~6 hours🎓 MSc level🧪 2 hands-on Python labs🌍 Open access
About this course. This self-paced course adapts a one-day intensive class delivered by Grum Gebreyesus (Center for Quantitative Genetics and Genomics, Aarhus University) under ASAP-Bio. It has been restructured for online self-study: read each module at your own pace, try the knowledge checks, and run the labs in your browser.

Watch: course introduction

What you will learn

  • Explain what “big data” means in livestock and why genomic and sensor data need different statistical tools.
  • Describe the digital-agriculture data pipeline, from sensors to on-farm decisions.
  • Recognise the main machine-learning methods, neural networks, support vector machines and tree ensembles, and when to use them.
  • Understand how digital images are formed and processed, and how convolution extracts information.
  • Explain how deep learning and convolutional neural networks (CNNs) learn from images.
  • Connect computer vision and high-throughput phenotyping to real breeding applications.

Course contents

1

Big data and data science in livestock

~40 minutes

By the end you can

  • State the “5 Vs” of big data and give livestock examples.
  • Distinguish tall from wide data and explain why each needs different methods.
  • Place breeding's classic mixed model in the modern multi-omics context.

Livestock science has become a data science. Milking robots, wearable sensors, cameras, genotyping chips and weather stations now generate streams of data on every animal, every day. “Big data” is usually described by the 5 Vs: Volume (how much), Velocity (how fast it arrives), Variety (tabular, images, sound, sequence), Veracity (how trustworthy) and Value (what decision it supports).

Not all big data is big in the same way. Tall data has many observations and relatively few variables, classical statistics works well and significance is easy to reach. Wide data is the “big p, small n” world: far more variables than animals, as when each animal carries hundreds of thousands of genetic markers. Here ordinary regression breaks down (collinearity, multiple testing, overfitting), so we turn to penalised / regularised regression and dimension-reduction techniques.

Key concept · big p, small nWhen you have more predictors than observations, a model can fit the training data perfectly yet predict new animals badly. Regularisation (shrinking coefficients) and reducing dimensions are how we keep predictions honest.

Animal breeding's workhorse is the mixed model, y = Xβ + Zu + e, separating fixed effects (e.g. herd-year-season) from random genetic merit (breeding values). Genomics made this model “wide”; multi-omics (transcriptomics, proteomics, microbiomics) is widening it further. AI does not replace this framework, it extends our ability to use messy, high-dimensional data within it.

Descriptivewhat happened Predictivewhat will happen Prescriptivewhat to do Optimisationbest decision From data to decisions
Analytics maturity: data becomes valuable as we move from describing the past to optimising future decisions.
Check: a genomic dataset has 2,000 animals and 600,000 SNP markers. Tall or wide?
Wide, far more variables (markers) than observations (animals). This “big p, small n” setting calls for regularised methods such as ridge/LASSO or genomic BLUP, not ordinary least squares.
2

Digital agriculture & precision livestock farming

~40 minutes

By the end you can

  • Define digital agriculture and precision livestock farming (PLF).
  • Describe the pipeline: collect → store → analyse → visualise → decide.
  • Explain why animal identification is the foundation of on-farm computer vision.

Digital agriculture combines sensors, communication networks, drones (UAVs), robotic machinery, data analytics and AI to manage farms more precisely. Applied to animals, this is precision livestock farming (PLF): continuous, automated, individual-level monitoring.

The value chain is a pipeline: collect data (wearables, cameras, milk meters), store it (structured tables and unstructured images/sound), analyse it, visualise it (dashboards, alerts), and turn it into smart decisions. Among all sensing technologies, wearable accelerometers are the most common, and animal behaviour (activity, rumination, oestrus) is the most-collected phenotype, but cameras are rising fast because a single image can be extraordinarily informative.

Key concept · animal identificationAlmost every on-farm vision system must first answer “which animal is this?”. Ear tags and RFID do this today; increasingly, 2D and 3D images identify animals directly. Identification is hardest when animals share the same colour, one reason depth (3D) cameras are valuable.
Check: why is animal identification described as the foundation of computer-vision systems on farm?
Because individual-level decisions (genetic merit, health, feeding, traceability) require linking each measurement to the right animal. Without reliable identity, an informative image can't be used for management or breeding.
3

Machine learning methods

~55 minutes · includes a lab

By the end you can

  • Distinguish supervised from unsupervised learning.
  • Explain neural networks, support vector machines and tree-based ensembles at a working level.
  • Recognise overfitting and the tools used to control it.

A charming starting point is Francis Galton's 1906 observation that the average guess of 800 fair-goers estimated an ox's weight almost perfectly, the “wisdom of crowds.” Modern ensemble methods use the same idea: many weak models combined beat any single one.

Supervised learning predicts a labelled outcome (e.g. body weight) from inputs; unsupervised learning finds structure without labels (e.g. clustering animals). Three families dominate:

Artificial neural networks (ANNs) are flexible non-linear regressions inspired by the brain: inputs feed weighted hidden units, an activation function (sigmoid, tanh, ReLU) adds non-linearity, and back-propagation tunes the weights. ANNs easily overfit, so we use early stopping and weight decay (regularisation).

inputs (x)hidden unitsoutput (ŷ)
A feed-forward neural network with one hidden layer: inputs are combined, transformed by an activation function, and mapped to a prediction.

Support vector machines (SVMs) find the boundary with the widest margin between classes; the “kernel trick” lets them draw curved boundaries for data that aren't linearly separable. Decision trees split data with nested if-then rules; on their own they're unstable, so we combine many: bagging, random forests (each tree sees a random subset of predictors) and boosting (each model fixes the previous one's mistakes).

Key concept · overfittingA model that memorises the training data fails on new animals. Cross-validation, regularisation, early stopping and ensembling all exist to keep models general.

🧪 Lab 1, Machine learning on real cull-cow data

Using the CullDairyCow dataset (401 cows: lactation, health events, 305-day production, body weight and price), build and compare partial least squares, ridge regression and a neural network in Python. You'll one-hot encode variables, split train/test, tune with grid search, and evaluate predictions. Runs free in your browser, no installation.

▶ Open Lab 1 in Google Colab

Dataset: CullDairyCow_Data.csv

Check: a random forest and boosting both combine many trees. What's the key difference?
A random forest builds trees independently in parallel on bootstrap samples (with random predictor subsets) and averages them. Boosting builds trees sequentially, each one giving more weight to the cases the previous trees got wrong.
4

Image processing & computer vision basics

~45 minutes · includes a lab

By the end you can

  • Explain how a digital image is formed and stored as numbers.
  • Read an image as a matrix of pixels and channels (RGB), and bit depth.
  • Apply point operators and linear filters, and define convolution.

Computer vision works because an organism's status, health, growth, behaviour, leaves visually distinguishable cues. Light is electromagnetic radiation; cameras (CCD or CMOS sensors with a Bayer filter) turn it into numbers. The eye sees colour through three cone types (sensitive to red, green, blue), and digital images mimic this with RGB channels.

An image is simply a matrix of numbers: a black-and-white image is one binary matrix, a grayscale image one matrix of intensities, and a colour image three stacked matrices (R, G, B). Bit depth sets how many levels each pixel can take, 8-bit gives 2⁸ = 256 levels, 16-bit gives 65,536.

Image = pixels Kernel (filter) slides across the image convolution Feature map edges / textures highlighted
Convolution slides a small kernel across the pixel matrix; different kernels blur, sharpen or detect edges, the same operation a CNN learns automatically.

Processing an image means applying operators. A point operator changes each pixel on its own (e.g. brightness scaling). A linear filter combines each pixel with its neighbours using a small grid of weights called a kernel, this operation is convolution, and it can blur (mean filter), sharpen, or detect edges depending on the kernel. Hold onto this idea: it is the heart of the deep-learning module.

🧪 Lab 2, Image processing in Python

Load an image, inspect its size and pixel statistics per channel, plot RGB histograms, and apply point operators and convolution filters (brightness, blur, sharpen, edge detection) to see how kernels transform an image.

▶ Open Lab 2 in Google Colab
Check: how many numbers represent one pixel in an 8-bit RGB image, and what is each one's range?
Three numbers, one per channel (R, G, B), each ranging 0–255 (2⁸ levels).
5

Deep learning & convolutional neural networks

~55 minutes

By the end you can

  • Trace the path from a single perceptron to a deep network.
  • Explain loss, gradient descent, back-propagation and regularisation.
  • Describe what convolutional and pooling layers do, and why CNNs suit images.

A perceptron is a single artificial neuron: it weights its inputs, sums them, and passes the result through an activation function (sigmoid, tanh, ReLU) that introduces non-linearity. Stack many neurons in many layers and you have a deep neural network.

Networks learn by minimising a loss function, mean squared error for continuous traits, cross-entropy for classification. Gradient descent nudges the weights downhill on the loss surface, and back-propagation efficiently computes those gradients layer by layer. Because deep models overfit readily, we apply dropout (randomly switching off connections during training) and early stopping (halting when validation performance stops improving).

For images we use convolutional neural networks (CNNs). Instead of hand-designing filters (Module 4), a CNN learns the kernels from data. Convolutional layers detect local patterns (edges → textures → parts → objects); pooling layers downsample to add robustness; a final dense layer turns the learned features into a prediction.

Inputimage Convlearn filters Pooldownsample Conv Pool Flatten +Dense Outputtrait / class A convolutional neural network for image-based phenotyping
A CNN learns its own filters: convolution and pooling layers build up from edges to whole-animal features, ending in a prediction such as body condition score.
Key concept · learned vs hand-crafted featuresThe big shift deep learning brought is that the model discovers the useful image features itself, instead of an expert designing them. This is why CNNs outperform classical methods on hard, unstructured images, at the cost of needing more data and GPU computing.
Check: what is the role of a pooling layer in a CNN?
Pooling downsamples the feature maps (e.g. taking the maximum in each small region). It shrinks the data, reduces computation, and makes the network more robust to small shifts in where a feature appears in the image (translation invariance).
6

High-throughput phenotyping & breeding applications

~45 minutes

By the end you can

  • Define high-throughput phenotyping (HTP) and the qualities of a good phenotype.
  • Give concrete examples of computer vision in animal breeding.
  • Explain enviromics and genotype-by-environment interaction (G×E).

The phenotype equation is simple to state and hard to satisfy: Phenotype = Genetics + Environment. Genomics gave us cheap genotypes; the bottleneck moved to phenotypes. High-throughput phenotyping uses cameras, wearable sensors, robots and drones to measure many animals, often and cheaply. A good phenotype is accurate and precise, measured non-invasively, and scalable to thousands of animals at low cost.

Computer vision now delivers traits that were once subjective or labour-intensive:

  • Body weight & growth, continuous monitoring of cattle weight and energy balance from images.
  • Body condition score, from 3-D images at >90% accuracy, a key health, welfare and feed-efficiency indicator.
  • Black soldier fly larvae, automated weight and sex prediction (YOLOv8 detection) for insect production.
  • Ribeye area & carcass shape in live calves from 3-D body shape.
  • Parasite detection, reading the ocular conjunctiva (FAMACHA) to flag parasitised sheep, removing human subjectivity.
  • Identification & behaviour, recognising individuals and their feeding behaviour without tags.

Sensors also describe the environment. Enviromics uses farm- and region-level environmental descriptors to study genotype-by-environment interaction (G×E), why the best animals in one system are not the best in another, a central question for breeding programmes across the diverse environments of East Africa and Denmark.

Why this matters for breedingCheaper, larger-scale, more objective phenotypes mean more animals with records, novel traits (welfare, efficiency, resilience), and more accurate breeding values, the raw material of genetic progress.
Check: HTP is often called a solution to a “bottleneck.” Which bottleneck, and why?
The phenotyping bottleneck. Genotyping became fast and cheap, so the limiting factor for genetic evaluation is now collecting enough accurate phenotypes. HTP (sensors and computer vision) relieves this by measuring many animals automatically.
7

Wrap-up & resources

~10 minutes

Key takeaways

  • AI and machine learning let us use big data for prediction, interpretation and causal inference in breeding.
  • Computer vision enables non-invasive, high-throughput phenotyping at large scale.
  • Neural networks, SVMs and tree ensembles are the core ML tools; CNNs are the workhorse for images.
  • The payoff for breeding is more, better and cheaper phenotypes, and therefore faster, fairer genetic progress.

Glossary

5 Vs, Volume, Velocity, Variety, Veracity, Value: the dimensions of big data.
Tall / Wide data, many observations vs many variables (“big p, small n”).
Regularisation, shrinking model complexity (ridge, LASSO, weight decay) to avoid overfitting.
Activation function, non-linear transform in a neuron (sigmoid, tanh, ReLU).
Back-propagation, algorithm to compute gradients for training neural networks.
Kernel / convolution, a small weight grid slid across an image to extract features.
CNN, convolutional neural network; learns image filters automatically.
Pooling, downsampling step that adds robustness and reduces computation.
HTP, high-throughput phenotyping: measuring many animals automatically.
Enviromics / G×E, using environmental data to study genotype-by-environment interaction.

Further reading & resources

  • Gianola, D. & Rosa, G. J. M. (2015). One hundred years of statistical developments in animal breeding. Annual Review of Animal Biosciences 3:19–56.
  • Kuhn, M. & Johnson, K. Applied Predictive Modeling. Springer.
  • Free, certified courses on data and sustainable agriculture at the FAO e-learning Academy.
📘Recommended textbook (free PDF)The standard, openly available text for the machine-learning methods in this course

This course applies statistical and machine-learning methods to high-throughput phenotyping and image data. The recommended textbook below is made freely available by its authors.

Ministry of Foreign Affairs of Denmark Danida Fellowship Centre
The project is funded by the Ministry of Foreign Affairs of Denmark and managed by Danida Fellowship Centre.
DANIDA Knowledge and Innovation Programme (KIP) 2025.