4

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);

2 Answers 2

2

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

2
  • Having a same problem while classifying using SVM or Random Forest. Not using large number of sample points. Any solution? Commented Feb 1, 2021 at 6:21
  • Code is working fine after changing the scale used for training. Commented Feb 1, 2021 at 6:36
0

For the training sample, you should use marker geometry instead of a polygon or rectangle.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.