[GIS] User memory limit exceeded error for classification in Google Earth Engine

google-earth-engineimage classification

I am trying to do classification using cart. Given below is the code that was used, but I am getting 'user memory limit exceeded' error. Is there no other way to rectify this other than by reducing the extent of the ROI, randomly sampling or by knocking out a few bands? Am I doing something wrong here? This is the asset that I am using to train: https://code.earthengine.google.com/?asset=users/RohitNandakumar/train

var sent = ee.ImageCollection("COPERNICUS/S2_SR"),
    table = ee.FeatureCollection("users/RohitNandakumar/train"),
    geometry = 
    /* color: #d63000 */
    /* displayProperties: [
      {
        "type": "rectangle"
      }
    ] */
    ee.Geometry.Polygon(
        [[[79.33418599339291, 29.71454696770813],
          [79.33418599339291, 29.317189386242045],
          [79.86496297093197, 29.317189386242045],
          [79.86496297093197, 29.71454696770813]]], null, false);

var land = sent.filterDate('2019-04-1','2019-11-01')
.filterMetadata("MGRS_TILE","equals",'44RLT')
.filter(ee.Filter.lt("CLOUDY_PIXEL_PERCENTAGE",5))
.sort('system:time_start');
var image = ee.Image(land.toList(land.size()).get(1)).clip(geometry);
var label = 'MC_ID';
var bands = ['B2','B3','B4','B5','B6','B7','B8','B8A','B9','B11','B12']
var training = image.select(bands).sampleRegions({
  collection: table,
  properties: [label],
  scale: 10
});
var trained = ee.Classifier.cart().train(training, label, bands);
var classified = image.select(bands).classify(trained);
Map.addLayer(classified,false);

Best Answer

There are two problems with your code - one small and one big. For starters, you end up training your classifier on more than 500,000 training data points. That's the big problem. The second is that calling ImageCollection.toList() which isn't very efficient. Sorting this out would get your classification running.

https://code.earthengine.google.com/bbb217ba3c52298c54d2f1a0412d1c64

Related Question