ofxGrt icon indicating copy to clipboard operation
ofxGrt copied to clipboard

Error when attempting set weights on ANBC

Open carloscastellanos opened this issue 6 years ago • 2 comments

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_vs2017_release\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!";
	}

carloscastellanos avatar Nov 14 '19 00:11 carloscastellanos

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!

kflak avatar Dec 09 '20 12:12 kflak

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

carloscastellanos avatar Jan 04 '21 04:01 carloscastellanos