Example #1
0
int cLibsvmLiveSink::myFinaliseInstance()
{
  int ap=0;

  int ret = cDataSink::myFinaliseInstance();
  if (ret==0) return 0;
  
  // TODO: binary model files...
  // load model
  SMILE_MSG(2,"loading LibSVM model for instance '%s' ...",getInstName()); 
  if((model=svm_load_model(modelfile))==0) {
    COMP_ERR("can't open libSVM model file '%s'",modelfile);
  }

  nClasses = svm_get_nr_class(model);
  svmType = svm_get_svm_type(model);

  if(predictProbability) {
    if ((svmType==NU_SVR) || (svmType==EPSILON_SVR)) {
      nClasses = 0;
      SMILE_MSG(2,"LibSVM prob. model (regression) for test data: target value = predicted value + z,\nz: Laplace distribution e^(-|z|/sigma)/(2sigma),sigma=%g",svm_get_svr_probability(model));
    } else {
      labels=(int *) malloc(nClasses*sizeof(int));
      svm_get_labels(model,labels);

      SMILE_MSG(3,"LibSVM %i labels in model '%s':",nClasses,modelfile);
      int j;
      for(j=0;j<nClasses;j++)
        SMILE_MSG(3,"  Label[%i] : '%d'",j,labels[j]);
	}
  }

  //?? move this in front of above if() block ?
  if ((predictProbability)&&(nClasses>0))
    probEstimates = (double *) malloc(nClasses*sizeof(double));

  // load scale
  if((scale=svm_load_scale(scalefile))==0) {
	COMP_ERR("can't open libSVM scale file '%s'",scalefile);
  }

  // load selection
  loadSelection(fselection);

  //TODO: check compatibility of getLevelN() (possibly after selection), number of features in model, and scale
  
  if (nClasses>0) {
    // load class mapping
    loadClasses(classes);
  } else {
    if (classes != NULL) SMILE_IWRN(2,"not loading given class mapping file for regression SVR model (there are no classes...)!");
  }

  return ret;
}
Example #2
0
int main(int argc, char *argv[])
{
  try {

    smileCommon_fixLocaleEnUs();

    // set up the smile logger
    LOGGER.setLogLevel(1);
    LOGGER.enableConsoleOutput();


    // commandline parser:
    cCommandlineParser cmdline(argc,argv);
    cmdline.addStr( "configfile", 'C', "Path to openSMILE config file", "smile.conf" );
    cmdline.addInt( "loglevel", 'l', "Verbosity level (0-9)", 2 );
#ifdef DEBUG
    cmdline.addBoolean( "debug", 'd', "Show debug messages (on/off)", 0 );
#endif
    cmdline.addInt( "nticks", 't', "Number of ticks to process (-1 = infinite) (only works for single thread processing, i.e. nThreads=1)", -1 );
    //cmdline.addBoolean( "configHelp", 'H', "Show documentation of registered config types (on/off)", 0 );
    cmdline.addBoolean( "components", 'L', "Show component list", 0 );
    cmdline.addStr( "configHelp", 'H', "Show documentation of registered config types (on/off/argument) (if an argument is given, show only documentation for config types beginning with the name given in the argument)", NULL, 0 );
    cmdline.addStr( "configDflt", 0, "Show default config section templates for each config type (on/off/argument) (if an argument is given, show only documentation for config types beginning with the name given in the argument, OR for a list of components in conjunctions with the 'cfgFileTemplate' option enabled)", NULL, 0 );
    cmdline.addBoolean( "cfgFileTemplate", 0, "Print a complete template config file for a configuration containing the components specified in a comma separated string as argument to the 'configDflt' option", 0 );
    cmdline.addBoolean( "cfgFileDescriptions", 0, "Include description in config file templates.", 0 );
    cmdline.addBoolean( "ccmdHelp", 'c', "Show custom commandline option help (those specified in config file)", 0 );
    cmdline.addStr( "logfile", 0, "set log file", "smile.log" );
    cmdline.addBoolean( "nologfile", 0, "don't write to a log file (e.g. on a read-only filesystem)", 0 );
    cmdline.addBoolean( "noconsoleoutput", 0, "don't output any messages to the console (log file is not affected by this option)", 0 );
    cmdline.addBoolean( "appendLogfile", 0, "append log messages to an existing logfile instead of overwriting the logfile at every start", 0 );

    int help = 0;
    if (cmdline.doParse() == -1) {
      LOGGER.setLogLevel(0);
      help = 1;
    }
    if (argc <= 1) {
      printf("\nNo commandline options were given.\n Please run ' SMILExtract -h ' to see some usage information!\n\n");
      return 10;
    }

    if (help==1) { return 0; }

    if (cmdline.getBoolean("nologfile")) {
      LOGGER.setLogFile((const char *)NULL,0,!(cmdline.getBoolean("noconsoleoutput")));
    } else {
      LOGGER.setLogFile(cmdline.getStr("logfile"),cmdline.getBoolean("appendLogfile"),!(cmdline.getBoolean("noconsoleoutput")));
    }
    LOGGER.setLogLevel(cmdline.getInt("loglevel"));
    SMILE_MSG(2,"openSMILE starting!");

#ifdef DEBUG  // ??
    if (!cmdline.getBoolean("debug"))
      LOGGER.setLogLevel(LOG_DEBUG, 0);
#endif

    SMILE_MSG(2,"config file is: %s",cmdline.getStr("configfile"));


    // create configManager:
    cConfigManager *configManager = new cConfigManager(&cmdline);


    cComponentManager *cMan = new cComponentManager(configManager,componentlist);


    const char *selStr=NULL;
    if (cmdline.isSet("configHelp")) {
#ifndef EXTERNAL_BUILD
      selStr = cmdline.getStr("configHelp");
      configManager->printTypeHelp(1/*!!! -> 1*/,selStr,0);
#endif
      help = 1;
    }
    if (cmdline.isSet("configDflt")) {
#ifndef EXTERNAL_BUILD
      int fullMode=0; 
      int wDescr = 0;
      if (cmdline.getBoolean("cfgFileTemplate")) fullMode=1;
      if (cmdline.getBoolean("cfgFileDescriptions")) wDescr=1;
      selStr = cmdline.getStr("configDflt");
      configManager->printTypeDfltConfig(selStr,1,fullMode,wDescr);
#endif
      help = 1;
    }
    if (cmdline.getBoolean("components")) {
#ifndef EXTERNAL_BUILD
      cMan->printComponentList();
#endif  // EXTERNAL_BUILD
      help = 1;
    }

    if (help==1) {
      delete configManager;
      delete cMan;
      return -1; 
    }


    // TODO: read config here and print ccmdHelp...
    // add the file config reader:
    try{ 
      configManager->addReader( new cFileConfigReader( cmdline.getStr("configfile"), -1, &cmdline) );
      configManager->readConfig();
    } catch (cConfigException *cc) {
      return 0;
    }

    /* re-parse the command-line to include options created in the config file */
    cmdline.doParse(1,0); // warn if unknown options are detected on the commandline
    if (cmdline.getBoolean("ccmdHelp")) {
      cmdline.showUsage();
      delete configManager;
      delete cMan;
      return -1;
    }

    /* create all instances specified in the config file */
    cMan->createInstances(0); // 0 = do not read config (we already did that above..)

    /*
    MAIN TICK LOOP :
    */
    cmanGlob = cMan;
    signal(SIGINT, INThandler); // install Ctrl+C signal handler

    /* run single or mutli-threaded, depending on componentManager config in config file */
    long long nTicks = cMan->runMultiThreaded(cmdline.getInt("nticks"));

    /* it is important that configManager is deleted BEFORE componentManger! 
      (since component Manger unregisters plugin Dlls, which might have allocated configTypes, etc.) */
    delete configManager;
    delete cMan;

  } catch(cSMILException *c) { 
    // free exception ?? 
    return EXIT_ERROR; 
  } 

  if (ctrlc) return EXIT_CTRLC;
  return EXIT_SUCCESS;
}
Example #3
0
// Perform audio extraction with openSMILE
int AudioAnalyzer::audioToCSV(string wavFileName, string csvFileName)
{
	try {
		string wavPath = wavFileName;
		string csvPath = csvFileName;
		string configPath = configFileName;
		
		// set up the smile logger
		LOGGER.setLogLevel(-1);
		//LOGGER.enableConsoleOutput();

		int arg1 = 0;
		char ** arg2 = NULL;

		// commandline parser:
		cCommandlineParser cmdline(arg1,arg2);

		SMILE_MSG(2,"openSMILE starting!");

		// create configManager:
		cConfigManager *configManager = new cConfigManager(&cmdline);
		
		cComponentManager *cMan = new cComponentManager(configManager,componentlist);

		// add the file config reader:
		try{ 
		  configManager->addReader( new cFileConfigReader( configPath.c_str() ) );
		  configManager->readConfig();
		} catch (cConfigException *cc) {
		  return 0;
		}
		
		ConfigInstance * instance = configManager->getInstance("waveSource");
		instance->setStr("filename", (const char*)wavPath.c_str());
		//SMILE_MSG(2, "fichier audio : %s", instance->getStr("filename"));
		
		instance = configManager->getInstance("csvSink");
		instance->setStr("filename", (const char*)csvPath.c_str());
		//SMILE_MSG(2, "fichier de config : %s", instance->getStr("filename"));

		
		/* re-parse the command-line to include options created in the config file */
		cmdline.doParse(1,0); // warn if unknown options are detected on the commandline
		
		/* create all instances specified in the config file */
		cMan->createInstances(0); // 0 = do not read config (we already did that above..)

		/*
		MAIN TICK LOOP :
		*/
		cmanGlob = cMan;
		signal(SIGINT, INThandler); // install Ctrl+C signal handler

		/* run single or mutli-threaded, depending on componentManager config in config file */
		cMan->runMultiThreaded(-1);  //long long nTicks = 

		/* it is important that configManager is deleted BEFORE componentManger! 
		  (since component Manger unregisters plugin Dlls, which might have allocated configTypes, etc.) */
		delete configManager;
		delete cMan;
		
		return 1;
	} catch(cSMILException *c) { 
		// free exception ?? 
		return 0; 
	} 
	return 0;
}