diff options
author | Determinant <[email protected]> | 2015-08-27 17:20:34 +0800 |
---|---|---|
committer | Determinant <[email protected]> | 2015-08-27 17:20:34 +0800 |
commit | 9e1a0931be43ea80fe7d41154007839b637d4e08 (patch) | |
tree | 3befde05800d9df242895c71e774a041f8bad9dc | |
parent | b50ec827c6fd7d95375e627a1bedd1236ef02e8c (diff) |
add frm expand and trim in kaldi_io
-rw-r--r-- | htk_io/init.lua | 14 | ||||
-rw-r--r-- | kaldi_io/init.lua | 51 |
2 files changed, 47 insertions, 18 deletions
diff --git a/htk_io/init.lua b/htk_io/init.lua index abaa794..b360b67 100644 --- a/htk_io/init.lua +++ b/htk_io/init.lua @@ -14,12 +14,14 @@ function TNetReader:__init(global_conf, reader_conf) reader_conf.conf_file, reader_conf.frm_ext) self.lab_repo = {} - for id, mlf_spec in pairs(reader_conf.mlfs) do - self.lab_repo[id] = nerv.TNetLabelRepo(mlf_spec.file, - mlf_spec.format, - mlf_spec.format_arg, - mlf_spec.dir, - mlf_spec.ext) + if reader_conf.mlfs then + for id, mlf_spec in pairs(reader_conf.mlfs) do + self.lab_repo[id] = nerv.TNetLabelRepo(mlf_spec.file, + mlf_spec.format, + mlf_spec.format_arg, + mlf_spec.dir, + mlf_spec.ext) + end end end diff --git a/kaldi_io/init.lua b/kaldi_io/init.lua index 930705e..3fc5b10 100644 --- a/kaldi_io/init.lua +++ b/kaldi_io/init.lua @@ -13,20 +13,24 @@ function KaldiReader:__init(global_conf, reader_conf) self.feat_repo = nerv.KaldiFeatureRepo(reader_conf.feature_rspecifier) self.lab_repo = {} - for id, mlf_spec in pairs(reader_conf.mlfs) do - if mlf_spec.format == nil then - nerv.error("format spec is expected for label %s", id) + if reader_conf.mlfs then + for id, mlf_spec in pairs(reader_conf.mlfs) do + if mlf_spec.format == nil then + nerv.error("format spec is expected for label %s", id) + end + self.lab_repo[id] = nerv.KaldiLabelRepo(mlf_spec.targets_rspecifier, + mlf_spec.format) end - self.lab_repo[id] = nerv.KaldiLabelRepo(mlf_spec.targets_rspecifier, - mlf_spec.format) end self.lookup_repo = {} - for id, lookup_spec in pairs(reader_conf.lookup) do - if lookup_spec.map_rspecifier == nil then - nerv.error("map spec is expected for lookup %s", id) + if reader_conf.lookup then + for id, lookup_spec in pairs(reader_conf.lookup) do + if lookup_spec.map_rspecifier == nil then + nerv.error("map spec is expected for lookup %s", id) + end + self.lookup_repo[id] = nerv.KaldiLookupFeatureRepo(lookup_spec.targets_rspecifier, + lookup_spec.map_rspecifier) end - self.lookup_repo[id] = nerv.KaldiLookupFeatureRepo(lookup_spec.targets_rspecifier, - lookup_spec.map_rspecifier) end end @@ -36,8 +40,31 @@ function KaldiReader:get_data() end local res = {} -- read Kaldi feature - local feat_utter = self.feat_repo:cur_utter(self.debug) - -- global transf + local raw = self.gconf.cumat_type.new_from_host(self.feat_repo:cur_utter(self.debug)) + local rearranged + if self.frm_ext and self.frm_ext > 0 then + local step = self.frm_ext * 2 + 1 + -- expand the feature + local expanded = self.gconf.cumat_type(raw:nrow(), raw:ncol() * step) + expanded:expand_frm(raw, self.frm_ext) + -- rearrange the feature (``transpose'' operation in TNet) + if self.gconf.rearrange then + rearranged = expanded:create() + rearranged:rearrange_frm(expanded, step) + else + rearranged = expanded + end + else + rearranged = raw + end + local feat_utter + if self.gconf.frm_trim then + feat_utter = self.gconf.mmat_type(rearranged:nrow() - self.gconf.frm_trim * 2, rearranged:ncol()) + rearranged:copy_toh(feat_utter, self.gconf.frm_trim, rearranged:nrow() - self.gconf.frm_trim) + else + feat_utter = self.gconf.mmat_type(rearranged:nrow(), rearranged:ncol()) + rearranged:copy_toh(feat_utter) + end res[self.feat_id] = feat_utter -- add corresponding labels for id, repo in pairs(self.lab_repo) do |