example.rst
Example: Handwritten Digit Classification
As an example for the classification task, we perform a classification of hand-written digits using the MNIST database. There, images of single hand-written digits are stored, and a training and test set is provided, which we can access with our bob.db.mnist database interface.
Note
In fact, to minimize the dependencies to other packages, the bob.db.mnist database interface is replaced by a local interface.
In our experiments, we simply use the pixel gray values as features. Since the gray values are discrete in range [0, 255], we can employ both the stump decision classifiers and the look-up-table's. Nevertheless, other discrete features, like Local Binary Patterns (LBP) could be used as well.
Running the example script
The script ./bin/boosting_example.py is provided to execute digit classification tasks.
This script has several command line parameters, which vary the behavior of the training and/or testing procedure.
All parameters have a long value (starting with --) and a shortcut (starting with a single -).
These parameters are (see also ./bin/boosting_example.py --help):
To control the type of training, you can select:
-
--trainer-type: Select the type of weak classifier. Possible values arestumpandlut -
--loss-type: Select the loss function. Possible values aretan,logandexp. By default, a loss function suitable to the trainer type is selected. -
--number-of-boosting-rounds: The number of weak classifiers to select. -
--multi-variate(only valid for LUT trainer): Perform multi-variate classification, or binary (one-to-one) classification. -
--feature-selection-style(only valid for multi-variate training): Select the feature for each outputindependentorshared?
To control the experimentation, you can choose:
-
--digits: The digits to classify. For multi-variate training, one classifier is trained for all given digits, while for uni-variate training all possible one-to-one classifiers are trained. -
--all: Select all 10 digits. -
--classifier-file: Save the trained classifier(s) into the given file and/or read the classifier(s) from this file. -
--force: Overwrite the given classifier file if it already exists.
For information and debugging purposes, it might be interesting to use:
-
--verbose(can be used several times): Increases the verbosity level from 0 (error) over 1 (warning) and 2 (info) to 3 (debug). Verbosity level 2 (-vv) is recommended. -
--number-of-elements: Reduce the number of elements per class (digit) to the given value.
Four different kinds of experiments can be performed:
-
Uni-variate classification using the stump classifier :py:class:`bob.learn.boosting.StumpMachine`, classifying digits 5 and 6:
$ ./bin/boosting_example.py -vv --trainer-type stump --digits 5 6 -
Uni-variate classification using the LUT classifier :py:class:`bob.learn.boosting.LUTMachine`, classifying digits 5 and 6:
$ ./bin/boosting_example.py -vv --trainer-type lut --digits 5 6 -
Multi-variate classification using LUT classifier :py:class:`bob.learn.boosting.LUTMachine` and shared features, classifying all 10 digits:
$ ./bin/boosting_example.py -vv --trainer-type lut --all-digits --multi-variate --feature-selection-style shared -
Multi-variate classification using LUT classifier :py:class:`bob.learn.boosting.LUTMachine` and independent features, classifying all 10 digits:
$ ./bin/boosting_example.py -vv --trainer-type lut --all-digits --multi-variate --feature-selection-style independent
All experiments should be able to run using several minutes of execution time. The results of the above experiments should be the following (split in the remaining classification error on the training set, and the error on the test set)
| Experiment | Training | Test |
| 1 | 91.04 % | 92.05 % |
| 2 | 100.0 % | 95.35 % |
| 3 | 97.59 % | 83.47 % |
| 4 | 99.04 % | 86.25 % |
Of course, you can try out different combinations of digits for experiments 1 and 2.