Intro to deep learning to track šŸŒ“deforestation in supply chains

Google Cloud + Google Earth Engine

9min video https://youtu.be/xUTbnsmSDTk airs tomorrow Oct 27 @9am PST

Introduction

In my experience, I have observed that itā€™s common in machine learning to surrender to the process of experimenting with many different algorithms in a trial and error fashion, until you get the desired result. My peers and I at Google have a šŸŒ People and Planet AI YouTube series where we talk about how to train and host a model for environmental purposes using Google Cloud and Google Earth Engine. Our focus is inspiring people to use deep learning, and if we could rename the series, we would call it AI for Minimalists šŸ˜‰ since we would recommend artificial neural networks for most of our use cases. And so in this episode we give an overview of how you can use deep learning for tracking deforestation in supply chains and what deep learning is. I also included a summary of the architecture and products you can use in this blog that I presented at the 2022 Geo For Good Summit. For those of you interested in diving even deeper into code, please visit our end-to-end sample (click ā€œopen in colabā€ at the bottom of the screen to view this tutorial in a notebook format).

Whatā€™s included in this article

  • What is Deep Learning?
  • Measuring deforestation in extractive supply chains with ML
  • When to build a custom model outside of Earth Engine?
  • How to build a model with Google Cloud & Earth Engine?
  • Try it out!

What is Deep Learning?

Out of the many ML algorithms out there, Iā€™m happy to share that deep learning or artificial neural networks is a technique that can be used for almost any supervised learning job.

List of 10 common algorithms. Artificial Neural Networks is the one we are focusing on.

In supervised learning, you tell a computer the right answers to look for, through examples. Deep learning is very flexible, and is a great go-to algorithm. Especially for images, audio, or video files which are types of multidimensional data. This is because each of these data types have one or more dimensions with specific values for each point.

3 common types of multidimensional data deep learning is great with. Images are RGB values across 2D space. Audio is amplitude across time. Video is RGB values across space & time.

And training a model to classify tree species using satellite images is kind of like an image segmentation problem, where every pixel in the image is classified.

Comparison of 3 RGB channels from traditional images vs 13 bands from satellite images

ā€œDeep learning approaches problems differentlyā€

Thereā€™s no writing a function with explicit & sequential steps that reviews every single pixel one by one for every image, as traditional software development does. Letā€™s say you wish to build a model that classifies tree species. You donā€™t spend time coding all the instructions, but instead give a computer examples of images with tree species labels, and let it learn from these examples. And when you want to add more species, itā€™s as simple as adding new images of that species to retrain the model.

6 images of different tree species

Measuring deforestation in extractive supply chains with ML

So letā€™s say we would like to measure deforestation using deep learning; to get started with building a model we first need a dataset that includes satellite images with an even amount of labels marking where there are trees and where there arenā€™t. Next, we choose a goal, here are a few common ones. In our case, we simply want to know if there are trees or not for every pixel, and so this would be a binary semantic segmentation problem.

4 common goals are regression, binary classification, multi-class classification, and semantic segmentation/classification.

And based on this goal, we expect the outputs to be the percentage of trees for every pixel; as a number between 0 and 1. Zero represents no trees, and one represents a high confidence there are trees.

Semantic Segmentation represented by a range between zero and one. Zero means there are no trees and One means there is high confidence there are trees.

But how do we go from input images into probabilities of trees? Well think about it this wayā€¦there are many ways to approach this problem, here are 3 common ways of doing so. My peers and I prefer using Fully convolutional networks when building a map with ML predictions.

View of three kinds of neural networks called DNN, CNN, and FCN. FCN is our preferred option.

And since a model is a collection of interconnected layers, we must come up with an arrangement of layers that transforms our data inputs based on our desired outputs. Each layer by the way has something called an activation function, which performs the transformations of each layer before it passes them to the next layer.

View of 3 layers for a fully convolutional network model as a good starting point. We use Activation function ReLU in the first 2 layers and Sigmoid in the third layer.

FYI Below is a handy dandy table, with our recommended activation and loss functions to choose from based on your goal. We hope this saves you time.

Table of with recommended activation and loss functions which can be visited in slide deck mentioned in blog.

We then reach the fourth and last layer. Depending on our goals at the beginning, we also choose an appropriate loss function that helps us score how well the model did during training.

After choosing layers and functions you will split your data into training and validation datasets. Just remember that all of this work is about experimenting repeatedly until you reach desired results. Our 8min episode gives this overview more in detail.

When to build a custom model outside of Earth Engine

So now that we covered what is deep learning, the next step is understanding which tools to use to build our deforestation model. For starters itā€™s important to call out that Google Earth Engine is a wonderful tool that helps organizations of all sizes find insights about changes on the planet, in order to make a climate positive impact. It has built-in machine learning algorithms (classifiers) that let users quickly spin them up, with just a basic machine learning background. This is fantastic place to start when using ML on geospatial data, however there are multiple situations where you will want to opt to build a custom model such as:

  • You want to use a popular ML library such as TensorFlow Keras.
  • You wish to build a state of the art model to build a global and accurate land cover map product such as Googleā€™s Dynamic World.
  • Or because you generally have too much data to process that you canā€™t execute it in just one task in Earth Engine (and are trying to figure out hacky ways to export your data).

Whenever you identify with any of these options, you will want to roll up your sleeves and dive into building a custom model, which does require expertise and of course working with multiple products. But I have good news, using deep learning is a great go-to algorithm.

How to build a model with Google Cloud & Earth Engine?

To get started, you will need an account with Google Earth Engine which is free for non-commercial entities and Google Cloud account which has a free tier if you are just getting started for all users. I have broken up the products you would use by function.

Diagram explaining the products used by their function. Earth Engine & Dataflow for data processing. Keras and Vertex AI for building an ML model. Cloud Storage for storing. Cloud Run for Web Service hosting or model hosting, and vizualization using Colab notebook and Earth Engine.

If you are interested in looking deeper into this overview, visit our slides here starting from slide 53 and read the speaker notes. Our code sample also walks through how to integrate with all of these projects end to end (just scroll down and click ā€œopen in colabā€). But here is a quick visual summary. The main place to start is to identify which are the inputs and which are the outputs.

Architectural diagram showing 6 steps which is identifying which labeled data to use from Earth Engineā€™s catalog, then extracting it using Dataflow, then storing the data in Cloud Storage, then building the model using Vertex AI which runs Keras, then storing the trained model into Cloud Storage and finally hosting the model somewhere to make predictions.

In our latest episodes for our People and Planet AI YouTube series, we walk through how to train a model and then host it in a relatively inexpensive web hosting platform called Cloud Run in episodes of less than 10mins.

Pros and Cons screenshot. Pro is Cloud Run is easy to use, has a generous free tier and can cost between 1 to 99 dollars. Cons is it lives outside of Earth Engine.

There are a few options presented in the slides, however the current best practice is to train a model using Vertex AI. Do note though that Google Earth Engine is currently not integrated with Vertex AI (we are working on this), but it is with the older (ML predecessor) called Cloud AI Platform (which is the recommended ML platform to use moving forward). As such, if you would like to import your model for detecting deforestation back into Earth Engine after training it in Vertex AI for example, you can host the model in Cloud AI Platform and get predictions. Just note that itā€™s a 24 hour paid service and so it can cost upwards of $100 or more a month to host your model to stream predictions. It also currently supports the following model building platforms if you donā€™t wish to use TensorFlow.

Pros and Cons of AI Platform. Pros is it is a convenient Enterprise grade tool thatā€™s connected to Earth Engine. Con is it can cost over 100 for running 24 hours and even more with GPUs

A cheaper alternative but without the convenience AI Platform offers is to manually translate the modelā€™s output, which is NumPy Arrays into Cloud Optimized GeoTIFFs in order to load it back into Earth Engine using Cloud Run. Within this web service you would store the NumPy arrays into a Cloud Storage bucket, then spin up a container image with GDAL, an open source geospatial library in order to convert them into Cloud Optimized GeoTIFF files into Cloud Storage. This way you can view predictions from your browser or Earth Engine.

Screenshot of architecture in 3 sections. First section shows NumPy arrays stored in cloud storage moving to a docker container image with GDAL geospatial library. These files are then output to Cloud Storage again with the file now being in GeoTIFF format.

Try it out

This was a quick overview of what deep learning and what Cloud products you can use to solve meaningful environmental challenges like detecting deforestation in extractive supply chains. If you would like to try it out, check out our code sample here (click ā€œopen in colabā€ at the bottom of the screen to view the tutorial in our notebook format or click this shortcut here).

āœØ Follow us!

Thank you for your passion in using machine learning for šŸŒ environmental resilience. If you wish to follow more of our future content. You can find us on Twitter and YouTube.

--

--

Sustainability and Tech (@open_eco_source Twitter)

Developer Advocate @Google. Vegan. Accessibility to cloud tech and permaculture knowledge 4 all. Decolonize. These are my opinions my friends.