Implements multi-layer perceptron (MLP) training

This algorithm is a legacy one. The API has changed since its implementation. New versions and forks will need to be updated.

Algorithms have at least one input and one output. All algorithm endpoints are organized in groups. Groups are used by the platform to indicate which inputs and outputs are synchronized together. The first group is automatically synchronized with the channel defined by the block in which the algorithm is deployed.

Group: main

Endpoint Name Data Format Nature
class_id system/uint64/1 Input
image system/array_2d_floats/1 Input
model tutorial/mlp/1 Output

Parameters allow users to change the configuration of an algorithm when scheduling an experiment

Name Description Type Default Range/Choices
number-of-iterations uint32 50
seed uint32 0
number-of-hidden-units uint32 10
xxxxxxxxxx
55
 
1
import bob
2
import numpy
3
4
5
def mlp_from_data(data):
6
    """Unmangles a dict of bob.machine.MLP from a BEAT Data object"""
7
8
    n_inputs  = data.input_subtract.shape[0]
9
    n_outputs = data.biases[-1].value.shape[0]
10
    n_hidden  = len(data.biases) - 1
11
    shape = [n_inputs]
12
    for i in range(n_hidden): shape.append(data.biases[i].value.shape[0])
13
    shape.append(n_outputs)
14
    mlp = bob.machine.MLP(shape)
15
16
    mlp.input_subtract = data.input_subtract
17
    mlp.input_divide   = data.input_divide
18
    weights = []
19
    for v in data.weights: weights.append(v.value)
20
    biases = []
21
    for v in data.biases:  biases.append(v.value)
22
    mlp.weights = weights
23
    mlp.biases  = biases
24
25
    return mlp
26
27
28
class Algorithm:
29
30
    def __init__(self):
31
        self.model = None
32
33
34
    def process(self, inputs, outputs):
35
36
      # retrieve the model
37
      if self.model is None:
38
        inputs['model'].next()
39
        self.model = mlp_from_data(inputs['model'].data)
40
41
      # probe image
42
      image = inputs['image'].data.value.flatten()
43
44
      scores = {}
45
      scores = self.model(image)
46
47
      # Get the class_id with maximum score
48
      max_id = scores.argmax()
49
      outputs['scores'].write({
50
            'real_identity': inputs['class_id'].data.value,
51
            'estimated_identity': numpy.uint64(max_id),
52
            'score': scores[max_id]
53
         })
54
55
      return True

The code for this algorithm in Python
The ruler at 80 columns indicate suggested POSIX line breaks (for readability).
The editor will automatically enlarge to accomodate the entirety of your input
Use keyboard shortcuts for search/replace and faster editing. For example, use Ctrl-F (PC) or Cmd-F (Mac) to search through this box

This algorithm implements a scoring procedure for a multi-layer perceptron (MLP) [Bishop] [Duda], a neural network architecture that has some well-defined characteristics such as a feed-forward structure.

This implementation relies on the Bob library.

The inputs are:

  • image: a two-dimensional array of floats (64 bits), which is flattened for the training procedure
  • class_id: an identifier for the class of the image, such that supervised training is possible

The output scores is the corresponding set of score values.

[Bishop]Pattern Recognition and Machine Learning, C.M. Bishop, chapter 5
[Duda]Pattern Classification, Duda, Hart and Stork, chapter 6
No experiments are using this algorithm.
Created with Raphaël 2.1.2[compare]tutorial/mlp_training/1tutorial/mlp_training/2Aug28tutorial/mlp_training/32014Sep62015Sep3
This algorithm was never executed.
Terms of Service | Contact Information | BEAT platform version 2.2.1b0 | © Idiap Research Institute - 2013-2025