-
Notifications
You must be signed in to change notification settings - Fork 0
/
CifarCrsDeltaSpe4.m
217 lines (162 loc) · 5.59 KB
/
CifarCrsDeltaSpe4.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
%recognition two supcategories of flowers and furniture
% %---neigh parametes---
% neigh=2;
% loadName=sprintf('cifarGrTrn_n%s',int2str(neigh));
% load(loadName,'cifarGrTrn');
% % cifarGrTrn=cifarGrTrn_n2;
%
% loadName=sprintf('cifarGrTst_n%s',int2str(neigh));
% load(loadName,'cifarGrTst');
% % cifarGrTst=cifarGrTst_n2;
% %-----------------------
load('cifarGrTrnEx','cifarGrTrnEx');
load('RGBPerTrn','RGBPerTrn');
load('isAnimTrn','isAnimTrn');
colmotionTr=[RGBPerTrn,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);
crsL=[crsL3;crsL7];
DTrn=cifarGrTrnEx(crsL,:);
RGBMtrn=colmotionTr(crsL,:);
fnCat=fine_labels(crsL,:);
% 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'};
fnList=[fnList3,fnList7];
for i=1:5
fnI3(i)=find(strcmp(fine_label_names,fnList3{i})~=0);
fnI7(i)=find(strcmp(fine_label_names,fnList7{i})~=0);
end
for i=1:5
fi=find(fnCat==fnI3(i)-1);
fnCatB(fi)=i*ones(size(fi));
end
for i=1:5
fi=find(fnCat==fnI7(i)-1);
fnCatB(fi)=(i+5)*ones(size(fi));
end
% fnL3=[];
% for i=1:5
% fnL3=[fnL3;find(fine_labels==(fnI3(i)-1))];
% end
%binary target
LCTrnSpe=zeros(length(crsL3)+length(crsL7),2);
LCTrnSpe(1:length(crsL3),1)=1;
LCTrnSpe(length(crsL3)+1:end,2)=1;
LFTrnSpe=zeros(length(LCTrnSpe),10);
for i=1:length(LCTrnSpe)
lbl=fnCatB(i);
LFTrnSpe(i,lbl)=1;
end
% save('LFTrnSpe','LFTrnSpe');
% save('LCTrnSpe','LCTrnSpe');
clear fnCatB crsL3 crsL7 fnI3 fnI7
%-------Test-------
load('cifarGrTstEx','cifarGrTstEx');
load('RGBPerTst','RGBPerTst');
load('isAnimTst','isAnimTst');
colmotionTe=[RGBPerTst,isAnimTst'];
%---extract rows corresponding to specific classes
load('test.mat')
%flower category
crsL3=find(coarse_labels==2);
%household furniture
crsL7=find(coarse_labels==6);
crsL=[crsL3;crsL7];
DTst=cifarGrTstEx(crsL,:);
RGBMtst=colmotionTe(crsL,:);
fnCat=fine_labels(crsL,:);
% %----binary coarse labels haven't made yet
fnList3={'orchid', 'poppy', 'rose', 'sunflower', 'tulip'};
fnList7={'bed','chair','couch','table','wardrobe'};
for i=1:5
fnI3(i)=find(strcmp(fine_label_names,fnList3{i})~=0);
fnI7(i)=find(strcmp(fine_label_names,fnList7{i})~=0);
end
for i=1:5
fi=find(fnCat==fnI3(i)-1);
fnCatB(fi)=i*ones(size(fi));
end
for i=1:5
fi=find(fnCat==fnI7(i)-1);
fnCatB(fi)=(i+5)*ones(size(fi));
end
%binary target
LCTstSpe=zeros(length(crsL3)+length(crsL7),2);
LCTstSpe(1:length(crsL3),1)=1;
LCTstSpe(length(crsL3)+1:end,2)=1;
LFTstSpe=zeros(length(LCTstSpe),10);
for i=1:length(LCTstSpe)
lbl=fnCatB(i);
LFTstSpe(i,lbl)=1;
end
% save('LFTstSpe','LFTstSpe');
% save('LCTstSpe','LCTstSpe');
clear fnCatB crsL3 crsL7 fnI3 fnI7
% % netName='500-500-2000';
% % DN.layersize = [500,500,2000];
% Cl=10;
% max_iter=5;
for iter=1:max_iter
iter
loadName='CifarNWRBM_DN_hBL3Ex500-500-2000_maxEp100';
load(loadName);
DN=CifarRBM;
load(loadName);
DN=CifarRBM{iter};
%delta
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];
%--coarse lables
tr_labelsCrs=double(LCTrnSpe);
te_labelsCrs=double(LCTstSpe);
%--fine lables
tr_labelsFn=double(LFTrnSpe);
te_labelsFn=double(LFTstSpe);
data = double(DTrn);
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 RGBMtrn];
w2probs = [w2probs ones(N,1)];
w3probs = 1./(1 + exp(-w2probs*w3));%w3probs = [w3probs ones(N,1)];
tr_patterns3=double(w3probs);
data = double(DTst);
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 RGBMtst];
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
netName='Ex500-500-2000';
saveName=sprintf('NW_spe_maxEp200_DeltaConf%s_MaxEp%d',netName,max_epochs);
save(saveName,'tr_accCrs','te_accCrs','tr_accFn','te_accFn',...
'CbTrnCrs1','CbTstCrs1','CbTrnFn1','CbTstFn1',...
'CbTrnCrs2','CbTstCrs2','CbTrnFn2','CbTstFn2',...
'CbTrnCrs3','CbTstCrs3','CbTrnFn3','CbTstFn3');