summaryrefslogblamecommitdiff
path: root/examples/tnet_preprocessing_example.lua
blob: 4f36aa866acfb5b05ca5675763ce7721db6da497 (plain) (tree)
1
2
3
4

                      

                      





















                                                                             
                                     








                                                                          



                             
 























                                                          




                                               
require 'libspeech'
require 'layer.affine'
require 'layer.bias'
require 'layer.window'
frm_ext = 5
feat_repo = nerv.TNetFeatureRepo(
                                "/slfs1/users/mfy43/swb_ivec/train_bp.scp",
                                "/slfs1/users/mfy43/swb_ivec/plp_0_d_a.conf",
                                frm_ext)
lab_repo = nerv.TNetLabelRepo(
                                "/slfs1/users/mfy43/swb_ivec/ref.mlf",
                                "map",
                                "/slfs1/users/mfy43/swb_ivec/dict",
                                "*/",
                                "lab")
feat_utter = feat_repo:cur_utter()
-- print(feat_utter)
-- lab_utter = lab_repo:get_utter(feat_repo, feat_utter:nrow() - frm_ext * 2)
-- print(lab_utter)
gconf = {mat_type = nerv.CuMatrixFloat}
cf = nerv.ChunkFile("global_transf.nerv", "r")
bias1 = cf:read_chunk("bias1", gconf)
window1 = cf:read_chunk("window1", gconf)
bias2 = cf:read_chunk("bias2", gconf)
window2 = cf:read_chunk("window2", gconf)

cf2 = nerv.ChunkFile("feat_256", "r")
input = cf2:read_chunk("input", gconf)

step = frm_ext * 2 + 1
expanded = nerv.CuMatrixFloat(feat_utter:nrow(), feat_utter:ncol() * step)
expanded:expand_frm(nerv.CuMatrixFloat.new_from_host(feat_utter), frm_ext)

rearranged = expanded:create()
rearranged:rearrange_frm(expanded, step)

output1 = {expanded:create()}
output2 = {expanded:create()}
output3 = {expanded:create()}
output4 = {expanded:create()}

blayer1 = nerv.BiasLayer("b1", gconf, {bias = bias1,
                                dim_in = {429},
                                dim_out = {429}})
wlayer1 = nerv.WindowLayer("w1", gconf, {window = window1,
                                dim_in = {429},
                                dim_out = {429}})
blayer2 = nerv.BiasLayer("b1", gconf, {bias = bias2,
                                dim_in = {429},
                                dim_out = {429}})
wlayer2 = nerv.WindowLayer("w1", gconf, {window = window2,
                                dim_in = {429},
                                dim_out = {429}})
blayer1:init()
wlayer1:init()
blayer2:init()
wlayer2:init()

blayer1:propagate({rearranged}, output1)
wlayer1:propagate(output1, output2)
blayer2:propagate(output2, output3)
wlayer2:propagate(output3, output4)

for i = 0, 157 - 10 do
    row_diff = input.trans[i] - output4[1][i + 5]
    for j = 0, row_diff:ncol() - 1 do
        nerv.utils.printf("%.8f ", row_diff[j])
    end
    nerv.utils.printf("\n")
end