This project implements a real-time drowning detection system using Convolutional Neural Networks (CNNs) with two popular architectures: GoogleNet and ResNet. The application provides both a graphical user interface for real-time detection and command-line interfaces for model training and evaluation. Now with advanced person detection and water/land classification, including enhanced small person detection!
- 👁️ Real-time person detection with counting and tracking
- 🔍 NEW! Enhanced small person detection with multi-scale analysis
- 🌊 Water area detection to identify if a person is in water or on land
- 💧 NEW! Advanced water detection for blue, green, and murky water conditions
⚠️ Drowning alert system with visual and logging notifications- 🎯 Real-time drowning detection from webcam, video files, and images
- 🧠 Two state-of-the-art CNN models: GoogleNet and ResNet
- 📊 Detailed model evaluation with confusion matrices and ROC curves
- 📸 Screenshot capture for evidence and record-keeping
- 📈 TensorBoard integration for monitoring training progress
- 🖥️ Modern and intuitive PyQt5-based graphical user interface
- 📁 Organized project structure for easy maintenance
- 🔄 NEW! Temporal tracking for more stable detection results
drowning-detection-cnn
├── src
│ ├── app.py # GUI application implementation
│ ├── main.py # Entry point with command-line arguments
│ ├── settings.py # Centralized configuration
│ ├── dataset.py # Advanced dataset handling with augmentation
│ ├── train.py # Training with tensorboard and early stopping
│ ├── evaluate.py # Comprehensive model evaluation
│ ├── utils.py # Utility functions and helpers
│ ├── models
│ │ ├── googlenet_model.py # GoogleNet implementation
│ │ └── resnet_model.py # ResNet implementation
├── data
│ ├── normal/ # Images of normal swimming
│ └── drowning/ # Images of drowning incidents
├── models # Saved model weights
├── results # Evaluation results and visualizations
├── setup.ps1 # Setup script for environment configuration
├── run_app.bat # Quick-start batch file for Windows
├── requirements.txt # Project dependencies
└── README.md # Project documentation
-
Run the setup script (requires PowerShell):
powershell -ExecutionPolicy Bypass -File setup.ps1 -
Launch the application:
run_app.bat
-
Create and activate a virtual environment:
python -m venv venv venv\Scripts\activate # Windows source venv/bin/activate # Linux/Mac -
Install dependencies:
pip install -r requirements.txt -
Run the application:
python src/main.py
Run the standard application in GUI mode:
run_app.bat
Run the enhanced detection application with better small person detection:
run_enhanced_mode.bat
Run the integrated application with both standard and enhanced detection:
run_integrated_app.bat
Command-line options for the integrated application:
python src/main_integrated.py --enhanced-only --model googlenet --video path/to/video.mp4
Available options:
--enhanced-only: Start with only the enhanced detection tab visible--model: Choose betweengooglenetorresnet--video: Specify a video file to use for testing
Train a model from command line:
python src/main.py --mode train --model googlenet --epochs 30 --batch-size 32
Available options:
--model: Choose betweengooglenetorresnet--data-dir: Specify the dataset directory--epochs: Number of training epochs--batch-size: Training batch size--learning-rate: Initial learning rate
Evaluate a trained model:
python src/main.py --mode evaluate --model googlenet --output-dir results
This project implements two CNN architectures:
- GoogleNet: A deep network with inception modules for efficient feature extraction
- ResNet: A residual network that uses skip connections to enable very deep architectures
Both models are pre-trained on ImageNet and fine-tuned on the drowning detection dataset using transfer learning.
The dataset should be organized as follows:
data/
├── normal/
│ ├── image1.jpg
│ ├── image2.jpg
│ └── ...
└── drowning/
├── image1.jpg
├── image2.jpg
└── ...
After evaluation, the system generates:
- Confusion matrices
- ROC curves
- Example predictions (correct and incorrect)
- Detailed classification reports
These outputs are saved in the results directory.
The application now includes advanced real-time person detection features:
The system uses YOLO (You Only Look Once) for detecting people in video streams and images, then classifies:
- Whether the person is in water or on land
- If in water, whether the person is drowning
- Person Detection: YOLO model identifies all people in the frame
- Water Detection: Color-based segmentation identifies water areas
- In-Water Classification: Checks if the lower portion of a person's bounding box overlaps with water
- Drowning Detection: For people in water, uses the CNN model to classify drowning status
- Select a video source (webcam or video file)
- Choose the drowning detection model (GoogleNet or ResNet)
- Click "Start Detection" to begin analysis
- The system will:
- Draw bounding boxes around detected people
- Label each person as "In Water" or "Not In Water"
- For people in water, classify and alert if drowning is detected
- Count and display statistics in real-time
- Visual Alerts: Red bounding boxes and text for drowning persons
- Alert Box: Changes to red with warning text when drowning is detected
- Detection Log: Records all significant events with timestamps
- Screenshot Feature: Capture evidence with the "Take Screenshot" button
For different water environments (pools, oceans, rivers), you may need to adjust the water detection parameters in the detection.py file:
# Adjust these HSV color ranges for different water types
self.water_lower = np.array([100, 50, 50]) # Blue-ish colors lower bound
self.water_upper = np.array([140, 255, 255]) # Blue-ish colors upper boundContributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
