Multi-Layer Perceptron (MLP)-based scoring

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: probes

Endpoint Name Data Format Nature
class_id system/uint64/1 Input
image system/array_2d_floats/1 Input
scores tutorial/multiclass_probe_scores/1 Output

Unnamed group

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

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

Experiments

Updated Name Databases/Protocols Analyzers
smarcel/tutorial/digit/2/mnist-mlp-nhu10-niter100-seed2001 mnist/1@idiap tutorial/multiclass_postperf/2
Created with Raphaël 2.1.2[compare]tutorial/mlp_scoring/1tutorial/mlp_scoring/3Aug282014Nov6

This table shows the number of times this algorithm has been successfully run using the given environment. Note this does not provide sufficient information to evaluate if the algorithm will run when submitted to different conditions.

Terms of Service | Contact Information | BEAT platform version 2.2.1b0 | © Idiap Research Institute - 2013-2025