From ab3887c6ca34e4d01daac3badb7b7468aaa36e43 Mon Sep 17 00:00:00 2001 From: yemaozi88 <428968@gmail.com> Date: Mon, 4 Feb 2019 20:32:12 +0100 Subject: [PATCH] sp is added to the model. --- .vs/acoustic_model/v15/.suo | Bin 97792 -> 97792 bytes acoustic_model/fame_hmm.py | 120 ++++++++++++++++++++++++++++++------ 2 files changed, 100 insertions(+), 20 deletions(-) diff --git a/.vs/acoustic_model/v15/.suo b/.vs/acoustic_model/v15/.suo index 7775f45e621950b937c9b0523a5af065e8b353f2..ce9095444dca9c05b39c00500ddc4d81ab0ec4d8 100644 GIT binary patch delta 2363 zcmb7^e^69a6vy{mc7cUOmY=TtTozDDlm+n@zg%EbGt`B|A4G(2P#T_Py}dXr^ZD&V1&ad+vSb z-upfGUDth`>%Ok5AV#mzXtZF|=kvj62t=GHk7tuyO@BlV4PK)%L|pYs3)@W;$VnU3 zZbl>;7{DZu2Jrb<%Z9%b%mF$z{wGEf;7u3WdH$YmZrTj==7UT%D(0Ie_@dA6 z>$Zh;94LvUNQNfniDu;b;P`goiKE&vBDAjuLVFP}P_58j^hFce zF9YkrMD4|xUwh&E+jE%b*WMq?MNCMK+P7<#z?rE1v*?S7Li-sfxg`Goc*z@M-JzEGqbb}4ugEqDghfOVi2Ost*1W}6WA8IdGRIBIL?E}u-P{BwPBbgLSE1-1>m z2Kasb@QJ!ya>v>gd*mPum@G`O7;lhl(7Hpum^dWIY27pL1`gsYd^cL0#w}SlWDAo` zY^hjr7f1!K1F`sS*bcB)?Y{xLU-g9?2jIU6I@OpPmV+bR<*ACZsEg#OOy0=kT*h6I z=3a9qyV!EMFSrZxCt6<7^Kuu8Q`{n;KSu?)(QlGakBlr)dh zlsfw%k}DX$*lJXat*2JP02d)6;b4Nh7Wxlj4fv7LI&1}w4iW`Mk#$<@rg!XEr0@`!o~rFi3t z<$7|Ww_T0sDv`dM)5TJ5Wx?EDIVes)N4nfXA&RYLNH;EqwVEa=wyGhL>lp5Ukb)Zz z8p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*ioLh!37ikMC@u-6`tiVp8IYLJ9j=BeAiE rKr5Nm_cl^tyzpVVlA=~rQf@qV4P8s)tg|uRxQ@=Jjy;9z21x!F_%~6M diff --git a/acoustic_model/fame_hmm.py b/acoustic_model/fame_hmm.py index 881dec3..19d5f56 100644 --- a/acoustic_model/fame_hmm.py +++ b/acoustic_model/fame_hmm.py @@ -25,13 +25,17 @@ make_label = 0 # it takes roughly 4800 sec on Surface pro 2. make_htk_files = 0 extract_features = 0 flat_start = 0 -train_model_without_sp = 1 +train_model_without_sp = 0 +add_sp = 0 +train_model_with_sp = 0 + # pre-defined values. dataset_list = ['devel', 'test', 'train'] hmmdefs_name = 'hmmdefs' +proto_name = 'proto39' lexicon_asr = os.path.join(default.fame_dir, 'lexicon', 'lex.asr') lexicon_oov = os.path.join(default.fame_dir, 'lexicon', 'lex.oov') @@ -41,7 +45,8 @@ config_hcopy = os.path.join(config_dir, 'config.HCopy') config_train = os.path.join(config_dir, 'config.train') global_ded = os.path.join(config_dir, 'global.ded') mkphones_led = os.path.join(config_dir, 'mkphones.led') -prototype = os.path.join(config_dir, 'proto39') +sil_hed = os.path.join(config_dir, 'sil.hed') +prototype = os.path.join(config_dir, proto_name) model_dir = os.path.join(default.htk_dir, 'model') @@ -55,6 +60,7 @@ lexicon_htk = os.path.join(lexicon_dir, 'lex.htk') phonelist_txt = os.path.join(config_dir, 'phonelist.txt') model0_dir = os.path.join(model_dir, 'hmm0') +model1_dir = os.path.join(model_dir, 'hmm1') feature_dir = os.path.join(default.htk_dir, 'mfc') if not os.path.exists(feature_dir): @@ -66,6 +72,13 @@ label_dir = os.path.join(default.htk_dir, 'label') if not os.path.exists(label_dir): os.makedirs(label_dir) +## training +hcompv_scp_train = os.path.join(tmp_dir, 'train.scp') +mlf_file_train = os.path.join(label_dir, 'train_phone.mlf') + +## train without sp +niter_max = 10 + ## ======================= make lexicon for HTK ======================= if make_lexicon: @@ -95,6 +108,7 @@ if make_lexicon: ## ======================= make label files ======================= if make_label: + # train_2002_gongfansaken_10347.lab is empty. should be removed. for dataset in dataset_list: timer_start = time.time() print("==== making label files on dataset {}".format(dataset)) @@ -216,45 +230,111 @@ if extract_features: ## ======================= flat start monophones ======================= if flat_start: - hcompv_scp = os.path.join(tmp_dir, 'test.scp') - timer_start = time.time() print('==== flat start ====') - pyhtk.flat_start(config_train, hcompv_scp, model0_dir, prototype) + pyhtk.flat_start(config_train, hcompv_scp_train, model0_dir, prototype) # allocate mean & variance to all phones in the phone list + print('>>> allocating mean & variance to all phones in the phone list...') pyhtk.create_hmmdefs( - os.path.join(model0_dir, 'proto39'), + os.path.join(model0_dir, proto_name), os.path.join(model0_dir, 'hmmdefs'), phonelist_txt) + + # make macros + print('>>> making macros...') + with open(os.path.join(model0_dir, 'vFloors')) as f: + lines = f.read() + with open(os.path.join(model0_dir, 'macros'), 'wb') as f: + f.write(bytes('~o 39\n' + lines, 'ascii')) + print("elapsed time: {}".format(time.time() - timer_start)) -## ======================= estimate monophones ======================= +## ======================= train model without short pause ======================= if train_model_without_sp: - hcompv_scp = os.path.join(tmp_dir, 'test.scp') - mlf_file = os.path.join(label_dir, 'test_phone.mlf') - output_dir = os.path.join(model_dir, 'hmm1') - fh.make_new_directory(output_dir) + fh.make_new_directory(model1_dir) print('==== train model without sp ====') - if not os.path.exists(os.path.join(output_dir, 'iter0')): - shutil.copytree(model0_dir, os.path.join(output_dir, 'iter0')) - niter = 1 - for niter in range(1, 5): + if not os.path.exists(os.path.join(model1_dir, 'iter0')): + shutil.copytree(model0_dir, os.path.join(model1_dir, 'iter0')) + for niter in range(1, niter_max): timer_start = time.time() hmm_n = 'iter' + str(niter) hmm_n_pre = 'iter' + str(niter-1) - modeln_dir = os.path.join(output_dir, hmm_n) - modeln_dir_pre = os.path.join(output_dir, hmm_n_pre) + modeln_dir = os.path.join(model1_dir, hmm_n) + modeln_dir_pre = os.path.join(model1_dir, hmm_n_pre) # re-estimation fh.make_new_directory(modeln_dir) pyhtk.re_estimation( config_train, - os.path.join(modeln_dir_pre, 'proto39'), + os.path.join(modeln_dir_pre, 'macros'), os.path.join(modeln_dir_pre, hmmdefs_name), modeln_dir, - hcompv_scp, phonelist_txt, - mlf_file=mlf_file) + hcompv_scp_train, phonelist_txt, + mlf_file=mlf_file_train) + print("elapsed time: {}".format(time.time() - timer_start)) + + +## ======================= adding sp to the model ======================= +if add_sp: + print('==== adding sp to the model ====') + + # make model with sp. + print('>>> modifying the last model in the previous step...') + modeln_dir_pre = os.path.join(model1_dir, 'iter'+str(niter_max-1)) + modeln_dir = modeln_dir_pre.replace('iter' + str(niter_max-1), 'iter' + str(niter_max)) + fh.make_new_directory(modeln_dir) + shutil.copy( + os.path.join(modeln_dir_pre, 'macros'), + os.path.join(modeln_dir, 'macros')) + shutil.copy( + os.path.join(modeln_dir_pre, hmmdefs_name), + os.path.join(modeln_dir, hmmdefs_name)) + + ## ======================= + ## manually make changes to modeln_dir/hmmdefs + ## ======================= + # add states 'sil'. + # http://www.f.waseda.jp/yusukekondo/htk.html#flat_start_estimation + #shutil.copy( + # os.path.join(model_dir, 'hmmdefs.txt'), + # os.path.join(modeln_dir, hmmdefs_name)) + + #hmmdefs_file_pre = os.path.join(modeln_dir_pre, hmmdefs_name) + hmmdefs_file = os.path.join(modeln_dir, hmmdefs_name) + macros_file = os.path.join(modeln_dir, 'macros') + #with open(hmmdefs_file_pre) as f: + # lines = f.read() + #lines_ = lines.split('~h ') + #sil_model = [line for line in lines_ if line.split('\n')[0].replace('"', '') == 'sil'][0] + + # update hmmdefs and macros. + print('>>> updating hmmdefs and macros...') + modeln_dir_pre = modeln_dir + modeln_dir = modeln_dir.replace('iter' + str(niter_max), 'iter' + str(niter_max+1)) + fh.make_new_directory(modeln_dir) + pyhtk.include_sil_in_hmmdefs(macros_file, hmmdefs_file, modeln_dir, sil_hed, phonelist_txt) + + +## ======================= train model with short pause ======================= +if train_model_with_sp: + print('==== train model with sp ====') + for niter in range(niter_max+1, niter_max*2+1): + timer_start = time.time() + hmm_n = 'iter' + str(niter) + hmm_n_pre = 'iter' + str(niter-1) + modeln_dir = os.path.join(model1_dir, hmm_n) + modeln_dir_pre = os.path.join(model1_dir, hmm_n_pre) + + # re-estimation + fh.make_new_directory(modeln_dir) + pyhtk.re_estimation( + config_train, + os.path.join(modeln_dir_pre, 'macros'), + os.path.join(modeln_dir_pre, hmmdefs_name), + modeln_dir, + hcompv_scp_train, phonelist_txt, + mlf_file=mlf_file_train) print("elapsed time: {}".format(time.time() - timer_start)) \ No newline at end of file