Skip to content

Thipv0302/Cloud-Classification-using-Deep-Learning

Repository files navigation

πŸŒ₯️ Cloud Classification using Deep Learning

Python TensorFlow License

A deep learning project for classifying cloud types from images using Convolutional Neural Networks (CNN) and Transfer Learning.

πŸ“‹ Table of Contents

🎯 Overview

This project implements a cloud classification system that can identify 7 different types of clouds:

  • Cirriform clouds (Cirrus)
  • Clear sky
  • Cumulonimbus clouds
  • Cumulus clouds
  • High cumuliform clouds
  • Stratiform clouds
  • Stratocumulus clouds

The system uses state-of-the-art deep learning models including ResNet50, EfficientNet, and MobileNetV2 with transfer learning for accurate classification.

✨ Features

  • πŸ”„ Multiple Model Architectures: Support for Simple CNN, ResNet50, EfficientNet, and MobileNetV2
  • πŸ“Š Comprehensive Evaluation: Confusion matrix, classification reports, and visualization tools
  • 🎨 Data Augmentation: Built-in augmentation to improve model generalization
  • πŸ“ˆ Training Monitoring: Real-time metrics tracking with early stopping and learning rate scheduling
  • πŸ” Easy Inference: Simple API for single image and batch predictions
  • πŸ“‰ Visualization Tools: Automatic generation of training curves and prediction visualizations

πŸš€ Installation

Prerequisites

  • Python 3.7 or higher
  • TensorFlow 2.10 or higher
  • CUDA (optional, for GPU acceleration)

Setup

  1. Clone the repository:
git clone https://github.com/yourusername/cloud-classification.git
cd cloud-classification
  1. Install dependencies:
pip install -r requirements.txt
  1. Verify installation:
python test_setup.py

πŸƒ Quick Start

1. Explore the Dataset

python data_loader.py

This will display dataset information and visualize sample images.

2. Train a Model

# Train with ResNet50 (recommended)
python train.py --model resnet50 --epochs 50 --batch_size 32

3. Evaluate the Model

python evaluate.py --model models/resnet50_YYYYMMDD_HHMMSS/best_model.h5 --visualize

4. Make Predictions

python predict.py --model models/resnet50_YYYYMMDD_HHMMSS/best_model.h5 --image path/to/image.jpg

πŸ’» Usage

Training

Basic Training

python train.py --model resnet50 --epochs 50

Advanced Training Options

python train.py \
    --model resnet50 \
    --epochs 50 \
    --batch_size 32 \
    --lr 0.001 \
    --save_dir models

Available Models

  • simple: Simple CNN from scratch
  • resnet50: ResNet50 with transfer learning (recommended)
  • efficientnet: EfficientNetB0 (high accuracy)
  • mobilenet: MobileNetV2 (lightweight, fast)

Training Options

  • --no_aug: Disable data augmentation
  • --unfreeze: Unfreeze base model for fine-tuning
  • --batch_size: Batch size (default: 32)
  • --lr: Learning rate (default: 0.001)

Evaluation

# Basic evaluation
python evaluate.py --model models/resnet50_YYYYMMDD_HHMMSS/best_model.h5

# With visualizations
python evaluate.py --model models/resnet50_YYYYMMDD_HHMMSS/best_model.h5 --visualize

Prediction

# Single image
python predict.py --model models/resnet50_YYYYMMDD_HHMMSS/best_model.h5 --image image.jpg

# Batch prediction
python predict.py --model models/resnet50_YYYYMMDD_HHMMSS/best_model.h5 --dir images/

# Top-K predictions
python predict.py --model models/resnet50_YYYYMMDD_HHMMSS/best_model.h5 --image image.jpg --top_k 5

Data Visualization

# Analyze dataset
python visualize_data.py --all

# Specific analyses
python visualize_data.py --stats    # Dataset statistics
python visualize_data.py --samples  # Visualize samples
python visualize_data.py --sizes    # Image size analysis

πŸ“ Project Structure

cloud-classification/
β”œβ”€β”€ clouds_train/              # Training dataset
β”‚   β”œβ”€β”€ cirriform clouds/
β”‚   β”œβ”€β”€ clear sky/
β”‚   β”œβ”€β”€ cumulonimbus clouds/
β”‚   β”œβ”€β”€ cumulus clouds/
β”‚   β”œβ”€β”€ high cumuliform clouds/
β”‚   β”œβ”€β”€ stratiform clouds/
β”‚   └── stratocumulus clouds/
β”œβ”€β”€ clouds_test/               # Test dataset
β”‚   └── [same structure as train]
β”œβ”€β”€ models/                    # Trained models (generated)
β”‚   └── resnet50_YYYYMMDD_HHMMSS/
β”‚       β”œβ”€β”€ best_model.h5
β”‚       β”œβ”€β”€ final_model.h5
β”‚       β”œβ”€β”€ class_mapping.json
β”‚       β”œβ”€β”€ training_log.csv
β”‚       └── training_curves.png
β”œβ”€β”€ evaluation_results/       # Evaluation outputs (generated)
β”œβ”€β”€ config.py                 # Configuration file
β”œβ”€β”€ data_loader.py             # Data loading and preprocessing
β”œβ”€β”€ model.py                   # Model architectures
β”œβ”€β”€ train.py                   # Training script
β”œβ”€β”€ evaluate.py                # Evaluation script
β”œβ”€β”€ predict.py                 # Prediction script
β”œβ”€β”€ visualize_data.py          # Data visualization tools
β”œβ”€β”€ example_usage.py           # Usage examples
β”œβ”€β”€ quick_start.py             # Quick start guide
β”œβ”€β”€ test_setup.py              # Setup verification
β”œβ”€β”€ requirements.txt           # Dependencies
└── README.md                  # This file

πŸ—οΈ Model Architectures

1. Simple CNN

A custom CNN architecture built from scratch with:

  • 4 convolutional blocks
  • Batch normalization and dropout
  • Global average pooling
  • Dense layers for classification

2. ResNet50 (Recommended)

Transfer learning with ImageNet pretrained ResNet50:

  • Freeze base model option
  • Fine-tuning support
  • High accuracy

3. EfficientNetB0

EfficientNet architecture optimized for accuracy and efficiency:

  • Compound scaling method
  • State-of-the-art performance

4. MobileNetV2

Lightweight model suitable for mobile and edge devices:

  • Depthwise separable convolutions
  • Fast inference time

πŸ“Š Results

After training, you'll get:

Model Files

  • best_model.h5: Best model based on validation accuracy
  • final_model.h5: Final model after all epochs
  • class_mapping.json: Class to index mapping
  • training_log.csv: Training history
  • training_curves.png: Visualization of training metrics

Evaluation Outputs

  • confusion_matrix.png: Confusion matrix visualization
  • class_metrics.png: Per-class precision, recall, F1-score
  • prediction_samples.png: Sample predictions with images
  • evaluation_report.txt: Detailed classification report

πŸ”§ Configuration

Edit config.py to customize:

# Image settings
IMG_SIZE = (224, 224)
BATCH_SIZE = 32
EPOCHS = 50
LEARNING_RATE = 0.001

# Model settings
MODEL_NAME = 'resnet50'
PRETRAINED = True
FREEZE_BASE = True

# Data augmentation
USE_AUGMENTATION = True
AUGMENTATION_CONFIG = {
    'rotation_range': 20,
    'width_shift_range': 0.1,
    'height_shift_range': 0.1,
    'shear_range': 0.1,
    'zoom_range': 0.1,
    'horizontal_flip': True,
    'brightness_range': [0.8, 1.2]
}

πŸ“ˆ Tips for Better Results

  1. Use Data Augmentation: Always enable augmentation to increase data diversity
  2. Transfer Learning: Use pretrained models (ResNet50, EfficientNet) instead of training from scratch
  3. Fine-tuning: After training with frozen base, unfreeze and fine-tune with lower learning rate
  4. Hyperparameter Tuning: Experiment with different learning rates and batch sizes
  5. Ensemble Methods: Combine multiple models for better accuracy

πŸ› Troubleshooting

GPU Not Detected

import tensorflow as tf
print(tf.config.list_physical_devices('GPU'))

Out of Memory

  • Reduce batch_size (e.g., --batch_size 16)
  • Use a lighter model (MobileNet)
  • Reduce image size in config.py

Training Too Slow

  • Use GPU acceleration
  • Increase batch_size if you have enough RAM
  • Use data generators (already implemented)

Import Errors

pip install -r requirements.txt

πŸ“š Examples

See example_usage.py for comprehensive usage examples:

python example_usage.py

This interactive script guides you through:

  1. Data exploration
  2. Data loading
  3. Model creation
  4. Training
  5. Evaluation
  6. Prediction

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • TensorFlow/Keras: Deep learning framework
  • ImageNet: Pretrained model weights
  • Dataset: Cloud images classification dataset

πŸ‘€ Author

Thipv0302

πŸ“§ Contact

For questions or suggestions, please open an issue on GitHub.


Made with ❀️ for cloud classification

⭐ If you find this project useful, please consider giving it a star!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages