-
Notifications
You must be signed in to change notification settings - Fork 62
/
plot_correlation_edge_boxes.m
201 lines (169 loc) · 5.97 KB
/
plot_correlation_edge_boxes.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
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
function plot_correlation_edge_boxes()
% Plots for analyzing the correlation between detector performance
% (R-CNN) on the different variants of EdgeBoxes.
% Also plots the recall curves for all the variants.
%
% Bonus feature: Rainbow colormap! Hand-tuned nice colors on the curve!
methods = get_method_configs();
IoUs = 0.5:0.05:0.9;
custom_names = arrayfun(@(x) sprintf('%.2f', x), IoUs, 'UniformOutput', false);
custom_names = [custom_names {'AR'}];
% select all edge box variants
method_selection = [13 14 16 19 20:25];
[~,order] = sort({methods(method_selection).short_name});
method_selection = method_selection(order);
methods = methods(method_selection);
for i = 1:numel(methods)
methods(i).sort_key = i;
end
% Recall matrix used for experiments nThresholds x nAlgorithms
ld = load('data/pascal_voc07_test_recall.mat');
R = ld.recalls(method_selection,:)';
ARs = ld.ARs(method_selection)';
T = ld.iou_thresholds;
ld = load('data/pascal_voc07_test_rcnn_aps.mat');
rcnn_AP = ld.aps(method_selection);
ld = load('data/pascal_voc07_test_frcn_aps.mat');
frcn_AP = ld.aps(method_selection);
ld = load('data/pascal_voc07_test_frcn_noregr_aps.mat');
frcn_noregr_AP = ld.aps(method_selection);
% assign distinct colors to the methods
n = numel(methods);
for i = 1:n
methods(i).line_style = '-';
end
% average recall
mirror_offset = 0.060;
offsets = zeros(n, 2);
offsets(:,1) = 0.010;
offsets(1,1) = offsets(1,1)-mirror_offset;
offsets(2,1) = offsets(2,1)-mirror_offset;
offsets(6,1) = offsets(6,1)-mirror_offset;
offsets(7,1) = offsets(7,1)-mirror_offset;
methods = plot_weighted_area_color_coded(ARs, ...
rcnn_AP, methods, custom_names, [0.3 0.6 43 57], true, offsets);
hei = 7; wid = 7;
set(gcf, 'Units','centimeters', 'Position',[0 0 wid hei]);
set(gcf, 'PaperPositionMode','auto');
printpdf('figures/RCNN_mAP_recall_area_voc07_edge_boxes.pdf');
mirror_offset = 0.060;
offsets = zeros(n, 2);
offsets(:,1) = 0.010;
offsets(1:4,1) = offsets(1:4,1)-mirror_offset;
offsets(5,2) = offsets(5,2)+0.5;
offsets(6:9,2) = offsets(6:9,2)-0.5;
plot_weighted_area_color_coded(ARs, ...
frcn_AP, methods, custom_names, [0.3 0.6 45 67], false, offsets);
hei = 7; wid = 7;
set(gcf, 'Units','centimeters', 'Position',[0 0 wid hei]);
set(gcf, 'PaperPositionMode','auto');
printpdf('figures/FRCN_mAP_recall_area_voc07_edge_boxes.pdf');
mirror_offset = 0.060;
offsets = zeros(n, 2);
offsets(:,1) = 0.010;
offsets(6:9,1) = offsets(6:9,1)-mirror_offset;
offsets(5:6,2) = offsets(5:6,2)+0.5;
offsets(1:4,2) = offsets(1:4,2)-0.6;
offsets(1:4,1) = offsets(1:4,1)-0.006;
plot_weighted_area_color_coded(ARs, ...
frcn_noregr_AP, methods, custom_names, [0.3 0.6 44 61], false, offsets);
hei = 7; wid = 7;
set(gcf, 'Units','centimeters', 'Position',[0 0 wid hei]);
set(gcf, 'PaperPositionMode','auto');
printpdf('figures/FRCN_noregr_mAP_recall_area_voc07_edge_boxes.pdf');
% plot recall curves for each parameter setting
fh = figure;
plot_overlap_recall_curve({methods.best_voc07_candidates_file}, ...
methods, 1000, fh, true, 'NorthEast', false, ...
custom_names);
[lh, hobj1] = legend(custom_names);
legend boxoff;
hei = 7;
wid = 7;
set(gcf, 'Units','centimeters', 'Position',[0 0 wid hei]);
set(gcf, 'PaperPositionMode','auto');
% change the length of the line samples in the legend
textobj = findobj(hobj1, 'type', 'line');
for i = 1:numel(textobj)
lineXData = get(textobj(i), 'XData');
lineXData(1) = lineXData(1) + 0.3;
set(textobj(i), 'XData', lineXData);
end
% move the legend more outside
P = get(lh, 'Position');
P(1) = P(1) + 0.05;
P(2) = P(2) + 0.05;
set(lh, 'Position', P);
printpdf('figures/recall_1000_voc07_edge_boxes.pdf')
end
function [methods] = plot_weighted_area_color_coded(areas, AP, methods, ...
custom_names, axis_lim, reassign_colors, label_offsets)
additional_methods = methods(end);
additional_areas = areas(end);
additional_AP = AP(end);
methods = methods(1:end-1);
areas = areas(1:end-1);
AP = AP(1:end-1);
S=corrcoef([areas' AP']); s = S(1,end);
figure;
x = 0.5:0.05:0.9;
y = cat(1, areas, AP);
xx = 0.5:0.002:0.9;
yy = spline(x, y, xx);
dists = sqrt(sum((yy(:,2:end) - yy(:,1:end-1)) .^ 2, 1));
dists = dists .* linspace(6,1,numel(dists));
dists = cumsum(dists);
colors = rainbow(dists, max(dists));
n = numel(xx);
for i = 2:n
plot(yy(1,(i-1):i), yy(2,(i-1):i), 'Color', colors(i-1,:), 'LineWidth', 1.5);
if i == 2; hold on; end
end
if reassign_colors
for i = 1:numel(methods)
[~,c_idx] = min((yy(1,:) - areas(i)) .^ 2 + (yy(2,:) - AP(i)) .^ 2);
c_idx = max(c_idx - 1, 1);
methods(i).color = colors(c_idx,:);
end
end
hold on;
p=polyfit(areas,AP,1); line([0 1],[p(2),sum(p)],'Color',[1 1 1]/3);
for i = 1:numel(methods)
plot(areas(i), AP(i), '.', 'MarkerSize', 20, 'Color', methods(i).color);
end
for i = 1:numel(additional_methods)
plot(additional_areas(i), additional_AP(i), '.', 'MarkerSize', 20, 'Color', 'k');
additional_methods(i).color = [0 0 0];
end
grid on;
% move the labels around, so it looks nice
xpos = [areas additional_areas];
ypos = [AP additional_AP];
xpos = xpos + label_offsets(:,1)';
ypos = ypos + label_offsets(:,2)';
text(xpos,ypos,custom_names);
xlabel(sprintf('average recall')); axis(axis_lim)
ylabel('mAP'); hold on;
hold off
% move the title inside of the plot
v = axis;
handle = title(sprintf('correlation=%.3f',s));
titlepos = [(v(2)-v(1))*0.5+v(1), (v(4)-v(3))*0.91+v(3), 0];
set(handle, 'Position', titlepos);
methods = [methods additional_methods];
end
function cmap = rainbow(k,n)
rainbow_cmap = [
255, 0, 0
255, 127, 0
255, 255, 0
0, 255, 0
0, 0, 255
75, 0, 130
143, 0, 255]/255;
idx = (k/n*size(rainbow_cmap,1));
idx = max(1, min(size(rainbow_cmap,1), idx));
x = (1:size(rainbow_cmap,1))';
y = rainbow_cmap;
cmap = interp1(x, y, idx);
end