-
-
Notifications
You must be signed in to change notification settings - Fork 225
/
compute_MAP.m
79 lines (56 loc) · 1.94 KB
/
compute_MAP.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
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
% 下面mAP的具体计算过程请参阅:http://yongyuan.name/blog/evaluation-of-information-retrieval.html
clear;clear all;
addpath('./database/');
queryFile = './queryImgs.txt';
classesFile = './databaseClasses.txt';
load feat4096Norml.mat
N = 9; % 如果用于论文中,把这个值设为你所用数据库的大小
fid = fopen(queryFile,'rt');
queryImgs = textscan(fid, '%s');
fclose(fid);
fid = fopen(classesFile,'rt');
classesAndNum = textscan(fid, '%s %d');
fclose(fid);
for i = 1:length(classesAndNum{1, 1})
classes{i,1} = classesAndNum{1, 1}{i,1}(1:3);
end
[numImg,d] = size(feat_norm);
querysNum = length(queryImgs{1, 1});
ap = zeros(querysNum,1);
for i =1:querysNum
queryName = queryImgs{1, 1}{i, 1};
queryClass = queryName(1:3);
[row,col]=ind2sub(size(imgNamList),strmatch(queryName,imgNamList,'exact'));
queryFeat = feat_norm(row, :);
[row1,col1]=ind2sub(size(classesAndNum{1, 1}),strmatch(queryClass,classes,'exact'));
queryClassNum = double(classesAndNum{1, 2}(row1,1));
%dist = distMat(queryFeat,feat_norm);
%dist = dist';
%[~, rank] = sort(dist, 'ascend');
dist = zeros(numImg, 1);
for j = 1:numImg
VecTemp = feat_norm(j, :);
dist(j) = queryFeat*VecTemp';
end
[~, rank] = sort(dist, 'descend');
similarTerm = 0;
precision = zeros(N,1);
for k = 1:N
topkClass = imgNamList{rank(k, 1), 1}(1:3);
if strcmp(queryClass,topkClass)==1;
similarTerm = similarTerm+1;
precision(k,1) = similarTerm/k;
end
end
for k = 1:N
topkClass = imgNamList{rank(k, 1), 1}(1:3);
% use for configure
subplot(4,3,k);
im = imread(imgNamList{rank(k, 1), 1});
imshow(im);
end
ap(i,1) = sum(precision)/queryClassNum;
fprintf('%s ap is %f \n',queryName,ap(i,1));
end
mAP = sum(ap)/querysNum;
fprintf('mAP is %f \n',mAP);