Skip to content

Custom YOLOv8 implementation for bird detection in images and videos, covering dataset preparation, training, and inference.

License

Notifications You must be signed in to change notification settings

Pushtogithub23/birds-detection-yolov8

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Birds Detection using YOLOv8 πŸ¦…

A custom implementation of YOLOv8 for detecting birds in images and videos. This project provides a complete pipeline from dataset preparation to model training and inference.

Python YOLOv8 Ultralytics Roboflow

crows_detected

kingfishers_detected

sparrow_detected_2

πŸ“‹ Table of Contents

✨ Features

  • Custom YOLOv8 model training for bird detection
  • Support for both image and video inference
  • Real-time object tracking in videos
  • Configurable confidence thresholds
  • Automatic annotation visualization
  • Support for both local files and URLs
  • Save capabilities for annotated images and videos

πŸ”§ Prerequisites

  • Python 3.8+
  • CUDA-compatible GPU (recommended)
  • Google Colab (optional, for free GPU access)

πŸ“¦ Installation

  1. Clone this repository:
git clone https://github.com/Pushtogithub23/birds-detection-yolov8.git
cd birds-detection-yolov8
  1. Install required packages:
pip install -r requirements.txt

πŸš€ Usage

Image Detection

# For local image
display_prediction("path/to/your/image.jpg", save_fig=True, filename="detected.jpg")

# For image URL
display_prediction("https://example.com/image.jpg", save_fig=True, filename="detected.jpg")

I have attached below few detections in images:

crows_detected_2

peacocks_detected

owls_detected

Video Detection

predict_in_videos(
    "path/to/your/video.mp4",
    save_video=True,
    filename="detected_video.mp4"
)

I have attached a video detection in GIF format below.

kingfisher_detected

πŸ“Š Dataset Preparation

  1. Create a Roboflow account and obtain your API key
  2. Update the API key in the notebook:
rf = Roboflow(api_key="YOUR_API_KEY")
  1. The dataset structure should be:
BIRDS-DETECTION-1/
β”œβ”€β”€ train/
β”œβ”€β”€ valid/
β”œβ”€β”€ test/
└── data.yaml

πŸ‹οΈ Model Training

The model is trained using YOLOv8-large (yolov8l.pt) as the base model:

model = YOLO('yolov8l.pt')
model.train(
    data="BIRDS-DETECTION-1/data.yaml",
    epochs=100,
    imgsz=640
)

Training parameters can be adjusted based on your needs:

  • epochs: Number of training epochs
  • imgsz: Input image size
  • batch: Batch size (adjust based on GPU memory)

🎯 Inference

Detection Function Features

  • Automatic thickness calculation based on image resolution
  • Dynamic text scaling
  • Confidence threshold filtering (default: 0.5)
  • Color-coded annotations using 'magma' colormap
  • Support for both image and video processing
  • Object tracking in videos using ByteTrack

Video Processing Features

  • Real-time object tracking
  • FPS-synchronized processing
  • Progress visualization
  • Press 'p' to stop processing

πŸ’‘ Best Practices

Dataset Preparation

  • Ensure the dataset is well-balanced
  • Include images with varying lighting conditions
  • Use data augmentation for better generalization

Training Tips

  • Monitor training metrics in runs/detect/train directory
  • Adjust confidence threshold based on application needs
  • Consider model ensembling for better results

Production Deployment

  • Move API keys to environment variables
  • Implement proper error handling
  • Consider model quantization for faster inference

πŸ’» GPU Requirements

This project was developed and tested on Google Colab with T4 GPU acceleration. When running on different hardware:

  • Adjust batch size according to available GPU memory
  • Modify image size if needed
  • Consider using model quantization for faster inference on less powerful hardware

About

Custom YOLOv8 implementation for bird detection in images and videos, covering dataset preparation, training, and inference.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published