Google Earth Engine – Using ee.Image.stratifiedSample() for Binary Classifier Training Samples

classificationgoogle-earth-enginesample

This is a follow-on question to How can one create a binary image from a FeatureCollection in Google Earth Engine?

The corresponding minimal example can be found here:
https://code.earthengine.google.com/3cbd9c722f8ceca84281327cecd8cdb8

I don't quite get how a raster image containing class labels for every pixel can be used to select training samples using GEE's in-built function ee.Image.stratifiedSample(). In the minimal example, the following error occurs:
"FeatureCollection (Error) Remote request too large (134217728 > 83886080) for output: [< Object >, < Object >, < Object >, < Object >, < Object >, < Object >, < Object >, < Object >, < Object >, < Object >, < Object >, < Object >, < Object >, < Object >, < Object >, < Object >]."

Although my question and the minimal example refer to a simply binary classifer (which could theoretically also be modelled as a one-class problem, as I am only interested in the foreground), the problem should be directly transferable to classical multi-class classification problems.

Maybe I am also misunderstanding the concept of ee.Image.stratifiedSample()? This possibly also relates to my other question What's the difference between sample, sampleRegions, and stratifiedSample in Google Earth Engine?

Best Answer

You're not doing anything wrong, it's just that S2 images have a lot of bands and taking the median() of them generates double valued pixels, so the tiles being passed back and forth between servers end up too large. When this occurs, you increase the tileScale, to tell the system to use smaller tiles.

var trainingSamples = s2_image.stratifiedSample({
  numPoints: 10, 
  classBand: 'binary_image', 
  region: ROI, 
  scale: 10,
  tileScale: 4
});

See https://developers.google.com/earth-engine/debugging#scaling-errors for more information on tileScale.

Related Question