Introduction

In some previous stories (herehere and here) we’ve used PyTorch and Fast.ai library to segment clouds in satellite images, using as reference a public dataset (Kaggle’s 38-Cloud: Cloud Segmentation in Satellite Images). However, there are cases when we need to prepare our own dataset from the beginning, and that can be time-consuming without the proper tools.

As it is not my objective here to explain GEE in depth, I will cover just the basics needed to accomplish our final goal, that is to obtain training patches ready to be consumed by any deep learning framework. The workflow I will present here, was done for Sentinel-2 images, but can be easily modified for any other imagery available in the Google Earth Engine platform.

These are the steps:

  • Select an image from a GEE image collection
  • Perform a supervised image classification within GEE
  • Export patches as TensorFlow records (TFRecords). Don’t worry if you don’t use TF (I don’t use it either), because we will convert it to NumPy afterwards.
  • Open patches in python, and parse them as as NumPy arrays

Selecting an Image in Google Earth Engine

The first thing we need is a free account to the GEE platform, that can be easily obtained in https://signup.earthengine.google.com/. After that, we will go to the code editor (https://code.earthengine.google.com/), and create a new empty script (**NEW **red button on the left). Within the empty script, copy and paste the following code and hit Run. That would zoom you directly to the Orós reservoir in the northeast of Brazil (Figure 1).

Image for post

Figure 1 — GEE code editor with a point created in the middle of the Orós reservoir, in Brazil.

To work on a different area, you can adjust the coordinates. A better way (that we will need in the next step, is to create a Point Geometry directly through the interface (**Insert Marker **button) and center the map on the newly created geometry.

The next step is to select an specific image for our region of interest. To do this we will open an image collection with **ee.ImageCollection**(S2_SR stands for Sentinel-2, Surface Reflectance — Level 2A products) and filter the images containing the point of interest and that lay within a specific period. We will consider a one-month period and display all the images to inspect them visually (Figure-2). The images will be available in the Layers tool. For this specific search, considering that my objective is to identify water surfaces, the last image (indexed as 3) will be the one used for the next step.

#water-detection #google-earth-engine #deep-learning #remote-sensing #deep learning

Creating training patches for Deep Learning Image Segmentation
7.25 GEEK