forked from happynear/FaceVerification
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lfwJB.m
42 lines (35 loc) · 1.52 KB
/
lfwJB.m
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
num = size(AllFeature1,2);
same_label = ones(6000,1);
same_label(3001:6000) = 0;
accuracies = zeros(10,1);
for i = 1 : 10
F1 = AllFeature1';
F1 = bsxfun(@rdivide, F1, sqrt(sum(F1.^2,2)));
F2 = AllFeature2';
F2 = bsxfun(@rdivide, F2, sqrt(sum(F2.^2,2)));
test_idx = [(i-1) * 300 + 1 : i*300, (i-1) * 300 + 3001 : i*300 + 3000];
train_idx = 1:6000;
train_idx(test_idx) = [];
train = [F1(train_idx,:);F2(train_idx,:)];
train_label = [lfw_label(train_idx,1);lfw_label(train_idx,2)];
[normX, PCAmap] = compute_mapping(train, 'PCA', 310);
[mappedX, mapping] = JointBayesian(normX, train_label);
F1 = bsxfun(@minus,F1,PCAmap.mean);
F1 = F1 * PCAmap.M;
F2 = bsxfun(@minus,F2,PCAmap.mean);
F2 = F2 * PCAmap.M;
% thresh = zeros(size(train_idx,2),1);
% for j = 1:size(train_idx,2)
% thresh(j) = F1(train_idx(j),:) * mapping.A * F1(train_idx(j),:)' + F2(train_idx(j),:) * mapping.A * F2(train_idx(j),:)' - 2 * F1(train_idx(j),:) * mapping.G * F2(train_idx(j),:)';
% end;
thresh = zeros(size(F1,1),1);
for j = 1:size(F1,1)
thresh(j) = F1(j,:) * mapping.A * F1(j,:)' + F2(j,:) * mapping.A * F2(j,:)' - 2 * F1(j,:) * mapping.G * F2(j,:)';
end;
cmd = [' -t 0 -h 0'];
model = svmtrain(same_label(train_idx),thresh(train_idx),cmd);
[class] = svmpredict(same_label(train_idx),thresh(train_idx),model);
[class, accuracy, deci] = svmpredict(same_label(test_idx),thresh(test_idx),model);
accuracies(i) = accuracy(1);
end;
mean(accuracies)