GRASS logo

Note: This document is for an older version of GRASS GIS that will be discontinued soon. You should upgrade, and read the current manual page.

Note: This addon document is for an older version of GRASS GIS that will be discontinued soon. You should upgrade your GRASS GIS installation, and read the current addon manual page.


r.object.activelearning - Active learning for classifying raster objects



r.object.activelearning --help
r.object.activelearning training_set=name test_set=name unlabeled_set=name [learning_steps=integer] [nbr_uncertainty=integer] [diversity_lambda=float] [c_svm=float] [gamma_parameter=float] [search_iter=integer] [update=name] [predictions=name] [training_updated=name] [unlabeled_updated=name] [--overwrite] [--help] [--verbose] [--quiet] [--ui]


Allow output files to overwrite existing files
Print usage summary
Verbose module output
Quiet module output
Force launching GUI dialog


training_set=name [required]
Training set (csv format)
test_set=name [required]
Test set (csv format)
unlabeled_set=name [required]
Unlabeled samples (csv format)
Number of samples to label at each iteration
Default: 5
Number of samples to select (based on uncertainty criterion) before applying the diversity criterion.
Default: 15
Lambda parameter used in the diversity heuristic
Default: 0.25
Penalty parameter C of the error term
Kernel coefficient
Number of parameter settings that are sampled in the automatic parameter search (C, gamma).
Default: 15
Training set update file
Output file for class predictions
Output file for the updated training file
Output file for the updated unlabeled file

Table of contents


This module uses SVM from the scikit-learn python package to perform classification on regions of raster maps. These regions can be the output of i.segment or r.clump.

The module enables learning with only a small initial labeled data set via active learning. This semi-supervised learning algorithm interactively query the user to label the regions that are most useful to improve the overall classification score. With this technique, the number of examples to learn the classification is often much lower than the number of examples needed in normal supervised algorithms. You should start the classification with a small training set and run the module multiple times to label new informative samples to improve the classification score. The score metric is the number of correctly predicted labels over the total number of samples in the test set.

The samples that are chosen to be labeled are the ones where the class prediction is the most uncertain [2]. Moreover, from the more uncertain samples, only the most different samples are kept [1]. This diversity heuristic takes into account for each uncertain sample the distance to its closest neighbour and the average distance to all other samples. This ensures that newly labeled samples are not redundant with each other.

The learning data should be composed of features extracted from the regions, for example with the i.segment.stats module. The features of the training set, the test set and the unlabeled set should be in three different files in csv format. The first line of each file must be a header containing the features' name. Every regions should be uniquely identified by the first attribute. The classes for the training and test examples should be the second attribute.

Example of a training and test files :


Example of an unlabeled file :


The training set can be easily updated once you have labeled new samples. Create a file to specify what label you give to which sample. This file in csv format should have a header and two attributes per line : the ID of the sample you have labeled and the label itself. The module will transfer the newly labeled samples from the unlabeled set to the training set, adding the class you have provided. This is done internally and does not modify your original files.

If the user wants to save the changes in new files according to the updates, new files can be created with the new labeled samples added to the training file and removed from the unlabeled file. Just specify the path of those output files in the parameters (training_updated, unlabeled_updated).

Example of an update file :


Here are more details on a few parameters :


The following examples are based on the data files found in this module repository.

Simple run without an update file

		r.object.activelearning training_set=/path/to/training_set.csv \
					test_set=/path/to/test_set.csv \

		Parameters used : C=146.398423284, gamma=0.0645567086567, lambda=0.25
		Class predictions written to predictions.csv
		Training set : 70
		Test set : 585
		Unlabeled set : 792
		Score : 0.321367521368

With an update file

The five samples output at the previous example have been labeled and added to the update file.
		r.object.activelearning training_set=/path/to/training_set.csv \
		                        test_set=/path/to/test_set.csv \
					unlabeled_set=/path/to/unlabeled_set.csv \

		Parameters used : C=101.580687073, gamma=0.00075388337475, lambda=0.25
		Class predictions written to predictions.csv
		Training set : 75
		Test set : 585
		Unlabeled set : 787
		Score : 0.454700854701


This module requires the scikit-learn python package. This module needs to be installed in your GRASS GIS Python environment. Please refer to's notes on how to install this package.

The memory usage for ~1450 samples of 52 features each is around ~650 kb. This number can vary due to the unpredictablity of the garbage collector's behaviour. Everything is computed in memory; therefore the size of the data is limited by the amount of RAM available.


[1] Bruzzone, L. and Persello, C. (2009). Active learning for classification of remote sensing images. 2009 IEEE International Geoscience and Remote Sensing Symposium. doi:10.1109/igarss.2009.5417857
[2] Tuia, D. et al (2011). A Survey of Active Learning Algorithms for Supervised Remote Sensing Image Classification. IEEE Journal of Selected Topics in Signal Processing, 5(3), 606-617. doi:10.1109/jstsp.2011.2139193


Lucas Lefèvre (ULB, Brussels, Belgium)


Available at: r.object.activelearning source code (history)

Latest change: Monday Jun 28 07:54:09 2021 in commit: 1cfc0af029a35a5d6c7dae5ca7204d0eb85dbc55

Note: This document is for an older version of GRASS GIS that will be discontinued soon. You should upgrade, and read the current manual page.

Note: This addon document is for an older version of GRASS GIS that will be discontinued soon. You should upgrade your GRASS GIS installation, and read the current addon manual page.

Main index | Raster index | Topics index | Keywords index | Graphical index | Full index

© 2003-2023 GRASS Development Team, GRASS GIS 7.8.9dev Reference Manual