nickgillian / grt

gesture recognition toolkit
862 stars 284 forks source link

DTW Classification - Errors using "predict" #131

Open hadarszostak opened 7 years ago

hadarszostak commented 7 years ago

Hi, I'm using your library with DTW classifier to recognize a gesture using time series Accelerometer data. I followed the code at these links :

  1. http://www.nickgillian.com/wiki/pmwiki.php/GRT/OpenframeworksDTWExample#Setup
  2. https://github.com/nickgillian/ofxGrt/blob/master/example_dtw/src/ofApp.cpp

Part of my code using GRT library:

VectorDouble samples(1);
MatrixDouble timeSeriesdata;
UINT gestureLabel = 1;                                                                  //~ }
TimeSeriesClassificationData trainingData;
trainingData.setDatasetName("B1");                                                                      
trainingData.setNumDimensions( 1 );
GestureRecognitionPipeline pipeline;

DTW dtw;
dtw.enableNullRejection(false); 
//dtw.setNullRejectionCoeff(4);            // no need because the class has only one Time Series Data
dtw.enableTrimTrainingData(true,0.1,90);
dtw.setOffsetTimeseriesUsingFirstSample(true);
dtw.setContrainWarpingPath(true);
pipeline.setClassifier(dtw);

std::cout<< "Ready to Record Template... " << std::endl; std::cin>>B;
A=0;

    //while this loop is running I'm moving the sensor to create a gesture template to train the pipeline with
while(A<300){
A+=1;
MPU_Right.MPU6DOF();                                                                                // read MPU6050 sensor accelerometer data
MPU_Right.show();                                                           // put the data on screen
std::cout << std::endl;
samples[0]=sqrt(pow(((float_t)MPU_Right.Accx/2048),2)+pow(((float_t)MPU_Right.Accy/2048),2)+pow(((float_t)MPU_Right.Accz/2048),2));     // the data I'm intrested to train the DTW pipeline with
timeSeriesdata.push_back(samples);
}

trainingData.addSample(gestureLabel,timeSeriesdata);
trainingData.save( " TrainingData.grt ");
timeSeriesdata.save( " TimeSeriesData.grt ");
timeSeriesdata.clear();

bool isTrained = pipeline.train(trainingData);
std::cout<< "Trained? :  " << isTrained << std::endl;
std::cout<< "Ready to Record Sample... " << std::endl; std::cin>>B;

//The Real-Time gesture recognition starts (hopefully)
while(1){
MPU_Right.MPU6DOF();
samples[0]=(sqrt(pow(((float_t)MPU_Right.Accx/2048),2)+pow(((float_t)MPU_Right.Accy/2048),2)+pow(((float_t)MPU_Right.Accz/2048),2))); // the data I'm intrested to recognize.
if(pipeline.getTrained()) {
bool Prediction = pipeline.predict( samples ); 
std::cout<< "Prediction : " << Prediction << std::endl;
pred=dtw.getPredictedClassLabel();
if(pred){
    std::cout<< pred << std::endl; 
}else std::cout << "||||" << std::endl;
samples.clear();
}

Executing the Real-Time loop (only twice for this example) , I get the following errors:

[TRAINING DTW] Training Template: 0 Class: 1           
Trained? :  1
Ready to Record Sample... 
5
[ERROR CircularBuffer] Can't push_back value to circular buffer as the buffer has not been initialized!
[ERROR] DTW.cpp predict_:374 The number of features in the model (1) do not match that of the input time series (0)
[ERROR] GestureRecognitionPipeline.cpp predict_classifier:1651 Prediction Failed! DTW.cpp predict_:374 The number of features in the model (1) do not match that of the input time series (0)
Prediction : 0
||||
[ERROR] GestureRecognitionPipeline.cpp predict_:1352 The dimensionality of the input Vector (0) does not match that of the input Vector dimensions of the pipeline (1)
Prediction : 0
||||

The first 3 errors are presented as .predict first execution is finished, for the reset loop iterations the last error is presented. trainingData file : TrainingData.txt

Can you help me with solving this please?

hadarszostak commented 7 years ago

Hi,

@nickgillian Is there an answer for my issue?

Hadar