Skip to content
Snippets Groups Projects
Select Git revision
  • b5190bfe2ba9d475af460a557ed42b5ce7ae02e6
  • master default protected
  • v2.0.19
  • v2.0.18
  • v2.0.17
  • v2.0.16
  • v2.0.15
  • v2.0.14
  • v2.0.13
  • v2.0.12
  • v2.0.11
  • v2.0.10
  • v2.0.9
  • v2.0.8
  • v2.0.7
  • v2.0.6
  • v2.0.5
  • v2.0.4
  • v2.0.3
  • v2.0.2
  • v2.0.1
  • v2.0.0
22 results

example.rst

Blame
  • user avatar
    Manuel Guenther authored
    Re-arranged the classes to fit better to the current structure of Bob packages; new README and documentation strategy.
    5725ca2f
    History
    example.rst 8.38 KiB

    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 are stump and lut
    • --loss-type: Select the loss function. Possible values are tan, log and exp. 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 output independent or shared?

    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:

    1. 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
    2. 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
    3. 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
    4. 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.

    One exemplary test case in details