-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeep_learning_4P_Live_I_Vgg16.m
404 lines (282 loc) · 13.9 KB
/
Deep_learning_4P_Live_I_Vgg16.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
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
clear;clc;close all;
addpath ( genpath ( 'Files mat' ) );
load('data.mat');
load('norm_dL1.mat')
load Cyclopean_L1.mat
% load ind_train
% load ind_test
load vgg16
Patch_1 = [];Patch_2 = [];Patch_3 = [];Patch_4 = [];
Patch_1(:,:,:,:) = Cyclopean_L1(1:180,1:320,:,:); % First patch
Patch_2(:,:,:,:) = Cyclopean_L1(1:180,321:640,:,:); % Second patch
Patch_3(:,:,:,:) = Cyclopean_L1(181:360,1:320,:,:); % Third patch
Patch_4(:,:,:,:) = Cyclopean_L1(181:360,321:640,:,:); % Fourth patch
repeat = 1; Average_R{1} = [0 0 0 0];
for R=1:repeat
% trainImages(:,:,1,:) = Cyclopean_L1(1:180,1:320,:);% First patch
% trainImages(:,:,1,366:730) = Cyclopean_L1(1:180,321:640,:); % Second patch
% trainImages(:,:,1,731:1095) = Cyclopean_L1(181:360,1:320,:); % Third patch
% trainImages(:,:,1,1096:1460) = Cyclopean_L1(181:360,321:640,:); % Fourth patch
%% Initialization
N_F = 128; % Number of Features to be extracted from each patch
Epoch = 50; %320
M_B = 16; %60
T_input = Patch_1;
T_output = [norm_dL1];
%layersTransfer = net_all.Layers(1:end);
TEST_output = []; Valid = []; Score_dmos = [];
All_NET= []; TEST_NET = [];
k = 5;
%% Divide dataset to 80%-20% (Non-overlapped)
cv = cvpartition(length(T_output), 'kfold',k);
for i=1:k
trainIdxs{i} = find(training(cv,i)); %trainIdxs{i} = find(ind_train(:,i)==1);
testIdxs{i} = find(test(cv,i)); %testIdxs{i} = find(ind_test(:,i)==1);
trainMatrix_IN{i} = [T_input(:,:,:,trainIdxs{i})]; %Inout and output for the network 80%
trainMatrix_OUT{i} = [T_output(trainIdxs{i})];
testMatrix_IN{i} = [T_input(:,:,:,testIdxs{i})]; %Input for Testing 20%
testMatrix_OUT{i} = [T_output(testIdxs{i})];
Subjectiv_S{i} = [dmos(testIdxs{i})];
end
%% Train the network for k times (Train on 80% and test on the rest 20%)
net = []; net_help = vgg16;
layers = [
imageInputLayer([180 320 3],"Name","imageinput")
net_help.Layers(2:end-9)
fullyConnectedLayer(N_F,"Name","fc_1")
reluLayer("Name","relu4")
fullyConnectedLayer(10,"Name","fc_11")
%reluLayer("Name","relu5")
fullyConnectedLayer(1,"Name","fc_3")
regressionLayer("Name","regressionoutput")];
% 'Plots','training-progress'
% 'Shuffle','every-epoch'
options = trainingOptions('sgdm',...
'LearnRateSchedule', 'piecewise',...
'LearnRateDropFactor', 0.9,...
'LearnRateDropPeriod', 10,...
'MiniBatchSize',M_B,...
'L2Regularization', 0.01,...
'Shuffle','every-epoch',...
'MaxEpochs',Epoch, ...
'InitialLearnRate',1e-2);
% Transfer Learning use : layersTransfer = alexnet.Layers(1:end-3);
for i = 1:k
net = trainNetwork(trainMatrix_IN{i},trainMatrix_OUT{i},layers,options)
%net.Layers
Models{1,i} = net; % save the model
layer = 'fc_1';
TF_Matrix_in_1{i} = activations(net,trainMatrix_IN{i},layer,'OutputAs','rows'); %feature extraction 80%
TF_Matrix_out_1{i} = activations(net,testMatrix_IN{i},layer,'OutputAs','rows');%feature extraction 20%
TEST_NET = predict(net,testMatrix_IN{i}); %compute and stock results
All_NET = [All_NET; TEST_NET];
Score_dmos = [Score_dmos; Subjectiv_S{i}]; %re-order the dmos score
end
%% Evaluate the Net_Model
Score_1 = All_NET;
disp('Results of Deep Patch 1 LIVE I>>>');
SB1 = [Score_dmos]; % Subjective Score
OB1 = Score_1; % Objective Score
%figure,
[Srocc,Krooc, cc,rmse] = logistic_cc(double(OB1),double(SB1))
%% Train the SVR with the extracted features Patch 1
Score_dmos = []; TEST_SVR=[]; All_SVR = [];
for i = 1:k
Mdln = fitrsvm(TF_Matrix_in_1{i}, trainMatrix_OUT{i},'verbose',0,'KernelFunction','Gaussian','KernelScale','auto');
TEST_SVR = Mdln.predict(TF_Matrix_out_1{i});
All_SVR = [All_SVR; TEST_SVR];
Score_dmos = [Score_dmos; Subjectiv_S{i}]; %re-order the dmos score
end
%% Evaluate the SVR_Model Patch 1
Score_2 = All_SVR;
disp('Results of SVR-Features Patch 1 LIVE I>>>');
SB2 = [Score_dmos]; % Subjective Score
OB2 = Score_2; % Objective Score
%figure,
[Srocc,Krooc, cc,rmse] = logistic_cc(double(OB2),double(SB2))
%% Second patch
%% Initialization
T_input = Patch_2 ;
T_output = [norm_dL1];
%layersTransfer = net_all.Layers(1:end);
TEST_output = []; Valid = []; Score_dmos = [];
All_NET= []; TEST_NET = [];
%% Divide dataset to 80%-20% (Non-overlapped)
for i=1:k
% trainIdxs{i} = find(ind_train(:,i)==1);
% testIdxs{i} = find(ind_test(:,i)==1);
trainMatrix_IN{i} = [T_input(:,:,:,trainIdxs{i})]; %Inout and output for the network 80%
trainMatrix_OUT{i} = [T_output(trainIdxs{i})];
testMatrix_IN{i} = [T_input(:,:,:,testIdxs{i})]; %Input for Testing 20%
testMatrix_OUT{i} = [T_output(testIdxs{i})];
Subjectiv_S{i} = [dmos(testIdxs{i})];
end
%% Train the network for k times (Train on 80% and test on the rest 20%)
net = [];
for i = 1:k
net = trainNetwork(trainMatrix_IN{i},trainMatrix_OUT{i},layers,options)
%net.Layers
Models{2,i} = net; % save the model
layer = 'fc_1';
TF_Matrix_in_2{i} = activations(net,trainMatrix_IN{i},layer,'OutputAs','rows'); %feature extraction 80%
TF_Matrix_out_2{i} = activations(net,testMatrix_IN{i},layer,'OutputAs','rows');%feature extraction 20%
TEST_NET = predict(net,testMatrix_IN{i}); %compute and stock results
All_NET = [All_NET; TEST_NET];
Score_dmos = [Score_dmos; Subjectiv_S{i}]; %re-order the dmos score
end
%% Evaluate the Net_Model
Score_1 = All_NET;
disp('Results of Deep Patch 2 LIVE I>>>');
SB1 = [Score_dmos]; % Subjective Score
OB1 = Score_1; % Objective Score
%figure,
[Srocc,Krooc, cc,rmse] = logistic_cc(double(OB1),double(SB1))
%% Train the SVR with the extracted features Patch 2
Score_dmos = []; TEST_SVR=[]; All_SVR = [];
for i = 1:k
Mdln = fitrsvm(TF_Matrix_in_2{i}, trainMatrix_OUT{i},'verbose',0,'KernelFunction','Gaussian','KernelScale','auto');
TEST_SVR = Mdln.predict(TF_Matrix_out_2{i});
All_SVR = [All_SVR; TEST_SVR];
Score_dmos = [Score_dmos; Subjectiv_S{i}]; %re-order the dmos score
end
%% Evaluate the SVR_Model Patch 2
Score_2 = All_SVR;
disp('Results of SVR-Features Patch 2 LIVE I>>>');
SB2 = [Score_dmos]; % Subjective Score
OB2 = Score_2; % Objective Score
%figure,
[Srocc,Krooc, cc,rmse] = logistic_cc(double(OB2),double(SB2))
%% 3rd Patch
%% Initialization
T_input = Patch_3 ;
T_output = [norm_dL1];
%layersTransfer = net_all.Layers(1:end);
TEST_output = []; Valid = []; Score_dmos = [];
All_NET= []; TEST_NET = [];
%% Divide dataset to 80%-20% (Non-overlapped)
for i=1:k
% trainIdxs{i} = find(ind_train(:,i)==1);
% testIdxs{i} = find(ind_test(:,i)==1);
trainMatrix_IN{i} = [T_input(:,:,:,trainIdxs{i})]; %Inout and output for the network 80%
trainMatrix_OUT{i} = [T_output(trainIdxs{i})];
testMatrix_IN{i} = [T_input(:,:,:,testIdxs{i})]; %Input for Testing 20%
testMatrix_OUT{i} = [T_output(testIdxs{i})];
Subjectiv_S{i} = [dmos(testIdxs{i})];
end
%% Train the network for k times (Train on 80% and test on the rest 20%)
% Transfer Learning use : layersTransfer = alexnet.Layers(1:end-3);
net = [];
for i = 1:k
net = trainNetwork(trainMatrix_IN{i},trainMatrix_OUT{i},layers,options)
%net.Layers
Models{3,i} = net; % save the model
layer = 'fc_1';
TF_Matrix_in_3{i} = activations(net,trainMatrix_IN{i},layer,'OutputAs','rows'); %feature extraction 80%
TF_Matrix_out_3{i} = activations(net,testMatrix_IN{i},layer,'OutputAs','rows');%feature extraction 20%
TEST_NET = predict(net,testMatrix_IN{i}); %compute and stock results
All_NET = [All_NET; TEST_NET];
Score_dmos = [Score_dmos; Subjectiv_S{i}]; %re-order the dmos score
end
%% Evaluate the Net_Model
Score_1 = All_NET;
disp('Results of Deep Patch 3 LIVE I>>>');
SB1 = [Score_dmos]; % Subjective Score
OB1 = Score_1; % Objective Score
%figure,
[Srocc,Krooc, cc,rmse] = logistic_cc(double(OB1),double(SB1))
%% Train the SVR with the extracted features Patch 3
Score_dmos = []; TEST_SVR=[]; All_SVR = [];
for i = 1:k
Mdln = fitrsvm(TF_Matrix_in_3{i}, trainMatrix_OUT{i},'verbose',0,'KernelFunction','Gaussian','KernelScale','auto');
TEST_SVR = Mdln.predict(TF_Matrix_out_3{i});
All_SVR = [All_SVR; TEST_SVR];
Score_dmos = [Score_dmos; Subjectiv_S{i}]; %re-order the dmos score
end
%% Evaluate the SVR_Model Patch 3
Score_2 = All_SVR;
disp('Results of SVR-Features Patch 3 LIVE I>>>');
SB2 = [Score_dmos]; % Subjective Score
OB2 = Score_2; % Objective Score
%figure,
[Srocc,Krooc, cc,rmse] = logistic_cc(double(OB2),double(SB2))
%% 4th Patch
%% Initialization
T_input = Patch_4 ;
T_output = [norm_dL1];
%layersTransfer = net_all.Layers(1:end);
TEST_output = []; Valid = []; Score_dmos = [];
All_NET= []; TEST_NET = [];
%% Divide dataset to 80%-20% (Non-overlapped)
for i=1:k
% trainIdxs{i} = find(ind_train(:,i)==1);
% testIdxs{i} = find(ind_test(:,i)==1);
trainMatrix_IN{i} = [T_input(:,:,:,trainIdxs{i})]; %Inout and output for the network 80%
trainMatrix_OUT{i} = [T_output(trainIdxs{i})];
testMatrix_IN{i} = [T_input(:,:,:,testIdxs{i})]; %Input for Testing 20%
testMatrix_OUT{i} = [T_output(testIdxs{i})];
Subjectiv_S{i} = [dmos(testIdxs{i})];
end
%% Train the network for k times (Train on 80% and test on the rest 20%)
% Transfer Learning use : layersTransfer = alexnet.Layers(1:end-3);
net = [];
for i = 1:k
net = trainNetwork(trainMatrix_IN{i},trainMatrix_OUT{i},layers,options)
%net.Layers
Models{4,i} = net; % save the model
layer = 'fc_1';
TF_Matrix_in_4{i} = activations(net,trainMatrix_IN{i},layer,'OutputAs','rows'); %feature extraction 80%
TF_Matrix_out_4{i} = activations(net,testMatrix_IN{i},layer,'OutputAs','rows');%feature extraction 20%
TEST_NET = predict(net,testMatrix_IN{i}); %compute and stock results
All_NET = [All_NET; TEST_NET];
Score_dmos = [Score_dmos; Subjectiv_S{i}]; %re-order the dmos score
end
%% Evaluate the Net_Model
Score_1 = All_NET;
disp('Results of Deep Patch 4 LIVE I>>>');
SB1 = [Score_dmos]; % Subjective Score
OB1 = Score_1; % Objective Score
%figure,
[Srocc,Krooc, cc,rmse] = logistic_cc(double(OB1),double(SB1))
%% Train the SVR with the extracted features Patch 4
Score_dmos = []; TEST_SVR=[]; All_SVR = [];
for i = 1:k
Mdln = fitrsvm(TF_Matrix_in_4{i}, trainMatrix_OUT{i},'verbose',0,'KernelFunction','Gaussian','KernelScale','auto');
TEST_SVR = Mdln.predict(TF_Matrix_out_4{i});
All_SVR = [All_SVR; TEST_SVR];
Score_dmos = [Score_dmos; Subjectiv_S{i}]; %re-order the dmos score
end
%% Evaluate the SVR_Model Patch 4
Score_2 = All_SVR;
disp('Results of SVR-Features Patch 4 LIVE I>>>');
SB2 = [Score_dmos]; % Subjective Score
OB2 = Score_2; % Objective Score
%figure,
[Srocc,Krooc, cc,rmse] = logistic_cc(double(OB2),double(SB2))
%% Train the SVR with the all extracted features all Patches
for i=1:k
TF_Matrix_in_all{i} = [TF_Matrix_in_1{i} TF_Matrix_in_2{i} TF_Matrix_in_3{i} TF_Matrix_in_4{i}];
TF_Matrix_out_all{i} = [TF_Matrix_out_1{i} TF_Matrix_out_2{i} TF_Matrix_out_3{i} TF_Matrix_out_4{i}];
end
Score_dmos = []; TEST_SVR=[]; All_SVR = []; DATA = []; DATA_C =[];
for i = 1:k
Mdln = fitrsvm(TF_Matrix_in_all{i}, trainMatrix_OUT{i},'verbose',0,'KernelFunction','Gaussian','KernelScale','auto');
TEST_SVR = Mdln.predict(TF_Matrix_out_all{i});
All_SVR = [All_SVR; TEST_SVR];
Score_dmos = [Score_dmos; Subjectiv_S{i}]; %re-order the dmos score to versus the nandomly split
DATA = [DATA; testIdxs{i}]; %re-order the dmos score to the first order of DMOS
end
%% Evaluate the SVR_Model -all Patches
for j=1:365
DATA_C(DATA(j)) = [All_SVR(j)]; %re-order the dmos score to the first order of DMOS
end
disp('Results of SVR-Features All Patches LIVE I>>>');
SB2 = dmos; % Subjective Score
OB2 = DATA_C'; % Objective Score
%figure,
[Srocc,Krooc, cc,rmse] = logistic_cc(double(OB2),double(SB2))
Score_Stock{R} = DATA_C';
Final_R{R}=[Srocc,Krooc, cc,rmse];
Average_R{1} = Average_R{1} + Final_R{R};
end
Average_R{1} = Average_R{1} / repeat;
disp(Average_R{1})