Land Cover Semantic Segmentation using PyTorch
Terra_Mask is an end-to-end computer vision project for semantic segmentation in land cover classification. It uses deep learning with PyTorch to classify features in high-resolution satellite imagery β such as buildings, woodland, water, and roads.
Built primarily for the LandCover.ai dataset, this project is modular and can be adapted to any semantic segmentation dataset.
This project enables you to:
- β Train segmentation models on land cover images
- β Test and infer with trained models
- β Prompt specific classes for prediction without retraining
Promptable Prediction: After training the model on all classes, you can selectively visualize only specific classes (e.g., just "buildings" and "water") by modifying the test_classes
in the config.
- Patches are created from large aerial images.
- Background-heavy patches are discarded.
- Data is split into train/val/test sets.
- Uses UNet from
segmentation_models_pytorch
- EfficientNet as the encoder backbone
- Decoder upsamples features to produce segmentation masks
- Uses Dice Loss for segmentation accuracy
- Learning rate scheduling for better optimization
- Patches are passed through the model
- Reconstructed masks are filtered by class
- Visualizations are generated and saved
Copy the dataset from LandCover.ai on Kaggle
Organize it as:
data/
βββ train/
β βββ images/ # Training satellite images
β βββ masks/ # Corresponding segmentation masks
βββ test/
βββ images/ # Testing satellite images
βββ masks/ # Corresponding segmentation masks
# Clone this repository
git clone https://github.com/souvikmajumder26/Land-Cover-Semantic-Segmentation-PyTorch.git
cd Land-Cover-Semantic-Segmentation-PyTorch
# Install required packages
pip install -r requirements.txt
cd src
python test.py
cd src
python inference.py
cd src
python train.py
docker build -t segment_project_image .
docker run --name segment_container -d segment_project_image
docker cp segment_container:/segment_project/models ./models
docker cp segment_container:/segment_project/logs ./logs
docker cp segment_container:/segment_project/output ./output
docker stop segment_container
docker rm segment_container
docker rmi segment_project_image
βββ config/
β βββ config.yaml # Configuration file (classes, model params)
βββ data/
β βββ train/
β βββ test/
βββ models/ # Pretrained weights
βββ output/
β βββ predicted_masks/ # .tif mask outputs
β βββ prediction_plots/ # .png visualizations
βββ logs/ # Training and testing logs
βββ src/
β βββ train.py
β βββ test.py
β βββ inference.py
βββ requirements.txt
βββ README.md
- PyTorch 2.0.1
- torchvision 0.15.2
- segmentation_models_pytorch 0.3.3
- EfficientNet (efficientnet-pytorch)
- timm (PyTorch Image Models)
- OpenCV (opencv-python-headless)
- patchify
- scikit-image, scikit-learn
- albumentations
- tifffile, Pillow, NumPy
- PyYAML
- tqdm
- split-folders
- filelock, joblib
- pretrainedmodels
- huggingface-hub
- Dice Loss
- Adam Optimizer
- LR Scheduler (PyTorch)
- Docker
This project is released under the MIT License.