Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Person Re-Identification (TorchReID + YOLOv8)

Open In Colab

Detects people in a scene and matches them against a reference photo using appearance-based Re-ID embeddings — simulating a real surveillance/CCTV search use case ("find this person in this camera frame"). Draws bounding boxes with match confidence and a timestamp overlay, like a real camera feed.

This is the fallback stage of the larger pipeline: used when face recognition can't resolve an identity (face too small, occluded, or angled away from camera), falling back to whole-body appearance matching instead.

Demo

Reference Scene (matched)
Reference Result

How It Works

  1. Detection — YOLOv8n (nano, fast) detects all people in the scene image
  2. Embedding — each detected person crop, and the reference photo, are passed through OSNet (via TorchReID) to get an appearance embedding
  3. Matching — cosine similarity between the reference embedding and each detected person's embedding
  4. Decision — similarity ≥ MATCH_THRESHOLD (default 50%) is flagged green as a match, below is flagged red

Repo Structure

.
├── reid_fr.ipynb   # Full Colab notebook: setup, detection, matching, annotated output
├── assets/          # Demo reference/result images
├── LICENSE
└── .gitignore

Setup (Google Colab)

Run the notebook top to bottom. It handles:

  1. Setup — installs PyTorch, TorchReID, and Ultralytics (YOLOv8)
  2. Model loading — YOLOv8n for detection, OSNet (osnet_x1_0) for Re-ID embeddings
  3. Image upload — prompts for a reference photo and a scene image
  4. Detection + matching — runs person detection on the scene, computes similarity to the reference for each detected person
  5. Annotated output — draws match/no-match boxes with similarity %, plus a timestamp overlay

Tuning

MATCH_THRESHOLD (in the config cell) controls the similarity cutoff for a "match." Lower catches more true matches but risks false positives; higher is stricter. 50% is a starting point — worth tuning against a labeled test set before presenting real numbers.

Datasets Considered for Evaluation

  • Market-1501 — recommended starting point, well-established Re-ID benchmark
  • MSMT17 — larger, more realistic multi-scene benchmark
  • WildTrack — multi-camera surveillance scenario, closest to the CCTV use case this module targets

Possible Extensions

  • Clothing color detection (extra signal for matching when face/body angle is poor)
  • Height estimation via MediaPipe Pose
  • Multi-camera tracking timelines (matching the same person across multiple camera feeds)
  • Auto-generated case file summaries

Tech Stack

TorchReID (OSNet) · YOLOv8 · PyTorch · OpenCV · Google Colab (GPU runtime)