关于LFW如何使用,网上资料非常少。这里给出一个比较好的。
这几天鼓捣LFW数据集。模型早跑完了,但是就是不知如何做一个验证。网上关于这个验证的说明非常少。
这里mark一下。
https://github.com/jakezhaojb/LFW_API
现在实验正在进行中。。。以后公布整个实验流程。敬请关注。
上面那个比较麻烦。因此我自己写了一份关于验证lfw的c++代码。
#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)
{
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));
}
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);
}
features.push_back(_feature);
}
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;
}
}
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130