本文整理汇总了C++中GestureRecognitionPipeline::getTrainingResults方法的典型用法代码示例。如果您正苦于以下问题:C++ GestureRecognitionPipeline::getTrainingResults方法的具体用法?C++ GestureRecognitionPipeline::getTrainingResults怎么用?C++ GestureRecognitionPipeline::getTrainingResults使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GestureRecognitionPipeline
的用法示例。
在下文中一共展示了GestureRecognitionPipeline::getTrainingResults方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: train
bool train( CommandLineParser &parser ){
infoLog << "Training regression model..." << endl;
string trainDatasetFilename = "";
string modelFilename = "";
//Get the filename
if( !parser.get("filename",trainDatasetFilename) ){
errorLog << "Failed to parse filename from command line! You can set the filename using the -f." << endl;
printHelp();
return false;
}
//Get the model filename
parser.get("model-filename",modelFilename);
//Load the training data to train the model
ClassificationData trainingData;
infoLog << "- Loading Training Data..." << endl;
if( !trainingData.load( trainDatasetFilename ) ){
errorLog << "Failed to load training data!\n";
return false;
}
const unsigned int N = trainingData.getNumDimensions();
const unsigned int K = trainingData.getNumClasses();
infoLog << "- Num training samples: " << trainingData.getNumSamples() << endl;
infoLog << "- Num input dimensions: " << N << endl;
infoLog << "- Num classes: " << K << endl;
float learningRate = 0;
float minChange = 0;
unsigned int maxEpoch = 0;
unsigned int batchSize = 0;
parser.get( "learning-rate", learningRate );
parser.get( "min-change", minChange );
parser.get( "max-epoch", maxEpoch );
parser.get( "batch-size", batchSize );
infoLog << "Softmax settings: learning-rate: " << learningRate << " min-change: " << minChange << " max-epoch: " << maxEpoch << " batch-size: " << batchSize << endl;
//Create a new softmax instance
bool enableScaling = true;
Softmax classifier(enableScaling,learningRate,minChange,maxEpoch,batchSize);
//Create a new pipeline that will hold the classifier
GestureRecognitionPipeline pipeline;
//Add the classifier to the pipeline
pipeline << classifier;
infoLog << "- Training model...\n";
//Train the classifier
if( !pipeline.train( trainingData ) ){
errorLog << "Failed to train model!" << endl;
return false;
}
infoLog << "- Model trained!" << endl;
infoLog << "- Saving model to: " << modelFilename << endl;
//Save the pipeline
if( pipeline.save( modelFilename ) ){
infoLog << "- Model saved." << endl;
}else warningLog << "Failed to save model to file: " << modelFilename << endl;
infoLog << "- TrainingTime: " << pipeline.getTrainingTime() << endl;
string logFilename = "";
if( parser.get( "log-filename", logFilename ) && logFilename.length() > 0 ){
infoLog << "Writing training log to: " << logFilename << endl;
fstream logFile( logFilename.c_str(), fstream::out );
if( !logFile.is_open() ){
errorLog << "Failed to open training log file: " << logFilename << endl;
return false;
}
Vector< TrainingResult > trainingResults = pipeline.getTrainingResults();
for(UINT i=0; i<trainingResults.getSize(); i++){
logFile << trainingResults[i].getTrainingIteration() << "\t" << trainingResults[i].getAccuracy() << endl;
}
logFile.close();
}
return true;
}