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.
This system combines two distinct paradigms of deep learning to achieve safer autonomous navigation:
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 (
-
$W_{class}$ represents the class-specific hazard weight (e.g.,structurevs.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.
- YOLO (v8/v11): Trained on a simplified version of the Semantic Drone Dataset (6 classes:
vegetation,structure,fence,living(people/animals),vehicle, andobstacle). 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.
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]
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
git clone https://github.com/VedhSontha/drone-obstacle-detection.git
cd drone_obstacle_detectionWe 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 ipykernelBefore running the main scripts or notebook, verify that your local environment is correctly configured:
python verify_environment.pyThis 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.
The main workflow is orchestrated step-by-step in DroNet_plus_YOLO.ipynb:
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
# ...
}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']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.
When testing the system in a real-world environment using a DJI Tello drone:
- Connect your computer to the Tello's Wi-Fi network.
- Launch the flight script:
python of-obstacledetection/DroNeTello/FlowDroNeTello.py
| 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.
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).
This project is licensed under the MIT License. See the LICENSE file under of-obstacledetection/ for details.