-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuildScores.m
39 lines (32 loc) · 1.5 KB
/
buildScores.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
addpath('../functions/InLocCIIRC_utils/params');
params = setupParams('s10e', true); % NOTE: mode can be anything, its specific params are not used here
featuresPath = fullfile(params.input.feature.dir, 'computed_features.mat');
files = dir(fullfile(params.dataset.db.cutouts.dir, '**/cutout*.jpg'));
nCutouts = size(files,1); % TODO: use the actual number from featuresPath
%x = matfile(featuresPath);
load(featuresPath, 'queryFeatures', 'cutoutFeatures');
nQueries = size(queryFeatures,2);
score = struct('queryname', {}, 'scores', {});
allCutoutFeatures = zeros(nCutouts, size(cutoutFeatures(1).features,1));
for i=1:nCutouts
allCutoutFeatures(i,:) = cutoutFeatures(i).features';
end
allCutoutFeatures = allCutoutFeatures';
tol = 1e-6;
if ~all(abs(vecnorm(allCutoutFeatures)-1.0)<tol)
fprintf('norm: %f\n', vecnorm(allCutoutFeatures));
error('Features are not normalized!');
end
for i=1:nQueries
fprintf('processing query %d/%d\n', i, nQueries);
thisQueryFeatures = queryFeatures(i).features';
if ~all(abs(norm(thisQueryFeatures)-1.0)<tol)
fprintf('norm: %f\n', norm(thisQueryFeatures));
error('Features are not normalized!');
end
thisQueryFeatures = repmat(thisQueryFeatures, nCutouts, 1)';
similarityScores = dot(thisQueryFeatures, allCutoutFeatures);
score(i).queryname = queryFeatures(i).queryname;
score(i).scores = single(similarityScores); % NOTE: this is not a probability distribution (and it does not have to be)
end
save(params.input.scores.path, 'score');