Multi-Layer Perceptron (MLP)-based scoring
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.
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 |
Endpoint Name | Data Format | Nature |
---|---|---|
model | tutorial/mlp/1 | Input |
xxxxxxxxxx
import bob
import numpy
import scipy.spatial
def mlp_from_data(data):
"""Unmangles a dict of bob.machine.MLP from a BEAT Data object"""
n_inputs = data.input_subtract.shape[0]
n_outputs = data.biases[-1].value.shape[0]
n_hidden = len(data.biases) - 1
shape = [n_inputs]
for i in range(n_hidden): shape.append(data.biases[i].value.shape[0])
shape.append(n_outputs)
mlp = bob.machine.MLP(shape)
mlp.input_subtract = data.input_subtract
mlp.input_divide = data.input_divide
weights = []
for v in data.weights: weights.append(v.value)
biases = []
for v in data.biases: biases.append(v.value)
mlp.weights = weights
mlp.biases = biases
return mlp
class Algorithm:
def __init__(self):
self.model = None
def process(self, inputs, outputs):
# retrieve the model
if self.model is None:
inputs['model'].next()
self.model = mlp_from_data(inputs['model'].data)
# probe image
image = inputs['image'].data.value.flatten()
scores = {}
scores = self.model(image)
# Get the class_id with maximum score
max_id = scores.argmax()
outputs['scores'].write({
'real_identity': inputs['class_id'].data.value,
'estimated_identity': numpy.uint64(max_id),
'score': scores[max_id]
})
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:
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 |
Updated | Name | Databases/Protocols | Analyzers | |||
---|---|---|---|---|---|---|
smarcel/tutorial/digit/2/mnist-mlp-nhu10-niter100-seed2001 | mnist/1@idiap | tutorial/multiclass_postperf/2 |
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.