nickgillian / ofxGrt

OpenFrameworks extension for the Gesture Recognition Toolkit
119 stars 27 forks source link

Error when attempting set weights on ANBC #33

Open carloscastellanos opened 4 years ago

carloscastellanos commented 4 years ago

I am getting an error when attempting to set weights for an ANBC. I have 6 dimension (x/y/z from L & R hands on Kinect).

The data is getting set and passed to the ANBC object (I checked). But when it comes time to train, I get the following error in the console:

[ERROR] c:\program files\of_v0.10.1_vs2017release\addons\ofxgrt\libs\grt\grt\classificationmodules\anbc\anbc.cpp GRT::ANBC::train:148 Failed to find the weights for class 1

What am I doing wrong?

Code below


// ==== GRT ==== //
    //Initialize the training and info variables
    infoText = "";
    trainingClassLabel = 1;
    recordGesture = false;

    trainingData.setNumDimensions(6);

    ANBC anbc;
    //Turn on null rejection, this lets the classifier output the predicted class label of 0 when the likelihood of a gesture is low
    anbc.enableNullRejection(true);

    //Set the null rejection coefficient. This controls the thresholds for the automatic null rejection
    //You can increase this value if you find that your real-time gestures are not being recognized
    //If you are getting too many false positives then you should decrease this value
    anbc.setNullRejectionCoeff(10);

    anbc.enableScaling(true);

    // add weights
    // class label 1: left hand, class labe 2: right hand, class label 3: both hands
    VectorDouble weightsL(6);
    weightsL[0] = 1;
    weightsL[1] = 1;
    weightsL[2] = 1;
    weightsL[3] = 0;
    weightsL[4] = 0;
    weightsL[5] = 0;
    VectorDouble weightsR(6);
    weightsR[0] = 0;
    weightsR[1] = 0;
    weightsR[2] = 0;
    weightsR[3] = 1;
    weightsR[4] = 1;
    weightsR[5] = 1;
    VectorDouble weightsLR(6);
    weightsLR[0] = 1;
    weightsLR[1] = 1;
    weightsLR[2] = 1;
    weightsLR[3] = 1;
    weightsLR[4] = 1;
    weightsLR[5] = 1;

    weights.setNumDimensions(6);
    weights.addSample(1, weightsL);
    weights.addSample(2, weightsR);
    weights.addSample(3, weightsLR);

    // set the weights
    if (anbc.setWeights(weights)) {
        infoText = "Weights set. ";
        infoText += ofToString(weights.getNumDimensions()) + " dimensions. ";
        infoText += ofToString(weights.getNumSamples()) + " samples.";
    } else {
        infoText = "Error setting weights!";
    }

    //Add the classifier to the first pipeline (after we do this, we don't need the ANBC classifier anymore)
    if (pipelines[0].setClassifier(anbc)) {
        infoText += " Classifier set to ANBC.";
    } else {
        infoText += " Error setting classifier!";
    }
kflak commented 3 years ago

Hi @carloscastellanos, did you manage to solve this issue? I'm running into a coredump when trying to do (more or less) what you do... On linux, so some things are probably quite different, but your example is the only one I found that actually shows how to set weights!

carloscastellanos commented 3 years ago

No. I haven't looked at in awhile. Sorry!