From 119f9091ea60d81efabd7d20ff2490b9e7084778 Mon Sep 17 00:00:00 2001 From: Eric Bi Date: Tue, 1 Dec 2015 17:03:39 +0800 Subject: add detection of utterances without alignment, and skip them --- kaldi_io/init.lua | 8 ++++++++ kaldi_io/src/cwrapper_kaldi.cpp | 8 ++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/kaldi_io/init.lua b/kaldi_io/init.lua index e538ee5..5193504 100644 --- a/kaldi_io/init.lua +++ b/kaldi_io/init.lua @@ -36,6 +36,7 @@ function KaldiReader:__init(global_conf, reader_conf) end function KaldiReader:get_data() + local fail_to_read_alignment = false if self.feat_repo:is_end() then return nil end @@ -75,6 +76,9 @@ function KaldiReader:get_data() local lab_utter = repo:get_utter(self.feat_repo, feat_utter:nrow(), self.debug) + if lab_utter == nil then + fail_to_read_alignment = true + end res[id] = lab_utter end -- add corresponding lookup features @@ -98,5 +102,9 @@ function KaldiReader:get_data() -- move the pointer to next self.feat_repo:next() collectgarbage("collect") + if fail_to_read_alignment then + nerv.info("[Kaldi IO] utterance %s alignment not found, skip it.", self.feat_repo:key()) + res = self:get_data() + end return res end diff --git a/kaldi_io/src/cwrapper_kaldi.cpp b/kaldi_io/src/cwrapper_kaldi.cpp index d16f316..542f1d0 100644 --- a/kaldi_io/src/cwrapper_kaldi.cpp +++ b/kaldi_io/src/cwrapper_kaldi.cpp @@ -150,8 +150,12 @@ extern "C" { Matrix *kaldi_label_repo_read_utterance(KaldiLabelRepo *repo, KaldiFeatureRepo *frepo, int nframes, lua_State *L, int debug) { - Matrix *mat; - kaldi::Posterior targets = repo->targets_reader->Value(frepo->utt); + Matrix *mat = NULL; + /* check if the alignment of the utterance exists, otherwise return NULL */ + kaldi::Posterior targets; + if (repo->targets_reader->HasKey(frepo->utt)) + targets = repo->targets_reader->Value(frepo->utt); + else return mat; int n = targets.size() < nframes ? targets.size() : nframes; int m = (int)targets[0].size(); -- cgit v1.2.3-70-g09d2 From 0465adc3cc86555a8bb752cab7c625e603e513ca Mon Sep 17 00:00:00 2001 From: Eric Bi Date: Wed, 2 Dec 2015 20:20:06 +0800 Subject: fix Makefile to find libluajit-5.1.so.2 --- kaldi_decode/src/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kaldi_decode/src/Makefile b/kaldi_decode/src/Makefile index 118420c..7cffbc2 100644 --- a/kaldi_decode/src/Makefile +++ b/kaldi_decode/src/Makefile @@ -5,7 +5,7 @@ CUDADIR := /usr/local/cuda/ nnet-forward: g++ -msse -msse2 -Wall -I $(KDIR)/src/ -pthread -DKALDI_DOUBLEPRECISION=0 -DHAVE_POSIX_MEMALIGN -Wno-sign-compare -Wno-unused-local-typedefs -Winit-self -DHAVE_EXECINFO_H=1 -rdynamic -DHAVE_CXXABI_H -DHAVE_ATLAS -I $(KDIR)/tools/ATLAS/include -I $(KDIR)/tools/openfst/include -Wno-sign-compare -g -fPIC -DHAVE_CUDA -I $(CUDADIR)/include -DKALDI_NO_EXPF -I $(NERVDIR)/install//include/luajit-2.0/ -I $(NERVDIR)/install/include/ -DLUA_USE_APICHECK -c -o nnet-forward.o nnet-forward.cc - g++ -rdynamic -Wl,-rpath=$(KDIR)/tools/openfst/lib -L$(CUDADIR)/lib64 -Wl,-rpath,$(CUDADIR)/lib64 -Wl,-rpath=$(KDIR)/src/lib -L. -L$(KDIR)/src/nnet/ -L$(KDIR)/src/cudamatrix/ -L$(KDIR)/src/lat/ -L$(KDIR)/src/hmm/ -L$(KDIR)/src/tree/ -L$(KDIR)/src/matrix/ -L$(KDIR)/src/util/ -L$(KDIR)/src/base/ nnet-forward.o $(KDIR)/src/nnet//libkaldi-nnet.so $(KDIR)/src/cudamatrix//libkaldi-cudamatrix.so $(KDIR)/src/lat//libkaldi-lat.so $(KDIR)/src/hmm//libkaldi-hmm.so $(KDIR)/src/tree//libkaldi-tree.so $(KDIR)/src/matrix//libkaldi-matrix.so $(KDIR)/src/util//libkaldi-util.so $(KDIR)/src/base//libkaldi-base.so -L$(KDIR)/tools/openfst/lib -lfst /usr/lib/liblapack.so /usr/lib/libcblas.so /usr/lib/libatlas.so /usr/lib/libf77blas.so -lm -lpthread -ldl -lcublas -lcudart -lkaldi-nnet -lkaldi-cudamatrix -lkaldi-lat -lkaldi-hmm -lkaldi-tree -lkaldi-matrix -lkaldi-util -lkaldi-base -lstdc++ -L$(NERVDIR)/install/lib -lnervcore -lluaT -rdynamic -Wl,-rpath=$(KDIR)//tools/openfst/lib -L$(DUDADIR)/lib64 -Wl,-rpath,$(CUDADIR)/lib64 -Wl,-rpath=$(KDIR)//src/lib -lfst -lm -lpthread -ldl -lcublas -lcudart -L $(NERVDIR)/luajit-2.0/src/ -lluajit -o nnet-forward + g++ -rdynamic -Wl,-rpath=$(KDIR)/tools/openfst/lib -L$(CUDADIR)/lib64 -Wl,-rpath=$(CUDADIR)/lib64 -Wl,-rpath=$(KDIR)/src/lib -L. -L$(KDIR)/src/nnet/ -L$(KDIR)/src/cudamatrix/ -L$(KDIR)/src/lat/ -L$(KDIR)/src/hmm/ -L$(KDIR)/src/tree/ -L$(KDIR)/src/matrix/ -L$(KDIR)/src/util/ -L$(KDIR)/src/base/ nnet-forward.o $(KDIR)/src/nnet//libkaldi-nnet.so $(KDIR)/src/cudamatrix//libkaldi-cudamatrix.so $(KDIR)/src/lat//libkaldi-lat.so $(KDIR)/src/hmm//libkaldi-hmm.so $(KDIR)/src/tree//libkaldi-tree.so $(KDIR)/src/matrix//libkaldi-matrix.so $(KDIR)/src/util//libkaldi-util.so $(KDIR)/src/base//libkaldi-base.so -L$(KDIR)/tools/openfst/lib -lfst /usr/lib/liblapack.so /usr/lib/libcblas.so /usr/lib/libatlas.so /usr/lib/libf77blas.so -lm -lpthread -ldl -lcublas -lcudart -lkaldi-nnet -lkaldi-cudamatrix -lkaldi-lat -lkaldi-hmm -lkaldi-tree -lkaldi-matrix -lkaldi-util -lkaldi-base -lstdc++ -L$(NERVDIR)/install/lib -Wl,-rpath=$(NERVDIR)/install/lib -lnervcore -lluaT -rdynamic -Wl,-rpath=$(KDIR)//tools/openfst/lib -L$(CUDADIR)/lib64 -Wl,-rpath=$(CUDADIR)/lib64 -Wl,-rpath=$(KDIR)//src/lib -lfst -lm -lpthread -ldl -lcublas -lcudart -L $(NERVDIR)/luajit-2.0/src/ -lluajit -o nnet-forward clean: -rm nnet-forward.o nnet-forward -- cgit v1.2.3-70-g09d2 From 24d56605428467e604afded423ba2ff49f2644e3 Mon Sep 17 00:00:00 2001 From: Eric Bi Date: Thu, 3 Dec 2015 20:12:59 +0800 Subject: fix last commit that broke decoding --- kaldi_io/init.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kaldi_io/init.lua b/kaldi_io/init.lua index 5193504..9f3ad55 100644 --- a/kaldi_io/init.lua +++ b/kaldi_io/init.lua @@ -76,7 +76,8 @@ function KaldiReader:get_data() local lab_utter = repo:get_utter(self.feat_repo, feat_utter:nrow(), self.debug) - if lab_utter == nil then + -- need provide 'gconf.decoding = true' while decoding + if not self.gconf.decoding and lab_utter == nil then fail_to_read_alignment = true end res[id] = lab_utter -- cgit v1.2.3-70-g09d2