-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDepressUtil.py
2866 lines (2722 loc) · 157 KB
/
DepressUtil.py
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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#Here starts the depression estimation processes
##from 2017.09.26, the stop criteria of training is changing to
####patched on 20180915, fix the bug(implementation logic error for tlabels) in Valid_on_TestSet_3NI
##
import numpy as np
import tensorflow as tf
import os, pickle, time, sys, traceback, collections
import DataSetPrepare
import tflearn
from DataSetPrepare import Dataset_Dictionary
import win_unicode_console
win_unicode_console.enable()
continue_test=True #set continuesly test for M7
OverTimes=20
M3N4S1={'eye_conv1_1_3x3/W:0':0,'eye_conv1_1_3x3/b:0':0,
'eye_conv1_2_3x3/W:0':0,'eye_conv1_2_3x3/b:0':0,
'eye_conv2_1_3x3/W:0':0,'eye_conv2_1_3x3/b:0':0,
'eye_conv2_2_3x3/W:0':0,'eye_conv2_2_3x3/b:0':0,
'eye_fc2/W:0':0, 'eye_fc2/b:0':0,
'eye_conv3_1_3x3/W:0':0,'eye_conv3_1_3x3/b:0':0,
'eye_conv3_2_3x3/W:0':0,'eye_conv3_2_3x3/b:0':0,
'eye_fc1/W:0':0,'eye_fc1/b:0':0}
M3N4S2={'middle_conv1_1_3x3/W:0':0,'middle_conv1_1_3x3/b:0':0,
'middle_conv1_2_3x3/W:0':0,'middle_conv1_2_3x3/b:0':0,
'middle_conv2_1_3x3/W:0':0,'middle_conv2_1_3x3/b:0':0,
'middle_conv2_2_3x3/W:0':0,'middle_conv2_2_3x3/b:0':0,
'middle_conv3_1_3x3/W:0':0,'middle_conv3_1_3x3/b:0':0,
'middle_conv3_2_3x3/W:0':0,'middle_conv3_2_3x3/b:0':0,
'middle_fc1/W:0':0,'middle_fc1/b:0':0}
M3N4S3={'mouth_conv1_1_3x3/W:0':0,'mouth_conv1_1_3x3/b:0':0,
'mouth_conv1_2_3x3/W:0':0,'mouth_conv1_2_3x3/b:0':0,
'mouth_conv2_1_3x3/W:0':0,'mouth_conv2_1_3x3/b:0':0,
'mouth_conv2_2_3x3/W:0':0,'mouth_conv2_2_3x3/b:0':0,
'mouth_conv3_1_3x3/W:0':0,'mouth_conv3_1_3x3/b:0':0,
'mouth_conv3_2_3x3/W:0':0,'mouth_conv3_2_3x3/b:0':0,
'mouth_fc1/W:0':0,'mouth_fc1/b:0':0}
M3N5S1={'eye_conv1_1_3x3/W:0':0,'eye_conv1_1_3x3/b:0':0,
'eye_conv1_2_3x3/W:0':0,'eye_conv1_2_3x3/b:0':0,
'eye_conv2_1_3x3/W:0':0,'eye_conv2_1_3x3/b:0':0,
'eye_conv2_2_3x3/W:0':0,'eye_conv2_2_3x3/b:0':0,
'eye_conv3_1_3x3/W:0':0,'eye_conv3_1_3x3/b:0':0,
'eye_conv3_2_3x3/W:0':0,'eye_conv3_2_3x3/b:0':0,
'eye_fc1/W:0':0,'eye_fc1/b:0':0}
M3N5S2={'middle_conv1_1_3x3/W:0':0,'middle_conv1_1_3x3/b:0':0,
'middle_conv1_2_3x3/W:0':0,'middle_conv1_2_3x3/b:0':0,
'middle_conv2_1_3x3/W:0':0,'middle_conv2_1_3x3/b:0':0,
'middle_conv2_2_3x3/W:0':0,'middle_conv2_2_3x3/b:0':0,
'middle_fc2/W:0':0, 'middle_fc2/b:0':0,
'middle_conv3_1_3x3/W:0':0,'middle_conv3_1_3x3/b:0':0,
'middle_conv3_2_3x3/W:0':0,'middle_conv3_2_3x3/b:0':0,
'middle_fc1/W:0':0,'middle_fc1/b:0':0}
M3N5S3={'mouth_conv1_1_3x3/W:0':0,'mouth_conv1_1_3x3/b:0':0,
'mouth_conv1_2_3x3/W:0':0,'mouth_conv1_2_3x3/b:0':0,
'mouth_conv2_1_3x3/W:0':0,'mouth_conv2_1_3x3/b:0':0,
'mouth_conv2_2_3x3/W:0':0,'mouth_conv2_2_3x3/b:0':0,
'mouth_fc2/W:0':0, 'mouth_fc2/b:0':0,
'mouth_conv3_1_3x3/W:0':0,'mouth_conv3_1_3x3/b:0':0,
'mouth_conv3_2_3x3/W:0':0,'mouth_conv3_2_3x3/b:0':0,
'mouth_fc1/W:0':0,'mouth_fc1/b:0':0}
lr_drate=0.8
batchsize_step=0
times=20 #which control the decay learning rate decays at every %times% epochs
test_bat=200
TestNumLimit = 200
Mini_Epochs = 140
show_threshold = 1.62
class SIMSTS():
def __init__(self, NC):
self.min=1.0
self.max=0.0
self.amout=0
self.mean=0
self.count=NC
def addFigure(self, figure):
if self.min>figure:
self.min=figure
if self.max<figure:
self.max=figure
self.amout=self.amout+figure
def getSTS(self):
self.mean=self.amout/self.count
return self.mean, self.max, self.min
def logfile(self, Module, Dataset, Network, NE, MSS, MSL):
filename='./logs/M%dtests/D%d_N%d.txt'%(Module, Dataset, Network)
if not os.path.exists(os.path.dirname(filename)):
os.makedirs(os.path.dirname(filename))
filein=open(filename,'a')
filein.write('MEAN:%.6f\tMAX:%.6f\tMIN:%.6f\tnum_estimators:%d\tmin_samples_split:%d\tmin_samples_leaf:%d\tD%d\tN%d\n'%(self.mean,
self.max, self.min, NE, MSS, MSL,Dataset, Network))
filein.close()
def initialize_dirs():
if not os.path.exists('./logs/VL'):
os.makedirs('./logs/VL')
if not os.path.exists('./saves'):
os.makedirs('./saves')
class LOSS_ANA:
'''The LOSS_ANA class collects the training losses and analyzes them.
The initial length should be divided by 50 with no remainder.'''
def __init__(self):
self.__Validation_Loss_List = []
self.__Current_Length = 0#indicates whether the Validation_Loss_List has reach the maximum Length
self.__Min_Loss = 10000.0
self.__Min_Loss_Second = 10001.0
@property
def minimun_loss(self):
return self.__Min_Loss
@property
def second_minimun_loss(self):
return self.__Min_Loss_Second
@property
def loss_length(self):
return self.__Current_Length
def setMinimun_loss(self, m):
self.__Min_Loss=m
def analyzeLossVariation(self, loss):
'''Analize the LastN*2 validation losses, where LastN is defined in __init__
Inputs:
loss: float type, the current loss of the validation set
Outputs:
boolean type: indicates whether the input is less than all others before it
'''
self.__Current_Length = self.__Current_Length + 1
flag=False
if loss < self.__Min_Loss:
self.__Min_Loss_Second = self.__Min_Loss
self.__Min_Loss = loss
flag=True
self.__Validation_Loss_List.append(loss)
return flag
def outputlosslist(self, logfilename):
'''input the file name to log out all the validation losses in the current training'''
fw=open(logfilename,'w')
for v in self.__Validation_Loss_List:
fw.write('%.16f\n'%(v))
fw.close()
def calR(predict_labels_in, groundtruth_labels_in, cn=7):
#print(len(predict_labels_in.shape))
#print(len(predict_labels_in))
#print(len(np.asarray(groundtruth_labels_in).shape))
#print(len(groundtruth_labels_in))
#exit()
if len(np.asarray(predict_labels_in).shape)==1:
predict_labels=DataSetPrepare.dense_to_one_hot(predict_labels_in, cn)
#print(predict_labels.shape)
else:
predict_labels=predict_labels_in
if len(np.asarray(groundtruth_labels_in).shape)==1:
groundtruth_labels=DataSetPrepare.dense_to_one_hot(groundtruth_labels_in, cn)
#print(groundtruth_labels.shape)
else:
groundtruth_labels=groundtruth_labels_in
assert len(predict_labels)==len(groundtruth_labels), ('predict_labels length: %d groundtruth_labels length: %d' % (len(predict_labels), len(groundtruth_labels)))
nc=len(groundtruth_labels)
g_c=np.zeros([cn])
#confusion_mat=[[0,0,0,0,0,0,0],
# [0,0,0,0,0,0,0],
# [0,0,0,0,0,0,0],
# [0,0,0,0,0,0,0],
# [0,0,0,0,0,0,0],
# [0,0,0,0,0,0,0],
# [0,0,0,0,0,0,0]]
confusion_mat=list(np.zeros([cn,cn]))
for i in range(nc):
cmi=list(groundtruth_labels[i]).index(max(groundtruth_labels[i]))
g_c[cmi]=g_c[cmi]+1
pri=list(predict_labels[i]).index(max(predict_labels[i]))
confusion_mat[cmi][pri]=confusion_mat[cmi][pri]+1
for i in range(len(g_c)):
if g_c[i]>0:
confusion_mat[i]=list(np.asarray(confusion_mat[i])/g_c[i])
return confusion_mat
def overAllAccuracy(conf_m, afc=None):
accuracy_for_every_categary=[]
r=len(conf_m)
if r>0:
c=len(conf_m[0])
else:
print('ERROR: Confusion Matrix is unexpected.')
exit()
assert r==c, ('ERROR: Confusion Matrix is unexpected for its unequal rows and cols: %d %d'%(r,c))
ac=0.0
for i in range(r):
ac=ac+conf_m[i][i]
accuracy_for_every_categary.append(conf_m[i][i])
ac=ac/r
if not afc is None:
afc=afc.extend(accuracy_for_every_categary)
del accuracy_for_every_categary
return ac
def Valid_on_TestSet(cn, sess, accuracy, sum_test, loss, softmax,
placeholder1, placeholder1_input,
placeholder_labels, placeholder_labels_input,afc=None):
'''Evalute the data with 1 network input in the session input
Inputs:
sess:
accuracy:
sum_test:
loss:
softmax:
Outputs:
v_accuracy:
valid_loss:
oaa:
confu_mat'''
ncount=len(placeholder_labels_input)
tlabels=[]
if ncount>TestNumLimit:
test_iter=np.floor_divide(ncount,test_bat)
v_accuracy=0
valid_loss=0
for ite in range(test_iter):
start=test_bat*ite
end=test_bat*(ite+1)
st, v_loss, tlab=sess.run([sum_test, loss, softmax], feed_dict={placeholder1:placeholder1_input[start:end],
placeholder_labels:placeholder_labels_input[start:end]})
v_accuracy=v_accuracy+st
valid_loss=valid_loss+v_loss
tlabels.extend(tlab)
if ncount%test_bat>0:
st, v_loss, tlab=sess.run([sum_test, loss, softmax], feed_dict={placeholder1:placeholder1_input[test_bat*test_iter:ncount],
placeholder_labels:placeholder_labels_input[test_bat*test_iter:ncount]})
v_accuracy=v_accuracy+st
valid_loss=valid_loss+v_loss
v_accuracy=v_accuracy/ncount
valid_loss=valid_loss/(test_iter+1)
tlabels.extend(tlab)
else:
v_accuracy, valid_loss, tlab = sess.run([accuracy, loss, softmax], feed_dict={placeholder1:placeholder1_input,
placeholder_labels:placeholder_labels_input})
tlabels.extend(tlab)
confu_mat=calR(tlabels, placeholder_labels_input, cn)
oaa=overAllAccuracy(confu_mat,afc=afc)
return v_accuracy, valid_loss, oaa, confu_mat
def Valid_on_TestSet_3NI(cn, sess, accuracy, sum_test, loss, softmax,
placeholder1, placeholder1_input,
placeholder2, placeholder2_input,
placeholder3, placeholder3_input,
placeholder_labels, placeholder_labels_input, afc=None):
'''Evalute the data with 3 network inputs in the session input
Inputs:
sess:
accuracy:
sum_test:
loss:
softmax:
Outputs:
v_accuracy:
valid_loss:
oaa:
confu_mat'''
ncount=len(placeholder_labels_input)
tlabels=[]
if ncount>TestNumLimit:
test_iter=np.floor_divide(ncount,test_bat)
v_accuracy=0
valid_loss=0
for ite in range(test_iter):
start=test_bat*ite
end=test_bat*(ite+1)
st, v_loss, tlab=sess.run([sum_test, loss, softmax], feed_dict={placeholder1:placeholder1_input[start:end],
placeholder2:placeholder2_input[start:end],
placeholder3:placeholder3_input[start:end],
placeholder_labels:placeholder_labels_input[start:end]})
v_accuracy=v_accuracy+st
valid_loss=valid_loss+v_loss
tlabels.extend(tlab)
if ncount%test_bat>0:
st, v_loss, tlab=sess.run([sum_test, loss, softmax], feed_dict={placeholder1:placeholder1_input[test_bat*test_iter:ncount],
placeholder2:placeholder2_input[test_bat*test_iter:ncount],
placeholder3:placeholder3_input[test_bat*test_iter:ncount],
placeholder_labels:placeholder_labels_input[test_bat*test_iter:ncount]})
tlabels.extend(tlab)
v_accuracy=v_accuracy+st
valid_loss=valid_loss+v_loss
v_accuracy=v_accuracy/ncount
valid_loss=valid_loss/(test_iter+1)
else:
v_accuracy, valid_loss, tlab = sess.run([accuracy, loss, softmax], feed_dict={placeholder1:placeholder1_input,
placeholder2:placeholder2_input,
placeholder3:placeholder3_input,
placeholder_labels:placeholder_labels_input})
tlabels.extend(tlab)
confu_mat=calR(tlabels, placeholder_labels_input, cn)
oaa=overAllAccuracy(confu_mat, afc=afc)
return v_accuracy, valid_loss, oaa, confu_mat
def logfile(file_record, runs, OAA, afc, valid_loss, valid_min_loss, final_train_loss, train_min_loss, TA, TC, ILR, FLR, LS, ites, Epo, cBS, iBS, input, CM, T, df):
file_record="Run%02d\tOverAllACC:%0.8f\tTestAccuracy:%.8f\tACs: %s\tFinalLoss:%.10f\tMinimunLoss:%.10f\tFinaltrainloss:%.10f\tMinimumtrainloss:%.10f\tTimeComsumed:%08.6f\tInitialLearningRate:%.8f\tFinalLearningRate:%.8f\tLearningStepForDroppingMagnitude:%08d\tTotalIterations:%08d\tEpoches:%08d\tcurrentBatchSize:%05d\tinitialBatchSize:%05d\tInput:%s\t%s\tTime:%s\tDataFile:%s"%(runs,
OAA, TA, str(afc), valid_loss, valid_min_loss, final_train_loss, train_min_loss, TC, ILR,FLR, LS,ites,Epo,cBS,iBS,str(input),str(CM),time.strftime('%Y%m%d%H%M%S',T),df)
return file_record
def logfileV2(file_record, runs, V_string, final_train_loss, train_min_loss, TC, ILR, FLR, LS, ites, Epo, cBS, iBS, input, CMstring, T, df):
file_record="Run%02d\t%s\tFinaltrainloss:%.10f\tMinimumtrainloss:%.10f\tTimeComsumed:%08.6f\tInitialLearningRate:%.8f\tFinalLearningRate:%.8f\tLearningStepForDroppingMagnitude:%08d\tTotalIterations:%08d\tEpoches:%08d\tcurrentBatchSize:%05d\tinitialBatchSize:%05d\tInput:%s\t%s\tTime:%s\tDataFile:%s"%(runs,
V_string, final_train_loss, train_min_loss, TC, ILR,FLR, LS,ites,Epo,cBS,iBS,str(input),str(CMstring),time.strftime('%Y%m%d%H%M%S',T),df)
return file_record
def logfileForSklearnModel(file_record, runs, model, TA, OAA, CM, df, train_ac, toaa, tcm):
modelstring=''
for v in str(model).splitlines():
modelstring=modelstring+v
file_record='Run%02d\tOverAllACC:%.8f\tTestAccuracy:%.8f\tTrainOAA:%.8f\tTrainAC:%.8f\tinput:%s\tCM:%s\tTCM:%s\t%s\t%s'%(runs, OAA, TA, toaa, train_ac, (sys.argv), str(CM), str(tcm), df, modelstring)
return file_record
def load(data_path, session, ignore_missing=False):
'''Load network weights.
data_path: The path to the numpy-serialized network weights
session: The current TensorFlow session
ignore_missing: If true, serialized weights for missing layers are ignored.
'''
data_dict = np.load(data_path).item()
for op_name in data_dict:
with tf.variable_scope(op_name, reuse=True):
for param_name, data in data_dict[op_name].items():
try:
var = tf.get_variable(param_name)
session.run(var.assign(data))
except ValueError:
if not ignore_missing:
raise
def restorefacepatchModel(TrainID, sess, NetworkType, graph):
vl=graph.get_collection(name='trainable_variables')
saver1=None
saver2=None
saver3=None
if NetworkType==4:
for v in vl:
if M3N4S1.get(v.name, -1)==0:
#print(M3N4S1[v.name])
M3N4S1[v.name]=v
#print(M3N4S1[v.name])
#exit(9)
elif M3N4S2.get(v.name, -1)==0:
M3N4S2[v.name]=v
elif M3N4S3.get(v.name, -1)==0:
M3N4S3[v.name]=v
saver1=tf.train.Saver(M3N4S1)
saver2=tf.train.Saver(M3N4S2)
saver3=tf.train.Saver(M3N4S3)
if TrainID%100>30:
saver1.restore(sess, './FPPTM/EyePatch_TrainonD502_TestonD531_N4_R4_20171025123948_1.59218006134_.ckpt')#OverAllACC:0.56836735 TestAccuracy:0.56836735 FinalLoss:1.5921800613
saver2.restore(sess, './FPPTM/MiddlePatch_TrainonD502_TestonD531_N4_R4_20171025113147_1.68774459362_.ckpt')#OverAllACC:0.46938776 TestAccuracy:0.46938776 FinalLoss:1.6877445936
saver3.restore(sess, './FPPTM/MouthPatch_TrainonD502_TestonD531_N4_R8_20171025144404_1.57691563368_.ckpt')#OverAllACC:0.58367347 TestAccuracy:0.58367347 FinalLoss:1.5769156337
elif TrainID%100<20:
saver1.restore(sess, './FPPTM/EyePatch_TrainonD532_TestonD501_N4_R9_20171019103910_1.51784744629_only_trainable_variables.ckpt')#OverAllACC:0.57857271 TestAccuracy:0.65412330 FinalLoss:1.5178474463
saver2.restore(sess, './FPPTM/MiddlePatch_TrainonD532_TestonD501_N4_R11_20171019080535_1.66863813767_only_trainable_variables.ckpt')#OverAllACC:0.44420250 TestAccuracy:0.49079263 FinalLoss:1.6686381377
saver3.restore(sess, './FPPTM/MouthPatch_TrainonD532_TestonD501_N4_R1_20171018224312_1.42820624205_only_trainable_variables.ckpt')#OverAllACC:0.68346248 TestAccuracy:0.74299440 FinalLoss:1.4282062420
else:
print('Unexpected case occurred when loading pretrain model in restorefacepatchModel')
exit(-1)
elif NetworkType==5:#for discrimination, N3 under tflearn was replaced as N5
for v in vl:
if M3N5S1.get(v.name, -1)==0:
M3N5S1[v.name]=v
elif M3N5S2.get(v.name, -1)==0:
M3N5S2[v.name]=v
elif M3N5S3.get(v.name, -1)==0:
M3N5S3[v.name]=v
saver1=tf.train.Saver(M3N5S1)
saver2=tf.train.Saver(M3N5S2)
saver3=tf.train.Saver(M3N5S3)
if TrainID%100>30:
saver1.restore(sess, './FPPTM/EyePatch_TrainonD502_TestonD531_N3_R10_20171102144530_1.5524974227_.ckpt')#Run10 OverAllACC:0.61836735 TestAccuracy:0.61836735 FinalLoss:1.5524974227
saver2.restore(sess, './FPPTM/MiddlePatch_TrainonD502_TestonD531_N3_R7_20171102190719_1.69338421822_.ckpt')#Run07 OverAllACC:0.46428571 TestAccuracy:0.46428571 FinalLoss:1.6933842182
saver3.restore(sess, './FPPTM/MouthPatch_TrainonD502_TestonD531_N3_R14_20171103033147_1.55810719728_.ckpt')#Run14 OverAllACC:0.60612245 TestAccuracy:0.60612245 FinalLoss:1.5581071973
elif TrainID%100<20:
saver1.restore(sess, './FPPTM/EyePatch_TrainonD532_TestonD501_N3_R0_20171102203504_1.5470389036_.ckpt')#Run00 OverAllACC:0.58779029 TestAccuracy:0.61569255 FinalLoss:1.5470389036
saver2.restore(sess, './FPPTM/MiddlePatch_TrainonD532_TestonD501_N3_R14_20171102201934_1.65476641288_.ckpt')#Run14 OverAllACC:0.46619803 TestAccuracy:0.51401121 FinalLoss:1.6547664129 MinimunLoss:1.6547664129
saver3.restore(sess, './FPPTM/MouthPatch_TrainonD532_TestonD501_N3_R9_20171102141218_1.41499766937_.ckpt')#Run09 OverAllACC:0.69564812 TestAccuracy:0.76220977 FinalLoss:1.4149976694
else:
print('Unexpected case occurred when loading pretrain model in restorefacepatchModel')
exit(-1)
else:
exit(3)
def restorevggModel(sess, NetworkType, graph):
vl=graph.get_collection(name='trainable_variables')
if NetworkType==10 or NetworkType==11 or NetworkType==12:
data_dict=np.load('./networkmodel/VGGFACE.npy').item()
#print(type(data_dict))
#print(len(data_dict))
##print(data_dict)
#for name in data_dict:
# print(name)
for v in vl:
#print(v.name)
namescope=v.name.split('/')[0]
var=v.name.split('/')[1]
val=data_dict.get(namescope, None)
#print(v.name, namescope, var, var.find('W:0'), var.find('b:0'), type(val))
if val==None:
continue
elif var.find('W:0')>-1:
shape=val['weights'].shape
#print(shape)
if shape[2]==3:
val['weights']=np.reshape(val['weights'][:,:,1,:],[shape[0], shape[1], 1, shape[3]])
sess.run(v.assign(val['weights']))
print('Variable %s restored'%(v.name))
elif var.find('b:0')>-1:
#shape=val['biases'].shape
sess.run(v.assign(val['biases']))
print('Variable %s restored'%(v.name))
else:
continue
else:
exit(3)
def loadPretrainedModel(NetworkType, network, session, module):
#if NetworkType==4 or NetworkType==0 or NetworkType==1 or NetworkType==2 or NetworkType==3:
if module==1:
if NetworkType==4 or NetworkType<10:
try:
print("Loading pretrained network model: VGGFACE.npy......")
network.load('./networkmodel/VGGFACE.npy', session, ignore_missing=True)
print('\nPreserved Model of VGGFACE was loaded.\n')
except:
print('ERROR: unable to load pretrain network weights')
traceback.print_exc()
exit(-1)
else:
print('No pretrain network weights are fit to the current network type. Please try another network type.')
exit()
elif module==4:
if NetworkType==4 or NetworkType<9:
try:
print("Loading pretrained network model: VGGFACE.npy......")
network.load('./networkmodel/VGGFACE.npy', session, ignore_missing=True)
print('\nPreserved Model of VGGFACE was loaded.\n')
except:
print('ERROR: unable to load pretrained VGGFACE network weights')
traceback.print_exc()
exit(-1)
elif NetworkType==30:
try:
print("Loading pretrained network model: ResNet50.npy......")
network.load('./networkmodel/ResNet50.npy', session, ignore_missing=True)
print('\nPreserved Model of ResNet50 was loaded.\n')
except:
print('ERROR: unable to load pretrained ResNet50 network weights')
traceback.print_exc()
exit(-1)
elif NetworkType==33:
try:
print("Loading pretrained network model: AlexNetoxford102.npy......")
network.load('./networkmodel/AlexNetoxford102.npy', session, ignore_missing=True)
print('\nPreserved Model of AlexNetoxford102 was loaded.\n')
except:
print('ERROR: unable to load pretrained AlexNetoxford102 network weights')
traceback.print_exc()
exit(-1)
else:
print('No pretrain network weights are fit to the current network type. Please try another network type.')
exit()
else:
print('Module %d has no pretrained model embedded. Please try another module or check the input again.'%(module))
exit()
Datasets = collections.namedtuple('Datasets', ['train', 'test', 'validation'])
def groupdata(Apredata, ValidID, TestID):
'''This function will delete the contents in Apredata.
Please be careful when you use it.'''
nl=len(Apredata)
train={'X':[], 'Y':[]}
test={'X':[], 'Y':[]}
valid={'X':[], 'Y':[]}
for i in range(nl):
if i==int(TestID):
test['X'].extend(Apredata[i]['X'])
del Apredata[i]['X']
test['Y'].extend(Apredata[i]['Y'])
del Apredata[i]['Y']
if ValidID==TestID:
valid=test
elif i==int(ValidID):
valid['X'].extend(Apredata[i]['X'])
del Apredata[i]['X']
valid['Y'].extend(Apredata[i]['Y'])
del Apredata[i]['Y']
else:
train['X'].extend(Apredata[i]['X'])
del Apredata[i]['X']
train['Y'].extend(Apredata[i]['Y'])
del Apredata[i]['Y']
return Datasets(train=train, test=test, validation=valid)
def multiprocessingUnitForModule8tests(metrics, sst, model_save_path, runs, t1, test_run,
NetworkType, data,facepatchpreprocessdatafilename, log,
n_estimators, min_samples_split, min_samples_leaf):
ct=time.time()
m8_model_save_path=model_save_path.replace('_R'+str(runs)+time.strftime('_%Y%m%d%H%M%S',time.localtime(t1)),
'_R'+str(test_run)+time.strftime('_%Y%m%d%H%M%S',time.localtime(ct)))
logpostfix='_E%d_MSS%d_MSL%d_'%(n_estimators, min_samples_split, min_samples_leaf)
if NetworkType%10==0:
from sklearn import tree
optm = tree.DecisionTreeClassifier(criterion='entropy', min_samples_split=min_samples_split,
min_samples_leaf=min_samples_leaf)
elif NetworkType%10==1:
from sklearn import tree
optm = tree.DecisionTreeClassifier(criterion='gini', min_samples_split=min_samples_split,
min_samples_leaf=min_samples_leaf)
elif NetworkType%10==2:
from sklearn.ensemble import RandomForestClassifier
optm = RandomForestClassifier(n_estimators=n_estimators, criterion='entropy',
min_samples_split=min_samples_split, min_samples_leaf=min_samples_leaf)
elif NetworkType%10==3:
from sklearn.ensemble import RandomForestClassifier
optm = RandomForestClassifier(n_estimators=n_estimators, criterion='gini',
min_samples_split=min_samples_split, min_samples_leaf=min_samples_leaf)
else:
print('ERROR:::::$$$$: Unexpected networktype encount.')
exit(-1)
m8_model_save_path=m8_model_save_path.replace('.ckpt', '_%s.ckpt'%(type(optm).__name__))
optm.fit(data.train['X'], data.train['Y'])
tY=optm.predict(data.train['X'])
train_acc=metrics.accuracy_score(np.asarray(data.train['Y']), tY)
tcm=calR(tY, data.train['Y'],cn)
toaa=overAllAccuracy(tcm)
pY=optm.predict(data.test['X'])
#print(pY.shape)
#print((np.asarray(data.test['Y'])).shape)
accuracy=metrics.accuracy_score(np.asarray(data.test['Y']), pY)
cm=calR(pY, data.test['Y'],cn)
oaa=overAllAccuracy(cm)
tt=time.time()
print('OT:%2d\tOAA:%.8f\tAcc:%.8f\tTOAA:%.8f\tTAc:%.8f\t%s\tT:%fs'%(test_run, oaa, accuracy, toaa, train_acc, str(type(optm).__name__),(tt-ct)))
sst.addFigure(oaa)
file_record=logfileForSklearnModel(file_record,test_run, optm, accuracy, oaa, cm, facepatchpreprocessdatafilename, train_acc, toaa, tcm)
#loss_a.setMinimun_loss(oaa)
modelname=m8_model_save_path.replace('.ckpt','_%s_.pkl'%(str(oaa)))
with open(modelname, 'wb') as fin:
pickle.dump(optm, fin, 4)
tt=time.time()
logf=log.replace('.txt',('_'+str(type(optm).__name__)+logpostfix+'.txt'))
filelog=open(logf,'a')
filelog.write('%s\t\t TotalTimeConsumed: %f\tOptimizer: %s\n'%(file_record, (tt-ct), str(type(optm).__name__)))
filelog.close()
return oaa
def savelistcontent(filename, list):
fw=open(filename, 'w')
for v in list:
fw.write('%s\n'%(str(v)))
fw.close()
def run(GPU_Device_ID, Module,
DataSet,ValidID,TestID,
NetworkType, runs
,cLR=0.0001,batchSize=15,loadONW=False,reshape=False):
try:
initialize_dirs()
'''GPU Option---------------------------------------------------------------------------------------------
Determine which GPU is going to be used
------------------------------------------------------------------------------------------------------------'''
print('GPU Option: %s'%(GPU_Device_ID))
if (0==GPU_Device_ID) or (1==GPU_Device_ID):
os.environ["CUDA_VISIBLE_DEVICES"]=str(GPU_Device_ID)
errorlog='./logs/errors_gpu'+str(GPU_Device_ID)+'.txt'
templog='./logs/templogs_newSC_gpu'+str(GPU_Device_ID)+'_M'+str(Module)+'_D'+str(DataSet)+'.txt'
else:
print("Usage: python finetune.py <GPUID> <Module> <NetworkType>\nGPUID must be 0 or 1\nModule must be 1, 2, or 3\nNetworkType must be 0, 1, 2, 3")
exit(-1)
'''GPU Option ENDS---------------------------------------------------------------------------------------'''
cn=7#category numbers
if int(DataSet)>60000:
cn=6
if int(DataSet==66505):
cn=7
mini_loss=10000
loss_a=LOSS_ANA()
file_record=None
t1=time.time()
logprefix='./logs/'
model_save_path=''
labelshape=[None, cn]
m1shape= [None, 128, 128, 1]
global Mini_Epochs
#
#
#
'''Input Data-------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------'''
#
##data set loading
#
D_f=False
if Module==2 and NetworkType<3:
D_f=True
dfile=Dataset_Dictionary.get(DataSet, False)
if dfile==False:
print('\nERROR: Unexpected DatasetID %d encouted.\n\n'%(int(DataSet)))
exit(-1)
logprefix="./logs/D%d_gpu"%(DataSet)
if Module==7:
print('Module 7: Face patches and Geometry')
elif Module==8:
print('Module 8: Face pathces cnn outputs')
else:
if Module==2 and NetworkType>9:
data = DataSetPrepare.loadCKplus10gdata_v4(dfile, ValidID, TestID, Module=Module, Df=False,reshape=False, one_hot=False, cn=cn)
else:
#data = DataSetPrepare.loadCKplus10gdata_v2(dfile, ValidID, TestID, Df=D_f,reshape=reshape, cn=cn)
data = DataSetPrepare.loadCKplus10gdata_v4(dfile, ValidID, TestID, Module=Module, Df=D_f, reshape=reshape, cn=cn)
if DataSet==2:
print("Processing 8 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==3:
print("Processing 8 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==4:
print("Processing 8 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==5:
print("Processing 8 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==6:
m2d=258
print("Processing 8 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==7:
print("Processing 8 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==8:
print("Processing 8 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==9:
m1shape= [None, 224, 224, 1]
print("Processing 8 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==10:
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==11:
m1shape= [None, 224, 224, 1]
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==12:
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==13:
m2d=258
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==15:
dfilet=Dataset_Dictionary.get(10)
#datatest = DataSetPrepare.loadCKplus10gdata_v2(dfilet, ValidID, TestID, Df=D_f,reshape=reshape, cn=cn)
datatest = DataSetPrepare.loadCKplus10gdata_v4(dfilet, ValidID, TestID, Module=Module, Df=D_f,reshape=reshape, cn=cn)
print('Before reset: %d'%data.test.num_examples)
data.test.reset(datatest.test.res_images, datatest.test.geometry,
datatest.test.eyep, datatest.test.middlep, datatest.test.mouthp, datatest.test.innerf,
datatest.test.labels)
data.validation.reset(datatest.validation.res_images, datatest.validation.geometry,
datatest.validation.eyep, datatest.validation.middlep, datatest.validation.mouthp, datatest.validation.innerf,
datatest.validation.labels)
print('After reset: %d'%data.test.num_examples)
del datatest
batchSize=60
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==16:
dfilet=Dataset_Dictionary.get(10)
#datatest = DataSetPrepare.loadCKplus10gdata_v2(dfilet, ValidID, TestID, Df=D_f,reshape=reshape, cn=cn)
datatest = DataSetPrepare.loadCKplus10gdata_v4(dfilet, ValidID, TestID, Module=Module, Df=D_f,reshape=reshape, cn=cn)
print('Before reset: %d'%data.test.num_examples)
data.test.reset(datatest.test.res_images, datatest.test.geometry,
datatest.test.eyep, datatest.test.middlep, datatest.test.mouthp, datatest.test.innerf,
datatest.test.labels)
data.validation.reset(datatest.validation.res_images, datatest.validation.geometry,
datatest.validation.eyep, datatest.validation.middlep, datatest.validation.mouthp, datatest.validation.innerf,
datatest.validation.labels)
print('After reset: %d'%data.test.num_examples)
del datatest
if runs%2==0:
batchSize=30
else:
batchSize=15
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==17:
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==18:
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==19:
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==33:
batchSize=35
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==32:
dfilet=Dataset_Dictionary.get(33)
#datatest = DataSetPrepare.loadCKplus10gdata_v2(dfilet, ValidID, TestID, Df=D_f,reshape=reshape, cn=cn)
datatest = DataSetPrepare.loadCKplus10gdata_v4(dfilet, ValidID, TestID, Module=Module, Df=D_f,reshape=reshape, cn=cn)
print('Before reset: %d'%data.test.num_examples)
data.test.reset(datatest.test.res_images, datatest.test.geometry,
datatest.test.eyep, datatest.test.middlep, datatest.test.mouthp, datatest.test.innerf,
datatest.test.labels)
data.validation.reset(datatest.validation.res_images, datatest.validation.geometry,
datatest.validation.eyep, datatest.validation.middlep, datatest.validation.mouthp, datatest.validation.innerf,
datatest.validation.labels)
print('After reset: %d'%data.test.num_examples)
del datatest
batchSize=70
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==34:
dfilet=Dataset_Dictionary.get(33)
#datatest = DataSetPrepare.loadCKplus10gdata_v2(dfilet, ValidID, TestID, Df=D_f,reshape=reshape, cn=cn)
datatest = DataSetPrepare.loadCKplus10gdata_v4(dfilet, ValidID, TestID, Module=Module, Df=D_f,reshape=reshape, cn=cn)
print('Before reset: %d'%data.test.num_examples)
data.test.reset(datatest.test.res_images, datatest.test.geometry,
datatest.test.eyep, datatest.test.middlep, datatest.test.mouthp, datatest.test.innerf,
datatest.test.labels)
data.validation.reset(datatest.validation.res_images, datatest.validation.geometry,
datatest.validation.eyep, datatest.validation.middlep, datatest.validation.mouthp, datatest.validation.innerf,
datatest.validation.labels)
print('After reset: %d'%data.test.num_examples)
del datatest
batchSize=70
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==42:
dfilet=Dataset_Dictionary.get(40)
#datatest = DataSetPrepare.loadCKplus10gdata_v2(dfilet, ValidID, TestID, Df=D_f,reshape=reshape, cn=cn)
datatest = DataSetPrepare.loadCKplus10gdata_v4(dfilet, ValidID, TestID, Module=Module, Df=D_f,reshape=reshape, cn=cn)
print('Before reset: %d'%data.test.num_examples)
data.test.reset(datatest.test.res_images, datatest.test.geometry,
datatest.test.eyep, datatest.test.middlep, datatest.test.mouthp, datatest.test.innerf,
datatest.test.labels)
data.validation.reset(datatest.validation.res_images, datatest.validation.geometry,
datatest.validation.eyep, datatest.validation.middlep, datatest.validation.mouthp, datatest.validation.innerf,
datatest.validation.labels)
print('After reset: %d'%data.test.num_examples)
del datatest
batchSize=60
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==40:
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==43:
dfilet=Dataset_Dictionary.get(40)
#datatest = DataSetPrepare.loadCKplus10gdata_v2(dfilet, ValidID, TestID, Df=D_f,reshape=reshape, cn=cn)
datatest = DataSetPrepare.loadCKplus10gdata_v4(dfilet, ValidID, TestID, Module=Module, Df=D_f,reshape=reshape, cn=cn)
print('Before reset: %d'%data.test.num_examples)
data.test.reset(datatest.test.res_images, datatest.test.geometry,
datatest.test.eyep, datatest.test.middlep, datatest.test.mouthp, datatest.test.innerf,
datatest.test.labels)
data.validation.reset(datatest.validation.res_images, datatest.validation.geometry,
datatest.validation.eyep, datatest.validation.middlep, datatest.validation.mouthp, datatest.validation.innerf,
datatest.validation.labels)
print('After reset: %d'%data.test.num_examples)
del datatest
batchSize=60
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==111:
batchSize=30
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==222:
dfilet=Dataset_Dictionary.get(111)
#datatest = DataSetPrepare.loadCKplus10gdata_v2(dfilet, ValidID, TestID, Df=D_f,reshape=reshape, cn=cn)
datatest = DataSetPrepare.loadCKplus10gdata_v4(dfilet, ValidID, TestID, Module=Module, Df=D_f,reshape=reshape, cn=cn)
print('Before reset: %d'%data.test.num_examples)
data.test.reset(datatest.test.res_images, datatest.test.geometry,
datatest.test.eyep, datatest.test.middlep, datatest.test.mouthp, datatest.test.innerf,
datatest.test.labels)
data.validation.reset(datatest.validation.res_images, datatest.validation.geometry,
datatest.validation.eyep, datatest.validation.middlep, datatest.validation.mouthp, datatest.validation.innerf,
datatest.validation.labels)
print('After reset: %d'%data.test.num_examples)
del datatest
batchSize=30
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==333:
dfilet=Dataset_Dictionary.get(444)
#datatest = DataSetPrepare.loadCKplus10gdata_v2(dfilet, ValidID, TestID, Df=D_f,reshape=reshape, cn=cn)
datatest = DataSetPrepare.loadCKplus10gdata_v4(dfilet, ValidID, TestID, Module=Module, Df=D_f,reshape=reshape, cn=cn)
print('Before reset: %d'%data.test.num_examples)
data.test.reset(datatest.test.res_images, datatest.test.geometry,
datatest.test.eyep, datatest.test.middlep, datatest.test.mouthp, datatest.test.innerf,
datatest.test.labels)
data.validation.reset(datatest.validation.res_images, datatest.validation.geometry,
datatest.validation.eyep, datatest.validation.middlep, datatest.validation.mouthp, datatest.validation.innerf,
datatest.validation.labels)
print('After reset: %d'%data.test.num_examples)
del datatest
batchSize=30
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==444:
batchSize=30
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==501:
if runs%2==0:
batchSize=30
else:
batchSize=15
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==502:
dfilet=Dataset_Dictionary.get(501)
#datatest = DataSetPrepare.loadCKplus10gdata_v2(dfilet, ValidID, TestID, Df=D_f,reshape=reshape, cn=cn)
datatest = DataSetPrepare.loadCKplus10gdata_v4(dfilet, ValidID, TestID,Module=Module, Df=D_f,reshape=reshape, cn=cn)
print('Before reset: %d'%data.test.num_examples)
data.test.reset(datatest.test.res_images, datatest.test.geometry,
datatest.test.eyep, datatest.test.middlep, datatest.test.mouthp, datatest.test.innerf,
datatest.test.labels)
data.validation.reset(datatest.validation.res_images, datatest.validation.geometry,
datatest.validation.eyep, datatest.validation.middlep, datatest.validation.mouthp, datatest.validation.innerf,
datatest.validation.labels)
print('After reset: %d'%data.test.num_examples)
del datatest
if runs%2==0:
batchSize=30
else:
batchSize=15
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==503:
if runs%2==0:
batchSize=30
else:
batchSize=15
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==531:
if runs%2==0:
batchSize=15
else:
batchSize=30
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==532:
dfilet=Dataset_Dictionary.get(531)
#datatest = DataSetPrepare.loadCKplus10gdata_v2(dfilet, ValidID, TestID, Df=D_f,reshape=reshape, cn=cn)
datatest = DataSetPrepare.loadCKplus10gdata_v4(dfilet, ValidID, TestID, Module=Module, Df=D_f,reshape=reshape, cn=cn)
print('Before reset: %d'%data.test.num_examples)
data.test.reset(datatest.test.res_images, datatest.test.geometry,
datatest.test.eyep, datatest.test.middlep, datatest.test.mouthp, datatest.test.innerf,
datatest.test.labels)
data.validation.reset(datatest.validation.res_images, datatest.validation.geometry,
datatest.validation.eyep, datatest.validation.middlep, datatest.validation.mouthp, datatest.validation.innerf,
datatest.validation.labels)
print('After reset: %d'%data.test.num_examples)
del datatest
if runs%2==0:
batchSize=15
else:
batchSize=30
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==551:
if runs%2==0:
batchSize=21
else:
batchSize=42
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==552:
if runs%2==0:
batchSize=21
else:
batchSize=42
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==553:
if runs%2==0:
batchSize=21
else:
batchSize=42
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==554:
if runs%2==0:
batchSize=21
else:
batchSize=42
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==610:
if runs%3==0:
batchSize=35
elif runs%3==1:
batchSize=70
else:
batchSize=128
Mini_Epochs=Mini_Epochs*2
cLR=0.00001
print("Processing dataset>>>>>>>>\n%s"%(logprefix))
elif DataSet==611:
if runs%3==0:
batchSize=35
elif runs%3==1:
batchSize=70
else:
batchSize=128
Mini_Epochs=Mini_Epochs*2
cLR=0.00001
print("Processing dataset>>>>>>>>\n%s"%(logprefix))
elif DataSet==620:
if runs%3==0:
batchSize=35
elif runs%3==1:
batchSize=70
else:
batchSize=128
Mini_Epochs=Mini_Epochs*2
cLR=0.00001
print("Processing dataset>>>>>>>>\n%s"%(logprefix))
elif DataSet==621:
if runs%3==0:
batchSize=35
elif runs%3==1:
batchSize=70
else:
batchSize=128
Mini_Epochs=Mini_Epochs*2
cLR=0.00001
print("Processing dataset>>>>>>>>\n%s"%(logprefix))
elif DataSet==1001:
if runs%2==0:
batchSize=30
else:
batchSize=15
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==1002:
dfilet=Dataset_Dictionary.get(1001)
datatest = DataSetPrepare.loadCKplus10gdata_v2(dfilet, ValidID, TestID, Df=D_f,reshape=reshape, cn=cn)
print('Before reset: %d'%data.test.num_examples)
data.test.reset(datatest.test.res_images, datatest.test.geometry,
datatest.test.eyep, datatest.test.middlep, datatest.test.mouthp, datatest.test.innerf,
datatest.test.labels)
data.validation.reset(datatest.validation.res_images, datatest.validation.geometry,
datatest.validation.eyep, datatest.validation.middlep, datatest.validation.mouthp, datatest.validation.innerf,
datatest.validation.labels)
print('After reset: %d'%data.test.num_examples)
if runs%2==0:
batchSize=30
else:
batchSize=30
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==66501:
batchSize=30
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==66502:
dfilet=Dataset_Dictionary.get(66501)
#datatest = DataSetPrepare.loadCKplus10gdata_v2(dfilet, ValidID, TestID, Df=D_f,reshape=reshape, cn=cn)
datatest = DataSetPrepare.loadCKplus10gdata_v4(dfilet, ValidID, TestID,Module=Module, Df=D_f,reshape=reshape, cn=cn)
print('Before reset: %d'%data.test.num_examples)
data.test.reset(datatest.test.res_images, datatest.test.geometry,
datatest.test.eyep, datatest.test.middlep, datatest.test.mouthp, datatest.test.innerf,
datatest.test.labels)
data.validation.reset(datatest.validation.res_images, datatest.validation.geometry,
datatest.validation.eyep, datatest.validation.middlep, datatest.validation.mouthp, datatest.validation.innerf,
datatest.validation.labels)
print('After reset: %d'%data.test.num_examples)
del datatest
batchSize=30
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==66503:
cLR=0.001
batchSize=30
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==66504:
#cLR=0.001
batchSize=30
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==66505:
#cLR=0.001
batchSize=30
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==66531:
batchSize=30
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==66532:
dfilet=Dataset_Dictionary.get(66531)
#datatest = DataSetPrepare.loadCKplus10gdata_v2(dfilet, ValidID, TestID, Df=D_f,reshape=reshape, cn=cn)
datatest = DataSetPrepare.loadCKplus10gdata_v4(dfilet, ValidID, TestID, Module=Module, Df=D_f,reshape=reshape, cn=cn)
print('Before reset: %d'%data.test.num_examples)
data.test.reset(datatest.test.res_images, datatest.test.geometry,
datatest.test.eyep, datatest.test.middlep, datatest.test.mouthp, datatest.test.innerf,
datatest.test.labels)
data.validation.reset(datatest.validation.res_images, datatest.validation.geometry,
datatest.validation.eyep, datatest.validation.middlep, datatest.validation.mouthp, datatest.validation.innerf,
datatest.validation.labels)
print('After reset: %d'%data.test.num_examples)
del datatest
batchSize=30
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==66554:
batchSize=30
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==66555:
batchSize=30
print("Processing 10 groups>>>>>>>>\n%s"%(logprefix))
elif DataSet==66610:
if runs%2==0:
batchSize=30
elif runs%2==1:
batchSize=60
cLR=0.00001
print("Processing dataset>>>>>>>>\n%s"%(logprefix))
elif DataSet==66611:
if runs%2==0:
batchSize=30
elif runs%2==1:
batchSize=60
cLR=0.00001