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

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
image system/array_2d_uint8/1 Input
id system/uint64/1 Input
projections system/array_2d_floats/1 Output

Unnamed group

Endpoint Name Data Format Nature
subspace_lda tutorial/linear_machine/1 Input
subspace_pca tutorial/linear_machine/1 Input
50
 
1
import bob
2
import numpy
3
4
5
def linear_machine_from_data(data):
6
    """Unmangles a bob.machine.LinearMachine from a BEAT Data object"""
7
8
    machine = bob.machine.LinearMachine(data.weights)
9
    machine.biases = data.biases
10
    machine.input_subtract = data.input_subtract
11
    machine.input_divide = data.input_divide
12
    return machine
13
14
15
16
class Algorithm:
17
18
    def __init__(self):
19
        self.pca_machine        = None
20
        self.lda_machine        = None
21
        self.projections        = []
22
23
24
    def process(self, inputs, outputs):
25
26
        # retrieve the linear machines once
27
        if self.pca_machine is None:
28
            inputs['subspace_pca'].next()
29
            self.pca_machine = linear_machine_from_data(inputs['subspace_pca'].data)
30
        if self.lda_machine is None:
31
            inputs['subspace_lda'].next()
32
            self.lda_machine = linear_machine_from_data(inputs['subspace_lda'].data)
33
34
        # collect all the image projections for the current template
35
        image = inputs['image'].data.value.flatten().astype('float')
36
        projection = self.lda_machine.forward(self.pca_machine.forward(image))
37
38
        self.projections.append(projection)
39
40
41
        # generate the results (when all the images of the current template have been
42
        # projected)
43
        if inputs["id"].isDataUnitDone():
44
            outputs['projections'].write({
45
                'value': numpy.array(self.projections, dtype=numpy.float64)
46
            })
47
48
            self.projections = []
49
50
        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 linearizes and accumulates images into a buffer, before applying two consecutive linear transformations (using projection matrices computed by principal component analysis (PCA) and by linear discriminant analysis (LDA)). The linear transformations rely on the Bob library.

The inputs are:

  • image: an image as a two-dimensional arrays of floats (64 bits)
  • id: an identifier which is used as follows: all images with the
    same identifier are accumulated into the same buffer
  • subspace_pca: a PCA-learnt linear transformation as a collection of
    weights, biases, input subtraction and input division factors.
  • subspace_lda: a LDA-learnt linear transformation as a collection of
    weights, biases, input subtraction and input division factors.

The output projections is a two-dimensional array of floats (64 bits), the number of rows corresponding to the number of accumulated images (with the same identifier), and the number of columns to the output dimensionality after applying the linear transformations.

No experiments are using this algorithm.
Created with Raphaël 2.1.2[compare]tutorial/linear_machine_x2_projection/1tutorial/linear_machine_x2_projection/2Jun27tutorial/linear_machine_x2_projection/32014Sep62015Sep3

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