AI SpillGuard Pro is a production-ready web application that leverages U-Net semantic segmentation with ResNet34 backbone to detect and classify oil spills in SAR (Synthetic Aperture Radar) satellite imagery. The system provides real-time detection, intelligent alerting, persistent storage, and comprehensive analytics for marine environmental monitoring.
- π― Multi-Class Segmentation: Distinguishes between oil spills, look-alikes, ships/wakes, and background with pixel-level precision.
- π¨ Intelligent Alert System: Configurable threshold-based monitoring with priority-ranked critical alerts.
- π Real-Time Visualization: Interactive overlay rendering with adjustable transparency and class toggles.
- πΎ Persistent Storage: Automatic saving of detection results, images, and searchable history.
- π Analytics Dashboard: Comprehensive statistics, coverage distribution, and historical trend analysis.
- π REST API Integration: FastAPI-based programmatic access with Docker deployment support.
- β‘ GPU Acceleration: Optimized PyTorch inference with CUDA support for high-throughput processing.
- π¨ Professional UI: Streamlit-based interface with responsive design and enterprise styling.
| Component | Technology |
|---|---|
| Deep Learning Framework | PyTorch 2.x |
| Model Architecture | U-Net with ResNet34 encoder (segmentation_models_pytorch) |
| Frontend | Streamlit 1.x |
| Backend API | FastAPI (optional deployment) |
| Image Processing | OpenCV, PIL, NumPy |
| Data Storage | JSON-based history tracking |
| Visualization | Matplotlib, Plotly |
| Development | Python 3.8+, Jupyter Notebooks |
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Streamlit Frontend β
β (User Interface + Visualization + Controls) β
ββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββΌββββββββββββββ
βΌ βΌ βΌ
βββββββββββββββ βββββββββββββββ βββββββββββββββ
βOilSpillDetectorβ βAlertSystem β βStorageManagerβ
β(Inference) β β(Monitoring) β β(Persistence) β
ββββββββ¬βββββββ βββββββββββββββ βββββββββββββββ
β
βΌ
βββββββββββββββββββββββ
β U-Net Model β
β (best_model.pth) β
β ResNet34 Encoder β
βββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββ
β Detection Results β
β β’ Segmentation Mask β
β β’ Statistics β
β β’ Alerts β
βββββββββββββββββββββββ
Component Interactions:
- OilSpillDetector: Handles model loading, preprocessing, inference, and post-processing.
- AlertSystem: Monitors detection statistics against configurable thresholds.
- StorageManager: Persists detection history to
history.json. - Streamlit UI: Orchestrates user interactions across detection, history, and API tabs.
- Python 3.8 or higher
- CUDA-compatible GPU (optional, for acceleration)
- 4GB+ RAM recommended
git clone <repository-url>
cd <project-directory>
pip install -r requirements.txt
Ensure best_model.pth exists in the project root:
ls -lh best_model.pth
If retraining the model:
python src/preprocess_train.py
python src/preprocess_val.py
python src/preprocess_test.py
streamlit run app.py
Access the application at http://localhost:8501
- Upload Image for Detection: Navigate to "Detection" tab, click "Browse files", and view results.
- Configure Alert Thresholds: Sidebar β Alert Thresholds (Adjust sliders for Oil Spill, Look-alike, etc.).
- Export Detection History: Navigate to "History" tab and click "Export History (CSV)".
from app import OilSpillDetector, AlertSystem
import cv2
# Initialize detector
detector = OilSpillDetector("best_model.pth")
alert_system = AlertSystem()
# Load image (ensure RGB format)
image = cv2.imread("satellite_image.png")
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
# Run detection
results = detector.predict(image_rgb)
# Access results
print(f"Oil Spill Coverage: {results['statistics']['Oil Spill']['percentage']:.2f}%")
# Check alerts
alerts = alert_system.check_alerts(results["statistics"])
for alert in alerts:
print(f"{alert['severity']}: {alert['message']}")Base URL: http://localhost:8000/api/v1
- **POST
/detect**: Detect oil spills in uploaded image. - **GET
/health**: Health check endpoint.
| Class ID | Class Name | RGB Color | Hex Code |
|---|---|---|---|
| 0 | Background | (0, 0, 0) | #000000 |
| 1 | Oil Spill | (255, 0, 124) | #FF007C |
| 2 | Look-alike | (255, 204, 51) | #FFCC33 |
| 3 | Ship/Wake | (51, 221, 255) | #33DDFF |
# Build Image
docker build -t ai-spillguard-api .
# Run Container
docker run -p 8000:8000 ai-spillguard-api
A contribution is considered complete when:
- β Follows PEP 8 style guidelines.
- β Type hints and Docstrings are added.
- β Unit tests pass without regression.
- β GPU/CPU compatibility is maintained.
This project is licensed under the MIT License.
Copyright (c) 2025 Prem Chand
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.
Built with β€οΈ for Environmental Protection and Marine Conservation.