| Speaker | Timing (60 mins total) | Outline |
Intro | Steve / Nick | 5 min |
|
Extracting more from each pixel with derived information | Eliana | 10 min |
|
A basic land classification task. Dealing with unbalanced classes | Steve / Nick | 10 min |
|
Hyperparameter Tuning | Steve / Nick | 8 min |
|
K-Fold Cross-Validation | Steve / Nick | 2 min |
|
Post-Processing | Andréa | 5 min |
|
Ensembling Multiple Models | Emma | 15 min |
|
Q&A | All | 5 min | |
| Link | Target |
Cropland Exercise | https://goo.gle/g4g24-croplands | https://colab.research.google.com/drive/1O1DyeamBnl2-jnFR6kljmnH7mGTn7Uxy?usp=sharing |
Cropland Solutions | https://goo.gle/g4g24-croplands-solution | https://colab.research.google.com/drive/1YnroAmIQH_Zl6q_I4T6fN817oF1iT2qa?usp=sharing |
| | |
| | https://code.earthengine.google.com/fb6dd088744a43b868ada67a38dadffd |
| | https://code.earthengine.google.com/91072ebc1a373fe5a7775a9d561fc91e |
Geo for Good Summit Sept 25th - What’s Happening Now?
Classifying the Land - Scaling and Improving the Accuracy of Classical ML APIs in EE
Room: Experiment
Data Catalog - new datasets and new capabilities �Room: Carina Nebula
Configuring your Earth Engine access
Room: Birr Castle
9:15-10:15am
10:15-10:45am
Coffee break outside Experiment, Carina Nebula and Birr Castle
10:45-12:15pm
Automating Earth Engine workflows
Room: Experiment
Sustainable Sourcing and Convergence of Evidence
Room: Carina Nebula
Importing into Earth Engine
Room: Birr Castle
12:15-1:45pm
Lunch outside Experiment
“Ask Me Anything” session with Earth Engine Product Managers in Experiment from 12:45-1:15pm
You are here
Classifying the Land Scaling and Improving the Accuracy of Classical Machine Learning APIs in Earth Engine
Steve Greenberg, Earth Engine Developer Relations Lead
Andréa P Nicolau, Spatial Informatics Group
Eliana Lima da Fonseca, Universidade Federal do Rio Grande do Sul
[Pre-recorded] Emma Izquierdo Verdiguier,
University of Natural Resources and Life Sciences (BOKU)�
September 2024 | #GeoForGood24
Classifying the Land Scaling and Improving the Accuracy of Classical Machine Learning APIs in Earth Engine
Nicholas Clinton, Earth Engine
[Pre-recorded] Andréa P Nicolau, Spatial Informatics Group
[Pre-recorded] Eliana Lima da Fonseca, Universidade Federal do Rio Grande do Sul
Emma Izquierdo Verdiguier, University of Natural Resources and Life Sciences (BOKU)
September 2024 | #GeoForGood24
Agenda
01
02
03
Introduction
Why classify?
Why not use deep learning?
Extracting more from your pixels
[Demo] Urban Forests in Porto Alegre
Hyperparameter Tuning
[Hands on Coding] Modifying Random Forest size
Post Processing
[Demo] Mangroves in Guyana
Ensembling Multiple Models
[Demo] Mapping Smallholder Farms
Q&A
04
05
06
#GeoForGood24
Introduction
Introduction
Introduction
Introduction
Different from Deep Neural Networks
Classical ML
Each Pixel is (typically) considered independently
Less computationally intense
Earth Engine supports with built-in APIs
Deep Learning
Classification is done on arrays of pixels
More computationally intense
Requires use of Tensorflow / PyTorch and Vertex AI
Easy to get started
Using classical machine learning in Earth Engine is very easy if the algorithm you want to use is built-in.
Various examples to adapt from, minimal set up allows you to focus on other important problems with machine learning instead.
Good results
Although some classical machine learning methods appear primitive compared to their neural-network counterparts, depending on the problem, can give good results.
Many analysis using algorithms such as random forest can lead to real work impact and good results.
Understandable
Classical machine learning models are well understood with lots of literature detailing their strengths and weaknesses.
Easier to cite for research and easier to introspect for internal state and learned features than a deep neural network which appears as a block box.
Why use a classical machine learning model?
The Machine Learning Journey
Assessment
Post Processing
Train Model
Gather and Prepare Data
The Machine Learning Journey
Assessment
Post Processing
Train Model
Gather and Prepare Data
Extracting more from each pixel with derived information
Identifying Urban Forests Extracting more from each pixel with derived information
�Eliana Lima da Fonseca
Professor at Universidade Federal do Rio Grande do Sul
Earth Engine Google Developer Expert
”
Demo
Urban forests in Landsat images
Landsat images
Long time-series
Good temporal resolution for urban areas
Limitations
Spatial resolution (30 meters)
Many different targets inside the same pixel
Some feasible solutions to improve the classification:
“ Choose the correct season to identify urban greens”
“ Looking for more information with derived information”
Building an urban vegetation time-series images
Limitations
Spatial resolution (30 meters)
Many different targets inside the same pixel
No samples collected for the past images
Validations metrics cannot be calculated
Solutions
Sub-pixel information
Visual inspection
Science validate methods
using Landsat 8 imagery and machine learning algorithms
Building an urban vegetation time-series images
Input data
Landsat 8 imagery (2014 - present)
Information in a sub-pixel level
Information in a sub-pixel level
Linear spectral mixture model in urban areas
The linear system´s solution gives the proportion (X) of each endmember inside each pixel.
These proportions are given in new bands
r = vegetation*x1 + builts*x2 + shadow*x3
Where:
r = pixel spectral reflectance
x1 = proportion value of the vegetations in the pixel
x2 = proportion value of the builts in the pixel
x3 = proportion value of the shadows in the pixel
Endmember spectral patterns
Endmember selection
Builts
Area with no trees and no shadows
Vegetation
Urban forest
Shadow/Asphalt
A shadow projected over the asphalt
Visual inspection over basemap (high resolution image)
Endmember selection
Input data: Sub-pixel information
Classification / clustering: CART classifier
Input data tests: using Summer and Winter images with/without endmembers images
Results
Basemap
Original bands
Derived information
Visual inspection over basemap (high resolution image) - Point (-51.2189, -30.05509)
Results
Basemap
Derived information
Winter (2021_06_01)
Derived information
Summer (2021_12_10)
Visual inspection over basemap (high resolution image) - Point (-51.2189, -30.05509)
Code for endmember selection
Code for classification
Building an urban vegetation time-series images
https://goo.gle/g4g24-endmembers
https://goo.gle/g4g24-unmixing
using Landsat 8 imagery and machine learning algorithms
The Machine Learning Journey
Assessment
Post Processing
Train Model
Gather and Prepare Data
A simple classification example
Predicting crops with USDA Croplands Dataset
https://goo.gle/g4g24-croplands
The Machine Learning Journey
Assessment
Post Processing
Train Model
Gather and Prepare Data
Hyperparameter Tuning
The Machine Learning Journey
Assessment
Post Processing
Train Model
Gather and Prepare Data
Hyperparameter Tuning
Removing isolated pixels
Removing Isolated Pixels
Mangrove Classification
�Andréa Puzzi Nicolau
Geospatial Data Scientist, Spatial Informatics Group
Earth Engine Google Developer Expert
”
Demo
Removing Isolated Pixels
Often when classifying an image to obtain a land use land cover map, we encounter isolated pixels in the final classified image. What are some ways of removing these isolated pixels?
Mangrove Classification
Removing Isolated Pixels
Often when classifying an image to obtain a land use land cover map, we encounter isolated pixels in the final classified image. What are some ways of removing these isolated pixels?
Mangrove Classification
Focal Mode Operator
var classifiedMode = classified.focalMode(3)
Focal Mode Operator
var classifiedMode = classified.focalMode(3)
Shortcut for .reduceNeighborhood() with a mode reducer ee.Reducer.mode()
Focal Mode Operator
var classifiedMode = classified.focalMode(3)
The mode operator gets the value that occurs most frequently within the neighborhood (kernel)
Focal Mode Operator
var classifiedMode = classified.focalMode(3)
Kernel radius
Focal Mode Operator
var classifiedMode = classified.focalMode(3)
Weighted Focal Mode
// Define 3x3 window with (euclidean) distance weights from corners.
var weights = [[1,2,1],
[2,3,2],
[1,2,1]];
// Create kernel.
var kernel = ee.Kernel.fixed(3,3,weights);
// Apply mode on neighborhood using weights.
var classifiedWmode = classified.focalMode({kernel: kernel})
Weighted Focal Mode
// Define 3x3 window with (euclidean) distance weights from corners.
var weights = [[1,2,1],
[2,3,2],
[1,2,1]];
// Create kernel.
var kernel = ee.Kernel.fixed(3,3,weights);
// Apply mode on neighborhood using weights.
var classifiedWmode = classified.focalMode({kernel: kernel})
Gives higher weight to closer pixels.
Controls for “over postprocessing”.
Weighted Focal Mode
Original Classification
Focal Mode
Weighted Focal Mode
Clustering
var seeds = ee.Algorithms.Image.Segmentation.seedGrid(5);
var snic = ee.Algorithms.Image.Segmentation.SNIC({
image: composite,
compactness: 0,
connectivity: 4,
neighborhoodSize: 10,
size: 2,
seeds: seeds
});
var clusters = snic.select('clusters');
var smoothed = classified.addBands(clusters);
var classifiedCluster = smoothed.reduceConnectedComponents({
reducer: ee.Reducer.mode(),
labelBand: 'clusters'
});
Clustering
var seeds = ee.Algorithms.Image.Segmentation.seedGrid(5);
var snic = ee.Algorithms.Image.Segmentation.SNIC({
image: composite,
compactness: 0,
connectivity: 4,
neighborhoodSize: 10,
size: 2,
seeds: seeds
});
var clusters = snic.select('clusters');
var smoothed = classified.addBands(clusters);
var classifiedCluster = smoothed.reduceConnectedComponents({
reducer: ee.Reducer.mode(),
labelBand: 'clusters'
});
Selects seed pixels for clustering. Seeds are created and used to form square “super-pixels” (can be hexagonal too).
Clustering
var seeds = ee.Algorithms.Image.Segmentation.seedGrid(5);
var snic = ee.Algorithms.Image.Segmentation.SNIC({
image: composite,
compactness: 0,
connectivity: 4,
neighborhoodSize: 10,
size: 2,
seeds: seeds
});
var clusters = snic.select('clusters');
var smoothed = classified.addBands(clusters);
var classifiedCluster = smoothed.reduceConnectedComponents({
reducer: ee.Reducer.mode(),
labelBand: 'clusters'
});
Superpixel clustering based on SNIC (Simple Non-Iterative Clustering)
Clustering
var seeds = ee.Algorithms.Image.Segmentation.seedGrid(5);
var snic = ee.Algorithms.Image.Segmentation.SNIC({
image: composite,
compactness: 0,
connectivity: 4,
neighborhoodSize: 10,
size: 2,
seeds: seeds
});
var clusters = snic.select('clusters');
var smoothed = classified.addBands(clusters);
var classifiedCluster = smoothed.reduceConnectedComponents({
reducer: ee.Reducer.mode(),
labelBand: 'clusters'
});
Superpixel clustering based on SNIC (Simple Non-Iterative Clustering)
Clustering
var seeds = ee.Algorithms.Image.Segmentation.seedGrid(5);
var snic = ee.Algorithms.Image.Segmentation.SNIC({
image: composite,
compactness: 0,
connectivity: 4,
neighborhoodSize: 10,
size: 2,
seeds: seeds
});
var clusters = snic.select('clusters');
var smoothed = classified.addBands(clusters);
var classifiedCluster = smoothed.reduceConnectedComponents({
reducer: ee.Reducer.mode(),
labelBand: 'clusters'
});
Applies a reducer to all of the pixels inside of each cluster. In this case, a mode reducer.
Original Classification
Focal Mode
Weighted Focal Mode
Clustering
When adding to the map…
…classified.reproject('EPSG:XXXX', null, 10)
Map.addLayer(...)
Neighborhood methods are scale-dependent so the results will change as you zoom in/out, this is why you need to force a reprojection to be able to see the changes on the map.
Alternatively, you can export the image as an asset and re-import it to see it.
Code
https://goo.gle/g4g24-mangroves
The Machine Learning Journey
Assessment
Post Processing
Train Model
Gather and Prepare Data
Ensembling Multiple Models
Crop Classification
Ensembling multiple models
�Emma Izquierdo-Verdiguier
University of Natural Resources and Life Sciences, Vienna (BOKU)
Earth Engine Google Developer Expert
”
Demo
Crop classification
Very complicated task!
#GeoForGood24
Crop classification
What Could Possibly Go Wrong?
Very complicated task!
#GeoForGood24
Crop classification
What Could Possibly Go Wrong?
Very complicated task!
#GeoForGood24
Crop classification
What Could Possibly Go Wrong?
Very complicated task!
#GeoForGood24
How can it be improved?
#GeoForGood24
#GeoForGood24
#GeoForGood24
Weights can be:
Cloud-based ensemble classifier
Aguilar, R., et al. "A cloud-based multi-temporal ensemble classifier to map smallholder farming systems." Remote sensing 10.5 (2018): 729.
Based classifiers
#GeoForGood24
How does it work?
#GeoForGood24
Classifier 1
Classifier 3
𝜅 = 0.58
𝜅 = 0.62
Simple example
Classifier 2
𝜅 = 0.65
Class 1
Class 2
#GeoForGood24
Simple example
Class 1
Class 2
#GeoForGood24
Simple example
Class 1
Class 2
Ensemble
#GeoForGood24
Ensemble in the Earth Engine code editor
#GeoForGood24
Ensemble in the Earth Engine code editor
var names_clas = ['LIN', 'POLY','RBF','RF','GB'];
//Based classifiers: weights obtained from the kappa values are needed:
var weight = ee.Number(kappa.divide(ee.Number(1).subtract(kappa))).log10();
...
//Classification maps:
base_img = base_img.set({
'weight':ee.Number(weight),
'Img_id':clas
}).rename('based_classifier');
#GeoForGood24
Ensemble in the Earth Engine code editor
var num_classifiers= ee.List.sequence(0,num_classifiers-1);
// Create an imageCollection with one image per class. Each image contains two bands (i.e., weight per class and the class number):
function ic_weight(cl){
var img_weight = ee.ImageCollection(num_classifiers.map(
function (classi){
...
}));
img_weight = img_weight.sum();
return img_weight.addBands(ee.Image.constant(cl).toByte())};
#GeoForGood24
Ensemble in the Earth Engine code editor
var ic_weight_cls = ee.List.sequence(0,num_classes-1).map(ic_weight);
ic_weight_cls = ee.ImageCollection(ic_weight_cls);
var enseble_class = ic_weight_cls.reduce(ee.Reducer.max(2));
enseble_class = enseble_class.rename(['weight','ensemble_cls']);
#GeoForGood24
Ensemble in the Earth Engine code editor
#GeoForGood24
Demo
#GeoForGood24
Ensemble in the Earth Engine code editor
#GeoForGood24
Q&A
Links for more information …
#GeoForGood24
Geo for Good Summit Sept 25th
Classifying the Land - Scaling and Improving the Accuracy of Classical ML APIs in EE
Room: Experiment
Data Catalog - new datasets and new capabilities �Room: Carina Nebula
Configuring your Earth Engine access
Room: Birr Castle
9:15-10:15am
10:15-10:45am
Coffee break outside Experiment, Carina Nebula and Birr Castle
10:45-12:15pm
Automating Earth Engine workflows
Room: Experiment
Sustainable Sourcing and Convergence of Evidence
Room: Carina Nebula
Importing into Earth Engine
Room: Birr Castle
12:15-1:45pm
Lunch outside Experiment
“Ask Me Anything” session with Earth Engine Product Managers in Experiment from 12:45-1:15pm
Sign up for Office Hours: goo.gle/g4g24-office-hours
The Machine Learning Journey
Assessment
Post Processing
Train Model
Gather and Prepare Data
K-Fold Cross Validation
K-Fold Cross Validation
All Samples
k random subsets
Validation
Training
Training
Training
Training
Training
Training
Training
Training
Training
fold 1 accuracy
Training
Validation
Training
Training
Training
Training
Training
Training
Training
Training
fold 2 accuracy
Training
Training
Validation
Training
Training
Training
Training
Training
Training
Training
fold 3 accuracy
Training
Training
Training
Training
Training
Training
Training
Training
Training
Validation
fold k accuracy
………
average accuracy
A simple classification example - https://goo.gle/g4g24-croplands
# We will use USDA NASS Cropland Data Layers as our labels to train on. Add the s2 bands to the CDL data.
cdl = ee.ImageCollection("USDA/NASS/CDL")
cdl = cdl.addBands(composite)
# Take a stratified sample. 1000 points per class.
sample = cdl.stratifiedSample(numPoints = 1000, classBand = 'cropland')�
# Partition the training into 3481 training and 1519 validation samples
training = sample.filter(ee.Filter.lt('random', 0.7))
validation = sample.filter(ee.Filter.gte('random', 0.7))
# Train a random forest
classifier = ee.Classifier.smileRandomForest(10).train(features = training, classProperty = 'cropland', inputProperties = composite.bandNames())
# Accuray on Test Set
testAccuracy = validation.classify(classifier).errorMatrix('cropland', 'classification').accuracy()
Hyperparameter Tuning
The Grid Search Method
You define the range of valid values for each parameter.
Let's code
https://goo.gle/g4g24-croplands
�
Solution: https://goo.gle/g4g24-croplands-solution