Compute the GMM Scores
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 |
---|---|---|
comparison_ids | system/array_1d_uint64/1 | Input |
probe_statistics | tutorial/gmm_statistics/1 | Input |
probe_id | system/uint64/1 | Input |
probe_client_id | system/uint64/1 | Input |
scores | tutorial/probe_scores/1 | Output |
Endpoint Name | Data Format | Nature |
---|---|---|
template_client_id | system/uint64/1 | Input |
template_id | system/uint64/1 | Input |
template_model | tutorial/gmm/1 | Input |
Endpoint Name | Data Format | Nature |
---|---|---|
ubm | tutorial/gmm/1 | Input |
xxxxxxxxxx
import bob
def gmm_from_data(data):
"""Unmangles a bob.machine.GMMMachine from a BEAT Data object"""
dim_c, dim_d = data.means.shape
gmm = bob.machine.GMMMachine(dim_c, dim_d)
gmm.weights = data.weights
gmm.means = data.means
gmm.variances = data.variances
gmm.variance_thresholds = data.variance_thresholds
return gmm
def stats_from_data(data):
"""Unmangles a bob.machine.GMMStats from a BEAT Data object"""
dim_c, dim_d = data.sum_px.shape
stat = bob.machine.GMMStats(dim_c, dim_d)
stat.t = long(data.t)
stat.n = data.n
stat.sum_px = data.sum_px
stat.sum_pxx = data.sum_pxx
return stat
class Algorithm:
def __init__(self):
self.ubm = None
self.templates = None
def process(self, inputs, outputs):
# retrieve the UBM once
if self.ubm is None:
inputs['ubm'].next()
self.ubm = gmm_from_data(inputs['ubm'].data)
# retrieve all the templates once
if self.templates is None:
self.templates = {}
group = inputs.groupOf('template_model')
while group.hasMoreData():
group.next()
template_id = group['template_id'].data.value
self.templates[template_id] = dict(
client_id = group['template_client_id'].data.value,
model = gmm_from_data(group['template_model'].data),
)
# process the probe
comparison_ids = inputs['comparison_ids'].data.value
statistics = stats_from_data(inputs['probe_statistics'].data)
scores = []
for comparison_id in comparison_ids:
template_client_identity = self.templates[comparison_id]['client_id']
score = bob.machine.linear_scoring([self.templates[comparison_id]['model']],
self.ubm, [statistics])[0,0]
scores.append({
'template_identity': template_client_identity,
'score': score,
})
outputs['scores'].write({
'client_identity': inputs['probe_client_id'].data.value,
'scores': scores
},
)
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
For a given set of feature vectors, a Gaussian Mixture Model (GMM) of the target client and an UBM-GMM, this algorithm computes the scoring using the linear scoring implemented on the Bob <https://www.idiap.ch/software/bob/docs/releases/last/sphinx/html/machine/generated/bob.machine.linear_scoring.html?highlight=linear%20scoring#bob.machine.linear_scoring>
This algorithm relies on the Bob library.
The inputs are:
The output are the scores.