Skip To Content ArcGIS for Developers Sign In Dashboard

ArcGIS API for Python

Download the samples Try it live

Automate Building Footprint Extraction using Deep learning

  • 🔬 Data Science
  • 🥠 Deep Learning and Instance Segmentation

Building footprints are often used for base map preparation, humanitarian aid, disaster management, and transportation planning

There are several ways of generating building footprints. These include manual digitization by using tools to draw outline of each building. However, it is a labor intensive and time consuming process.

This sample shows how ArcGIS API for Python can be used to train a deep learning model to extract building footprints using satellite images. The trained model can be deployed on ArcGIS Pro or ArcGIS Enterprise to extract building footprints.

In this workflow, we will basically have three steps.

  • Export Training Data
  • Train a Model
  • Deploy Model and Extract Footprints

Export training data for deep learning

Training data can be exported using the 'Export Training Data For Deep Learning' tool available in ArcGIS Pro as well as ArcGIS Enterprise. For this example we prepared training data in 'RCNN Masks' format using a 'chip_size' of 400px and 'cell_size' of 30cm in ArcGIS Pro.

In [2]:
from arcgis.gis import GIS
gis = GIS('home')

The item below is a feature layer of building footprints for Berlin.

In [3]:
rcnn_labelled_data = gis.content.search('MaskRCNN_training_data_Berlin', 'feature layer')[0]
rcnn_labelled_data
Out[3]:
MaskRCNN_training_data_Berlin
Building FootprintFeature Layer Collection by api_data_owner
Last Modified: February 21, 2020
0 comments, 0 views

You can use the 'Export Training Data' for Deep Learning tool to export training samples for training the model. For this sample, choose RCNN Masks as the export format.

arcpy.ia.ExportTrainingDataForDeepLearning("World_Imagery", r"D:\data\maskrcnn_training_data_maskrcnn_400px_30cm", "berlin_building_footprints", "TIFF", 400, 400, 0, 0, "ONLY_TILES_WITH_FEATURES", "RCNN_Masks", 0, "classvalue", 0, None, 0, "MAP_SPACE", "PROCESS_AS_MOSAICKED_IMAGE", "NO_BLACKEN", "FIXED_SIZE")

This will create all the necessary files needed for the next step in the specified 'Output Folder'. These files serve as our training data.

Model training

This step would be done using jupyter notebook and documentation is available here to install and setup environment.

Necessary Imports

In [1]:
from arcgis.learn import MaskRCNN, prepare_data

prepare_data function takes path to training data and creates a fastai databunch with specified transformation, batch size, split percentage, etc.

In [2]:
data = prepare_data(r'\data\maskrcnn_data\buildings\', 
                    batch_size=4, 
                    chip_size=400)

Visualize training data

To get a sense of what the training data looks like, use the show_batch() method to randomly pick a few training chips and visualize them. The chips are overlaid with masks representing the building footprints in each image chip.

In [3]:
data.show_batch(rows=4)