From 3f742c01540b8bad940d66331d562082a63d975b Mon Sep 17 00:00:00 2001 From: Determinant Date: Wed, 13 Jan 2016 12:05:48 +0800 Subject: support pure CPU reader --- htk_io/init.lua | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'htk_io') diff --git a/htk_io/init.lua b/htk_io/init.lua index b360b67..1cdabf1 100644 --- a/htk_io/init.lua +++ b/htk_io/init.lua @@ -6,6 +6,11 @@ function TNetReader:__init(global_conf, reader_conf) self.feat_id = reader_conf.id self.frm_ext = reader_conf.frm_ext self.gconf = global_conf + if self.gconf.use_cpu then + self.mat_type = self.gconf.mmat_type + else + self.mat_type = self.gconf.cumat_type + end self.debug = global_conf.debug if self.debug == nil then self.debug = false @@ -31,12 +36,15 @@ function TNetReader:get_data() end local res = {} -- read HTK feature - local raw = self.gconf.cumat_type.new_from_host(self.feat_repo:cur_utter(self.debug)) + local raw = self.feat_repo:cur_utter(self.debug) + if not self.gconf.use_cpu then + raw = self.gconf.cumat_type.new_from_host(raw) + end 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) + local expanded = self.mat_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 @@ -53,8 +61,12 @@ function TNetReader:get_data() 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) + if self.gconf.use_cpu then + feat_utter = rearranged + else + feat_utter = self.gconf.mmat_type(rearranged:nrow(), rearranged:ncol()) + rearranged:copy_toh(feat_utter) + end end res[self.feat_id] = feat_utter -- add corresponding labels -- cgit v1.2.3-70-g09d2