This version of the UBM training, normalize the data before the kmeans 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.

Unnamed group

Endpoint Name Data Format Nature
features system/array_2d_floats/1 Input
ubm tutorial/gmm/1 Output

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

Name Description Type Default Range/Choices
number-of-gaussians uint32 100
maximum-number-of-iterations uint32 10
xxxxxxxxxx
110
 
1
import bob
2
import numpy
3
from bob.machine import GMMMachine
4
5
6
7
class Algorithm:
8
9
    def __init__(self):
10
        self.number_of_gaussians = 100
11
        self.max_iterations = 10
12
        self.data = []
13
14
15
    def setup(self, parameters):
16
        self.number_of_gaussians = parameters.get('number-of-gaussians',
17
                                                  self.number_of_gaussians)
18
19
        self.max_iterations = parameters.get('maximum-number-of-iterations',
20
                                             self.max_iterations)
21
22
        return True
23
      
24
    def __normalize_std_array__(self, array):
25
      """Applies a unit variance normalization to an array"""
26
27
      # Initializes variables
28
      n_samples = array.shape[0]
29
      length = array.shape[1]
30
      mean = numpy.ndarray((length,), 'float64')
31
      std = numpy.ndarray((length,), 'float64')
32
33
      mean.fill(0)
34
      std.fill(0)
35
36
      # Computes mean and variance
37
      for k in range(n_samples):
38
        x = array[k,:].astype('float64')
39
        mean += x
40
        std += (x ** 2)
41
42
      mean /= n_samples
43
      std /= n_samples
44
      std -= (mean ** 2)
45
      std = std ** 0.5 # sqrt(std)
46
  
47
      ar_std_list = []
48
      for k in range(n_samples):
49
        ar_std_list.append(array[k,:].astype('float64') / std)
50
      ar_std = numpy.vstack(ar_std_list)
51
52
      return (ar_std,std)
53
54
55
    def __multiply_vectors_by_factors__(self, matrix, vector):
56
      """Used to unnormalize some data"""
57
      for i in range(0, matrix.shape[0]):
58
        for j in range(0, matrix.shape[1]):
59
          matrix[i, j] *= vector[j]      
60
61
62
    def process(self, inputs, outputs):
63
        self.data.append(inputs["features"].data.value)
64
65
        if not(inputs.hasMoreData()):
66
            # create array set used for training
67
            training_set = numpy.vstack(self.data)
68
            input_size = training_set.shape[1]            
69
70
            # create the KMeans and UBM machine
71
            kmeans = bob.machine.KMeansMachine(int(self.number_of_gaussians), input_size)
72
            ubm = bob.machine.GMMMachine(int(self.number_of_gaussians), input_size)
73
74
            # create the KMeansTrainer
75
            kmeans_trainer = bob.trainer.KMeansTrainer()
76
            kmeans_trainer.initialization_method = bob.trainer.KMeansTrainer.RANDOM_NO_DUPLICATE
77
            kmeans_trainer.max_iterations = int(self.max_iterations)
78
79
            # train using the KMeansTrainer            
80
            normalized_data, std_array = self.__normalize_std_array__(training_set) #normlize before training
81
            kmeans_trainer.train(kmeans, normalized_data)
82
83
            (variances, weights) = kmeans.get_variances_and_weights_for_each_cluster(normalized_data)
84
            means = kmeans.means
85
           
86
            #undoing the normalization
87
            self.__multiply_vectors_by_factors__(means, std_array)
88
            self.__multiply_vectors_by_factors__(variances, std_array ** 2)
89
            
90
91
            # initialize the GMM
92
            ubm.means = means
93
            ubm.variances = variances
94
            ubm.weights = weights
95
96
            # train the GMM
97
            trainer = bob.trainer.ML_GMMTrainer()
98
            trainer.max_iterations = int(self.max_iterations)
99
            trainer.train(ubm, training_set)
100
101
            # outputs data
102
            outputs["ubm"].write({
103
                'weights':              ubm.weights,
104
                'means':                ubm.means,
105
                'variances':            ubm.variances,
106
                'variance_thresholds':  ubm.variance_thresholds,
107
            })
108
109
        return True
110

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 Gaussian Mixture Models (GMM), this algorithm implements the Universal Background Model (UBM) training described in [Reynolds2000].

First, this algorithm estimates the means, diagonal covariance matrix and the weights of each gaussian component using the KMeans clustering. After, only the means are re-estimated using the Maximum Likelihood (ML) estimator.

This version of the UBM training normalizes the input data before the kmeans training.

This algorithm relies on the Bob library.

The input, features, is a training set of floating point vectors as a two-dimensional array of floats (64 bits), the number of rows corresponding to the number of training samples, and the number of columns to the dimensionality of the training samples. The output, ubm, is the GMM trained using the ML estimator.

[Reynolds2000]
  1. Reynolds, T. Quatieri, R. Dunn: Speaker verification using adapted Gaussian mixture models. Digital signal processing 10.1 (2000): 19-41.
No experiments are using this algorithm.
Created with Raphaël 2.1.2[compare]tpereira/ubm_training/1tpereira/ubm_training/2Aug29tpereira/ubm_training_nomalize_kmeans/12014Sep5tpereira/ubm_training/6Mar282015Jul22

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