예제 #1
0
/** 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;
}
예제 #2
0
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();
}
예제 #3
0
Texture* Resources::getTexture(const string& name)
{
    bool exists = textures.exists(name);
    if (exists)
    {
        return textures.get(name);
    }
    else
    {
        Texture* t = new Texture(name);
        if (!this->loadTexture(t))
        {
            delete t;
            return false;
        }
        textures.set(name, t);
        return t;
    }
}
예제 #4
0
void TreeOPE::GetTaxaLabels(NEWICKNODE *node, LabelMap &lm)
{
    if (node->Nchildren == 0)
    {
        std::string temp(node->label);
        lm.push(temp);
    }
    else
        for (int i = 0; i<node->Nchildren; i++)
            GetTaxaLabels(node->child[i], lm);
};
예제 #5
0
/** 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;
}
예제 #6
0
void BowICETrainI::process(const Identity &client,const ::RunSet& runset,
                           const TrainerProperties &tprops,
                           const Current& current)
{	
  localAndClientMsg(VLogger::DEBUG, NULL, "starting BOW training process\n");
  callbackPtr = TrainerCallbackHandlerPrx::uncheckedCast(
                     current.con->createProxy(client)->ice_oneway());		
  localAndClientMsg( VLogger::DEBUG_2, callbackPtr, 
                     "starting BOW training process, got callback pointer\n");

  PropertiesPtr props = (current.adapter->getCommunicator()->getProperties());
  std::string CVAC_DataDir = props->getProperty("CVAC.DataDir");

  // argument error checking: any data? consistent multiclass or pos/neg purpose?
  if (!checkPurposedLists( runset.purposedLists, callbackPtr ))
    return;

  DetectorDataArchive dda;
  bowCV* pBowCV = initialize(callbackPtr, tprops, dda, current);
  if ( NULL==pBowCV )
  {
    localAndClientMsg(VLogger::ERROR, callbackPtr,
                      "Trainer not initialized, aborting.\n");
    return;
  }

  // Ingest the data for processing, one purposed list at a time.
  // Also, determine if the classIDs match nicely to the labels;
  // if so, add appropriate annotations into the trained model file.
  LabelMap labelmap;
  bool labelsMatch = true;
  for (size_t listidx = 0; listidx < runset.purposedLists.size(); listidx++)
  {
    processPurposedList( runset.purposedLists[listidx], pBowCV,
                         callbackPtr, CVAC_DataDir,
                         labelmap, &labelsMatch );
  }
  if ( !labelsMatch ) labelmap.clear();
  if ( !hasUniqueLabels(labelmap) ) labelmap.clear();

  // create a sandbox for this client
  std::string connectName = cvac::getClientConnectionName(current);
  std::string clientName = mServiceMan->getSandbox()->createClientName(
    mServiceMan->getServiceName(), connectName);
  std::string tTempDir = mServiceMan->getSandbox()->createTrainingDir(clientName);
  // TODO: when should this tTempDir be deleted?

  localAndClientMsg(VLogger::INFO, callbackPtr, 
                    "Starting actual training procedure...\n"); 
  // Tell ServiceManager that we will listen for stop
  mServiceMan->setStoppable();

  //
  // run the actual training procedure on the previously ingested data;
  // this sets the pBowCV to point to files that it created,
  // and it adds some properties directly to the DDA
  //
  bool fTrain = pBowCV->train_run(tTempDir, mServiceMan);
  
  // Tell ServiceManager that we are done listening for stop
  mServiceMan->clearStop();  
  if(!fTrain)
  {
    deleteDirectory(tTempDir);
    localAndClientMsg(VLogger::ERROR, callbackPtr,
                      "Error during the training of BoW.\n");
    return;
  }

  // create the archive of the trained model
  FilePath trainedModel =
    createArchive( dda, pBowCV, labelmap, clientName, CVAC_DataDir, tTempDir );
  callbackPtr->createdDetector(trainedModel);

  delete pBowCV;
  pBowCV = NULL;

  localAndClientMsg(VLogger::INFO, callbackPtr, "Training procedure completed.\n");
}
예제 #7
0
// ---------------------------------------------------------------------------
//	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();
}