From 04dfaaf9350c342e6c288bcdaab81dfee24eec6b Mon Sep 17 00:00:00 2001 From: berak Date: Fri, 20 Feb 2015 14:55:26 +0100 Subject: [PATCH] add a 'split' train method to datasets/lfw_benckmark --- modules/datasets/samples/fr_lfw_benchmark.cpp | 79 +++++++++++++------ 1 file changed, 57 insertions(+), 22 deletions(-) diff --git a/modules/datasets/samples/fr_lfw_benchmark.cpp b/modules/datasets/samples/fr_lfw_benchmark.cpp index 9f578b54a..7ec939e98 100644 --- a/modules/datasets/samples/fr_lfw_benchmark.cpp +++ b/modules/datasets/samples/fr_lfw_benchmark.cpp @@ -78,7 +78,9 @@ int main(int argc, const char *argv[]) { const char *keys = "{ help h usage ? | | show this message }" - "{ path p |true| path to dataset (lfw2 folder) }"; + "{ path p |true| path to dataset (lfw2 folder) }" + "{ train t |dev | train method: 'dev'(pairsDevTrain.txt) or 'split'(pairs.txt) }"; + CommandLineParser parser(argc, argv, keys); string path(parser.get("path")); if (parser.has("help") || path=="true") @@ -86,6 +88,7 @@ int main(int argc, const char *argv[]) parser.printMessage(); return -1; } + string trainMethod(parser.get("train")); // These vectors hold the images and corresponding labels. vector images; @@ -97,24 +100,12 @@ int main(int argc, const char *argv[]) unsigned int numSplits = dataset->getNumSplits(); printf("splits number: %u\n", numSplits); - printf("train size: %u\n", (unsigned int)dataset->getTrain().size()); + if (trainMethod == "dev") + printf("train size: %u\n", (unsigned int)dataset->getTrain().size()); + else + printf("train size: %u\n", (numSplits-1) * (unsigned int)dataset->getTest().size()); printf("test size: %u\n", (unsigned int)dataset->getTest().size()); - for (unsigned int i=0; igetTrain().size(); ++i) - { - FR_lfwObj *example = static_cast(dataset->getTrain()[i].get()); - - int currNum = getLabel(example->image1); - Mat img = imread(path+example->image1, IMREAD_GRAYSCALE); - images.push_back(img); - labels.push_back(currNum); - - currNum = getLabel(example->image2); - img = imread(path+example->image2, IMREAD_GRAYSCALE); - images.push_back(img); - labels.push_back(currNum); - } - // 2200 pairsDevTrain, first split: correct: 373, from: 600 -> 62.1667% Ptr model = createLBPHFaceRecognizer(); // 2200 pairsDevTrain, first split: correct: correct: 369, from: 600 -> 61.5% @@ -122,14 +113,58 @@ int main(int argc, const char *argv[]) // 2200 pairsDevTrain, first split: correct: 372, from: 600 -> 62% //Ptr model = createFisherFaceRecognizer(); - model->train(images, labels); - //string saveModelPath = "face-rec-model.txt"; - //cout << "Saving the trained model to " << saveModelPath << endl; - //model->save(saveModelPath); + if (trainMethod == "dev") // train on personsDevTrain.txt + { + for (unsigned int i=0; igetTrain().size(); ++i) + { + FR_lfwObj *example = static_cast(dataset->getTrain()[i].get()); + + int currNum = getLabel(example->image1); + Mat img = imread(path+example->image1, IMREAD_GRAYSCALE); + images.push_back(img); + labels.push_back(currNum); + + currNum = getLabel(example->image2); + img = imread(path+example->image2, IMREAD_GRAYSCALE); + images.push_back(img); + labels.push_back(currNum); + } + model->train(images, labels); + //string saveModelPath = "face-rec-model.txt"; + //cout << "Saving the trained model to " << saveModelPath << endl; + //model->save(saveModelPath); + } vector p; for (unsigned int j=0; j > &curr = dataset->getTest(j2); + for (unsigned int i=0; i(curr[i].get()); + + int currNum = getLabel(example->image1); + Mat img = imread(path+example->image1, IMREAD_GRAYSCALE); + images.push_back(img); + labels.push_back(currNum); + + currNum = getLabel(example->image2); + img = imread(path+example->image2, IMREAD_GRAYSCALE); + images.push_back(img); + labels.push_back(currNum); + } + } + model->train(images, labels); + } + unsigned int incorrect = 0, correct = 0; vector < Ptr > &curr = dataset->getTest(j); for (unsigned int i=0; i