Computer-vision monitoring for endangered Arabian Tahr conservation: detect and count the species, flag human/animal intruders, and classify habitat from field-camera and drone footage.
Tahr Guardian is a computer-vision pipeline built for wildlife conservation and anti-poaching monitoring for a wildlife reserve on the Arabian Peninsula. It analyzes video from field cameras and drones to:
- Detect and count the endangered Arabian Tahr in each frame.
- Flag intruders — humans and donkeys — that should not be present in protected habitat.
- Classify the surrounding habitat (Desert, Greenland, Snow) directly from the imagery.
Detection uses an Ultralytics YOLO model (trained with both YOLOv8 and YOLOv11), habitat classification uses OpenAI CLIP (zero-shot, via text prompts), and tracking uses an OpenCV CSRT tracker to assign stable IDs and avoid double-counting across frames. The repository also includes an experimental self-improving loop that saves low-confidence detections and periodically retrains the model on them.
- Tahr detection & counting — bounding boxes, per-frame counts, and on-screen overlays.
- Intruder alerting — humans and donkeys are labelled as intruders with separate counts and console notifications per frame.
- Habitat classification — zero-shot CLIP (
ViT-B/32) maps each frame to Desert, Greenland, or Snow from natural-language descriptions. - Multi-object tracking — OpenCV CSRT trackers assign consistent IDs for unique-object counting.
- Self-improving retraining (experimental) — low-confidence detections are cropped and saved in YOLO label format, then used to periodically retrain the model.
- Evaluation tooling — confusion-matrix generation plus full YOLOv8 / YOLOv11 training artifacts
(PR/F1 curves, results, confusion matrices) under
trainYOLOV8/andtrainYOLOV11/. - Annotated video output — processed frames are written to an output video with all overlays.
- Language: Python
- Detection: Ultralytics YOLO (YOLOv8 & YOLOv11)
- Classification: OpenAI CLIP (
ViT-B/32) - Vision / video I/O: OpenCV
- ML / numerics: PyTorch, NumPy, scikit-learn
- Visualization: Matplotlib, Pillow
.
├── intruder.py # Detection + intruder flagging + CLIP habitat classification
├── Intruder_Learning.py # Same pipeline + self-improving low-confidence retraining loop
├── tracking.py # YOLO detection + CSRT tracking for unique Tahr counting
├── trainYOLOV8/ # YOLOv8 training run (args, metrics, curves, confusion matrices)
├── trainYOLOV11/ # YOLOv11 training run (args, metrics, curves, confusion matrices)
└── YOLOV8/ # (placeholder)
git clone https://github.com/ube09/Tahr-Guardian.git
cd TahrGuardianpython -m venv env
# Windows:
env\Scripts\activate
# macOS / Linux:
source env/bin/activatepip install --upgrade pip
pip install opencv-python ultralytics numpy torch torchvision clip scikit-learn matplotlib PillowA CUDA-capable GPU is recommended but optional — the code falls back to CPU automatically.
- Place your trained YOLO weights (e.g.
v11.pt) in the project root, or update theYOLO_WEIGHTS_PATHconstant in the script you run. - Set the input video path via
VIDEO_PATHand the output path viaOUTPUT_VIDEO_PATH.
Detection + intruder flagging + habitat classification:
python intruder.pyDetection + self-improving retraining loop:
python Intruder_Learning.pyDetection + CSRT tracking for unique Tahr counting:
python tracking.pyEach script displays processed frames in a window (press q to quit early) and writes an
annotated output video to disk.
Key constants are set at the top of each script:
VIDEO_PATH,OUTPUT_VIDEO_PATH,YOLO_WEIGHTS_PATH- Confidence thresholds (detection cutoff, and the low-confidence threshold for retraining)
class_names, colors, and thehabitat_descriptions/habitat_namesused by CLIP
Trained on a custom Tahr dataset (25 epochs). Final validation metrics:
| Model | Precision | Recall | mAP@50 | mAP@50-95 |
|---|---|---|---|---|
| YOLOv11 | ~0.96 | ~0.94 | ~0.97 | ~0.60 |
| YOLOv8 | ~0.97 | ~0.94 | ~0.97 | ~0.59 |
See trainYOLOV8/ and trainYOLOV11/ for full curves, confusion matrices, and results.csv.
Usama Bin Ejaz — AI/ML Engineer | Data Scientist | Founder, UBE Labs
- GitHub: github.com/ube09
- Website: usamabinejaz.com