-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplda_train.py
71 lines (51 loc) · 1.55 KB
/
plda_train.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# train plda model, save and load the model, enroll, generate scores
import bob.learn.em
import numpy
import pickle
import bob
data1 = numpy.array(
[[3,-3,100],
[4,-4,50],
[40,-40,150]], dtype=numpy.float64)
data2 = numpy.array(
[[3,6,-50],
[4,8,-100],
[1, 4, 62],
[40,79,-800]], dtype=numpy.float64)
dummy_data = [data1,data2]
embedding_dim = 3
F_rank = 1
G_rank = 2
pldabase = bob.learn.em.PLDABase(embedding_dim, F_rank, G_rank)
trainer = bob.learn.em.PLDATrainer()
bob.learn.em.train(trainer, pldabase, dummy_data, max_iterations=40)
# saver
f = bob.io.base.HDF5File('plda_train.hdf5', 'w')
# save model
pldabase.save(f)
print(pldabase)
# main plda trained model
plda = bob.learn.em.PLDAMachine(pldabase)
# loader
f = bob.io.base.HDF5File('plda_train.hdf5', 'r')
pldabase_2 = bob.learn.em.PLDABase(embedding_dim, F_rank, G_rank)
pldabase_2.load(f)
# main plda trained model loaded
plda_2 = bob.learn.em.PLDAMachine(pldabase_2)
# main plda trained model loaded
plda_2 = bob.learn.em.PLDAMachine(pldabase_2)
# dummy no weight
pldabase_3 = bob.learn.em.PLDABase(embedding_dim, F_rank, G_rank)
plda_3 = bob.learn.em.PLDAMachine(pldabase_3)
# check plda results for online and loaded model
samples = numpy.array(
[[3.5,-3.4,102],
[4.5,-4.3,56]], dtype=numpy.float64)
loglike = plda.compute_log_likelihood(samples)
loglike_2 = plda_2.compute_log_likelihood(samples)
loglike_3 = plda_3.compute_log_likelihood(samples)
print(loglike)
print('---------------')
print(loglike_2)
print('---------------')
print(loglike_3)