SpaceNet 2 building detector

Model summary

Instance segmentation of building footprints in 30 cm satellite imagery. The model is Detectron2 Mask R-CNN R50-FPN, initialized from COCO and trained on all four SpaceNet 2 cities at once: Las Vegas, Paris, Shanghai and Khartoum. It returns a mask, a bounding box and a confidence score for every building.

At the score threshold of 0.544 it reaches a macro F1 of 0.7447 across the four cities on the validation split, and 0.8941 in Las Vegas.

Author: Benjamin J. Britton, University of Cincinnati.

Try it: an interactive demo runs in a Docker container (see Interactive demo), with twelve validation tiles and image upload.

Intended use

  • Building footprint extraction from high-resolution overhead RGB imagery
  • Urban mapping, settlement analysis and change-detection pipelines
  • A pretrained starting point for fine-tuning on other cities or sensors
  • Teaching and benchmarking in geospatial computer vision

Training data

SpaceNet 2: Building Detection v2 (Van Etten et al. 2018), CC BY-SA 4.0.

  • WorldView-3 pan-sharpened RGB (PS-RGB), 30 cm, 650 × 650 px tiles, 16-bit.
  • Building footprint polygons for four areas of interest: Las Vegas, Paris, Shanghai and Khartoum.
  • 10,592 tiles, split 80/20 within each city with a fixed split seed: 8,474 for training and 2,118 for validation. The split file is configs/spacenet2_split.json in the code repository.
  • The 2,069 tiles with no buildings stay in the training set as negatives.

Input specification

Three-band 8-bit RGB. SpaceNet PS-RGB tiles are 16-bit; each band is stretched to 8-bit per image, linearly between the 2nd and 98th percentiles of its nonzero pixels (zeros are nodata borders). inference_example.py applies this automatically to 16-bit GeoTIFFs. The model resizes each tile to 800 px on the short side.

8-bit RGB images can be used directly. For low-contrast imagery, the same percentile stretch (--stretch) usually helps. The model is trained on 30 cm imagery, so imagery at roughly 30–50 cm suits it best.

Training procedure

setting value
architecture Mask R-CNN, ResNet-50 FPN, one class
initialization detectron2 model zoo mask_rcnn_R_50_FPN_3x (COCO)
iterations 6,000 (about 11.3 epochs), batch 16
learning rate 0.02, 1,000 warmup iterations, ×0.1 at 4,000 and 5,500
input size short side 640–800 px (training), 800 px (inference)
precision mixed (fp16)
seed 0
hardware one NVIDIA RTX A5000, 1 h 45 min

config.yaml is the complete, self-contained configuration.

Evaluation

All figures are on the 2,118-tile validation split, which the model did not train on.

SpaceNet F1 (IoU ≥ 0.5)

One score threshold, 0.544, applies to every city. It was selected on the training split. The macro score is the mean of the four city scores, as the SpaceNet metric defines it.

city this checkpoint (seed 0) three seeds, mean ± sd
Las Vegas 0.8941 0.8948 ± 0.0007
Paris 0.7762 0.7787 ± 0.0032
Shanghai 0.6828 0.6848 ± 0.0018
Khartoum 0.6257 0.6254 ± 0.0004
macro 0.7447 0.7459 ± 0.0012

Three independent training runs agree to about 0.001 F1 per city, so the released checkpoint is representative.

COCO metrics (this checkpoint)

AP AP50
segmentation 49.44 81.21
bounding box 52.76 82.06

Sources

In the code repository: REPRODUCE.md (per-city F1 at 0.544 for all three seeds, and the commands that produce them) and LAB_NOTEBOOK.md (entries of 2026-08-27 to 2026-08-29). Training run: W&B project benjbritton-geoai/benjbritton_FA26, seed 0.

Limitations

  • Trained and evaluated on WorldView-3 30 cm imagery of four cities. Performance on other sensors, resolutions and regions has not been measured.

How to use

pip install torch torchvision rasterio opencv-python huggingface_hub
pip install 'git+https://github.com/facebookresearch/detectron2.git'
hf download benjbritton/spacenet2-building-detector --local-dir spacenet2-detector
cd spacenet2-detector
python inference_example.py --image your_tile.tif --score 0.544 --overlay detections.png

The script prints each building's score, bounding box and mask area in pixel coordinates, and --overlay writes the image with footprints outlined. Use --device cpu without a GPU.

From Python:

from inference_example import load_tile, build_predictor, predict
predictor = build_predictor("config.yaml", "model_final.pth", device="cuda", score=0.544)
instances = predict(predictor, load_tile("your_tile.tif"))

Interactive demo

A Gradio app with the model, detectron2 and twelve SpaceNet 2 validation tiles (three per city) is published as a Docker image. With Docker installed:

docker run -p 7860:7860 ghcr.io/benjbritton/spacenet2-building-detector:v1.0

Then open http://localhost:7860. Pick a tile or upload an overhead RGB image; the app outlines each detected building and, on the example tiles, shows the SpaceNet footprints and the tile's F1 at IoU ≥ 0.5. It runs on CPU, a few seconds per tile.

The Dockerfile and app source are in the code repository.

Files

file
model_final.pth Detectron2 checkpoint, iteration 6,000, 351 MB
config.yaml Full, self-contained Detectron2 config
inference_example.py Loads a tile, runs the model, prints and draws footprints
examples/ Twelve validation tiles (8-bit, training stretch applied) and their SpaceNet footprints in pixel coordinates, used by the demo

SHA-256 of model_final.pth:

59dad1c07551a25e57709e880158de7b75a2d4f4d5db2e5439bd1cab0ded99a9

License

The model weights are released under CC BY-SA 4.0, the license of the SpaceNet imagery they were trained on, and carry its attribution and ShareAlike terms. inference_example.py is MIT licensed. The COCO initialization weights from the detectron2 model zoo are Apache-2.0.

Citation

This model:

@misc{britton2026spacenet2,
  author       = {Britton, Benjamin J.},
  title        = {SpaceNet 2 building detector: Mask R-CNN R50-FPN for building footprints in 30 cm satellite imagery},
  year         = {2026},
  publisher    = {Hugging Face},
  howpublished = {\url{https://huggingface.co/benjbritton/spacenet2-building-detector}}
}

Training data:

Van Etten, A., Lindenbaum, D., & Bacastow, T. M. (2018). SpaceNet: A Remote Sensing Dataset and Challenge Series. arXiv:1807.01232. https://arxiv.org/abs/1807.01232

The SpaceNet Dataset by SpaceNet Partners is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Links

Downloads last month
18
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Paper for benjbritton/spacenet2-building-detector

Evaluation results

  • SpaceNet F1, macro over cities (IoU 0.5, score 0.544) on SpaceNet 2 validation split (2,118 tiles, four cities)
    self-reported
    0.745
  • SpaceNet F1, Las Vegas on SpaceNet 2 validation split (2,118 tiles, four cities)
    self-reported
    0.894
  • SpaceNet F1, Paris on SpaceNet 2 validation split (2,118 tiles, four cities)
    self-reported
    0.776
  • SpaceNet F1, Shanghai on SpaceNet 2 validation split (2,118 tiles, four cities)
    self-reported
    0.683
  • SpaceNet F1, Khartoum on SpaceNet 2 validation split (2,118 tiles, four cities)
    self-reported
    0.626
  • segm AP on SpaceNet 2 validation split (2,118 tiles, four cities)
    self-reported
    49.440
  • bbox AP on SpaceNet 2 validation split (2,118 tiles, four cities)
    self-reported
    52.760