I am developing face recognize on android,why the predict method always return 0

asked 2014-04-21 02:32:15 -0500

rainNight gravatar image

updated 2014-04-21 03:23:10 -0500

I was developing face recognize on android, but I missed a problem, when I use the predict method to predict persons, the return values is 0 everytime. The api sad that -1 states this face is unknown. Now,I want to know why is it. could you help me. thanks! My code

vector<Mat> images;
vector<jint> labels;
jint num_components = 10;
jdouble threshold = 10.0;
Mat& predictImg = *(Mat*)predictImgAddr;
//person1
images.push_back(imread("/sdcard/s1/1.bmp"));
labels.push_back(0);
images.push_back(imread("/sdcard/s1/2.bmp"));
labels.push_back(0);
images.push_back(imread("/sdcard/s1/3.bmp"));
labels.push_back(0);
images.push_back(imread("/sdcard/s1/4.bmp"));
labels.push_back(0);

//person2
images.push_back(imread("/sdcard/s2/1.bmp"));
labels.push_back(1);
images.push_back(imread("/sdcard/s2/2.bmp"));
labels.push_back(1);
images.push_back(imread("/sdcard/s2/3.bmp"));
labels.push_back(1);
images.push_back(imread("/sdcard/s2/4.bmp"));
labels.push_back(1);
Ptr<FaceRecognizer> model = createFisherFaceRecognizer(num_components, threshold);
model->train(images,labels);
jint predicted = model->predict(predictImg);
return predicted; `
edit retag flag offensive close merge delete

Comments

1

if you don't set a threshold value in the constructor / create method, it will always return the 'closest' face, not -1.

for a start, try using the returned confidence value from the wrong prediction as threshold

berak gravatar imageberak ( 2014-04-21 02:49:34 -0500 )edit

the closest is meaning first push_back()? I really don't set the threshold, but I using threshold init the createFisherFaceRecognizer() method.

rainNight gravatar imagerainNight ( 2014-04-21 03:17:52 -0500 )edit

use the 2nd predict version:

int predictImg;

double predictDistance;

model->predict(predictImg, predictDistance);

the 'closest' is in respect to the distance above. try this for all your images, and you'll get an impression of the distribution of that. then choose a threshold value. (it will be more like 10000)

berak gravatar imageberak ( 2014-04-21 03:28:59 -0500 )edit

thank you, when I add the model->set("threshold",0.0) method, the return is not 0,but -1, could you tell me how many values is suitable for setting the threshold. thanks again!

rainNight gravatar imagerainNight ( 2014-04-21 03:34:14 -0500 )edit

yea, 0 for threshold will reject all (while the default, DBL_MAX will reject none)

try without any threshold first, collect resulting distances for as many test images possible, and take the smallest wrong prediction as threshold further on.

also, this value depends heavily on your data. you might have to adjust it later with every train run

berak gravatar imageberak ( 2014-04-21 03:37:21 -0500 )edit