The World is changing every day and monitoring that change on ground can be a tedious and labor intensive task. so, is there a way to automate it?
This notebook will walk you through how deep learning can be used to perform change detection using satellite images.
One of the popular models available in the
arcgis.learn module of ArcGIS API for Python,
ChangeDetector is used to identify areas of persistent change between two different time periods using remotely sensed images. It can help you identify where new buildings have come up for instance. This model is based upon the latest research in deep learning and works well with objects of various sizes.
ChangeDetector model workflow consists of three parts:
- Preparing the training data,
- training a model
- using the trained model for inferencing.
Let’s first prepare the training data.
In the cells below, we have provided the input rasters and input mask polygons needed to export training data.
from arcgis.gis import GIS gis = GIS('home')
input_data = gis.content.get('3ebf8ca5f6c245d69e2e0f4358986ed3') input_data
mask_polygons = gis.content.get('6ee0b48611c44b31b499f6cbe202686f') mask_polygons
ChangeDetector model requires data in this folder format : images_after, images_before and labels folder. The label indicates where there are changes in the before and after images.
These images are too large to process in the GPU memory for training the model, so we need to create small image chips or tiles. Training data can be exported by using the
Export Training Data For Deep Learning tool available in ArcGIS Pro as well as ArcGIS Image Server.
- Input Raster: 2014rasters
- Tile Size X & Tile Size Y: 256
- Stride X & Stride Y: 64
- Meta Data Format: 'Export Tiles'
- Environments: 0.3
As shown below, the above tool needs to be run thrice each for image before, image after and the change labels in order to create training data.
This step would be done using jupyter notebook and documentation is available here to install and setup environment.
import os from pathlib import Path from arcgis.learn import prepare_data, ChangeDetector
We have already exported the data which can be directly downloaded using the steps below:
training_data = gis.content.get('d284e2083b254f6b8508f9cf41f53713') training_data
filepath = training_data.download(file_name=training_data.name)
import zipfile with zipfile.ZipFile(filepath, 'r') as zip_ref: zip_ref.extractall(Path(filepath).parent)
data_path = Path(os.path.join(os.path.splitext(filepath)))
prepare_data function takes path to training data and creates a fast.ai databunch with specified transformation, batch size, split percentage, etc.
data = prepare_data(data_path, chip_size=256, dataset_type='ChangeDetection', batch_size=4 )
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.