Skip to content

alicia01101/dl_coding_task

Repository files navigation

EuroSAT Classification Project

This project implements deep learning classification on the EuroSAT RGB and multispectral satellite imagery datasets for the mandatory coding task in "Deep Learning for Master Students" module.

Project Structure

.
├── task1.py              # Data splitting (train/val/test)
├── task2.py              # RGB classification with EfficientNet-B0
├── Final_model.py        # Test set evaluation and reproducibility check
├── task3.py              # Multispectral classification with late fusion
├── run_all.sh            # Script to run all tasks
├── run_task2.sh          # SLURM script for cluster (Tasks 1+2)
├── run_task3.sh          # SLURM script for cluster (Task 3)
├── environment_minimal.yml  # Conda environment specification
└── output/               # All outputs saved here (created automatically)
    ├── splits/           # Train/val/test split files
    ├── plots/            # Training curves
    ├── ranked_images/    # Top-5 and bottom-5 images per class
    ├── best_model_weights.pth     # Best RGB model
    ├── best_model_task3.pth       # Best multispectral model
    ├── test_logits.pt    # Saved logits for reproducibility
    └── mean_std_cache.pt # Dataset statistics cache

Quick Start

1. Configure Paths

Edit run_all.sh and set the project path at the top of the file:

export PROJECT_ROOT="/absolute/path/to/this/project"

Note: Datasets will be automatically downloaded to $HOME/datasets/ if not already present. You can change the DATASET_BASE variable in run_all.sh if you want them elsewhere.

2. Run All Tasks

bash run_all.sh

This single command will:

  • Create and activate the conda environment (dl_task_env)
  • Run Task 1 (data splitting)
  • Run Task 2 (RGB classification)
  • Run Final_model.py (test evaluation)
  • Run Task 3 (multispectral classification, if dataset path is set)

All outputs will be saved to output/ directory.

Individual Tasks

Task 1: Data Splitting

Creates reproducible train/val/test splits (2500/1000/2000 images total).

export PROJECT_ROOT="/path/to/project"
export DATASET_ROOT="/path/to/EuroSAT_RGB"
python task1.py

Output: output/splits/train.txt, output/splits/val.txt, output/splits/test.txt

Task 2: RGB Classification

Trains EfficientNet-B0 with different learning rates and augmentation settings.

python task2.py

Output:

  • output/best_model_weights.pth - Best model weights
  • output/plots/results.png - Training curves (accuracy & TPR)
  • output/mean_std_cache.pt - Dataset statistics

Evaluation on Test Set

Evaluates the best model and generates visualizations.

python Final_model.py

Output:

  • output/test_logits.pt - Logits for reproducibility check
  • output/ranked_images/class_*_top5_bottom5.png - Top/bottom scoring images

Reproducibility check: To compare newly computed logits with saved ones, edit Final_model.py line 220:

# Change from:
evaluate(..., save_logits=True, compare_logits=False)
# To:
evaluate(..., save_logits=False, compare_logits=True)

Task 3: Multispectral Classification

Late-fusion classification using 6 bands from EuroSAT_MS dataset.

export DATASET_ROOT="/path/to/EuroSAT_MS"
python task3.py

Output: output/best_model_task3.pth

Technical Details

Task 1

  • Splitting: Per-class stratified splitting using sklearn.train_test_split
  • Reproducibility: Fixed random seed (3745356)
  • Verification: Checks that splits are disjoint

Task 2

  • Model: EfficientNet-B0 pretrained on ImageNet
  • Augmentations tested: None, ColorJitter, GaussianBlur
  • Learning rates tested: 0.01, 0.001
  • Optimizer: SGD with momentum (0.9)
  • Epochs: 10
  • Metrics: Accuracy, average TPR per class

Task 3

  • Model: EfficientNet-B0 with late fusion
  • Bands used: B02, B03, B04, B08, B11, B12 (indices 1,2,3,7,10,11)
  • Architecture:
    • Same feature extractor processes two groups of 3 bands (shared weights)
    • Features concatenated after global average pooling
    • Single linear layer for classification
  • Normalization: [0, 65535] → [0, 1], then per-band standardization

Running on Cluster (SLURM)

For execution on the Uni cluster, use the provided SLURM scripts:

# RGB classification (Tasks 1 + 2 + evaluation)
sbatch run_task2.sh

# Multispectral classification (Task 3)
sbatch run_task3.sh

Edit the scripts to set:

  • #SBATCH parameters (partition, time, resources)
  • PROJECT_ROOT and DATASET_ROOT paths

Requirements

  • Python 3.11
  • PyTorch + torchvision
  • scikit-learn, scikit-image
  • matplotlib, numpy, pandas, pillow

All dependencies are listed in environment_minimal.yml.

Reproducibility

To verify reproducibility:

  1. Run Final_model.py with save_logits=True → saves logits
  2. Run again with compare_logits=True → compares new vs. saved logits

About

Mandatory Coding Task for Deep Learning Lecture

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors