ArcGIS Developers
Dashboard

ArcGIS API for Python

multi-class change detection using image segmentation deep learning models

  • 🔬 Data Science
  • 🥠 Deep Learning and image segmentation

Introduction

Change detection is a process used in global remote sensing to find changes in landcover over a period of time, either by natural or man-made activities, over large areas. This process is used in many applications, including in environmental monitoring, disaster evaluation, and urban expansion studies. Current change detection methods typically follow one of two approaches, utilizing either post-classification analysis or difference image analysis. These methods are often resource-heavy and time intensive.

In this notebook, we will show a novel way to detect and classify change using semantic segmentation models available in arcgis.learn. For more details about the image segmentation model and its workings, refer to How U-net works? in the guide section.

Necessary imports

In [1]:
import os, zipfile
from pathlib import Path
from os import listdir
from os.path import isfile, join

from arcgis import GIS
from arcgis.learn import prepare_data, PSPNetClassifier, UnetClassifier, DeepLab

Connect to your GIS

In [4]:
gis = GIS('Home')
ent_gis = GIS('https://pythonapi.playground.esri.com/portal', 'arcgis_python', 'amazing_arcgis_123')

Export training data

For this scenario, we have landsat-7 imagery and a classified change map with class information between two time periods (2001-2016) collected over Egypt, with a spatial resolution of 30 m. We will export this data in the “Classified Tiles” metadata format available in the Export Training Data For Deep Learning tool. The tool is available in ArcGIS Pro and ArcGIS Image Server.

For the model to identify changes between imagery, we will build composite imagery from two different time periods using the composite tool in ArcGIS Pro. It will be provided as an Input Raster to the model, and the change map will be provided as labels. The change map was produced by providing the change detection wizard available in ArcGIS Pro, with land use and land cover classification maps from two time periods (2011, 2016) or the from and to raster. The 'to class' or the class to which it has changed to, is used as change labels for the model training. The change detection wizard tool was used in order to create a change dataset. If change raster is already avialable it can be used directly to export and train the model.

  • Input Raster: Composite_imagery_2001_2016
  • Input feature class or classified raster: change_map_2001_2016
  • Tile Size X & Tile Size Y: 256
  • Stride X & Stride Y: 128
  • Meta Data Format: 'Classified Tiles' as we are training a segmentation model.
  • Environments: Set optimum Cell Size, Processing Extent.

The rasters used for exporting the training dataset are provided below:

In [5]:
landsat_composite_2001_16 = ent_gis.content.get('dbe2221e4e1240e986586f0eb3a1479b')
landsat_composite_2001_16
Out[5]:
train_area_landsat_composite_2001_16
Landsat composite of year 2001 and 2016Imagery Layer by api_data_owner
Last Modified: April 02, 2021
0 comments, 0 views
In [6]:
landsat_changemap_2001_16 = ent_gis.content.get('8eef999714d64e9f9494030b9c5f76c2')
landsat_changemap_2001_16
Out[6]:
train_area_changemap_tif
Landsat change map for training change detection model from 2001 to 2016Imagery Layer by api_data_owner
Last Modified: April 02, 2021
0 comments, 1 views
Export Training Data for Deep Learning tool

Prepare the data

Alternatively, we have also provided a subset of training data containing a few samples with the rasters used for exporting the training dataset. You may use the data directly to carry out the experiments.

In [7]:
training_data = gis.content.get('3aedfa7e790541a79730eb1db47ed419')
training_data
Out[7]:
multi_change_detection_dataset
Mutli-class change detection datasetImage Collection by api_data_owner
Last Modified: April 02, 2021
0 comments, 10 views
In [8]:
filepath = training_data.download(file_name=training_data.name)
In [5]:
#Extract the data from the zipped image collection

with zipfile.ZipFile(filepath, 'r') as zip_ref:
    zip_ref.extractall(Path(filepath).parent)
In [6]:
data=prepare_data(path=Path(filepath).parent, batch_size=2, class_mapping={1:'to forest',2:'to savannas',3:'to grasslands',4:'to wetlands',5:'to croplands',6:'to urban',7:'to tundra',8:'to barren',9:'to water',10:'to open shrublands',11:'No change'})

Displayed below are the various change class values with names with which pixels of the change raster are assigned

In [12]:
data.class_mapping
Out[12]:
{1: 'to forest',
 2: 'to savannas',
 3: 'to grasslands',
 4: 'to wetlands',
 5: 'to croplands',
 6: 'to urban',
 7: 'to tundra',
 8: 'to barren',
 9: 'to water',
 10: 'to open shrublands',
 11: 'No change'}

Visualize a few samples from your training data

To get a better sense of the training data, we will use the show_batch() method in arcgis.learn. This method randomly picks a few training chips, overlayed by their respective labels, and visualizes them.

  • alpha: Opacity of overlayed labels over the training chips
In [9]:
data.show_batch(alpha=0.5)