Skip to content

Repository files navigation

Wildlife Intrusion Detection

Real-time wild-animal intrusion detection using a custom-trained YOLOv5 model, with hardware alert triggers over a serial link.

Python PyTorch YOLOv5 OpenCV

What it is

A computer-vision system that watches a camera feed (webcam, video file, or stream) and detects wild animals in real time so that nearby personnel can be warned before an intrusion becomes dangerous. It is built on the YOLOv5 detection pipeline with custom-trained weights (best.pt), and distinguishes wild animals from domestic ones. When a wild animal is detected, the system fires an alert signal to external hardware (e.g. a microcontroller driving sirens/deterrents) over a serial port.

How it works

  1. detect.py runs YOLOv5 inference on the input source (defaults: webcam 0, custom weights best.pt, confidence threshold 0.65).
  2. Each frame is annotated with bounding boxes and class labels, and results can be saved as images/video, text labels, or CSV.
  3. When one of the trained wild-animal classes is detected — Tiger, Bison, Elephant, Leopard, Lion, Deer — a class-specific single-character code (T, B, E, L, M, D) is written to a serial port (9600 baud, see serial_test.py), where connected hardware can trigger the appropriate alert.
  4. A separate image-classification stage lives in classify/ with its own trained weights (classify/best_classify.pt).

Features

  • Custom-trained YOLOv5 weights for six wild-animal classes (Tiger, Bison, Elephant, Leopard, Lion, Deer)
  • Real-time inference on webcam, video files, RTSP/HTTP streams, image folders, or screenshots
  • Serial-port alert triggers (pyserial) so a microcontroller can react per detected species
  • Annotated output saved to runs/detect/ (video/images), with optional --save-txt and --save-csv exports
  • Full YOLOv5 toolchain included: train.py for training on custom datasets, val.py for evaluation, export.py for ONNX/TensorRT and other export formats
  • Sample test videos (test.mp4, v10.mp4) and dataset images in images/

Tech stack

  • Detection: YOLOv5 (PyTorch), Ultralytics utilities
  • Vision: OpenCV
  • Hardware link: pyserial (UART, 9600 baud)
  • Models: custom-trained best.pt (detection), classify/best_classify.pt (classification), plus stock yolov5s.pt

Getting started

# Install the standard YOLOv5 dependencies (PyTorch, OpenCV, ultralytics, etc.)
# plus pyserial for the hardware alert link
pip install torch torchvision opencv-python ultralytics pyserial

# Run detection on the default webcam with the custom wildlife weights
python detect.py

# Or on a sample video
python detect.py --weights best.pt --source test.mp4

# Validate / retrain
python val.py --weights best.pt
python train.py --weights yolov5s.pt --data <your-dataset>.yaml

Note: detect.py imports the serial sender at startup, which opens a serial port (configured as COM4 in serial_test.py). To run with the hardware alerts, connect your microcontroller and adjust the port name for your machine.


Built by Manu Rathan Setty

About

Real-time wildlife intrusion detection with a custom-trained YOLOv5 model — detects tigers, elephants, leopards and more, and triggers hardware alerts over a serial link

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages