Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

the way you setup your train data looks broken.

look here:

trainingDataMat.put(i, j, trainingList[i][j]); // trainingDataMat is where ?

in the 1st run, you have 18 features, so you pushback a row of 18 here:

v_features.push_back(trainingDataMat.reshape(1,1));

but in the 2nd run, since you reuse trainingDataMat , you already got 36 cols, if you reshape it, and it gets longer and longer....

i think, you should do like this instead:

trainingList = readFromFile(featureVector, trainingRow, trainingCol);
for(int i=0; i<trainingRow; i++){
   Mat a_row = new Mat(1, trainingCol, CV_32F); // a **local** Mat w. correct size and type 
   for(int j=0; j<trainingCol; j++) {
        Log.i(TAG, "Data of data" + "[" + i + "," + j + "]" + " " + trainingList[i][j]);
        a_row.put(i, j, trainingList[i][j]);
    }
    v_features.push_back(a_row); // no need to reshape, it's already a row.
}

final checklist:

  • train labels need to be Mat(trainRows, 1, CV_32S);
  • train data needs to be Mat(trainRows, trainCols, CV_32F);
  • test data needs to be Mat(1, trainCols, CV_32F);

the way you setup your train data looks broken.

look here:

trainingDataMat.put(i, j, trainingList[i][j]); // trainingDataMat is where ?

in the 1st run, you have 18 features, so you pushback a row of 18 here:

v_features.push_back(trainingDataMat.reshape(1,1));

but in the 2nd run, since you reuse trainingDataMat , you already got 36 cols, if you reshape it, and it gets longer and longer....

i think, you should do like this instead:

trainingList = readFromFile(featureVector, trainingRow, trainingCol);
for(int i=0; i<trainingRow; i++){
   Mat a_row = new Mat(1, trainingCol, CV_32F); // a **local** Mat w. correct size and type 
   for(int j=0; j<trainingCol; j++) {
        Log.i(TAG, "Data of data" + "[" + i + "," + j + "]" + " " + trainingList[i][j]);
        a_row.put(i, j, trainingList[i][j]);
    }
    v_features.push_back(a_row); // no need to reshape, it's already a row.
}

final checklist:

  • train labels need to be Mat(trainRows, 1, CV_32S);
  • train data needs to be Mat(trainRows, trainCols, CV_32F);
  • test data needs to be Mat(1, Mat(testRows, trainCols, CV_32F);CV_32F);

    ( yes, you can test several samples at the same time, but you need to use an (empty) result Mat in predict)

the way you setup your train data looks broken.

look here:

trainingDataMat.put(i, j, trainingList[i][j]); // trainingDataMat is where ?

in the 1st run, you have 18 features, so you pushback a row of 18 here:

v_features.push_back(trainingDataMat.reshape(1,1));

but in the 2nd run, since you reuse trainingDataMat , you already got 36 cols, if you reshape it, and it gets longer and longer....

i think, you should do like this instead:instead(same problem for your testing data!):

trainingList = readFromFile(featureVector, trainingRow, trainingCol);
for(int i=0; i<trainingRow; i++){
   Mat a_row = new Mat(1, trainingCol, CV_32F); // a **local** Mat w. correct size and type 
   for(int j=0; j<trainingCol; j++) {
        Log.i(TAG, "Data of data" + "[" + i + "," + j + "]" + " " + trainingList[i][j]);
        a_row.put(i, j, trainingList[i][j]);
    }
    v_features.push_back(a_row); // no need to reshape, it's already a row.
}

final checklist:

  • train labels need to be Mat(trainRows, 1, CV_32S);
  • train data needs to be Mat(trainRows, trainCols, CV_32F);
  • test data needs to be Mat(testRows, trainCols, CV_32F);

    ( yes, you can test several samples at the same time, but you need to use an (empty) result Mat in predict)


Mat result = new Mat(); //since we have more than 1 sample
classifier.predict(testingData, result);