summaryrefslogtreecommitdiff
path: root/kaldi_io/init.lua
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2015-08-27 17:20:34 +0800
committerDeterminant <[email protected]>2015-08-27 17:20:34 +0800
commit9e1a0931be43ea80fe7d41154007839b637d4e08 (patch)
tree3befde05800d9df242895c71e774a041f8bad9dc /kaldi_io/init.lua
parentb50ec827c6fd7d95375e627a1bedd1236ef02e8c (diff)
add frm expand and trim in kaldi_io
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