-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrainSVM2layers.m
47 lines (41 loc) · 1.24 KB
/
trainSVM2layers.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
%% TRAINING
load( 'training.mat' );
% train SVM to learn main emotion
%Mdl1 = trainSVM( faces, 'dex_chalearn_features_fc7', 'label1' );
Mdl1 = trainSVM( faces, 'dex_chalearn_features_fc7', 'label2' );
Mdl2 = cell(7,1);
for kk=1:7
kk
% create subset with second emotion
n = 1;
for jj=1:length( faces )
%if( strcmp( faces{jj}.label1, num2str( kk ) ) )
if( strcmp( faces{jj}.label2, num2str( kk ) ) )
faces2{n} = faces{jj};
n = n+1;
end
end
%Mdl2{ kk } = trainSVM( faces2, 'dex_chalearn_features_fc7', 'label2' );
Mdl2{ kk } = trainSVM( faces2, 'dex_chalearn_features_fc7', 'label1' );
end
%% VALIDATION
load( 'validation.mat' );
% apply all models
Y1 = applyModel( Mdl1, facesVal, 'dex_chalearn_features_fc7' );
Y2 = cell(7,1);
for kk=1:7
Y2{kk} = applyModel( Mdl2{ kk }, facesVal, 'dex_chalearn_features_fc7' );
end
for kk=1:length( facesVal )
if Y1(kk) == 'N'
Y{kk} = 'N_N';
else
%Y{ kk } = [char( Y1( kk )) '_' char( Y2{ grp2idx( Y1(kk) )}(kk) )];
Y{ kk } = [char( Y2{ grp2idx( Y1(kk) )}(kk) ) '_' char( Y1( kk ))];
end
end
fileID = fopen('predictions.txt','w');
for kk = 1:length( Y )
fprintf(fileID, '%s\n', Y{kk});
end
fclose( fileID );