A Streamlit-based web application for removing atmospheric haze from images using the AOD-Net (All-in-One Dehazing Network) deep learning model.
This application provides a user-friendly web interface for image dehazing, allowing users to upload hazy images and receive dehazed results. The application uses a pre-trained AOD-Net model to process images and remove atmospheric haze while preserving fine details.
- Streamlit Interface: Modern, intuitive web application built with Streamlit
- AOD-Net Model: State-of-the-art deep learning model for image dehazing
- File Validation: Comprehensive validation including file type, size, and dimension constraints
- Real-time Processing: Live feedback during image processing
- Side-by-side Comparison: View original and dehazed images side by side
- Error Handling: Robust error handling with user-friendly messages
- Easy Download: One-click download of dehazed results
The model was trained on the NYU2 dataset (Silberman et al., 2012), which includes:
- Ground Truth Images: Approximately 1,500 images in the
ori_images/folder- Naming format:
NYU2_x.jpgwherexis an integer
- Naming format:
- Hazy Images: Approximately 27,000 synthetically hazed images in the
hazy_images/folder- Naming format:
NYU2_x_y_zwhereyandzvary to indicate different haze levels - Multiple hazed versions are provided for each ground truth image
- Naming format:
This dataset provides a comprehensive range of hazy conditions, supporting effective model training for diverse scenarios.
Reference: Silberman, N., Hoiem, D., Kohli, P., & Fergus, R. (2012). Indoor segmentation and support inference from RGBD images. In A. Fitzgibbon, S. Lazebnik, P. Perona, Y. Sato, & C. Schmid (Eds.), Computer vision – ECCV 2012 (Vol. 7576, pp. 346-360). Springer. https://doi.org/10.1007/978-3-642-33715-4_54
- Clone the repository:
git clone <repository-url>
cd Dehazing-Algorithms- Create and activate a virtual environment:
python -m venv env
source env/bin/activate # On Windows: env\Scripts\activate- Install dependencies:
pip install -r requirements.txtNote: On macOS, you may need to install Apache Arrow for Streamlit:
brew install apache-arrow- Ensure you have the trained model weights in
saved_model/dehazer_epoch_9.pth
Start the Streamlit application:
streamlit run streamlit_app.pyThe application will automatically open in your browser at http://localhost:8501
- Upload an Image: Click "Choose an image file" and select a hazy image (PNG, JPG, or JPEG)
- Wait for Processing: The model will process your image (this may take a few seconds)
- View Results: Compare the original and dehazed images side by side
- Download: Click the download button to save your dehazed image
To train the dehazing model (AOD-Net), follow these steps:
-
Download the Google Colab Notebook (
AOD_Net.ipynb) -
Set Up Your Environment: Install the necessary libraries:
!pip install torch torchvision scikit-image opencv-python-
Upload and Organize Your Dataset:
- Organize your dataset with two folders:
ori_images/: ~1500 ground truth images (e.g., "NYU2_x.jpg")hazy_images/: ~27K hazy images (e.g., "NYU2_x_y_z")
- Upload the images to Google Colab or link them from cloud storage
- Organize your dataset with two folders:
-
Set the Model Configuration:
- In the Args class, configure paths to your dataset, learning rate, weight decay, and other training parameters
-
Data Preparation:
- The DehazeDataManager class handles loading and splitting the dataset into training, validation, and test sets
-
Model Definition:
- The AODNet class is initialized and transferred to the GPU for training
-
Start the Training Process:
- The BaseTrainer class's
fitmethod trains the model over multiple epochs - Checkpoints are saved after each epoch
- The BaseTrainer class's
-
Evaluate on the Test Set:
- After training, the model is evaluated on the test set for each epoch
- The evaluate method computes SSIM and FSIM metrics
- The best performing model is saved
-
Save the Trained Model:
- Model checkpoints are saved in the
snapshotsfolder - Load the best model for further evaluation or inference
- Model checkpoints are saved in the
Key configuration settings can be found in config.py:
- File Upload Limits: Maximum file size (10 MB), image dimensions
- Model Path: Location of the trained model weights
- Image Constraints: Minimum and maximum image dimensions
Dehazing-Algorithms/
├── streamlit_app.py # Streamlit application (main entry point)
├── config.py # Configuration constants
├── model.py # AOD-Net model implementation
├── requirements.txt # Python dependencies
├── saved_model/ # Trained model weights
│ └── dehazer_epoch_9.pth # Pre-trained model file
└── AOD_Net.ipynb # Training notebook (optional)
- File Validation: Checks file type, size, and dimensions
- Error Handling: Clear error messages for common issues
- Progress Indicators: Visual feedback during processing
- Image Comparison: Side-by-side view of original and processed images
- Format Preservation: Maintains original image format when possible