I want to classify and check the accuracy of for identifying the land cover. But it is taking lots of time to execute and finally giving some error like:"Computation Timed out" My code is given below. I am also sharing the link for the same.


// ---------Cloud Masking function

function maskS2clouds(image) {
  var qa = image.select('QA60');

  // Bits 10 and 11 are clouds and cirrus, respectively.
  var cloudBitMask = ee.Number(2).pow(10).int();
  var cirrusBitMask = ee.Number(2).pow(11).int();

  // Both flags should be set to zero, indicating clear conditions
  var mask = qa.bitwiseAnd(cloudBitMask).eq(0).and(

  // Return the masked and scaled data.
  return image.updateMask(mask).divide(10000);

//---------- AOI of Study Area

//var table = ee.FeatureCollection(users/abhikbetal/Jorhat_NDVIClass);
var boundary = ee.FeatureCollection('ft:1rbhNtC1TqDBvY9Rt2BZR-DjhpIPuC3nU5kmz49WW');//Jorhat Boundary
//var boundary = ee.FeatureCollection('ft:1ABffZYEE4XhMTOXsoSfWENKXBK2fQfOrdMplEaVo');//Midnapur Boundary

// ---------  Import of Images (Sentinel _ 2 multispectral)

var image = ee.ImageCollection(sent2img

//----------- Selection of Bands
//var bands = ['B2', 'B3', 'B4','B5','B6','B7','B8','B8A'];

//----------  Preprocessing 

var mosaic = image.mosaic()
var clip = mosaic.clip(boundary);
print('clip', clip);

//----------   FCC creation and visualisation of AOI     
Map.addLayer(clip, {bands: ['B8','B4','B3'], min: 0, max: 0.3},'clip');

// -----------  NDVI  calculation

var ndvi = clip.expression(
    ' ((NIR - RED) / (NIR + RED))', {
      'NIR': clip.select('B8'),
      'RED': clip.select('B4'),

clip = clip.addBands(ndvi)

//---------- Colour Palette

var palette = ['196fda', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718',
               '74A901', '66A000', '529400', '3E8601', '207401', '056201',
               '004C00', '023B01', '012E01', '011D01', '011301'];

// ---------- Map display

Map.addLayer(ndvi, {min:0, max:1, palette: palette},"NDVI");

// -------- Training Classes 
//var classProperty = 'lulc';
 var newfc = wb.merge(plantation).merge(fallow).merge(agriland2).merge(habitation).merge(sandyarea).merge(deepplantation);
 var bands = ['nd','B11','B6'];
 var classProperty = 'lulc';

//var filterrandom0 = ee.Filter.greaterThan('random',0.2);
//var trainingsample = newfc.filter(filterrandom0);

//var filterrandom1 = ee.Filter.lessThan('random',0.2);
//var accuracysample = newfc.filter(filterrandom1);

 var training = clip.select(bands).sampleRegions({
    collection: newfc, 
    properties: [classProperty], 
    scale: 20,

//print (training);
//var bands = ['nd'];
var classifier = ee.Classifier.cart().train({
  features: training, 
  classProperty: classProperty, 
  inputProperties: bands
print('CART, explained', classifier.explain());
var classified = clip.select(bands).classify(classifier);

{min: 1, max: 7, palette: ['#1e82ff', '#7e8b4c', '#88ff72','#ff1455','#c2b2bc','#fbff2a','#008800']}, 

var withRandom =training.randomColumn('random');

// We want to reserve some of the data for testing, to avoid overfitting the model.
var split = 0.7;  // Roughly 70% training, 30% testing.
var trainingPartition = withRandom.filter(ee.Filter.lt('random', split));
var testingPartition = withRandom.filter(ee.Filter.gte('random', split));

// Trained with 70% of our data.
var trainedClassifier = ee.Classifier.randomForest().train({
  features: trainingPartition,
 classProperty: 'lulc',
  inputProperties: bands

// Classify the test FeatureCollection.
var test = testingPartition.classify(trainedClassifier);
// Print the confusion matrix.
var confusionMatrix = test.errorMatrix(classProperty, 'classification');
print('Confusion Matrix', confusionMatrix);
//print('Resubstitution error matrix: ', trainAccuracy);
print('Training overall accuracy: ', confusionMatrix.accuracy());

  collection: training, 
  description: 'Jorhat_NewNdviClass', 
  assetId: 'Jorhat_NDVIClass'

1 Answer 1


The calculation works fine with me. (See picture) Google has implemented a limitation on how much memory you can use in Earth Engine. In the profiler you can see what uses the most memory. But I have computed much more memory intensive stuff before than this code, maybe it has also to do with your internet connection.

Try to safe memory by not adding all layers and only print the things you need. Also don't scroll while processing. Also, there is a built in normalizedDifference function you can use to calculate the NDVI, which also safes memory.

enter image description here

  • Thanks for the guidance on saving memory in Earth- Engine. What is the maximum allowed memory usage for an account in GEE?
    – Avik Betal
    Oct 16, 2018 at 12:23
  • 4
    I'm confused, how would the user's internet connection have anything to do with the computation timing out. Isn't it happening on Google's servers?
    – fionag11
    Jan 3, 2021 at 0:34

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.