multi-class change detection using image segmentation deep learning models

  • 🔬 Data Science
  • 🥠 Deep Learning and image segmentation


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

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

gis = GIS(profile='your_online_profile')
ent_gis = GIS(profile='your_enterprise_profile')

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:

landsat_composite_2001_16 = ent_gis.content.get('dbe2221e4e1240e986586f0eb3a1479b')
Landsat composite of year 2001 and 2016Imagery Layer by api_data_owner
Last Modified: April 02, 2021
0 comments, 0 views
landsat_changemap_2001_16 = ent_gis.content.get('8eef999714d64e9f9494030b9c5f76c2')
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.

training_data = gis.content.get('3aedfa7e790541a79730eb1db47ed419')
Mutli-class change detection datasetImage Collection by api_data_owner
Last Modified: April 02, 2021
0 comments, 10 views
filepath =
#Extract the data from the zipped image collection
with zipfile.ZipFile(filepath, 'r') as zip_ref:
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

{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
<Figure size 1080x1080 with 9 Axes>

Train change detection model

Load UNet model architecture

model = UnetClassifier(data)


#model = PSPNetClassifier(data)


#model = DeepLab(data)

Tune for optimal learning rate

lr = model.lr_find()
<Figure size 432x288 with 1 Axes>

Fit the model

To train the model, we use the fit() method. To start, we will train our model for 10 epochs. The number of epochs defines how many times a model will be exposed to the entire training set.

  • epochs: Number of cycles of training on the data.
  • lr: Learning rate to be used for training the model., lr)

Here, with 10 epochs, we see that both the training and validation losses have decreased significantly, indicating that the model is learning to detect changes.

Visualize results

It is a good practice to visualize the results obtained from the model with the actual ground truth data. The show_results function picks random samples, and visualizes the ground truth and model predictions side by side. This enables us to preview the results of the model within the notebook.

<Figure size 720x1800 with 10 Axes>

Save the model

We will save the model that we trained as a 'Deep Learning Package' ('.dlpk' format). A Deep Learning package is the standard format used to deploy deep learning models on the ArcGIS platform.

We will use the save() method to save the trained model. By default, it will be saved to a sub-folder inside the training data folder with the name "models".'unet_change_model_e10')

Compute model metrics


Model inferencing

Generate a change raster utilizing the Classify Pixels Using Deep Learning tool

After training the change detection model and saving the weights for detecting changes, we can use the Classify Pixels Using Deep Learning tool, available in both ArcGIS Pro and ArcGIS Enterprise, for inferencing at scale. The test raster is a composite of 2001 and 2016 rasters, for another geographically identical location.

test_data = ent_gis.content.get('8e0ca6e7cefb45289eccc0e7ae2c9bfd')
Test raster for model inferencingImagery Layer by api_data_owner
Last Modified: April 05, 2021
0 comments, 0 views
Classify Pixels Using Deep Learning tool

with arcpy.EnvManager(cellSize=0.0002694460214, processorType='GPU', gpuId = '0'):

`out_classified_raster = arcpy.ia.ClassifyPixelsUsingDeepLearning("test_area_change_landsat.tif", r"C:\Esri\unet_multiclass_change\models\model.emd", "padding 56;batch_size 4;predict_background True;tile_size 224")`


Visualize change map

The image below displays the final test areas used for model predictions for 2011 and 2016, as well as the final predicted areas of change from 2011 to 2016.

(Left) 2011, (Mid) 2016, and (Right) predicted change from 2011 to 2016


In this notebook, we demonstrated how to use image segmentation models, i.e. U-Net, DeepLab, PSPNet, available in arcgis.learn, to detect multi-class changes between imagery of two time-periods.


[1] Olaf Ronneberger, Philipp Fischer, Thomas Brox: U-Net: Convolutional Networks for Biomedical Image Segmentation, 2015;arXiv:1505.04597

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.