summaryrefslogtreecommitdiff
path: root/kaldi_io/init.lua
diff options
context:
space:
mode:
authorYimmon Zhuang <[email protected]>2015-08-27 19:46:01 +0800
committerYimmon Zhuang <[email protected]>2015-08-27 19:46:01 +0800
commitd7ff508792874628bf65f3f2607824b73db5ddbb (patch)
tree530f345a34fda5d87303f3c2e64a8aa99d0d0894 /kaldi_io/init.lua
parent77084d50207b6078460e83fe6f069967a6e11ccc (diff)
parent9e1a0931be43ea80fe7d41154007839b637d4e08 (diff)
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'kaldi_io/init.lua')
-rw-r--r--kaldi_io/init.lua51
1 files changed, 39 insertions, 12 deletions
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