LFW的正确率,使用方法

关于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;
}
   
   
  • 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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值