ArcGIS Developers

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 [1]:
from arcgis.gis import GIS
gis = GIS('home')
portal = GIS('')

The items below are high resolution satellite imagery and a feature layer of building footprints for Berlin which will be used for exporting training data.

In [2]:
berlin_imagery = portal.content.get('c0bd94a10c4649fcb755ee375ae45f2f')
berlin_imageryImagery Layer by api_data_owner
Last Modified: May 25, 2021
0 comments, 0 views
In [3]:
rcnn_labelled_data = gis.content.get('7d3f633a325f4dcf962c82284098ce9d')
Building FootprintFeature Layer Collection by api_data_owner
Last Modified: January 25, 2021
0 comments, 1,892 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("Berlin_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 [4]:
import os
from pathlib import Path
from arcgis.learn import MaskRCNN, prepare_data
from arcgis.gis import GIS

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

In [5]:
training_data = gis.content.get('637825446a3641c2b602ee854776ed47')
Image Collection by api_data_owner
Last Modified: December 06, 2020
0 comments, 42 views
In [6]:
filepath =
In [7]:
import zipfile
with zipfile.ZipFile(filepath, 'r') as zip_ref:
In [8]:
data_path = Path(os.path.join(os.path.splitext(filepath)[0]))
In [10]:
data = prepare_data(data_path, 

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 [11]: