This page has example workflows to demonstrate uses of TensorFlow with Earth Engine. See the TensorFlow page for more details. These examples are written using the Earth Engine Python API and TensorFlow running in Colab Notebooks.
Multi-class prediction with a DNN
A "deep" neural network (DNN) is simply an artificial neural network (ANN) with one or more hidden layers. This example demonstrates a very simple DNN with a single hidden layer. The DNN takes spectral vectors as inputs (i.e. one pixel at a time) and outputs a single class label and class probabilities per pixel. The Colab notebook below demonstrates creating the DNN, training it with data from Earth Engine, making predictions on exported imagery and importing the predictions to Earth Engine.
Hostable DNN for prediction in Earth Engine
To get predictions from your trained model directly in Earth Engine (e.g. in the
Code Editor), you need to host the model
on Google AI Platform. This guide
demonstrates how to save a trained model in
format, prepare the model for hosting with the
earthengine model prepare
command, and get predictions in Earth Engine interactively with
Logistic regression the TensorFlow way
Classical machine learning methods such as logistic regression are natural to implement in TensorFlow. This notebook demonstrates a logistic regression based deforestation detector from before and after annual composites. Note that this very simplistic model is just for demonstration purposes; add a few hidden layers for higher accuracy.
Regression with an FCNN
A "convolutional" neural network (CNN) contains one or more convolutional layers, in which inputs are neighborhoods of pixels, resulting in a network that is not fully-connected, but is suited to identifying spatial patterns. A fully convolutional neural network (FCNN) does not contain a fully-connected layer as output. This means that it does not learn a global output (i.e. a single output per image), but rather localized outputs (i.e. per-pixel).
This Colab notebook demonstrates the use of the UNET model, an FCNN developed for medical image segmentation, for predicting a continuous [0,1] output in each pixel from 256x256 neighborhoods of pixels. Specifically, this example shows how to export patches of data to train the network and how to overtile image patches for inference, to eliminate tile boundary artifacts.
Training on AI Platform
For relatively large models (like the FCNN example), the longevity of the free virtual
machine on which Colab notebooks run may not be sufficient for a long-running training
job. Specifically, if the expected prediction error is not minimized on the evaluation
dataset, then more training iterations may be prudent. For performing large training
jobs in the Cloud, this Colab notebook demonstrates how to
package your training
code, start a
training job, prepare a
earthengine model prepare command, and get predictions in Earth
Engine interactively with