/** check for duplicate labels (with a different Purpose) */ bool hasUniqueLabels( const LabelMap& labelmap ) { set<string> lablist; for (LabelMap::const_iterator it=labelmap.begin(); it!=labelmap.end(); it++) { string name = it->second; if (lablist.find( it->second )!=lablist.end() ) { return false; } lablist.insert( name ); } return true; }
void ParserBase::popLabelInfo() { assert(!m_labelInfos.empty()); LabelInfo &info = m_labelInfos.back(); LabelMap labels = info.labels; // shallow copy for (unsigned int i = 0; i < info.gotos.size(); i++) { const GotoInfo &gotoInfo = info.gotos[i]; LabelMap::const_iterator iter = info.labels.find(gotoInfo.label); if (iter == info.labels.end()) { invalidateGoto(gotoInfo.stmt, UndefLabel); error("'goto' to undefined label '%s': %s", gotoInfo.label.c_str(), getMessage(gotoInfo.loc.get()).c_str()); continue; } const LabelStmtInfo &labelInfo = iter->second; if (gotoInfo.label.find(YIELD_LABEL_PREFIX) == 0) { labels.erase(gotoInfo.label); continue; } int labelScopeId = labelInfo.scopeId; bool found = false; for (int j = gotoInfo.scopes.size() - 1; j >= 0; j--) { if (labelScopeId == gotoInfo.scopes[j]) { found = true; break; } } if (!found) { invalidateGoto(gotoInfo.stmt, InvalidBlock); error("'goto' into loop or switch statement " "is disallowed: %s", getMessage(gotoInfo.loc.get()).c_str()); continue; } else { labels.erase(gotoInfo.label); } } // now invalidate all un-used labels for (LabelMap::const_iterator it(labels.begin()); it != labels.end(); ++it) { invalidateLabel(it->second.stmt); } m_labelInfos.pop_back(); }
/** archive the trained model and return a CVAC style path to the archive; * This file should include the following: * Name of Detector * Name of Extractor * Name of Matcher * Filename of vocabulary * Filename of svm result * OpenCV Version * Optional: one-class ID */ FilePath BowICETrainI::createArchive( DetectorDataArchive& dda, bowCV* pBowCV, const LabelMap& labelmap, const string& clientName, const string& CVAC_DataDir, const string& tempDir ) { std::string clientDir = mServiceMan->getSandbox()->createClientDir(clientName); std::string archiveFilename = getDateFilename(clientDir, "bow")+ ".zip"; dda.setArchiveFilename(archiveFilename); dda.addFile(bowCV::BOW_VOC_FILE, tempDir + "/" + pBowCV->filenameVocabulary); dda.addFile(bowCV::BOW_SVM_FILE, tempDir + "/" + pBowCV->filenameSVM); for (LabelMap::const_iterator it=labelmap.begin(); it!=labelmap.end(); it++) { string classID = "labelname_" + getPurposeName( it->first ); dda.setProperty( classID, it->second ); } dda.createArchive(tempDir); mServiceMan->getSandbox()->deleteTrainingDir(clientName); // create a CVAC FilePath out of the DDA file system path FilePath file; file.filename = getFileName(archiveFilename); std::string relDir; int idx = clientDir.find(CVAC_DataDir.c_str(), 0, CVAC_DataDir.length()); if (idx == 0) { relDir = clientDir.substr(CVAC_DataDir.length() + 1); }else { relDir = clientDir; } file.directory.relativePath = relDir; return file; }
// --------------------------------------------------------------------------- // LorisMorpher updateEnvelopes // --------------------------------------------------------------------------- // Taking it on faith that the EnvelopeReaders will not be destroyed before // we are done using them! // long LorisMorpher::updateEnvelopes( void ) { // first render all the labeled (morphed) Partials: // std::cerr << "** Morphing Partials labeled " << labelMap.begin()->first; // std::cerr << " to " << (--labelMap.end())->first << std::endl; long envidx = 0; LabelMap::iterator it; for( it = labelMap.begin(); it != labelMap.end(); ++it, ++envidx ) { long label = it->first; std::pair<long, long> & indices = it->second; Breakpoint & bp = morphed_envelopes.valueAt(envidx); long isrc = indices.first; long itgt = indices.second; // this should not happen: if ( itgt < 0 && isrc < 0 ) { #ifdef DEBUG_LORISGENS std::cerr << "HEY!!!! The labelMap had a pair of bogus indices in it at pos " << envidx << std::endl; #endif continue; } // note: the time argument for all these morphParameters calls // is irrelevant, since it is only used to index the morphing // functions, which, as defined above, do not use the time // argument, they can only return their current value. if ( itgt < 0 ) { // morph from the source to a dummy: // std::cerr << "** Fading from source " << envidx << std::endl; bp = morpher.fadeSrcBreakpoint( src_reader->valueAt(isrc), 0 ); } else if ( isrc < 0 ) { // morph from a dummy to the target: // std::cerr << "** Fading to target " << envidx << std::endl; bp = morpher.fadeTgtBreakpoint( tgt_reader->valueAt(itgt), 0 ); } else { // morph from the source to the target: // std::cerr << "** Morphing source to target " << envidx << std::endl; bp = morpher.morphBreakpoints( src_reader->valueAt(isrc), tgt_reader->valueAt(itgt), 0 ); } } // render unlabeled source Partials: // std::cerr << "** Crossfading " << src_unlabeled.size(); // std::cerr << " unlabeled source Partials" << std::endl; for( long i = 0; i < src_unlabeled.size(); ++i, ++envidx ) { // fade from the source: Breakpoint & bp = morphed_envelopes.valueAt(envidx); bp = morpher.fadeSrcBreakpoint( src_reader->valueAt( src_unlabeled[i] ), 0 ); } // render unlabeled target Partials: // std::cerr << "** Crossfading " << tgt_unlabeled.size(); // std::cerr << " unlabeled target Partials" << std::endl; for( long i = 0; i < tgt_unlabeled.size(); ++i, ++envidx ) { // fade to the target: Breakpoint & bp = morphed_envelopes.valueAt(envidx); bp = morpher.fadeTgtBreakpoint( tgt_reader->valueAt( tgt_unlabeled[i] ), 0 ); } // tag these envelopes: EnvelopeReader::Tags()[ tag ] = &morphed_envelopes; return morphed_envelopes.size(); }