关于LFW如何使用,网上资料非常少。这里给出一个比较好的。
这几天鼓捣LFW数据集。模型早跑完了,但是就是不知如何做一个验证。网上关于这个验证的说明非常少。 这里mark一下。 https://github.com/jakezhaojb/LFW_API
现在实验正在进行中。。。以后公布整个实验流程。敬请关注。
上面那个比较麻烦。因此我自己写了一份关于验证lfw的c++代码。
/************************************************************************* File Name: test.cpp Author: bin.wang Mail: sa615168@mail.ustc.edu.cn Created Time: Mon 16 Jan 2017 03:37:30 PM CST ************************************************************************/ #include <iostream> #include <fstream> #include <typeinfo> #include <cmath> #include <vector> #include <algorithm> using namespace std; #define PAIR_LINES 3000 #define FEA_LENGTH 1024 #define FEA_NUMS 13233 int main(int argc, char** argv) { //read positive pairs & negative pairs form file fstream pos_pair("./POSTIVE_PAIR.txt"); fstream neg_pair("./NEGATIVE_PAIR.txt"); fstream lfw_feature("./wwwfea.txt"); vector< pair<int,int> > pos_vec; vector< pair<int,int> > neg_vec; int pos_left = 0, neg_left = 0; int pos_right = 0, neg_right = 0; for(int i =0; i<PAIR_LINES; ++i) { pos_pair >> pos_left >> pos_right; pos_vec.push_back(make_pair(pos_left,pos_right)); neg_pair >> neg_left >> neg_right; neg_vec.push_back(make_pair(neg_left,neg_right)); } //cout << pos_vec.size() << " "<< (pos_vec[1]).first <<" "<< (pos_vec[1]).second << endl; //cout << neg_vec.size() << " "<< (neg_vec[1]).first <<" "<< (neg_vec[1]).second << endl; // vector< vector<float> > features; features.reserve(FEA_NUMS); while( !lfw_feature.eof() ) { float keyPoint1 = 0; float keyPoint2 = 0; float keyPoint3 = 0; float keyPoint4 = 0; vector<float> _feature; _feature.reserve(FEA_LENGTH); for(int i = 0; i< FEA_LENGTH; i += 4) { lfw_feature >> keyPoint1 >> keyPoint2 >> keyPoint3 >> keyPoint4; _feature.push_back(keyPoint1); _feature.push_back(keyPoint2); _feature.push_back(keyPoint3); _feature.push_back(keyPoint4); } //cout << features.size() << endl; //cout << _feature.size() << endl; features.push_back(_feature); } //cout << features[0][0] << " "<< features[0][1] <<" " <<features[0][2] << endl; vector< pair<double ,int> > scores; int pair_id = 0; for(auto pos_it = pos_vec.begin(); pos_it != pos_vec.end(); ++pos_it) { pair_id++; double innerPorduct = 0; double sum_left = 0, sum_right = 0; double _norm = 0; int pair_first = (pos_it->first) - 1; int pair_second = (pos_it->second) - 1; for(auto lit = features[pair_first].begin(), rit = features[pair_second].begin(); lit != features[pair_first].end(), rit != features[pair_second].end(); ++lit, ++rit) { innerPorduct += (*lit)*(*rit); sum_left += (*lit) * (*lit); sum_right +=(*rit) * (*rit); } _norm = sqrt(sum_left) * sqrt(sum_right); scores.push_back(make_pair(innerPorduct/_norm,pair_id)); } for(auto neg_it = neg_vec.begin(); neg_it != neg_vec.end(); ++neg_it ) { pair_id++; double innerPorduct = 0; double sum_left = 0, sum_right = 0; double _norm = 0; int pair_first = (neg_it->first) -1; int pair_second = (neg_it->second) -1; for(auto lit = features[pair_first].begin(), rit = features[pair_second].begin(); lit != features[pair_first].end(), rit != features[pair_second].end(); ++lit, ++rit) { innerPorduct += (*lit)*(*rit); sum_left += (*lit) * (*lit); sum_right +=(*rit) * (*rit); } _norm = sqrt(sum_left) * sqrt(sum_right); scores.push_back(make_pair(innerPorduct/_norm , pair_id)); } stable_sort(scores.begin(),scores.end()); fstream hh("./scores.txt"); for(auto s : scores) { hh << s.first << " " << s.second << endl; } int index = 0; for(int i = 0; i <3000; ++i) { if(scores[i].second < 3000) { ++index; cout << scores[i].first << " " << scores[i].second << endl; } } //cout << scores[1].first <<" "<< scores[1].second << endl; //cout << scores.size()<< endl; //cout <<typeid(features[1]).name()<< endl; return 0; } 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130