Skip to content

Commit

Permalink
Added a check for inconsistent frameMode and Truncated settings. Also…
Browse files Browse the repository at this point in the history
… addresed some minor CR feedback.
  • Loading branch information
amitaga committed Feb 6, 2016
1 parent 2f9a48c commit f321625
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
5 changes: 3 additions & 2 deletions Source/CNTK/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ void TestReader(const ConfigParameters& configBase)
GetFileConfigNames(readerConfig, featureNames, labelNames);

// setup minibatch matrices
Matrix<ElemType> featuresMatrix(0);
Matrix<ElemType> labelsMatrix(0);
int deviceId = 0;
Matrix<ElemType> featuresMatrix(deviceId);
Matrix<ElemType> labelsMatrix(deviceId);
std::map<std::wstring, Matrix<ElemType>*> matrices;
matrices[featureNames[0]] = &featuresMatrix;
matrices[labelNames[0]] = &labelsMatrix;
Expand Down
5 changes: 5 additions & 0 deletions Source/Readers/HTKMLFReader/HTKMLFReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,11 @@ void HTKMLFReader<ElemType>::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");
Expand Down
22 changes: 11 additions & 11 deletions Source/Readers/HTKMLFReader/utterancesourcemulti.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class minibatchutterancesourcemulti : public minibatchsource
std::vector<std::vector<utterancechunkdata>> allchunks; // set of utterances organized in chunks, referred to by an iterator (not an index)
std::vector<unique_ptr<biggrowablevector<CLASSIDTYPE>>> classids; // [classidsbegin+t] concatenation of all state sequences

bool generatePhoneBoundaries;
bool m_generatePhoneBoundaries;
std::vector<unique_ptr<biggrowablevector<HMMIDTYPE>>> phoneboundaries;
bool issupervised() const
{
Expand Down Expand Up @@ -416,7 +416,7 @@ class minibatchutterancesourcemulti : public minibatchsource
template <class UTTREF>
std::vector<shiftedvector<biggrowablevector<HMMIDTYPE>>> 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<shiftedvector<biggrowablevector<HMMIDTYPE>>> allphoneboundaries;
Expand Down Expand Up @@ -448,7 +448,7 @@ class minibatchutterancesourcemulti : public minibatchsource
minibatchutterancesourcemulti(const std::vector<std::vector<wstring>> &infiles, const std::vector<map<wstring, std::vector<msra::asr::htkmlfentry>>> &labels,
std::vector<size_t> vdim, std::vector<size_t> udim, std::vector<size_t> leftcontext, std::vector<size_t> rightcontext, size_t randomizationrange,
const latticesource &lattices, const map<wstring, msra::lattices::lattice::htkmlfwordsequence> &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
{
Expand Down Expand Up @@ -477,7 +477,7 @@ class minibatchutterancesourcemulti : public minibatchsource
foreach_index (i, labels)
{
classids.push_back(unique_ptr<biggrowablevector<CLASSIDTYPE>>(new biggrowablevector<CLASSIDTYPE>()));
if (generatePhoneBoundaries)
if (m_generatePhoneBoundaries)
phoneboundaries.push_back(unique_ptr<biggrowablevector<HMMIDTYPE>>(new biggrowablevector<HMMIDTYPE>()));

// std::pair<std::vector<wstring>,std::vector<wstring>> latticetocs;
Expand Down Expand Up @@ -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);
Expand All @@ -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())
Expand Down Expand Up @@ -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());
Expand All @@ -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
Expand Down Expand Up @@ -1377,7 +1377,7 @@ class minibatchutterancesourcemulti : public minibatchsource
{
auto uttclassids = getclassids(uttref);
std::vector<shiftedvector<biggrowablevector<HMMIDTYPE>>> uttphoneboudaries;
if (generatePhoneBoundaries)
if (m_generatePhoneBoundaries)
uttphoneboudaries = getphonebound(uttref);
foreach_index (j, uttclassids)
{
Expand All @@ -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];
}
}
Expand Down
5 changes: 3 additions & 2 deletions Tests/UnitTests/EvalTest/CNTKEvalTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ void DoCommand(const ConfigParameters& configRoot)
std::map<std::wstring, Matrix<ElemType>*> outputMatrices;
std::wstring inputName = L"features";
std::wstring outputName = L"CE.BFF.FF.P";
Matrix<ElemType>* matrix = inputMatrices[inputName] = new Matrix<ElemType>(dimFeatures, mbSize, 0);
outputMatrices[outputName] = new Matrix<ElemType>(dimLabels, mbSize, 0);
int deviceId = 0;
Matrix<ElemType>* matrix = inputMatrices[inputName] = new Matrix<ElemType>(dimFeatures, mbSize, deviceId);
outputMatrices[outputName] = new Matrix<ElemType>(dimLabels, mbSize, deviceId);

std::map<std::wstring, std::vector<ElemType>*> input;
std::map<std::wstring, std::vector<ElemType>*> output;
Expand Down

0 comments on commit f321625

Please sign in to comment.