CABNet is a novel deep learning architecture for building extraction from remote sensing imagery. It features adaptive multi-scale convolution, corner-guided enhancement, bidirectional feature pyramid, and dual-stream boundary refinement for accurate building segmentation.
- Content-Adaptive Scale Convolution (CASC): Dynamically predicts optimal receptive field scale based on content
- Corner-Guided Feature Enhancement (CGFE): Leverages building corner detection for enhanced feature representation
- Bidirectional Feature Pyramid (BiFPN): Efficient top-down and bottom-up feature fusion
- Local Window Cross-Attention (LWCA): Linear complexity attention mechanism with relative position encoding
- Dual-Stream Boundary Refinement (DSBR): Independent semantic and boundary modeling with interactive enhancement
Input Image
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Encoder (ResNet-50) β
β βββββββββββ βββββββββββ βββββββββββ βββββββββββ β
β β C1 β β β C2 β β β C3 β β β C4 β β
β β H/4 β β H/8 β β H/16 β β H/32 β β
β βββββββββββ βββββββββββ ββββββ¬βββββ ββββββ¬βββββ β
ββββββββββββββββββββββββββββββββββββββββββΌβββββββββββββββΌββββββββ
β β
ββββββββββββββββββββββββββ
β CASC + CGFE + LWCA β
β (Feature Enhancement) β
ββββββββββββββββββββββββββ
β
ββββββββββββββββββββββββββ
β BiFPN β
β (Bidirectional Fusion) β
ββββββββββββββββββββββββββ
β
ββββββββββββββββββββββββββ
β DSBR β
β (Boundary Refinement) β
ββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββ
β Segmentation β Boundary β
βββββββββββββββββββββββββββββββββ
- Python >= 3.8
- PyTorch >= 2.0
- CUDA >= 11.8 (for GPU support)
git clone https://github.com/yourusername/CABNet.git
cd CABNet
pip install -r requirements.txtimport torch
from models import CABNet
# Create model
model = CABNet(num_classes=2, backbone='resnet50', pretrained=True)
model.eval()
# Inference
image = torch.randn(1, 3, 512, 512)
with torch.no_grad():
outputs = model(image)
segmentation = outputs['seg'].argmax(dim=1)
boundary = outputs['boundary']import torch
from models import CABNet, CABNetLoss
# Create model and loss
model = CABNet(num_classes=2, backbone='resnet50', pretrained=True).cuda()
criterion = CABNetLoss(num_classes=2, lambda_boundary=2.0, lambda_corner=0.5)
optimizer = torch.optim.AdamW(model.parameters(), lr=1e-4, weight_decay=1e-4)
# Training loop
model.train()
for epoch in range(200):
for images, masks, boundaries in train_loader:
images = images.cuda()
targets = {
'seg': masks.cuda(),
'boundary': boundaries.cuda()
}
outputs = model(images)
loss_dict = criterion(outputs, targets)
optimizer.zero_grad()
loss_dict['total'].backward()
torch.nn.utils.clip_grad_norm_(model.parameters(), max_norm=1.0)
optimizer.step()See train.py for a complete training script.
CABNet/
βββ configs/
β βββ default.yaml # Default configuration
βββ datasets/
β βββ building_dataset.py # Dataset implementation
βββ models/
β βββ __init__.py
β βββ cabnet.py # CABNet model
βββ utils/
β βββ __init__.py
β βββ metrics.py # Evaluation metrics
β βββ visualization.py # Visualization tools
βββ docs/
β βββ assets/ # Documentation assets
βββ train.py # Training script
βββ test.py # Testing script
βββ requirements.txt # Dependencies
βββ LICENSE # MIT License
βββ README.md # This file
| Dataset | IoU (%) | F1 (%) | Boundary IoU (%) |
|---|---|---|---|
| WHU Building | - | - | - |
| Inria Aerial | - | - | - |
| Massachusetts Buildings | - | - | - |
Results will be updated after training.
CASC dynamically predicts optimal receptive field scale for each spatial location:
CGFE leverages Harris corner detection to enhance structural features:
The total loss combines multiple components:
Where:
-
$\mathcal{L}_{semantic}$ : Cross-Entropy + LovΓ‘sz-Softmax Loss -
$\mathcal{L}_{boundary}$ : Boundary IoU Loss -
$\mathcal{L}_{corner}$ : Corner Supervision Loss
Key hyperparameters in configs/default.yaml:
| Parameter | Default | Description |
|---|---|---|
num_classes |
2 | Number of segmentation classes |
backbone |
resnet50 | Encoder backbone |
lr |
1e-4 | Learning rate |
weight_decay |
1e-4 | Weight decay |
lambda_boundary |
2.0 | Boundary loss weight |
lambda_corner |
0.5 | Corner loss weight |
window_size |
8 | LWCA window size |
- Learning Rate: Start with 1e-4, use cosine annealing
- Data Augmentation: Random flip, rotation, color jitter
- Mixed Precision: Enable AMP for faster training
- Gradient Clipping: Clip gradients to max_norm=1.0
- Warm-up: Use 5-10 epochs of warm-up
If you find this work useful, please cite:
@article{cabnet2024,
title={CABNet: Content-Adaptive Building Segmentation Network},
author={Your Name},
journal={arXiv preprint arXiv:XXXX.XXXXX},
year={2024}
}This project is licensed under the MIT License - see the LICENSE file for details.
- EfficientDet for BiFPN inspiration
- Swin Transformer for window attention mechanism
- torchvision for ResNet backbone
For questions or collaboration, please open an issue or contact your.email@example.com.
Made with β€οΈ for the remote sensing community
