From f3216254fd078279494e84cc1a5e94e904b6741a Mon Sep 17 00:00:00 2001 From: Amit Agarwal Date: Fri, 5 Feb 2016 23:06:15 -0800 Subject: [PATCH] Added a check for inconsistent frameMode and Truncated settings. Also addresed some minor CR feedback. --- Source/CNTK/tests.cpp | 5 +++-- Source/Readers/HTKMLFReader/HTKMLFReader.cpp | 5 +++++ .../HTKMLFReader/utterancesourcemulti.h | 22 +++++++++---------- Tests/UnitTests/EvalTest/CNTKEvalTest.cpp | 5 +++-- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/Source/CNTK/tests.cpp b/Source/CNTK/tests.cpp index 7071c57a4172..cfa2f3d70444 100644 --- a/Source/CNTK/tests.cpp +++ b/Source/CNTK/tests.cpp @@ -115,8 +115,9 @@ void TestReader(const ConfigParameters& configBase) GetFileConfigNames(readerConfig, featureNames, labelNames); // setup minibatch matrices - Matrix featuresMatrix(0); - Matrix labelsMatrix(0); + int deviceId = 0; + Matrix featuresMatrix(deviceId); + Matrix labelsMatrix(deviceId); std::map*> matrices; matrices[featureNames[0]] = &featuresMatrix; matrices[labelNames[0]] = &labelsMatrix; diff --git a/Source/Readers/HTKMLFReader/HTKMLFReader.cpp b/Source/Readers/HTKMLFReader/HTKMLFReader.cpp index 37bab4a73f60..77901331f596 100644 --- a/Source/Readers/HTKMLFReader/HTKMLFReader.cpp +++ b/Source/Readers/HTKMLFReader/HTKMLFReader.cpp @@ -302,6 +302,11 @@ void HTKMLFReader::PrepareForTrainingOrTesting(const ConfigRecordType& m_frameMode = readerConfig(L"frameMode", true); m_verbosity = readerConfig(L"verbosity", 2); + if (m_frameMode && m_truncated) + { + InvalidArgument("'Truncated' cannot be 'true' in frameMode (i.e. when 'frameMode' is 'true')"); + } + // determine if we partial minibatches are desired wstring minibatchMode(readerConfig(L"minibatchMode", L"partial")); m_partialMinibatch = EqualCI(minibatchMode, L"partial"); diff --git a/Source/Readers/HTKMLFReader/utterancesourcemulti.h b/Source/Readers/HTKMLFReader/utterancesourcemulti.h index 5ecb304e158b..e5dda77d2530 100644 --- a/Source/Readers/HTKMLFReader/utterancesourcemulti.h +++ b/Source/Readers/HTKMLFReader/utterancesourcemulti.h @@ -189,7 +189,7 @@ class minibatchutterancesourcemulti : public minibatchsource std::vector> allchunks; // set of utterances organized in chunks, referred to by an iterator (not an index) std::vector>> classids; // [classidsbegin+t] concatenation of all state sequences - bool generatePhoneBoundaries; + bool m_generatePhoneBoundaries; std::vector>> phoneboundaries; bool issupervised() const { @@ -416,7 +416,7 @@ class minibatchutterancesourcemulti : public minibatchsource template std::vector>> getphonebound(const UTTREF &uttref) // return sub-vector of classids[] for a given utterance { - if (!generatePhoneBoundaries) + if (!m_generatePhoneBoundaries) LogicError("getphonebound: generation of phone boundaries is not enabled for this utterance source!"); std::vector>> allphoneboundaries; @@ -448,7 +448,7 @@ class minibatchutterancesourcemulti : public minibatchsource minibatchutterancesourcemulti(const std::vector> &infiles, const std::vector>> &labels, std::vector vdim, std::vector udim, std::vector leftcontext, std::vector rightcontext, size_t randomizationrange, const latticesource &lattices, const map &allwordtranscripts, const bool framemode) - : vdim(vdim), leftcontext(leftcontext), rightcontext(rightcontext), sampperiod(0), featdim(0), randomizationrange(randomizationrange), currentsweep(SIZE_MAX), lattices(lattices), allwordtranscripts(allwordtranscripts), framemode(framemode), chunksinram(0), timegetbatch(0), verbosity(2), generatePhoneBoundaries(!lattices.empty()) + : vdim(vdim), leftcontext(leftcontext), rightcontext(rightcontext), sampperiod(0), featdim(0), randomizationrange(randomizationrange), currentsweep(SIZE_MAX), lattices(lattices), allwordtranscripts(allwordtranscripts), framemode(framemode), chunksinram(0), timegetbatch(0), verbosity(2), m_generatePhoneBoundaries(!lattices.empty()) // [v-hansu] change framemode (lattices.empty()) into framemode (false) to run utterance mode without lattice // you also need to change another line, search : [v-hansu] comment out to run utterance mode without lattice { @@ -477,7 +477,7 @@ class minibatchutterancesourcemulti : public minibatchsource foreach_index (i, labels) { classids.push_back(unique_ptr>(new biggrowablevector())); - if (generatePhoneBoundaries) + if (m_generatePhoneBoundaries) phoneboundaries.push_back(unique_ptr>(new biggrowablevector())); // std::pair,std::vector> latticetocs; @@ -657,7 +657,7 @@ class minibatchutterancesourcemulti : public minibatchsource for (size_t t = e.firstframe; t < e.firstframe + e.numframes; t++) { classids[j]->push_back(e.classid); - if (generatePhoneBoundaries) + if (m_generatePhoneBoundaries) { if (e.phonestart != 0 && t == e.firstframe) phoneboundaries[j]->push_back((HMMIDTYPE)e.phonestart); @@ -671,7 +671,7 @@ class minibatchutterancesourcemulti : public minibatchsource } classids[j]->push_back((CLASSIDTYPE) -1); // append a boundary marker marker for checking - if (generatePhoneBoundaries) + if (m_generatePhoneBoundaries) phoneboundaries[j]->push_back((HMMIDTYPE) -1); // append a boundary marker marker for checking if (!labels[j].empty() && classids[j]->size() != _totalframes + utteranceset.size()) @@ -1298,7 +1298,7 @@ class minibatchutterancesourcemulti : public minibatchsource // resize feat and uids feat.resize(vdim.size()); uids.resize(classids.size()); - if (generatePhoneBoundaries) + if (m_generatePhoneBoundaries) phoneboundaries.resize(classids.size()); sentendmark.resize(vdim.size()); assert(feat.size() == vdim.size()); @@ -1314,13 +1314,13 @@ class minibatchutterancesourcemulti : public minibatchsource if (issupervised()) // empty means unsupervised training -> return empty uids { uids[j].resize(tspos); - if (generatePhoneBoundaries) + if (m_generatePhoneBoundaries) phoneboundaries[j].resize(tspos); } else { uids[i].clear(); - if (generatePhoneBoundaries) + if (m_generatePhoneBoundaries) phoneboundaries[i].clear(); } latticepairs.clear(); // will push_back() below @@ -1377,7 +1377,7 @@ class minibatchutterancesourcemulti : public minibatchsource { auto uttclassids = getclassids(uttref); std::vector>> uttphoneboudaries; - if (generatePhoneBoundaries) + if (m_generatePhoneBoundaries) uttphoneboudaries = getphonebound(uttref); foreach_index (j, uttclassids) { @@ -1386,7 +1386,7 @@ class minibatchutterancesourcemulti : public minibatchsource if (issupervised()) { uids[j][t + tspos] = uttclassids[j][t]; - if (generatePhoneBoundaries) + if (m_generatePhoneBoundaries) phoneboundaries[j][t + tspos] = uttphoneboudaries[j][t]; } } diff --git a/Tests/UnitTests/EvalTest/CNTKEvalTest.cpp b/Tests/UnitTests/EvalTest/CNTKEvalTest.cpp index 71a80d1d0b5f..625303d77264 100644 --- a/Tests/UnitTests/EvalTest/CNTKEvalTest.cpp +++ b/Tests/UnitTests/EvalTest/CNTKEvalTest.cpp @@ -36,8 +36,9 @@ void DoCommand(const ConfigParameters& configRoot) std::map*> outputMatrices; std::wstring inputName = L"features"; std::wstring outputName = L"CE.BFF.FF.P"; - Matrix* matrix = inputMatrices[inputName] = new Matrix(dimFeatures, mbSize, 0); - outputMatrices[outputName] = new Matrix(dimLabels, mbSize, 0); + int deviceId = 0; + Matrix* matrix = inputMatrices[inputName] = new Matrix(dimFeatures, mbSize, deviceId); + outputMatrices[outputName] = new Matrix(dimLabels, mbSize, deviceId); std::map*> input; std::map*> output;