本文整理汇总了C++中GestureRecognitionPipeline::getPredictedClassLabel方法的典型用法代码示例。如果您正苦于以下问题:C++ GestureRecognitionPipeline::getPredictedClassLabel方法的具体用法?C++ GestureRecognitionPipeline::getPredictedClassLabel怎么用?C++ GestureRecognitionPipeline::getPredictedClassLabel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GestureRecognitionPipeline
的用法示例。
在下文中一共展示了GestureRecognitionPipeline::getPredictedClassLabel方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main (int argc, const char * argv[])
{
//Create a new gesture recognition pipeline
GestureRecognitionPipeline pipeline;
//Add an ANBC module
pipeline.setClassifier( ANBC() );
//Add a ClassLabelFilter as a post processing module with a minCount of 5 and a buffer size of 10
pipeline.addPostProcessingModule( ClassLabelFilter(5,10) );
//Load some training data to train and test the classifier
ClassificationData trainingData;
ClassificationData testData;
if( !trainingData.loadDatasetFromFile("ClassLabelFilterTrainingData.txt") ){
cout << "Failed to load training data!\n";
return EXIT_FAILURE;
}
if( !testData.loadDatasetFromFile("ClassLabelFilterTestData.txt") ){
cout << "Failed to load training data!\n";
return EXIT_FAILURE;
}
//Train the classifier
if( !pipeline.train( trainingData ) ){
cout << "Failed to train classifier!\n";
return EXIT_FAILURE;
}
//Use the test dataset to demonstrate the output of the ClassLabelFilter
for(UINT i=0; i<testData.getNumSamples(); i++){
VectorDouble inputVector = testData[i].getSample();
if( !pipeline.predict( inputVector ) ){
cout << "Failed to perform prediction for test sampel: " << i <<"\n";
return EXIT_FAILURE;
}
//Get the predicted class label (this will be the processed class label)
UINT predictedClassLabel = pipeline.getPredictedClassLabel();
//Get the unprocessed class label (i.e. the direct output of the classifier)
UINT unprocessedClassLabel = pipeline.getUnProcessedPredictedClassLabel();
//Also print the results to the screen
cout << "Processed Class Label: \t" << predictedClassLabel << "\tUnprocessed Class Label: \t" << unprocessedClassLabel << endl;
}
return EXIT_SUCCESS;
}
示例2: findGesture
std::string GRT_Recognizer::findGesture(VectorDouble input)
{
if( pipeline.getTrained()){
pipeline.predict(input);
UINT label = pipeline.getPredictedClassLabel();
if(pipeline.getMaximumLikelihood() < 0.6)
return "";
}
return "";
}
示例3: main
int main (int argc, const char * argv[])
{
GestureRecognitionPipeline pipeline;
ANBC anbc;
ClassificationData trainingData;
trainingData.loadDatasetFromFile("training-data.txt")
pipeline.setClassifier(anbc);
pipeline.train(trainingData);
VectorDouble inputVector(SAMPLE_DIMENSION) = getDataFromSensor();
pipeline.predict(inputVector);
UINT predictedClassLabel = pipeline.getPredictedClassLabel();
double maxLikelihood = pipeline.getMaximumLikelihood();
printf("predictedClassLabel : %d , MaximumLikelihood : %f \n", predictedClassLabel, maxLikelihood);
return EXIT_SUCCESS;
}
开发者ID:AravinthPanch,项目名称:gesture-recognition-for-human-robot-interaction,代码行数:20,代码来源:grt-pipeline.cpp
示例4: metrics_separate_data
void metrics_separate_data(){
// Training and test data
ClassificationData trainingData;
ClassificationData testData;
string file_path = "../../../data/";
if( !trainingData.loadDatasetFromFile(file_path + "train/grt/12345.txt") ){
std::cout <<"Failed to load training data!\n";
}
ANBC anbc;
anbc.enableScaling(true);
anbc.enableNullRejection(true);
SVM svm(SVM::RBF_KERNEL);
svm.enableScaling(true);
svm.enableNullRejection(true);
MinDist minDist;
minDist.setNumClusters(4);
minDist.enableScaling(true);
minDist.enableNullRejection(true);
ofstream outputFileStream("accuracy-mindist.csv");
outputFileStream << "classLabel,nullRejectionCoeff,accuracy, \n";
for(int class_name = 1; class_name<=5; class_name++){
if( !testData.loadDatasetFromFile(file_path + "test/grt/" + to_string(class_name) + ".txt") ){
std::cout <<"Failed to load training data!\n";
}
for(double nullRejectionCoeff = 0; nullRejectionCoeff <= 10; nullRejectionCoeff=nullRejectionCoeff+0.2){
// anbc.setNullRejectionCoeff(nullRejectionCoeff);
// svm.setNullRejectionCoeff(nullRejectionCoeff);
minDist.setNullRejectionCoeff(nullRejectionCoeff);
GestureRecognitionPipeline pipeline;
// pipeline.setClassifier(anbc);
// pipeline.setClassifier(svm);
pipeline.setClassifier(minDist);
// Train the pipeline
if( !pipeline.train( trainingData ) ){
std::cout << "Failed to train classifier!\n";
}
// Evaluation
double accuracy = 0;
for(UINT i=0; i<testData.getNumSamples(); i++){
UINT actualClassLabel = testData[i].getClassLabel();
vector< double > inputVector = testData[i].getSample();
if( !pipeline.predict( inputVector )){
std::cout << "Failed to perform prediction for test sampel: " << i <<"\n";
}
UINT predictedClassLabel = pipeline.getPredictedClassLabel();
if( actualClassLabel == predictedClassLabel) accuracy++;
}
outputFileStream << class_name << ',' << nullRejectionCoeff << ',' << accuracy/double(testData.getNumSamples())*100.0 << '\n';
cout<< "Done" << endl;
}
}
//---------------------- Null Gesture Test -----------------//
int class_name = 0;
if( !testData.loadDatasetFromFile(file_path + "test/grt/" + to_string(class_name) + ".txt") ){
std::cout <<"Failed to load training data!\n";
}
for(double nullRejectionCoeff = 0; nullRejectionCoeff <= 10; nullRejectionCoeff=nullRejectionCoeff+0.2){
// anbc.setNullRejectionCoeff(nullRejectionCoeff);
// svm.setNullRejectionCoeff(nullRejectionCoeff);
minDist.setNullRejectionCoeff(nullRejectionCoeff);
GestureRecognitionPipeline pipeline;
// pipeline.setClassifier(anbc);
// pipeline.setClassifier(svm);
pipeline.setClassifier(minDist);
// Train the pipeline
if( !pipeline.train( trainingData ) ){
std::cout << "Failed to train classifier!\n";
//.........这里部分代码省略.........
示例5: metrics_subset_data
void metrics_subset_data(){
ANBC anbc;
anbc.enableScaling(true);
anbc.enableNullRejection(true);
MinDist minDist;
minDist.setNumClusters(4);
minDist.enableScaling(true);
minDist.enableNullRejection(true);
// ofstream opRecall("anbc-recall-nr-0-10.csv");
// opRecall <<"nrCoeff,class0,class1,class2,class3,class4,class5\n";
//
// ofstream opInstanceRes("anbc-prediction-nr-2.csv");
// opInstanceRes <<"actualClass,predictedClass,maximumLikelihood,lZ,lY,lZ,rZ,rY,rZ\n";
//
// ofstream opMetrics("anbc-precision-recall-fmeasure-nr-2.csv");
// opMetrics <<"class1,class2,class3,class4,class5\n";
//
// ofstream opConfusion("anbc-confusion-nr-2.csv");
// opConfusion <<"class0,class1,class2,class3,class4,class5\n";
ofstream opRecall("mindist-recall-nr-0-10.csv");
opRecall <<"nrCoeff,class0,class1,class2,class3,class4,class5\n";
ofstream opInstanceRes("mindist-prediction-nr-2.csv");
opInstanceRes <<"actualClass,predictedClass,maximumLikelihood,lZ,lY,lZ,rZ,rY,rZ\n";
ofstream opMetrics("mindist-precision-recall-fmeasure-nr-2.csv");
opMetrics <<"class1,class2,class3,class4,class5\n";
ofstream opConfusion("mindist-confusion-nr-2.csv");
opConfusion <<"class0,class1,class2,class3,class4,class5\n";
// Training and test data
ClassificationData trainingData;
ClassificationData testData;
ClassificationData nullGestureData;
string file_path = "../../../data/";
if( !trainingData.loadDatasetFromFile(file_path + "train/grt/hri-training-dataset.txt") ){
std::cout <<"Failed to load training data!\n";
}
if( !nullGestureData.loadDatasetFromFile(file_path + "test/grt/0.txt") ){
std::cout <<"Failed to load null gesture data!\n";
}
testData = trainingData.partition(90);
testData.sortClassLabels();
// testData.saveDatasetToFile("anbc-validation-subset.txt");
testData.saveDatasetToFile("mindist-validation-subset.txt");
for(double nullRejectionCoeff = 0; nullRejectionCoeff <= 10; nullRejectionCoeff=nullRejectionCoeff+0.2){
// anbc.setNullRejectionCoeff(nullRejectionCoeff);
// GestureRecognitionPipeline pipeline;
// pipeline.setClassifier(anbc);
minDist.setNullRejectionCoeff(nullRejectionCoeff);
GestureRecognitionPipeline pipeline;
pipeline.setClassifier(minDist);
pipeline.train(trainingData);
pipeline.test(testData);
TestResult testRes = pipeline.getTestResults();
opRecall << nullRejectionCoeff << ",";
//null rejection prediction
double accuracy = 0;
for(UINT i=0; i<nullGestureData.getNumSamples(); i++){
vector< double > inputVector = nullGestureData[i].getSample();
if( !pipeline.predict( inputVector )){
std::cout << "Failed to perform prediction for test sampel: " << i <<"\n";
}
UINT predictedClassLabel = pipeline.getPredictedClassLabel();
if(predictedClassLabel == 0 ) accuracy++;
}
opRecall << accuracy/double(nullGestureData.getNumSamples()) << ",";
// other classes prediction
for(int cl = 0; cl < testRes.recall.size(); cl++ ){
opRecall << testRes.recall[cl];
if(cl < testRes.recall.size() - 1){
opRecall << ",";
}
//.........这里部分代码省略.........
示例6: prediction_axis_data
void prediction_axis_data(){
// Training and test data
ClassificationData trainingData;
ClassificationData testData;
string file_path = "../../../data/";
string class_name = "5";
if( !trainingData.loadDatasetFromFile(file_path + "train/grt/" + class_name + ".txt") ){
std::cout <<"Failed to load training data!\n";
}
if( !testData.loadDatasetFromFile(file_path + "test/grt/" + class_name + ".txt") ){
std::cout <<"Failed to load training data!\n";
}
// Pipeline setup
ANBC anbc;
anbc.setNullRejectionCoeff(1);
anbc.enableScaling(true);
anbc.enableNullRejection(true);
GestureRecognitionPipeline pipeline;
pipeline.setClassifier(anbc);
// Train the pipeline
if( !pipeline.train( trainingData ) ){
std::cout << "Failed to train classifier!\n";
}
// File stream
ofstream outputFileStream(class_name + ".csv");
// Evaluation
double accuracy = 0;
outputFileStream << "actualClass,predictedClass,maximumLikelihood,lZ,lY,lZ,rZ,rY,rZ \n";
for(UINT i=0; i<testData.getNumSamples(); i++){
UINT actualClassLabel = testData[i].getClassLabel();
vector< double > inputVector = testData[i].getSample();
if( !pipeline.predict( inputVector )){
std::cout << "Failed to perform prediction for test sampel: " << i <<"\n";
}
UINT predictedClassLabel = pipeline.getPredictedClassLabel();
double maximumLikelihood = pipeline.getMaximumLikelihood();
outputFileStream << actualClassLabel << "," << predictedClassLabel << "," << maximumLikelihood << ","
<< inputVector[0] << "," << inputVector[1] << "," << inputVector[2] << "," << inputVector[3] << "," << inputVector[4] << "," << inputVector[5] << "\n";
if( actualClassLabel == predictedClassLabel) accuracy++;
}
std::cout << "Test Accuracy testHandsUp : " << accuracy/double(testData.getNumSamples())*100.0 << " %\n";
}