Skip to content

About

Autonomous drone obstacle detection and collision avoidance system using a hybrid YOLO + DroNet fusion engine with depth-aware safety scoring.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

Drone Obstacle Detection & Collision Avoidance

Python Version Deep Learning Frameworks YOLO Models OpenCV DJI Tello

An advanced, hybrid collision avoidance and obstacle detection system for autonomous drones. This project integrates the spatial object detection capabilities of YOLO (v8/11) with the collision probability estimation of DroNet, combined with a custom Depth-Aware Safety Scoring Algorithm to build a robust, redundant flight safety system.


๐Ÿ“Œ Core Architecture & Features

This system combines two distinct paradigms of deep learning to achieve safer autonomous navigation:

1. The "Waterfall Problem" Solved (Depth-Aware Safety)

Standard bounding-box detectors often fail to understand depth. A large distant structure (like a far-off mountain or waterfall) can trigger a false positive, causing the drone to halt unnecessarily.

  • Our Depth-Aware Safety Algorithm uses object size and vertical frame coordinates as a depth proxy.
  • Large, distant background objects are correctly filtered out as low-risk.
  • Small, close obstacles directly entering the central flight path (corridor) dynamically scale up the danger score, triggering immediate braking.

The Safety Score ($S_{hazard}$) for a detected obstacle is computed as: $$S_{hazard} = W_{class} \times \left( \alpha \cdot \text{Area}{ratio} + \beta \cdot (1 - Y{normalized}) \right)$$ where:

  • $W_{class}$ represents the class-specific hazard weight (e.g., structure vs. living).
  • $\text{Area}_{ratio}$ is the bounding box area relative to the total frame size (larger boxes represent closer obstacles).
  • $Y_{normalized}$ is the vertical coordinate of the box center (closer ground obstacles occupy lower positions in the frame, while distant mountains sit near the horizon).
  • $\alpha, \beta$ are scaling coefficients weighting size vs. perspective height.

2. YOLO + DroNet Hybrid Fusion

  • YOLO (v8/v11): Trained on a simplified version of the Semantic Drone Dataset (6 classes: vegetation, structure, fence, living (people/animals), vehicle, and obstacle). It maps what and where objects are in the frame.
  • DroNet: A lightweight convolutional neural network that estimates continuous collision probability and steering angles based on visual input.
  • The Fusion Engine: Merges YOLO's spatial semantics and class details with DroNet's continuous collision probabilities to eliminate false alarms and ensure double-layered safety checks.

๐Ÿ—๏ธ System Architecture

graph TD
    InputFrame[FPV Video Frame] --> YOLO[YOLOv8/11 Inference]
    InputFrame --> DroNet[DroNet Inference]
    
    YOLO --> Detects[Bounding Boxes & Classes]
    Detects --> Filter1[Filter 1: Vertical Position Check]
    Detects --> Filter2[Filter 2: Size Ratio / Depth Proxy]
    
    Filter1 --> PathCorridor{Is in Flight Corridor?}
    Filter2 --> PathCorridor
    
    PathCorridor -- Yes --> SafetyScore[Calculate YOLO Danger Score]
    PathCorridor -- No --> Ignore[Ignore / Low Risk]
    
    DroNet --> CollisionProb[DroNet Collision Probability]
    
    SafetyScore --> Fusion[Safety Fusion Engine]
    CollisionProb --> Fusion
    
    Fusion --> Decision{Safety Decision}
    Decision -- Danger > Threshold --> Brake[Brake / Hover / Intervention]
    Decision -- Safe --> Continue[Continue Flight Path]
Loading

๐Ÿ“‚ Project Structure

drone_obstacle_detection/
โ”œโ”€โ”€ DroNet_plus_YOLO.ipynb     # Main development, training, and execution notebook
โ”œโ”€โ”€ SemanticDrone.yaml         # YOLO training configuration (classes & paths)
โ”œโ”€โ”€ class_dict_seg.csv         # Original Semantic Drone Dataset category mapping
โ”œโ”€โ”€ yolo11n.pt / yolov8n.pt    # Pre-trained COCO base weights
โ”œโ”€โ”€ dataset/                   # [Ignored in Git] Raw training images & masks
โ”œโ”€โ”€ SemanticDrone-YOLO/        # [Ignored in Git] Generated YOLO dataset format
โ”œโ”€โ”€ outputs/                   # Exported videos with overlays (Telemetry, Bounding boxes)
โ”‚   โ”œโ”€โ”€ hybrid_outputnew4.mp4  # Stable FPV test output
โ”‚   โ””โ”€โ”€ hybrid_outputnew55.mp4 # Dynamic environment test output
โ”œโ”€โ”€ semantic_drone_training/   # Training metrics, curves, and best/last weights
โ”‚   โ””โ”€โ”€ yolov8n_semantic/
โ”‚       โ”œโ”€โ”€ weights/
โ”‚       โ”‚   โ”œโ”€โ”€ best.pt        # Custom YOLO weights trained on Semantic Drone Dataset
โ”‚       โ”‚   โ””โ”€โ”€ last.pt        # Last epoch checkpoints
โ”‚       โ”œโ”€โ”€ confusion_matrix.png
โ”‚       โ””โ”€โ”€ results.png
โ””โ”€โ”€ of-obstacledetection/      # Submodule containing original DroNet code & flight integration
    โ”œโ”€โ”€ DroNeTello/
    โ”‚   โ”œโ”€โ”€ models/            # Pre-trained DroNet model structures and weights
    โ”‚   โ”œโ”€โ”€ DroNeTello.py      # Standard Tello flight interface
    โ”‚   โ””โ”€โ”€ FlowDroNeTello.py  # Optical Flow-enhanced DroNet controller
    โ””โ”€โ”€ requirements.txt       # Core dependencies for flight tests

๐Ÿ› ๏ธ Setup & Installation

1. Clone the Project

git clone https://github.com/VedhSontha/drone-obstacle-detection.git
cd drone_obstacle_detection

2. Configure Environment

We recommend using a python virtual environment (Python 3.10+ is required):

python -m venv venv
# Windows:
venv\Scripts\activate
# macOS/Linux:
# source venv/bin/activate

pip install -r of-obstacledetection/requirements.txt
pip install ultralytics opencv-python matplotlib tqdm ipykernel

3. Verify the Environment

Before running the main scripts or notebook, verify that your local environment is correctly configured:

python verify_environment.py

This script will check your Python, PyTorch (and CUDA GPU availability), OpenCV, and Ultralytics installations, and confirm that all required local model weights and structures exist. It will return a success/failure status code accordingly.


๐Ÿš€ Pipeline Workflow

The main workflow is orchestrated step-by-step in DroNet_plus_YOLO.ipynb:

Step 1: Segmentation Mask to YOLO Bounding Boxes

Converts the dense pixel-level labels of the Semantic Drone Dataset into lightweight YOLO bounding box format, mapping 20+ fine-grained classes into 6 major target classes:

OBSTACLE_CLASSES = {
    'tree': {'seg_id': 19, 'yolo_id': 0},       # Vegetation
    'fence': {'seg_id': 2, 'yolo_id': 2},      # Fences
    'person': {'seg_id': 11, 'yolo_id': 3},     # Living Things
    'car': {'seg_id': 8, 'yolo_id': 4},         # Vehicles
    # ...
}

Step 2: Custom YOLO Training

Trains the YOLO model on your converted dataset. The configuration details are parsed from SemanticDrone.yaml:

path: SemanticDrone-YOLO
train: train/images
val: val/images
nc: 6
names: ['vegetation', 'structure', 'fence', 'living', 'vehicle', 'obstacle']

Step 3: Run the Safety Assessment Engine

Run inferences concurrently on video streams or live FPV feeds. The telemetry overlays a central flight path boundary (35% to 65% width) and dynamically calculates real-time hazard stats.


๐ŸŽฎ DJI Tello Quadcopter Controls

When testing the system in a real-world environment using a DJI Tello drone:

  1. Connect your computer to the Tello's Wi-Fi network.
  2. Launch the flight script:
    python of-obstacledetection/DroNeTello/FlowDroNeTello.py

Keyboard Bindings:

Key Command
Tab Takeoff
Shift Land
Space Emergency Motor Shutdown
W, S, A, D Pitch & Roll (Forward, backward, left, right)
Q, E Yaw (Rotate counter-clockwise / clockwise)
R, F Altitude (Move up / down)
# Arm/Disarm Autopilot (DroNet Control)
O Show/Hide Optical Flow Window
C Start/Stop Video Recording

Warning

Pressing any manual flight command (W,S,A,D) instantly disarms the autopilot for safety. Be prepared to manually override the flight paths if the drone exhibits unexpected behavior.


๐Ÿ“Š Evaluation Metrics

The training results and performance curves are preserved under the semantic_drone_training/yolov8n_semantic/ directory:

  • BoxPR_curve.png / BoxF1_curve.png: Show overall precision, recall, and optimal confidence thresholds.
  • confusion_matrix.png: Represents classification accuracy and identifies class leakage (e.g., distinguishing structures from generic obstacles).

๐Ÿ›ก๏ธ License

This project is licensed under the MIT License. See the LICENSE file under of-obstacledetection/ for details.

About

Autonomous drone obstacle detection and collision avoidance system using a hybrid YOLO + DroNet fusion engine with depth-aware safety scoring.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages