-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTargetTRN.py
59 lines (42 loc) · 1.48 KB
/
TargetTRN.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
from __future__ import division
import numpy as numpy
import pickle
import os
import sys
import code
import math
from accStat import Collect_Stats, MAPaDapt, Loglikelihood, htkread, multi_thread
#======================================
# 3. MAP - target model formation ||
#======================================
nmix=4
ubmDir= 'GMM' + str(nmix)
MapItr, Tau =3, 10.0 #[no of MAP iteration], [value of relevance factor]
Tardest='MAP' + str(MapItr) + '_Tau' + str(Tau) #output directory of target model
if not os.path.exists(Tardest):
os.makedirs(Tardest)
#load UBM (previous trained)
with open(ubmDir + '/' + 'ubm') as f:
print "load ubm .. %s" %(ubmDir + '/' + 'ubm')
ubm_mu, ubm_cov, ubm_w = pickle.load(f)
print ubm_mu.shape, ubm_cov.shape, ubm_w.shape
#load the target training list file
tarList=[]; scpFile=[]
with open('target.ndx','r') as fin:
for x in fin:
x=x.split(','); mFile=x[0]; fFile=x[1].strip('\n')
tarList.append(mFile)
scpFile.append(fFile)
#for target wise model
unQtarget=set(tarList)
for x in unQtarget:
print x
index = [i for i in range(len(tarList)) if x in tarList[i]]
trnFile=[]
for i,j in enumerate(index):
trnFile.append(scpFile[j])
#call map subroutine
m_, v_, w_=MAPaDapt(trnFile, ubm_mu, ubm_cov, ubm_w, Tau, MapItr, 'Mean')
#save target model
with open(Tardest + '/' + x, 'w') as f:
pickle.dump([m_, v_, w_], f)