Patch-wise Land Cover Classification using Sentinel-2 Satellite and Deep Learning

Behzad Valipour Shokouhi
5 min readAug 15, 2022

--

Growing population, urban sprawl, changes in land cover, and land use result in an increased need for systematic and accurate land cover and land use information. Highly accurate information on land cover and land use is essential for decision-makers, urban planners, mapping of ecosystem services, deforestation analysis, detection of land cover changes, and many others. Satellite imagery is recognized as one of the most important data sources for land cover mapping, monitoring the dynamics of the land cover changes at local, regional, national, and global scales. (Link)

Europe land-cover mapped in 10 m resolution (Link)

For this project, I followed the tutorial from the book titled ‘Deep Learning for
Remote Sensing Images with Open Source Software
’, however, decided to use Registry of Open Data on AWS to download the Sentinel-2 images, and the ground truth dataset is available in the Github repo

Download Sentinel-2 images

As mentioned before, to download the S2 satellite data I used Registry of Open Data on AWS. The following steps are required:

  1. Install AWS command line https://aws.amazon.com/cli/
  2. Go to the related website https://registry.opendata.aws/sentinel-2-l2a-cogs/
  3. Use the following command to have access to the data in the S3 bucket:
aws s3 ls --no-sign-request s3://sentinel-cogs-inventory/

4. The datasets are in Military Grid Reference System (MGRS) Coordinates, therefore, to find the related code for AIO use the following website: https://mappingsupport.com/p2/coordinates-mgrs-gissurfer-maps.html

It is possible to visualize the thumbs in QGIS using the following instruction on YouTube: https://youtu.be/OWlem1MJiwY

The required image for this study is located in the following path:

aws s3 ls --no-sign-request s3://sentinel-cogs/sentinel-s2-l2a-cogs/54/S/UE/2019/5/S2A_54SUE_20190508_0_L2A/

After being sure that it is correct and what you are looking for, you can download the directory of data to the local machine using the following code:

aws s3 cp --no-sign-request s3://sentinel-cogs/sentinel-s2-l2a-cogs/54/S/UE/2019/5/S2A_54SUE_20190508_0_L2A/ --recursive

or you can download the B04, B03, B02, and B08 separately to your machine as follows:

aws s3 cp --no-sign-request s3://sentinel-cogs/sentinel-s2-l2a-cogs/54/S/UE/2019/5/S2A_54SUE_20190508_0_L2A/B04.tif B04.tif

Data Pre-Processing

Normalization Sentinel-2 data

Data normalization is a fundamental pre-processing step. In most machine learning frameworks, parameters are often defaulted to be suited for centered reduced distributions and values within the [1; +1] range. For the current dataset, we normalized all remote sensing images channels with their
maximum value.

Sampling

There are two ground truth images as follows:

  • terrain_truth_epsg32654_A.tif
  • terrain_truth_epsg32654_B.tif

Each includes 6 classes (0: "Water", 1: "Golf course", 2: "Park and grassland", 3: "Buildings", 4: "Forest", 5: "Farm"). The first one was used for training and the second one was for validation and test. At first, it is required to generate random sample points inside each class, for this purpose, I used the sample function in the Pyspatialml package. 500 patches with 16x16 Px size were generated for each class, so in total there were 3000 sample patches that each covered 160x160 m in the ground.

The same approach was conducted for the second ground truth image, however, later on, 10% of the data was used for test and the rest for validation

Data Loader

The data loader design relies on two packages including Rasterio, and GeoPandas. This way, it is possible to extract the data exactly from the image.

The result of the data loader was printed

Design Model

One simple CNN and one FCN was designed as follows:

Simple CNN model
FCN architecture for patch-wise classification
FCN architecture in Pytorch

Training & Validation

After designing the model architecture, I used the Pytorch Lightening framework to train and validation. Augmentation was considered during training to create a variety. Cross Entropy was used as a Loss function and monitoring overall accuracy for early stopping and, the model checkpoint was considered.

Since the number of samples is only 3000, therefore I decided to implement modeling in different Batch sizes to see which one model can learn better. In the end, three versions of the models were trained based on model architecture and Baych size as follows:

  • Simple CNN, Batch size 8
  • FCN, Batch size 8
  • FCN, Batch size 2

Result

The result shows that as the Batch size is smaller it can reach better accuracy in small Epoch numbers. It is because weights are changing regularly so it can get better values. On the other hand, FCN had better results compared to simple CNN which was expected.

Validation accuracy for 3 models (V1: Orange, V2:Blue, V3: Red )
Validation loss for 3 models (V1: Orange, V2:Blue, V3: Red )

The statistical metrics based on test data show 75% overall accuracy, 75%, and 74% weighted average for recall and precision, respectively.

Statistical metrics for the best model

Except for Park and grassland class, the rest of the classes have reasonable accuracy.

Confusion Metrics for the best model

Inference

I implement the inference on the small AOI for visualization purposes.

The result of Inference

Code: https://github.com/behzad89/Patch_wise_Land_Cover_Classification

References

Waśniewski, Adam, Agata Hościło, and Milena Chmielewska. “Can a Hierarchical Classification of Sentinel-2 Data Improve Land Cover Mapping?.” Remote Sensing 14.4 (2022): 989.

https://pytorch.org/

https://www.pytorchlightning.ai

--

--

No responses yet