model->load not trained?

asked 2016-05-14 05:50:49 -0600

atv gravatar image

So i saved a fisher faces model in a textile, and i try to load it back in. When loading it back in, i should not have to train (right?) but when i run, i get:

Checking for previous trained model [face-rec-model.txt]
OpenCV Error: Unspecified error (File can't be opened for writing!) in load, file /tmp/opencv-20160502-20452       13c59z2/opencv-2.4.12/modules/contrib/src/facerec.cpp, line 398
 face-rec-model.txt does not exist
 Training..
 Saving the trained model to face-rec-model.txt
 Camera dropped frame!
Arrived before resize
Arrived after resize
  OpenCV Error: Bad argument (This Fisherfaces model is not computed yet. Did you call Fisherfaces::train?) in       predict, file /tmp/opencv-20160502-20452-13c59z2/opencv-2.4.12/modules/contrib/src/facerec.cpp, line 620
libc++abi.dylib: terminating with uncaught exception of type cv::Exception: /tmp/opencv-20160502-20452-13c59z2/opencv-2.4.12/modules/contrib/src/facerec.cpp:620: error: (-5) This Fisherfaces model is not computed yet. Did you call Fisherfaces::train? in function predict

Abort trap: 6

Can i not predict straight away on a loaded model? I can supply the code if needed but i didn't want to clutter the posting or have someone else do the homework for me. One other thing, i do a resize :

cv::resize(face, face_resized, Size(im_width, im_height), 1.0, 1.0, INTER_CUBIC);

Where im_width and im_height are based on images[0].cols and images[0].rows. When loading the model, i use this :

string facerecAlgorithm = "FaceRecognizer.Fisherfaces"; // Update for other models
Ptr<FaceRecognizer>model=Algorithm::create<FaceRecognizer>(facerecAlgorithm);
Mat check_labels;
try {
    cout << "Checking for previous trained model [" << saveModelPath << "]" << endl;
    model->load(saveModelPath);
    check_labels=model->get<Mat>("labels");
    } catch(cv::Exception &e) {}
if(check_labels.rows<=0) {
    cerr << saveModelPath << " does not exist" << ends;

// Read in the data (fails if no valid input filename is given, but you'll get an error message):
try {
    read_csv(fn_csv, images, labels,labelsInfo);
} catch (cv::Exception& e) {
    cerr << "Error opening file \"" << fn_csv << "\". Reason: " << e.msg << endl;
    // nothing more we can do
    exit(1);
}
// Get the height from the first image. We'll need this
// later in code to reshape the images to their original
// size AND we need to reshape incoming faces to this size:
im_width = images[0].cols;
im_height = images[0].rows;

// Do initial training
<snip>

 }
else {
im_width=check_labels.cols;
im_height=check_labels.rows;
}

images is a Vector<mat> whereas check_labels is a Mat. I suspect it's something in the resize function but i am not entirely sure.

Thank you for any comments or help you can give me.

edit retag flag offensive close merge delete