-
Notifications
You must be signed in to change notification settings - Fork 4
/
Evaluation_Default_Mode.m
195 lines (167 loc) · 8.25 KB
/
Evaluation_Default_Mode.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
addpath('functionset');
% Add MatCaffe Path
matcaffe_path = 'caffe-master/matlab/';
addpath(matcaffe_path)
caffe.set_mode_gpu();
caffe.reset_all;
caffe.set_device(2); % Setting GPU here
GLOBAL_BATCH_SIZE = 6;
GLOBAL_ENCODER_NAME = 'DenseNet1651or';
GLOBAL_ENCODER_INPUT_NAME = 'data';
GLOBAL_ENCODER_INPUT_WIDTH = 224;
GLOBAL_ENCODER_INPUT_HEIGHT = 224;
GLOBAL_ENCODER_INPUT_CHANNEL = 003;
GLOBAL_ENCODER_OUTPUT_WIDTH = 008;
GLOBAL_ENCODER_OUTPUT_HEIGHT = 008;
GLOBAL_ENCODER_OUTPUT_CHANNEL = 1056;
% for Ordinal Depth 3
GLOBAL_DECODER01_OUTPUT_NAME = 'DenseNet16520or/pred_2D_008_008_ch068';
GLOBAL_DECODER01_OUTPUT_WIDTH = 008;
GLOBAL_DECODER01_OUTPUT_HEIGHT = 008;
GLOBAL_DECODER01_OUTPUT_CHANNEL = 068;
% for Relative Depth 3
GLOBAL_DECODER02_OUTPUT_NAME = 'DenseNet16521or/pred_2D_008_008_ch2560';
GLOBAL_DECODER02_OUTPUT_WIDTH = 008;
GLOBAL_DECODER02_OUTPUT_HEIGHT = 008;
GLOBAL_DECODER02_OUTPUT_CHANNEL = 2560;
GLOBAL_DECODER02_OUTPUT_CHANNEL_REDUCED = 064;
% for Relative Depth 4
GLOBAL_DECODER04_OUTPUT_NAME = 'DenseNet16523or/pred_2D_016_016_ch1000';
GLOBAL_DECODER04_OUTPUT_WIDTH = 016;
GLOBAL_DECODER04_OUTPUT_HEIGHT = 016;
GLOBAL_DECODER04_OUTPUT_CHANNEL = 1000;
GLOBAL_DECODER04_OUTPUT_CHANNEL_REDUCED = 025;
% for Relative Depth 5
GLOBAL_DECODER06_OUTPUT_NAME = 'DenseNet16525or/pred_2D_032_032_ch1000';
GLOBAL_DECODER06_OUTPUT_WIDTH = 032;
GLOBAL_DECODER06_OUTPUT_HEIGHT = 032;
GLOBAL_DECODER06_OUTPUT_CHANNEL = 1000;
GLOBAL_DECODER06_OUTPUT_CHANNEL_REDUCED = 025;
GLOBAL_DECODER02_INPUT_HEIGHT = GLOBAL_ENCODER_OUTPUT_HEIGHT;
% for Relative Depth 6
GLOBAL_DECODER08_OUTPUT_NAME = 'DenseNet16527or/pred_2D_064_064_ch1000';
GLOBAL_DECODER08_OUTPUT_WIDTH = 064;
GLOBAL_DECODER08_OUTPUT_HEIGHT = 064;
GLOBAL_DECODER08_OUTPUT_CHANNEL = 1000;
GLOBAL_DECODER08_OUTPUT_CHANNEL_REDUCED = 025;
%% Load Image & depth
if ~exist('imset')
load('dataset/nyu_depth_v2_labeled.mat', 'images')
load('dataset/nyu_depth_v2_labeled.mat', 'depths')
load('dataset/splits.mat', 'testNdxs', 'trainNdxs')
imset_test = images(45:471, 41:601, :, testNdxs);
gtset_test = depths(45:471, 41:601, testNdxs);
imset_train = images(45:471, 41:601, :, trainNdxs);
gtset_train = depths(45:471, 41:601, trainNdxs);
clear images; clear depths; clear testNdxs;
end
% test
resultpath = 'results/';
if ~exist( resultpath, 'dir' );
mkdir( resultpath );
end
%% Encoder
net_name = ['models/', 'default_mode_net', '.prototxt'];
model_name = ['Snapshot/default_mode_net.caffemodel'];
net = caffe.get_net(net_name, 'test');
net.copy_from(model_name);
%% Batch resape
data_sz = net.blobs('data').shape();
data_sz(4) = GLOBAL_BATCH_SIZE;
net.blobs('data').reshape(data_sz);
data_sz = net.blobs('label_008_008_ch068').shape();
data_sz(4) = GLOBAL_BATCH_SIZE;
net.blobs('label_008_008_ch068').reshape(data_sz);
data_sz = net.blobs('label_008_008_ch2560').shape();
data_sz(4) = GLOBAL_BATCH_SIZE;
net.blobs('label_008_008_ch2560').reshape(data_sz);
data_sz = net.blobs('label_016_016_ch1000').shape();
data_sz(4) = GLOBAL_BATCH_SIZE;
net.blobs('label_016_016_ch1000').reshape(data_sz);
data_sz = net.blobs('label_032_032_ch1000').shape();
data_sz(4) = GLOBAL_BATCH_SIZE;
net.blobs('label_032_032_ch1000').reshape(data_sz);
data_sz = net.blobs('label_064_064_ch1000').shape();
data_sz(4) = GLOBAL_BATCH_SIZE;
net.blobs('label_064_064_ch1000').reshape(data_sz);
net.forward_prefilled;
for data_train_test = [0,1]
%% image setting
if data_train_test == 0
data_class = 'train';
data_num = 795;
% image RGB -> BGR
imset2 = double(imset_train(:,:,[3 2 1],:));
elseif data_train_test == 1
data_class = 'test';
data_num = 654;
% image RGB -> BGR
imset2 = double(imset_test(:,:,[3 2 1],:));
end
% image subtract mean value
imset2(:,:,1,:) = imset2(:,:,1,:) - 104;
imset2(:,:,2,:) = imset2(:,:,2,:) - 117;
imset2(:,:,3,:) = imset2(:,:,3,:) - 123;
%% Space for prediction
modelre_01_temp = zeros( GLOBAL_DECODER01_OUTPUT_HEIGHT, GLOBAL_DECODER01_OUTPUT_WIDTH, data_num, 2 );
modelre_02_temp = zeros( GLOBAL_DECODER02_OUTPUT_HEIGHT, GLOBAL_DECODER02_OUTPUT_WIDTH, GLOBAL_DECODER02_OUTPUT_CHANNEL_REDUCED, data_num, 2 );
modelre_04_temp = zeros( GLOBAL_DECODER04_OUTPUT_HEIGHT, GLOBAL_DECODER04_OUTPUT_WIDTH, GLOBAL_DECODER04_OUTPUT_CHANNEL_REDUCED, data_num, 2 );
modelre_06_temp = zeros( GLOBAL_DECODER06_OUTPUT_HEIGHT, GLOBAL_DECODER06_OUTPUT_WIDTH, GLOBAL_DECODER06_OUTPUT_CHANNEL_REDUCED, data_num, 2 );
modelre_08_temp = zeros( GLOBAL_DECODER08_OUTPUT_HEIGHT, GLOBAL_DECODER08_OUTPUT_WIDTH, GLOBAL_DECODER08_OUTPUT_CHANNEL_REDUCED, data_num, 2 );
%% Prediction step
disp('Prediction Start')
tic
for image_flip = 1 : 2
im = zeros(size(imset2,1), size(imset2,2), size(imset2,3), GLOBAL_BATCH_SIZE);
for fInd = 1 : GLOBAL_BATCH_SIZE : data_num
fInd_start = fInd;
fInd_end = min(fInd + (GLOBAL_BATCH_SIZE-1), data_num);
if image_flip == 1 % NO-FLIP (left-right)
im(:, :, :, 1 : fInd_end-fInd_start+1) = imset2(:,:,:,fInd_start:fInd_end);
elseif image_flip == 2 % FLIP (left-right)
im(:, :, :, 1 : fInd_end-fInd_start+1) = flip(imset2(:,:,:,fInd_start:fInd_end), 2);
end
%% Result
% encoder
net.blobs(GLOBAL_ENCODER_INPUT_NAME).set_data( single( permute( imresize(im, [GLOBAL_ENCODER_INPUT_HEIGHT GLOBAL_ENCODER_INPUT_WIDTH]), [2 1 3 4] ) ) );
net.forward_prefilled;
pred_01_label = permute(net.blobs(GLOBAL_DECODER01_OUTPUT_NAME).get_data, [2 1 3 4]);
pred_02_label = permute(net.blobs(GLOBAL_DECODER02_OUTPUT_NAME).get_data, [2 1 3 4]);
pred_04_label = permute(net.blobs(GLOBAL_DECODER04_OUTPUT_NAME).get_data, [2 1 3 4]);
pred_06_label = permute(net.blobs(GLOBAL_DECODER06_OUTPUT_NAME).get_data, [2 1 3 4]);
pred_08_label = permute(net.blobs(GLOBAL_DECODER08_OUTPUT_NAME).get_data, [2 1 3 4]);
for index_batch = fInd_start : fInd_end
pred_01 = ch068_labeling_inv(round(pred_01_label(:, :, :, index_batch-fInd_start+1)));
pred_02 = relative_labeling_v1_inv(round(pred_02_label(:, :, :, index_batch-fInd_start+1)));
pred_04 = relative_labeling_v2_inv(round(pred_04_label(:, :, :, index_batch-fInd_start+1)));
pred_06 = relative_labeling_v3_inv(round(pred_06_label(:, :, :, index_batch-fInd_start+1)));
pred_08 = relative_labeling_v4_inv(round(pred_08_label(:, :, :, index_batch-fInd_start+1)));
if image_flip == 1 % NO-FLIP (left-right)
% PASS
elseif image_flip == 2 % NO-FLIP (left-right)
pred_01 = flip(pred_01,2);
pred_02 = reshape(flip(flip(reshape(pred_02, 008,008,008,008),2),4),008,008,008*008);
pred_04 = reshape(flip(flip(reshape(pred_04, 016,016,005,005),2),4),016,016,005*005);
pred_06 = reshape(flip(flip(reshape(pred_06, 032,032,005,005),2),4),032,032,005*005);
pred_08 = reshape(flip(flip(reshape(pred_08, 064,064,005,005),2),4),064,064,005*005);
end
modelre_01_temp(:,:,index_batch, image_flip) = pred_01;
modelre_02_temp(:, :, :, index_batch, image_flip) = pred_02;
modelre_04_temp(:, :, :, index_batch, image_flip) = pred_04;
modelre_06_temp(:, :, :, index_batch, image_flip) = pred_06;
modelre_08_temp(:, :, :, index_batch, image_flip) = pred_08;
end
disp(num2str(fInd))
toc
end
end
modelre_01 = modelre_01_temp(:,:,:,1)/2 + modelre_01_temp(:,:,:,2)/2;
modelre_02 = modelre_02_temp(:,:,:,:,1)/2 + modelre_02_temp(:,:,:,:,2)/2;
modelre_04 = modelre_04_temp(:,:,:,:,1)/2 + modelre_04_temp(:,:,:,:,2)/2;
modelre_06 = modelre_06_temp(:,:,:,:,1)/2 + modelre_06_temp(:,:,:,:,2)/2;
modelre_08 = modelre_08_temp(:,:,:,:,1)/2 + modelre_08_temp(:,:,:,:,2)/2;
mkdir(['results']);
save(['results/default_mode_results_', data_class, '.mat'], ...
'modelre_01', 'modelre_02', 'modelre_04', 'modelre_06', 'modelre_08', '-v7.3');
end
caffe.reset_all