-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrerank_script.m
More file actions
74 lines (53 loc) · 2.85 KB
/
rerank_script.m
File metadata and controls
74 lines (53 loc) · 2.85 KB
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
addpath('./utils/'); %for the utility functions
%%SET VARIABLES
%vocab = 20000;
%hits = 15;
%features='surf';
%mod1='mod1'; %/patches
%mod2='mod2';
%%OBS: requires a csv with first N matches to be reranked to exist: matches_for_mod2_in_mod1_features.csv !!!
%% (Makefile will make sure it's done first if it doesn't, but if running by hand make sure it exists!)
%%if saving desired:
%saveit=true;
%save_to='resultsfolder';
%%intermediate reporting verbosity:
%verbose=false;
%%what to do; only reranking or also eval?
%evlt=false;
%TODO: to allow eval on top, reranking function should return a table with row names (queries) again. Patches can be saved by imgname_PATCHNR,
% and eval will still work.
% The query needs to be read in (only the first one suffices, we assume all queries are same sized?) and then its size will be the size
% of the patches for retrieval.
% RetrieveMatches can be used within reranking too.
% So basically: * get names of all queries (either from folder or csv)
% * for each query find all patches that are cut of its highly ranked hits
% * create new Bof on all of these new patch imges
% * call retrieveal function with new bof
% * call eval function on results, if desired
%Get all guery names from old savename csv
oldmatches = readtable(fullfile(save_to, strcat('matches_for_', mod2, '_in_', mod1, '_', features,'.csv')), 'ReadVariableNames', true, 'ReadRowNames', true, 'Delimiter', ',', 'VariableNamingRule', 'preserve');
%get suffix (if csv, folder whould be features instead of img), or just check feature type
if strcmp(features, 'surf')
%%% using SURF
bof_folder = fullfile('data', mod1, 'patches');
query_folder = fullfile('data', mod2);
else %%% assume SIFT or RESNET, precomputed csvs needed
bof_folder = fullfile('data', mod1, 'patches', 'features', features);
query_folder = fullfile('data', mod2, 'features', features);
end
matches = RerankRetrievals(oldmatches, query_folder, bof_folder, features, vocab, hits, verbose=verbose);
savename = strcat(mod2, '_in_', mod1, '_', features, '_reranked');
if saveit
writetable(matches, fullfile(save_to, strcat('matches_for_',savename,'.csv')), 'WriteRowNames', true);
fprintf("* Reranked retrieval results saved in %s/matches_for_%s.csv\n", save_to, savename);
end
%do eval on new matches table if desired
if evlt
[correct, alla] = EvalMatches(matches, verbose=verbose);
if saveit
writetable(correct, fullfile(save_to, strcat('success_',savename,'.csv')), 'WriteRowNames', true);
fprintf("* Reranked retrieval evaluation results saved in %s/success_%s.csv", save_to, savename);
end
fprintf("\n---> After reranking, the query correctly retrieved (within %d-hits) in: %d/%d cases.", hits, alla, height(matches));
end
fprintf("\n \n");