-
Notifications
You must be signed in to change notification settings - Fork 0
/
CifarCrsDeltaSpe4ArNaDN.m
194 lines (136 loc) · 4.92 KB
/
CifarCrsDeltaSpe4ArNaDN.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
%--with mot inf
load('cifarGrTrnEx','cifarGrTrnEx');
% load('RGBPerTrn','RGBPerTrn');
load('isAnimTrn','isAnimTrn');
motionTr=[isAnimTrn'];
load('meta.mat');
%---extract rows corresponding to specific classes
load('train.mat')
%flower category
% crsL3=find(coarse_labels==2);
%household furniture
crsL7=find(coarse_labels==6);
DTrn7=cifarGrTrnEx(crsL7,:);
Mtrn7=motionTr(crsL7,:);
fnCat7=fine_labels(crsL7,:);
% fnNm=fine_label_names(fnCat+1);
%-----binary coarse labels haven't made yet
% fnList3={'orchid', 'poppy', 'rose', 'sunflower', 'tulip'};
fnList7={'bed','chair','couch','table','wardrobe'};
for i=1:5
fnI7(i)=find(strcmp(fine_label_names,fnList7{i})~=0);
end
for i=1:5
fi=find(fnCat7==fnI7(i)-1);
fnCatB7(fi)=i*ones(size(fi));
end
LFTrn7=zeros(length(fnI7),5);
for i=1:length(fnCat7)
lbl=fnCatB7(i);
LFTrn7(i,lbl)=1;
end
% save('LFTrnSpe','LFTrnSpe');
% save('LCTrnSpe','LCTrnSpe');
clear fnCatB crsL7 fnI7
%-------Test-------
load('cifarGrTstEx','cifarGrTstEx');
% load('RGBPerTst','RGBPerTst');
load('isAnimTst','isAnimTst');
% colmotionTe=[RGBPerTst,isAnimTst'];
motionTe=[isAnimTst'];
%---extract rows corresponding to specific classes
load('test.mat')
%flower category
crsL7=find(coarse_labels==2);
%household furniture
% crsL7=find(coarse_labels==6);
DTst7=cifarGrTstEx(crsL7,:);
Mtst7=motionTe(crsL7,:);
fnCat7=fine_labels(crsL7,:);
% %----binary coarse labels haven't made yet
% fnList3={'orchid', 'poppy', 'rose', 'sunflower', 'tulip'};
fnList7={'bed','chair','couch','table','wardrobe'};
for i=1:5
fnI7(i)=find(strcmp(fine_label_names,fnList7{i})~=0);
end
for i=1:5
fi=find(fnCat7==fnI7(i)-1);
fnCatB7(fi)=i*ones(size(fi));
end
LFTst7=zeros(length(fnI7),5);
for i=1:length(fnCat7)
lbl=fnCatB7(i);
LFTst7(i,lbl)=1;
end
% save('LFTstSpe','LFTstSpe');
% save('LCTstSpe','LCTstSpe');
clear fnCatB crsL7 fnI7
% % netName='500-500-2000';
% % DN.layersize = [500,500,2000];
% Cl=10;
% max_iter=5;
for iter=1:max_iter
iter
% %--RBM trained on Art+Nat
% loadName='CifarNWRBM_DN_hB_L3Gr500-500-2000_maxEp100.mat';
% %--RBM trained on only Art
% loadName='CifarNWGrMoRBM_DN_hBArt600-1000-2000_maxEp400';
%--RBM trained on Nat
loadName='CifarNWGrMotRBM_DN_hBNat600-1000-2000_maxEp400';
load(loadName);
DN=CifarRBM;
load(loadName);
DN=CifarRBM{iter};
% %--coarse lables
% tr_labelsCrs=double(LCTrn7);
% te_labelsCrs=double(LCTst7);
%--fine lables
tr_labelsFn=double(LFTrn7);
te_labelsFn=double(LFTst7);
w1=[DN.L{1,1}.vishid;DN.L{1,1}.hidbiases];
w2=[DN.L{1,2}.vishid;DN.L{1,2}.hidbiases];
w3=[DN.L{1,3}.vishid;DN.L{1,3}.hidbiases];
data = double(DTrn7);
N=size(data,1);
data = [data ones(N,1)];
w1probs = 1./(1 + exp(-data*w1));
tr_patterns1=double(w1probs);
%concatenate RGBM
w1probs = [w1probs ones(N,1)];
w2probs = 1./(1 + exp(-w1probs*w2));
tr_patterns2=double(w2probs);
w2probs = [w2probs Mtrn7];
w2probs = [w2probs ones(N,1)];
w3probs = 1./(1 + exp(-w2probs*w3));%w3probs = [w3probs ones(N,1)];
tr_patterns3=double(w3probs);
data = double(DTst7);
N=size(data,1);
data = [data ones(N,1)];
w1probs = 1./(1 + exp(-data*w1));
te_patterns1=double(w1probs);
%concatenate RGBM
w1probs = [w1probs ones(N,1)];
w2probs = 1./(1 + exp(-w1probs*w2));
te_patterns2=double(w2probs);
w2probs = [w2probs Mtst7];
w2probs = [w2probs ones(N,1)];
w3probs = 1./(1 + exp(-w2probs*w3));%w3probs = [w3probs ones(N,1)];
te_patterns3=double(w3probs);
max_epochs = 3000;
% [tr_accCrs(iter,1), te_accCrs(iter,1),CbTrnCrs1,CbTstCrs1] = DeltaClfrConf(tr_patterns1, tr_labelsCrs, te_patterns1,te_labelsCrs,max_epochs);
[tr_accFn(iter,1), te_accFn(iter,1),CbTrnFn1,CbTstFn1] = DeltaClfrConf(tr_patterns1, tr_labelsFn, te_patterns1,te_labelsFn,max_epochs);
% [tr_accCrs(iter,2), te_accCrs(iter,2),CbTrnCrs2,CbTstCrs2] = DeltaClfrConf(tr_patterns2, tr_labelsCrs, te_patterns2, te_labelsCrs,max_epochs);
[tr_accFn(iter,2), te_accFn(iter,2),CbTrnFn2,CbTstFn2] = DeltaClfrConf(tr_patterns2, tr_labelsFn, te_patterns2, te_labelsFn,max_epochs);
% [tr_accCrs(iter,3), te_accCrs(iter,3),CbTrnCrs3,CbTstCrs3] = DeltaClfrConf2(tr_patterns3, tr_labelsCrs, te_patterns3, te_labelsCrs,max_epochs);
[tr_accFn(iter,3), te_accFn(iter,3),CbTrnFn3,CbTstFn3] = DeltaClfrConf2(tr_patterns3, tr_labelsFn, te_patterns3, te_labelsFn,max_epochs);
end
%--save delta results on Art representation
% netName='Ex500-500-2000';
% saveName=sprintf('NW_ArtFn_DNArt_DeltaConf%s_DeltaMaxEp%d',netName,max_epochs);
%--save delta results on Art+Nat representation
netName='600-1000-2000';
saveName=sprintf('NW_ArtFn_DNNat_DeltaConf%s_DeltaMaxEp%d',netName,max_epochs);
save(saveName,'tr_accFn','te_accFn',...
'CbTrnFn1','CbTstFn1',...
'CbTrnFn2','CbTstFn2',...
'CbTrnFn3','CbTstFn3');