Google Earth Engine – Using MULTIPROBABILITY Output Mode in Classifier

google-earth-engine

I'm trying to perform a land cover classification task on Landsat 8 images using the RandomForest classifier in Google Earth Engine. I'd like to obtain an output where for each class I get a separate band with the corresponding posterior class probabilities. According to the Google Earth Engine documentation, this should be possible through the 'MULTIPROBABILITY' output mode.

However, when I try to use this output mode, the result is a single-band image. I have tried this will most other classifiers and always get a single band result.
Below is the code snippet:

// Define bands and classifier
var bands = ['B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B10', 'B11', 'NDVI'];
var classifier = ee.Classifier.smileRandomForest({
  numberOfTrees: 100,
  minLeafPopulation: 3,
  bagFraction: 0.5,
  seed: 0,
}).setOutputMode('MULTIPROBABILITY').train({
  features: training,
  classProperty: 'classCode',
  inputProperties: bands
});

// Classify the image
var probabilities = composite.select(bands).classify(classifier);

// Print band names and types to the console
print('Band names: ', probabilities.bandNames());
print('Band types: ', probabilities.bandTypes());

Here, 'training' is a feature collection of training samples, and 'composite' is a cloud-free image composite of Landsat 8 images. When I inspect the band names and types of the 'probabilities' image, I get a single band.

I was wondering if I'm using the 'MULTIPROBABILITY' output mode correctly, or if there is another way to obtain the class probabilities for each class separately?

Best Answer

After much trial and error, I was able to find the solution. The output of a classifier with multiprobability output type is an array band.

So, after classifying the data, the output must be flattened:

// Classify the image
var probabilities = composite.select(bands).classify(classifier);

// Extract the probabilities for each cover type
var probabilities = classified.arrayFlatten([['bare', 'grass', 'trees', 'uluhe']]);

This results in an object with each band representing the probability of class membership for every class considered!

Related Question