Telling Cats Apart

two-stage cat face recognition

November 2025

  • computer vision
  • YOLOv8
  • Siamese network
  • PyTorch
  • metric learning

Overview

Recognising a specific cat is harder than spotting a cat: you need open-set identification that still works when there are only a handful of photos per individual. I split the problem into two stages that each do one job well.

How it works

  • Stage 1 · Detection: a fine-tuned YOLOv8-Nano locates and crops the cat's face, kept small enough for low-power deployment.
  • Stage 2 · Identification: a Siamese network with an EfficientNet-B0 backbone, trained with triplet-margin loss, maps each face to an embedding. Identity is decided by Euclidean distance between embeddings, so new cats can be verified without retraining: few-shot and open-set by design.

Results

  • 95% test accuracy
  • Precision 0.967 · Recall 0.933 · F1 0.95
  • ROC-AUC 0.9807, with the decision threshold tuned for robustness

What I learned

That "detect, then compare" beats "classify everything at once" when the set of identities is open and the examples are few. Metric learning let the model answer "is this the same cat?" even for cats it had never trained on.