Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.

Farm Animal Tracking Project

Project for tracking farm animals.Sample YT



Download repository and install dependencies

$ git clone
$ cd farm-animal-tracking
$ pip install -r requirements.txt

Download detection model weights

  1. To download precompiled model weights Google Drive
  2. Unzip archive to model/detection_model

Download recognition model weights

  1. To download precompiled model weights Google Drive
  2. Unzip archive to model/siamese/weights



To visualize animal detection on video use:

$ python

or for image:

$ python


To visualize animal tracking on video use:

$ python --video=<path to video>


Dataset for learning of model can be obtained at PSRG website.

EDA (Exploratory Data Analysis)

  • Run:
docker-compose -f eda/docker-compose.yaml up
  • Go to localhost:8001 and enter token from console

Siamese network

You can download current best weights from Google Drive MobileNetV2 Google Drive EfficientNetB5 Google Drive ResNet101V2. Put them into ./model/siamese/weights and use the path as --weights parameter.


Make sure you have cropped dataset in ./data/cropped_animals folder. Please check ./data/ documentation for more info.

$ python

Generate Embeddings for Test dataset and visualize it

Instead of running this script manually (requires ~30GB of RAM) you can use pre-generated train/test/concat files in ./data/visualization. Just select two files with the same postfix, vecs-$1.tsv and meta-$1.tsv, it's important to use the same postfix, otherwise length won't match.

$ python helpers/


  • --datatype: either train or test (default train), which data should be used for embeddings
  • --weights: string (default siam-118_0.0633.h5), specify weights file from mode/siamese/weights/MobileNetV2/ folder

This is going to produce two files:

  • vecs.tsv - list of embeddings for test dataset
  • meta.tsv - list of labels for embeddings

You can visualize those embeddings in application. Just upload them as a custom data (use Load option).

Average class values - Video

Test day data - Video

Train all data - Video

Generate tracking data

$ cd data
$ python

This is going to produce tracking data from videos, so we can evaluate model. Look for frames_tracking.json and pigs_tracking.json inside ./data/tracking/. For more details check Wiki.

Testing two images

You can specify the weights for the model. Please use weights marked with the lowest number (loss value).

$ python


--weights siam-118_0.0633.h5