Semantic segmentation of satellite imagery using U-Net. Assigns labels to each pixel for land cover (buildings, vegetation, roads, water). Ideal for analyzing satellite data.
This project performs semantic segmentation on satellite imagery to classify each pixel into distinct land cover categories such as buildings, roads, vegetation, water, and unlabeled areas. It uses the U-Net architecture for precise pixel-wise classification. The dataset is pre-processed into smaller patches to train the model effectively on large images, and the final model is evaluated using custom metrics.
-
Dataset Preprocessing:
- Images and masks are processed into fixed-size patches using the
patchify
library. - Pixel values are scaled using MinMaxScaler for better model performance.
- Labels are converted from RGB format to class indices using a mapping of land cover types.
- Images and masks are processed into fixed-size patches using the
-
U-Net Architecture:
- A custom U-Net implementation is used, which features:
- Contraction path with convolutional and max-pooling layers.
- Expansive path with transposed convolutions and skip connections.
- Softmax activation for multi-class segmentation.
- A custom U-Net implementation is used, which features:
-
Custom Loss Functions:
- Dice Loss: Encourages overlap between predicted and true segmentations.
- Focal Loss: Mitigates class imbalance by focusing on harder-to-classify pixels.
- Combined as
Total Loss
.
-
Performance Metrics:
- Jaccard Coefficient (IoU): Measures overlap accuracy.
- Accuracy: Pixel-wise correctness of predictions.
-
Visualization:
- Random samples of images and masks can be visualized to confirm data integrity.
-
Data Preparation:
- Satellite images are high-resolution; patching ensures memory efficiency.
- RGB masks are converted to integer class labels for categorical segmentation.
-
Model Design:
- U-Net was selected for its proven success in biomedical and geospatial segmentation tasks.
- Skip connections in U-Net help preserve spatial information.
-
Custom Loss Functions:
- Dice loss handles imbalanced datasets effectively.
- Focal loss ensures the model focuses on difficult pixels.
-
Class Weights:
- Weights are applied to address the imbalance in class distribution.
-
Evaluation:
- IoU (Jaccard Coefficient) was chosen as a primary metric as it directly measures segmentation quality.
-
Setup Environment:
- Install the required libraries:
pip install tensorflow numpy matplotlib scikit-learn patchify segmentation-models-pytorch
- Install the required libraries:
-
Prepare Dataset:
- Place the dataset in the directory structure:
root_directory/ ├── images/ └── masks/
- Place the dataset in the directory structure:
-
Run Training:
- Execute the
main.py
file to train the U-Net model:python main.py
- Execute the
-
Model Summary:
- The U-Net model architecture is displayed using Keras's
model.summary()
.
- The U-Net model architecture is displayed using Keras's
- The trained model can accurately predict segmentation masks for satellite imagery.
- Performance metrics such as IoU and accuracy are logged during training.
main.py
: Contains the full implementation, including data preparation, model creation, training, and evaluation.simple_multi_unet_model.py
(Optional): Provides additional U-Net functionality if required.
- TensorFlow 2.x
- NumPy
- OpenCV
- Patchify
- Scikit-learn
- Matplotlib
- Segmentation Models (PyTorch)
- Ensure sufficient system memory and GPU support for faster training.
- Adjust the
patch_size
andbatch_size
to fit your hardware capabilities. - Consider fine-tuning the model for specific datasets or use cases.
- Integrate data augmentation for improved generalization.
- Experiment with advanced architectures like DeepLabv3+ or transformers for segmentation.
- Deploy the trained model using frameworks like TensorFlow Serving.
- The U-Net architecture was inspired by the original U-Net paper for biomedical segmentation.
- Thanks to the open-source libraries that make this project possible.