-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_evaluation_house.m
More file actions
269 lines (201 loc) · 8.15 KB
/
run_evaluation_house.m
File metadata and controls
269 lines (201 loc) · 8.15 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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
% Load data. The data in the file house_sync_data is created from the
% stereo matching code of Pachauri et al., NIPS, 2013
% ( http://pages.cs.wisc.edu/~pachauri/perm-sync/ )
%
% It contains the following variables:
% Wnoise The (noisy) matrix of pairwise permutations
% m The number of points observed in each image
% k The total number of images
% data The keypoint coordinates in each image
%
% The ground truth is given by the identity pairwise matching matrix, i.e.
% Pgt = kron(ones(k),speye(m));
%
% Author and copyright: Florian Bernard (f.bernardpi@gmail.com)
%
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU Affero General Public License as published
% by the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU Affero General Public License for more details.
% You should have received a copy of the GNU Affero General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>.
%
load house_sync_data
addpath(genpath(pwd));
%%
dimVector = repmat(m,k,1);
Wcell = mat2cell(Wnoise, dimVector, dimVector);
allErrors = [];
allObjectives = [];
allRuntimes = [];
allFscores = [];
allMethods = {'MatchEig', 'MatchALS', 'Spectral', 'NmfSync', 'Ours'};
% If you want to run MatchALS it is recommended to install MOSEK (also see
% README.txt)
% addpath(genpath('~/code/git/code/src/toolboxes/mosek/9.1'))
runMatchALS = 0; % disabled by default for runtime reasons
% number of objects that are used to create gradually increasing permutation
% synchronisation problems
kValues = 20:111;
for i=1:numel(kValues)
% note that this variable only stores the obtained matchings from the
% most recent iteration (due to memory reasons); it is later used to
% visualse these results (see further below)
allP = {};
% number of objects we synchronise
currK = kValues(i);
disp(['Processing k = ' num2str(currK)]);
% subsample the original pairwise matchings to create a sequence of
% permutation synchronisation problems with increasing size
subIdx = round(linspace(1,k,currK));
% noisy pairwise matching matrix
currWnoise = cell2mat(Wcell(subIdx,subIdx));
% vector containing the number of points for each image
currDimVector = dimVector(subIdx);
% ground truth
currPgt = kron(ones(currK),speye(m));
% synchronisation objective that we want to maximise
obj = @(U) trace(U'*currWnoise*U);
%% MatchEig
s = tic();
P_matchEig = MatchEIG(currWnoise,m,currK,currDimVector, 0);
timeMatchEig = toc(s);
objMatchEig = nan; % not cycle-consistent, so there does not exist a binary U matrix that would allow us to call obj()
fscoreMatchEig = fscore(currPgt, P_matchEig);
allP{end+1} = P_matchEig;
%% MatchALS
if ( runMatchALS )
s = tic();
Z_matchALS = mmatch_CVX_ALS(currWnoise,currDimVector,'pselect',0.7, ...
'maxiter',100,'univsize',2*m,'verbose',false);
timeMatchAls = toc(s);
fscoreMatchAls = fscore(currPgt, Z_matchALS);
allP{end+1} = Z_matchALS;
else
timeMatchAls = nan;
fscoreMatchAls = nan; %fscore(currPgt, Z_matchALS);
allP{end+1} = [];
end
objMatchAls = nan; % not cycle-consistent, so there does not exist a binary U matrix that would allow us to call obj()
%% Spectral
s = tic();
[Pspectral,~,~,U_spectral] = mmatch_spectral(currWnoise,currDimVector,m);
timeMatchSpectral = toc(s);
objSpectral = obj(U_spectral);
fscoreSpectral = fscore(currPgt, Pspectral);
allP{end+1} = Pspectral;
%% NmfSync
s = tic();
[ZnmfSync, UnmfSync] = nmfSync(full(currWnoise), currDimVector, m, []);
timeMatchNmfSync = toc(s);
objNmfSync = obj(UnmfSync);
fscoreNmfSync = fscore(currPgt, ZnmfSync);
allP{end+1} = ZnmfSync;
%% Ours
s = tic();
[P_our, U_our] = SparseStiefelSync(currWnoise, currDimVector, m, 0);
timeOur = toc(s);
objOur = obj(U_our);
fscoreOur = fscore(currPgt, P_our);
allP{end+1} = P_our;
%% store all results
allObjectives(end+1,:) = [objMatchEig objMatchAls objSpectral objNmfSync objOur]./currK^2;
allRuntimes(end+1,:) = [timeMatchEig timeMatchAls timeMatchSpectral timeMatchNmfSync timeOur];
allFscores(end+1,:) = [fscoreMatchEig fscoreMatchAls fscoreSpectral fscoreNmfSync fscoreOur];
end
%% create plots
lineWidth = 2;
figure('color', 'w', 'position', [100 100 1200 300]);
linetypes = {'-.','-.','-', '-','-'};
nMethods = numel(allMethods);
colorMap = [0.650980392156863,0.807843137254902,0.890196078431373;0.121568627450980,0.470588235294118,0.705882352941177;0.698039215686275,0.874509803921569,0.541176470588235;0.200000000000000,0.627450980392157,0.172549019607843;0.984313725490196,0.603921568627451,0.600000000000000];
% fscore
subplot 131
hold on;
for jj=1:nMethods
plot(kValues,allFscores(:,jj)', ...
'linewidth', lineWidth, ...
'color', colorMap(jj,:), 'linestyle', linetypes{jj});
end
legend(allMethods, 'orientation', 'horizontal');
xlim([kValues(1) kValues(end)]);
xlabel('k');
ylabel('fscore');
% objectives
subplot 132
hold on;
for jj=3:nMethods
plot(kValues,allObjectives(:,jj)', ...
'linewidth', lineWidth, ...
'color', colorMap(jj,:), 'linestyle', linetypes{jj});
end
xlim([kValues(1) kValues(end)]);
xlabel('k');
ylabel('objective');
% runtime
subplot 133
hold on;
for jj=1:nMethods
plot(kValues,allRuntimes(:,jj)', ...
'linewidth', lineWidth, ...
'color', colorMap(jj,:), 'linestyle', linetypes{jj});
end
xlim([kValues(1) kValues(end)]);
xlabel('k');
ylabel('runtime [s]');
%% show result images
imFolder = 'house_images/';
lw = 2;
sz = 200;
% add new rows for any pair of image indices (between 1 and 111) to visualise
subIdx = [1 111];
for i=1:size(subIdx,1)
%%
I1 = imread([imFolder 'house.seq' num2str(subIdx(i,1)-1) '.png']);
I2 = imread([imFolder 'house.seq' num2str(subIdx(i,2)-1) '.png']);
[r,c] = size(I1);
pts1 = data{subIdx(i,1)};
pts2 = data{subIdx(i,2)};
% crop images to allow for a tighter visualisation
I1LeftOffset = 140;
I1RightOffset = 510;
I2LeftOffset = 80;
I2RightOffset = 360;
I2(:,1:I2LeftOffset) = [];
I2(:,I2RightOffset:end) = [];
I1(:,I1RightOffset:end) = [];
pts1(:,1) = pts1(:,1) - I1LeftOffset;
pts2(:,1) = pts2(:,1) - I1LeftOffset + I1RightOffset - I2LeftOffset;
II = [I1, I2];
II(:,1:I1LeftOffset) = [];
cols = lines(size(pts1,1));
for methodIdx=1:numel(allMethods)
if ( ~isempty(allP{methodIdx}) )
matchingGt = 1:size(pts1,1);
iidx = (1+(subIdx(i,1)-1)*m):subIdx(i,1)*m;
jidx = (1+(subIdx(i,2)-1)*m):subIdx(i,2)*m;
currP = allP{methodIdx}(iidx,jidx);
currMatching = zeros(1,m);
[i1,i2] = find(currP);
currMatching(i2) = i1;
correctIdx = find(matchingGt==currMatching);
wrongIdx = find(matchingGt~=currMatching & currMatching~=0);
missingIdx = find(currMatching==0);
figure
imshow(II)
hold on
scatter(pts1(:,1), pts1(:,2),sz, cols, 'filled', 'markeredgecolor', 'k', 'linewidth', 2)
scatter(pts2(:,1), pts2(:,2),sz, cols, 'filled', 'markeredgecolor', 'k', 'linewidth', 2)
line([pts1(correctIdx,1), pts2(currMatching(correctIdx),1)]', [pts1((correctIdx),2), pts2(currMatching(correctIdx),2)]', 'color', 'g', 'linewidth', lw);
line([pts1((wrongIdx),1), pts2(currMatching(wrongIdx),1)]', [pts1((wrongIdx),2), pts2(currMatching(wrongIdx),2)]', 'color', 'r', 'linewidth', lw);
drawnow;
title(allMethods{methodIdx})
end
end
end