Downloads · 30 days
138
4% of all-time downloads
Pranilllllll/segformer-satellite-segementation
segformer-satellite-segementation is a image segmentation model from Pranilllllll. Use it for the image segmentation task on the model card, and read the license before you ship it in a product. It is set up for transformers. The card lists the license as mit.
This model is a fine-tuned SegFormer-B0 for semantic segmentation of satellite imagery over Kathmandu Valley, Nepal. It classifies each pixel into one of 7 land-use categories: Background, Residential Area, Road, Rive…
Downloads · 30 days
138
4% of all-time downloads
All-time downloads
3.3K
Public
Parameters
3.7M
14.9 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors14.9 MB · 100%
From the Hugging Face model README
This model is a fine-tuned SegFormer-B0 for semantic segmentation of satellite imagery over Kathmandu Valley, Nepal. It classifies each pixel into one of 7 land-use categories: Background, Residential Area, Road, River, Forest, and Unused Land. The model is intended for urban planning, GIS analysis, and geospatial research applications.
nvidia/mit-b0 (SegFormer-B0 pretrained on ImageNet)Pranilllllll/segformer-satellite-segementationThis model can be used out-of-the-box for satellite image segmentation over Kathmandu Valley or similar urban/semi-urban landscapes. It accepts a 512×512 RGB satellite image and outputs a per-pixel land-use classification mask.
import torch
import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
from transformers import SegformerForSemanticSegmentation, SegformerFeatureExtractor
device = "cuda" if torch.cuda.is_available() else "cpu"
HF_REPO = "Pranilllllll/segformer-satellite-segementation"
model = SegformerForSemanticSegmentation.from_pretrained(HF_REPO).to(device)
processor = SegformerFeatureExtractor.from_pretrained(HF_REPO)
model.eval()
image = Image.open("path_to_your_satellite_image.png").convert("RGB")
inputs = processor(images=image, return_tensors="pt")
pixel_values = inputs["pixel_values"].to(device)
with torch.no_grad():
outputs = model(pixel_values=pixel_values)
logits = outputs.logits # [1, 7, H, W]
pred_mask = torch.argmax(logits, dim=1).squeeze().cpu().numpy()
colors = np.array([
[0, 0, 0], # Background
[128, 0, 0], # Residential Area
[0, 128, 0], # Road
[0, 0, 128], # River
[0, 128, 128], # Forest
[128, 128, 0], # Unused Land
[128, 0, 128], # (reserved)
], dtype=np.uint8)
seg_image = colors[pred_mask]
plt.imsave("prediction.png", seg_image)
print("Inference complete. Prediction saved as prediction.png")
This model can be plugged into larger GIS pipelines for:
Validate predictions on your specific region before using results for critical planning decisions. Cross-checking against GIS datasets (e.g., OpenStreetMap) is recommended.
Install dependencies:
pip install torch transformers Pillow matplotlib
Then use the inference script in the Direct Use section above.
A custom dataset was built from satellite imagery of Kathmandu Valley, Nepal, divided into a grid of tiles.
| Class ID | Class Name | RGB Color |
|---|---|---|
| 0 | Background | (0, 0, 0) |
| 1 | Residential Area | (128, 0, 0) |
| 2 | Road | (0, 128, 0) |
| 3 | River | (0, 0, 128) |
| 4 | Forest | (0, 128, 128) |
| 5 | Unused Land | (128, 128, 0) |
SegformerFeatureExtractorApplied using albumentations:
| Hyperparameter | Value |
|---|---|
| Input size | 512 × 512 |
| Batch size | 16 |
| Optimizer | AdamW |
| Learning rate | 3e-5 |
| Loss function | Weighted Cross-Entropy |
| Epochs | 300 (early stopping, patience=25) |
| Cross-validation | 3-fold |
| Training regime | bf16 mixed precision |
Inverse frequency class weights were computed from the training set and applied to the cross-entropy loss, ensuring rare classes (Road, River) contribute proportionally during training.
Cross-validation results are reported as mean ± standard deviation of mIoU across 3 folds. Training curves (loss, mIoU, gradient norm) are available in the eval_plots/ directory.
The stable gradient norm across training confirms the MiT encoder converged effectively without vanishing gradient issues.
nvidia/mit-b0)@misc{praniil2024kathmandu-segmentation,
author = {praniil},
title = {Kathmandu Valley Satellite Image Segmentation with SegFormer-B0},
year = {2024},
publisher = {GitHub},
howpublished = {\url{https://github.com/praniil/satellite-image-segmentation}},
}
Open an issue at https://github.com/praniil/satellite-image-segmentation/issues