Skip To Content ArcGIS for Developers Sign In Dashboard

ArcGIS API for Python

Download the samples Try it live

Detecting Swimming Pools using Satellite Imagery and Deep Learning

  • 🔬 Data Science
  • 🥠 Deep Learning and Object Detection

Prerequisites

  • Please refer to the prerequisites section in our guide for more information. This sample demonstrates how to do export training data and model inference using ArcGIS Image Server. Alternatively, they can be done using ArcGIS Pro as well.
  • If you have already exported training samples using ArcGIS Pro, you can jump straight to the training section. The saved model can also be imported into ArcGIS Pro directly.

Introduction and objective

Deep Learning has achieved great success with state of the art results, but taking it to the field and solving real-world problems is still a challenge. Integration of the latest research in AI with ArcGIS opens up a world of opportunities. This notebook demonstrates an end-to-end deep learning workflow in using ArcGIS API for Python. The workflow consists of three major steps: (1) extracting training data, (2) train a deep learning object detection model, (3) deploy the model for inference and create maps. To better illustrate this process, we choose detecting swmming pools in Redlands, CA using remote sensing imagery.

Part 1 - export training data for deep learning

Import ArcGIS API for Python and get connected to your GIS

In [1]:
import arcgis
import sys
from arcgis import GIS, learn
from arcgis.raster import analytics
from arcgis.raster.functions import extract_band, apply, clip
from arcgis.raster.analytics import list_datastore_content
from arcgis.learn import SingleShotDetector, prepare_data, Model, list_models, detect_objects 
arcgis.env.verbose = True
from arcgis.geocoding import geocode
In [2]:
gis = GIS(url='https://pythonapi.playground.esri.com/portal', username="arcgis_python", password="amazing_arcgis_123")

Prepare data that will be used for training data export

To export training data, we need a labeled feature class that contains the bounding box for each object, and a raster layer that contains all the pixels and band information. In this swimming pool detection case, we have created feature class by hand labelling the bounding box of each swimming pool in Redlands using ArcGIS Pro and USA NAIP Imagery: Color Infrared as raster data.

In [3]:
pool_bb = gis.content.search("SwimmingPoolLabels", item_type='Feature Layer Collection')[0]
pool_bb
Out[3]:
SwimmingPoolLabels
SwimmingPoolLabelsFeature Layer Collection by arcgis_python
Last Modified: March 23, 2020
0 comments, 4 views
In [4]:
pool_bb_layer = pool_bb.layers[0]
pool_bb_layer.url
Out[4]:
'https://pythonapi.playground.esri.com/server/rest/services/Hosted/SwimmingPoolLabels/FeatureServer/0'
In [5]:
m = gis.map("Prospect Park, Redlands, CA")
m

In [6]:
m.basemap = 'gray'

Now let's retrieve the NAIP image layer.

In [7]:
naip_item = gis.content.search("naip_ml", item_type="Imagery Layer", outside_org=True)[0]
naip_item
Out[7]:
naip_ml
naip_mlImagery Layer by arcgis_python
Last Modified: April 14, 2020
0 comments, 0 views
In [8]:
naiplayer = naip_item.layers[0]
naiplayer
Out[8]: