research log

Muzzle-Based Livestock Identification
Technical & Field Report

Published 2026-07-16

ProjectPlantsat–UNDP Nepal Livestock Biometric Identification Initiative
StatusOngoing — dataset collection and model iteration in progress
Period2024 – Present

Broader Goal

Conventional livestock identification methods — ear-tagging, branding, and injectable RFID chips — are invasive, painful, and prone to tampering or loss. The goal of this project is to demonstrate that a photograph of an animal's muzzle is sufficient to uniquely identify an individual animal, replacing these methods with a non-invasive, camera-based biometric system.

This research has direct relevance to agricultural insurance programs, livestock traceability, and farmer-support initiatives run by programs such as UNDP in Nepal, where reliable cattle identification is critical to determining ownership and insurance eligibility.


My Role

This project is an active initiative at Plantsat, undertaken in collaboration with the United Nations Development Programme (UNDP) in Nepal. My contributions include:


Technical Architecture

Core Approach: Siamese Neural Networks

The system is built on Siamese Neural Networks — a twin-branch architecture where both branches share identical weights. Given a pair of muzzle images, each branch independently generates a high-dimensional embedding vector. The Euclidean distance between the two embeddings determines whether the pair belongs to the same individual animal.

This approach is well-suited to livestock identification because:

Backbone Architectures Evaluated

We conducted a systematic comparative study across five state-of-the-art backbone architectures:

CategoryBackboneCharacteristics
CNNVGG16Strong spatial feature extraction; higher parameter count
CNNResNet50Residual connections for better gradient flow
CNNResNet152Deeper variant; stronger feature representations
TransformerViT-BaseGlobal self-attention; class token output for identity embedding
TransformerViT-LargeLarger capacity; stronger global context modelling

Convolutional backbones excel at capturing local spatial features such as individual groove patterns. Vision Transformers capture global structural context through self-attention — hypothesized to better represent overall muzzle topology.

Objective Function: Contrastive Loss

Embeddings are optimized using Contrastive Loss, which pulls same-identity pairs together and pushes different-identity pairs apart:

L=(1 − Y) · d²+Y · max(margin − d, 0)²

This forces the network to learn an embedding space where same-animal pairs cluster closely together while different-animal pairs are pushed beyond the margin threshold.

Dataset Construction

A key engineering contribution is the dynamic pair-sampling dataset class, which generates balanced positive (same identity) and negative (different identity) pairs during training. Without careful class balancing, the model encounters far more negative pairs, degrading performance. Our implementation maintains a controlled positive-to-negative ratio across every training batch.

Explainable AI: Grad-CAM Visualization

Deep learning models are often criticized as black boxes. To validate that our model is attending to the correct features, we implemented Gradient-weighted Class Activation Mapping (Grad-CAM):

  1. Forward and backward hooks are registered on the final convolutional or attention layer
  2. Gradients flowing back from the loss are averaged to produce per-channel importance weights
  3. These weights are applied to feature map activations and summed to produce a saliency map
  4. The saliency map is overlaid on the original input image as a visual heatmap

This lets us visually confirm that the network attends to anatomical muzzle groove patterns — the actual biometric signal — rather than background artifacts like fence posts, shadows, or farm environments. This interpretability step is essential for academic credibility and for demonstrating trustworthiness to UNDP program officers.


Field Findings: Why Single-Environment Data Is Not Enough

Farm Campaign

We conducted testing campaigns across multiple farms in Nepal under varying conditions — different lighting (morning, afternoon, overcast), different camera distances, different animal postures, and different environmental backgrounds.

Key Finding: Models trained on single-environment datasets failed to generalize across farms. A model trained on morning images from one farm performed poorly on afternoon images from another. This confirmed that multi-environment, multi-condition data collection is not optional — it is a core requirement for building a model that works reliably in deployment.

We updated our data collection strategy to systematically capture images across:

Post-Mortem Muzzle Study: Slaughterhouse Collaboration

A specific challenge for livestock insurance programs is identifying dead cattle after slaughter — for example, to verify that the animal being claimed under an insurance policy is the same animal that was insured.

The muzzle changes significantly after death: it compresses, loses tissue hydration, and the groove patterns shift. To study this, we collaborated with a slaughterhouse and collected muzzle images at controlled time intervals:

Time PointPhysiological Condition
12 hours before slaughterBaseline — fully alive and alert
2 hours before slaughterMild pre-slaughter stress
Immediately before slaughterHigh stress; muscle tension elevated
Immediately after slaughterImmediate post-mortem; tissue still fresh
2 hours after slaughterTissue compression visible; groove patterns shifted

Training on this multi-interval dataset allowed the model to learn the trajectory of muzzle change over time, making it robust to post-mortem identification — a crucial capability for agricultural insurance verification.


Mobile Data Collection Application

To enable structured, large-scale data collection across all farm sites and time intervals, we built a dedicated mobile data-collection application using Flutter. The app:

This application continues to be used in ongoing data collection campaigns as we scale the dataset to improve model accuracy.


Current Status & Next Stage

The training pipeline is functional across all five backbone architectures. Evaluation is conducted via a robust binary inference pipeline with tunable Euclidean distance thresholds, computing accuracy, precision, recall, F1-score, and confusion matrices for each backbone configuration.

The dataset collection is ongoing. This is a long-horizon research project — the model's accuracy continues to improve as more multi-environment and post-mortem data is added. Working with UNDP Nepal, the goal is to scale the dataset to cover a representative sample of livestock across Nepal's diverse agricultural regions.

Next engineering milestone: Optimize the best-performing backbone through:

The end goal is real-time, edge inference on the mobile data-collection app itself — eliminating server-side inference dependency in low-connectivity farm environments.