-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconcat_train_test.py
687 lines (547 loc) · 25.5 KB
/
concat_train_test.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
# -*- coding: utf-8 -*-
"""
Train and Test the multi-DJSTN Models with multi-layers
"""
import numpy as np
import time
import random
import os
import math
import keras
import datetime
import tensorflow as tf
import matplotlib.pyplot as plt
from keras import optimizers
from keras.callbacks import ModelCheckpoint
from keras.callbacks import ReduceLROnPlateau, EarlyStopping
from keras.callbacks import Callback
from keras import backend as K
# from tensorflow.python.keras import backend as K
import os
import copy
os.environ["CUDA_VISIBLE_DEVICES"] = "2"
class TestCallback(Callback):
def __init__(self, test_data, test_acc_history, test_loss_history):
self.test_data = test_data
self.test_acc_history = test_acc_history
self.test_loss_history = test_loss_history
def on_epoch_end(self, epoch, logs={}):
x, y = self.test_data
loss, acc = self.model.evaluate(x, y, verbose=0)
print('Testing loss : %.2f%%' % loss)
print('Testing acc : %.2f%%' % acc)
test_acc_history = self.test_acc_history
test_loss_history = self.test_loss_history
test_acc_history.append(acc)
test_loss_history.append(loss)
return test_acc_history, test_loss_history
def train_test_valid_random(x, y, train_idxs, valid_idxs, test_idxs,
app=True):
X_train = []
Y_train = []
X_train_d = []
Y_train_d = []
for i in range(len(train_idxs)):
X_train.append(x[train_idxs[i]])
Y_train.append(y[train_idxs[i]])
X_test = []
Y_test = []
X_test_d = []
Y_test_d = []
for i in range(len(test_idxs)):
X_test.append(x[test_idxs[i]])
Y_test.append(y[test_idxs[i]])
X_valid = []
Y_valid = []
X_valid_d = []
Y_valid_d = []
for i in range(len(valid_idxs)):
X_valid.append(x[valid_idxs[i]])
Y_valid.append(y[valid_idxs[i]])
X_train = np.asarray(X_train)
X_valid = np.asarray(X_valid)
X_test = np.asarray(X_test)
Y_train = np.asarray(Y_train)
Y_valid = np.asarray(Y_valid)
Y_test = np.asarray(Y_test)
return X_train, Y_train, X_test, Y_test, X_valid, Y_valid
def train_test_valid_random_split(numbers, x, y, data, app=True):
# neu : number of neutral dataset
# aug2 : number of how many times the nuetral dataset augmented
# aug : number of how many time the other expression datasets augmented
if data == 0 or data == 5: # CKP
aug2 = 2
neu = 600
aug = 14
elif data == 1 or data == 6: # MMI
neu = 416
aug2 = 2
aug = 14
elif data == 2 or data == 7: # FERA
neu = 0
aug2 = 1
aug = 14
train_idxs = []
test_idxs = []
valid_idxs = []
# split nuetral emotion dataset
if neu:
dataset_neu = []
for i in range(int(neu / aug2)):
dataset_neu.append(i)
random.shuffle(dataset_neu)
# 0.65 : 0.2 : 0.15 = train : test : val
train_idx_neu = int(len(dataset_neu) * 0.65)
test_idx_neu = int(len(dataset_neu) * 0.85)
for i in range(train_idx_neu):
for j in range(aug2):
train_idxs.append(numbers[dataset_neu[i] * aug2 + j])
for i in range(test_idx_neu - train_idx_neu):
for j in range(aug2):
test_idxs.append(numbers[dataset_neu[i + train_idx_neu] * aug2 + j])
for i in range(len(dataset_neu) - test_idx_neu):
for j in range(aug2):
valid_idxs.append(numbers[dataset_neu[i + test_idx_neu] * aug2 + j])
# split other emotion dataset
dataset = []
emotion_num = int((len(x) - neu) / aug)
for i in range(emotion_num):
dataset.append(i)
random.shuffle(dataset)
# 0.65 : 0.2 : 0.15 = train : test : val
train_idx = int(len(dataset) * 0.65)
test_idx = int(len(dataset) * 0.85)
for i in range(train_idx):
for j in range(aug):
num = neu + dataset[i] * aug + j
train_idxs.append(numbers[dataset[i] * aug + j + neu])
for i in range(test_idx - train_idx):
for j in range(aug):
test_idxs.append(numbers[dataset[i + train_idx] * aug + j + neu])
for i in range(len(dataset) - test_idx):
for j in range(aug):
valid_idxs.append(numbers[dataset[i + test_idx] * aug + j + neu])
return train_idxs, valid_idxs, test_idxs
def train_valid_random(x, y, train_idxs, valid_idxs, app=True):
X_train = []
Y_train = []
for i in range(len(train_idxs)):
X_train.append(x[train_idxs[i]])
Y_train.append(y[train_idxs[i]])
X_valid = []
Y_valid = []
for i in range(len(valid_idxs)):
X_valid.append(x[valid_idxs[i]])
Y_valid.append(y[valid_idxs[i]])
X_train = np.asarray(X_train)
X_valid = np.asarray(X_valid)
Y_train = np.asarray(Y_train)
Y_valid = np.asarray(Y_valid)
return X_train, Y_train, X_valid, Y_valid
def train_valid_random_split(numbers, x, y, data, app=True):
# neu : number of neutral dataset
# aug2 : number of how many times the nuetral dataset augmented
# aug : number of how many time the other expression datasets augmented
if data == 0 or data == 5: # CKP
aug2 = 2
neu = 600
aug = 14
elif data == 1 or data == 6: # MMI
neu = 416
aug2 = 2
aug = 14
elif data == 2 or data == 7: # FERA
neu = 0
aug2 = 1
aug = 14
elif data == 3 or data == 8: # AFEW
neu = 0
aug2 = 1
aug = 4
train_idxs = []
valid_idxs = []
# split nuetral emotion dataset
if neu:
dataset_neu = []
for i in range(int(neu / aug2)):
dataset_neu.append(i)
random.shuffle(dataset_neu)
# 0.8 : 0.2 = train : val
train_idx_neu = int(len(dataset_neu) * 0.8)
for i in range(train_idx_neu):
for j in range(aug2):
train_idxs.append(numbers[dataset_neu[i] * aug2 + j])
for i in range(len(dataset_neu) - train_idx_neu):
for j in range(aug2):
valid_idxs.append(numbers[dataset_neu[i + train_idx_neu] * aug2 + j])
# split other emotion datasets
dataset = []
emotion_num = int((len(x) - neu) / aug)
for i in range(emotion_num):
dataset.append(i)
# for i in range(int(len(x) / aug)):
# dataset.append(i)
random.shuffle(dataset)
# 0.8 : 0.2 = train : val
train_idx = int(len(dataset) * 0.8)
for i in range(train_idx):
for j in range(aug):
num = neu + dataset[i] * aug + j
train_idxs.append(numbers[dataset[i] * aug + j + neu])
for i in range(len(dataset) - train_idx):
for j in range(aug):
valid_idxs.append(numbers[dataset[i + train_idx] * aug + j + neu])
return train_idxs, valid_idxs
def test_random(x, y, test_idxs, app=True):
X_test = []
Y_test = []
for i in range(len(test_idxs)):
X_test.append(x[test_idxs[i]])
Y_test.append(y[test_idxs[i]])
X_test = np.asarray(X_test)
Y_test = np.asarray(Y_test)
return X_test, Y_test
def hybrid_network(x, r):
# x for dataset selection
# r for iteration
print(x, r)
time = datetime.datetime.now()
t = time.strftime('%Y%m%d-%H%M%S')
from concat_atten import attModels
if x == 0 or x == 5: # ck+
jf_class = 7
emotions = ['neutral', 'angry', 'disgust', 'fear', 'happy', 'sad', 'surprise']
print('-----------------------------------------')
print('-------------------CK+-------------------')
print('-----------------------------------------')
elif x == 1 or x == 6: # mmi
jf_class = 7
emotions = ['neutral', 'angry', 'disgust', 'fear', 'happy', 'sad', 'surprise']
print('-----------------------------------------')
print('-------------------MMI-------------------')
print('-----------------------------------------')
elif x == 2 or x == 7: # fera
jf_class = 5
emotions = ['relief', 'anger', 'fear', 'joy', 'sadness']
print('-----------------------------------------')
print('------------------FERA-------------------')
print('-----------------------------------------')
elif x == 3 or x == 8: # afew
jf_class = 7
emotions = ['neutral', 'angry', 'disgust', 'fear', 'happy', 'sad', 'surprise']
print('-----------------------------------------')
print('------------------AFEW-------------------')
print('-----------------------------------------')
elif x == 4 or x == 9: # All
jf_class = 5
emotions = ['relief', 'anger', 'fear', 'joy', 'sadness']
print('-----------------------------------------')
print('------------------ALL--------------------')
print('-----------------------------------------')
# num = []
for it in range(r):
now = datetime.datetime.now()
dataset = ['ckp_min', 'mmi_min', 'fera_min', 'afew_min', 'all_min', 'ckp_over', 'mmi_over', 'fera_over',
'afew_over', 'all_over']
if x <= 4:
mo = 'Minimum'
mo2 = 'minimum'
else:
mo = 'Overlapped'
mo2 = 'over'
dataset1 = ['CKP', 'MMI', 'FERA', 'AFEW', 'ALL', 'CKP', 'MMI', 'FERA', 'AFEW', 'ALL']
dataset2 = ['ckp', 'mmi', 'fera', 'afew', 'all', 'ckp', 'mmi', 'fera', 'afew', 'all']
pre = ['pre', 'lbp', 'norm', 'normlbp']
pre2 = ['preprocessed', 'lbp', 'normalized', 'norm_lbp']
modeldir = 'weights/{}/{}/{}/'.format(dataset[x], t, pre[it])
if not os.path.exists(modeldir):
os.makedirs(modeldir)
save_dir = 'graph/{}/{}/{}'.format(dataset[x], t, pre[it])
if not os.path.exists(save_dir):
os.makedirs(save_dir)
if x == 3 or x == 8:
# tv(train+validation) dataset
appx1_tv = np.load(
'FER_npy_dataset/{}_{}/Train/{}/new_{}_aug_{}_s_{}_x.npy'.format(dataset1[x], mo2, pre2[it], dataset2[x], mo2,
pre[it]))
appx2_tv = np.load(
'FER_npy_dataset/{}_{}/Train/{}/new_{}_aug_{}_f_{}_x.npy'.format(dataset1[x], mo2, pre2[it], dataset2[x], mo2,
pre[it]))
appx3_tv = np.load(
'FER_npy_dataset/{}_{}/Train/{}/new_{}_aug_{}_m_{}_x.npy'.format(dataset1[x], mo2, pre2[it], dataset2[x], mo2,
pre[it]))
appy1_tv = np.load(
'FER_npy_dataset/{}_{}/Train/{}/new_{}_aug_{}_s_{}_y.npy'.format(dataset1[x], mo2, pre2[it], dataset2[x], mo2,
pre[it]))
appy2_tv = np.load(
'FER_npy_dataset/{}_{}/Train/{}/new_{}_aug_{}_f_{}_y.npy'.format(dataset1[x], mo2, pre2[it], dataset2[x], mo2,
pre[it]))
appy3_tv = np.load(
'FER_npy_dataset/{}_{}/Train/{}/new_{}_aug_{}_m_{}_y.npy'.format(dataset1[x], mo2, pre2[it], dataset2[x], mo2,
pre[it]))
# test dataset
appx1_t = np.load(
'FER_npy_dataset/{}_{}/Test/{}/new_{}_aug_{}_s_{}_x.npy'.format(dataset1[x], mo2, pre2[it], dataset2[x],
mo2,
pre[it]))
appx2_t = np.load(
'FER_npy_dataset/{}_{}/Test/{}/new_{}_aug_{}_f_{}_x.npy'.format(dataset1[x], mo2, pre2[it], dataset2[x],
mo2,
pre[it]))
appx3_t = np.load(
'FER_npy_dataset/{}_{}/Test/{}/new_{}_aug_{}_m_{}_x.npy'.format(dataset1[x], mo2, pre2[it], dataset2[x],
mo2,
pre[it]))
appy1_t = np.load(
'FER_npy_dataset/{}_{}/Test/{}/new_{}_aug_{}_s_{}_y.npy'.format(dataset1[x], mo2, pre2[it], dataset2[x],
mo2,
pre[it]))
appy2_t = np.load(
'FER_npy_dataset/{}_{}/Test/{}/new_{}_aug_{}_f_{}_y.npy'.format(dataset1[x], mo2, pre2[it], dataset2[x],
mo2,
pre[it]))
appy3_t = np.load(
'FER_npy_dataset/{}_{}/Test/{}/new_{}_aug_{}_m_{}_y.npy'.format(dataset1[x], mo2, pre2[it], dataset2[x],
mo2,
pre[it]))
else:
appx1 = np.load(
'FER_npy_dataset/{}_{}_14/ALL/{}/{}_aug_{}_s_{}_x.npy'.format(dataset1[x], mo2, pre2[it], dataset2[x],
mo2,
pre[it]))
appx2 = np.load(
'FER_npy_dataset/{}_{}_14/ALL/{}/{}_aug_{}_f_{}_x.npy'.format(dataset1[x], mo2, pre2[it], dataset2[x],
mo2,
pre[it]))
appx3 = np.load(
'FER_npy_dataset/{}_{}_14/ALL/{}/{}_aug_{}_m_{}_x.npy'.format(dataset1[x], mo2, pre2[it], dataset2[x],
mo2,
pre[it]))
appy1 = np.load(
'FER_npy_dataset/{}_{}_14/ALL/{}/{}_aug_{}_s_{}_y.npy'.format(dataset1[x], mo2, pre2[it], dataset2[x],
mo2,
pre[it]))
appy2 = np.load(
'FER_npy_dataset/{}_{}_14/ALL/{}/{}_aug_{}_f_{}_y.npy'.format(dataset1[x], mo2, pre2[it], dataset2[x],
mo2,
pre[it]))
appy3 = np.load(
'FER_npy_dataset/{}_{}_14/ALL/{}/{}_aug_{}_m_{}_y.npy'.format(dataset1[x], mo2, pre2[it], dataset2[x],
mo2,
pre[it]))
if pre[it] == 'pre': # pre
print('-----------------------------------------')
print('-------------------PRE-------------------')
print('-----------------------------------------')
elif pre[it] == 'lbp': # lbp
print('-----------------------------------------')
print('-------------------LBP-------------------')
print('-----------------------------------------')
elif pre[it] == 'norm': # norm
print('-----------------------------------------')
print('------------------NORM-------------------')
print('-----------------------------------------')
elif pre[it] == 'normlbp': # norm_lbp
print('-----------------------------------------')
print('------------------nLBP-------------------')
print('-----------------------------------------')
if x == 3 or x == 8:
# random index shuffle for train_test_valid split
numbers_tv = []
for i in range(len(appy1_tv)):
numbers_tv.append(i)
# random index shuffle for train_test_valid split
numbers_test = []
for i in range(len(appy1_t)):
numbers_test.append(i)
else:
# random index shuffle for train_test_valid split
numbers = []
for i in range(len(appy1)):
numbers.append(i)
if it == 0:
if x == 3 or x == 8:
train_idxs, valid_idxs = train_valid_random_split(numbers_tv, appx1_tv, appy1_tv, x, True)
test_idxs = numbers_test[:len(appy1_tv)]
random.shuffle(test_idxs)
random.shuffle(train_idxs)
random.shuffle(valid_idxs)
else:
train_idxs, valid_idxs, test_idxs = train_test_valid_random_split(numbers, appx1, appy1, x, True)
random.shuffle(train_idxs)
random.shuffle(test_idxs)
random.shuffle(valid_idxs)
# idx not fixed
if x == 3 or x == 8:
# slow
X_app_train1, Y_app_train1, X_app_valid1, Y_app_valid1 = train_valid_random(
appx1_tv, appy1_tv, train_idxs, valid_idxs, True)
# fast
X_app_train2, Y_app_train2, X_app_valid2, Y_app_valid2 = train_valid_random(
appx2_tv, appy2_tv, train_idxs, valid_idxs, True)
# middle
X_app_train3, Y_app_train3, X_app_valid3, Y_app_valid3 = train_valid_random(
appx3_tv, appy3_tv, train_idxs, valid_idxs, True)
# slow
X_app_test1, Y_app_test1 = test_random(appx1_t, appy1_t, test_idxs, True)
# fast
X_app_test2, Y_app_test2 = test_random(appx2_t, appy2_t, test_idxs, True)
# middle
X_app_test3, Y_app_test3 = test_random(appx3_t, appy3_t, test_idxs, True)
else:
# slow
X_app_train1, Y_app_train1, X_app_test1, Y_app_test1, X_app_valid1, Y_app_valid1 = train_test_valid_random(
appx1, appy1, train_idxs, valid_idxs, test_idxs, True)
# fast
X_app_train2, Y_app_train2, X_app_test2, Y_app_test2, X_app_valid2, Y_app_valid2 = train_test_valid_random(
appx2, appy2, train_idxs, valid_idxs, test_idxs, True)
# middle
X_app_train3, Y_app_train3, X_app_test3, Y_app_test3, X_app_valid3, Y_app_valid3 = train_test_valid_random(
appx3, appy3, train_idxs, valid_idxs, test_idxs, True)
import csv
test_idxs_s = sorted(test_idxs)
with open('{}/test_indexs.csv'.format(save_dir), 'w') as csvfile:
writer = csv.writer(csvfile, delimiter=',',
quotechar='|', quoting=csv.QUOTE_MINIMAL)
writer.writerow(test_idxs_s)
ep = 150 # epoch
batch = 32
adam = optimizers.Adam(lr=0.0001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False)
#################################################
print("++++++++++++++++++++++++++++")
print("++++++++++DATA Concat+++++++")
print("++++++++++++++++++++++++++++")
print("++++++++++++++++++++++++++++")
print("+++++++++++++ATT++++++++++++")
print("++++++++++++++++++++++++++++")
# attention model
model_atten = attModels(X_app_train1, X_app_train3, X_app_train2, jf_class)
modelweight_name = 'concat_atten_network.h5'
modelweight_path = os.path.join(modeldir, modelweight_name)
cp_callback = ModelCheckpoint(modelweight_path,
monitor='val_accuracy', mode='max',
save_best_only=True,
save_weights_only=True,
verbose=1)
early_stopping = EarlyStopping(monitor='val_loss', mode='min', verbose=1, patience=100)
early_stopping2 = EarlyStopping(monitor='val_accuracy', mode='max', verbose=1, patience=100, baseline=1)
model_atten.compile(loss="categorical_crossentropy", optimizer=adam, metrics=['accuracy'])
# model_atten.summary()
Y_app_train1_1 = np.expand_dims(Y_app_train1, axis=1)
Y_app_valid1_1 = np.expand_dims(Y_app_valid1, axis=1)
app_history1 = model_atten.fit([X_app_train1, X_app_train3, X_app_train2],
Y_app_train1_1,
batch_size=batch,
validation_data=([X_app_valid1, X_app_valid3, X_app_valid2], Y_app_valid1_1),
epochs=ep,
shuffle=True,
verbose=1,
callbacks=[cp_callback])
# without weighted model
# model_soft.load_weights(modelweight_path)
Y_app_test1_1 = np.expand_dims(Y_app_test1, axis=1)
scores1 = model_atten.evaluate([X_app_test1, X_app_test3, X_app_test2], Y_app_test1_1)
appacc1 = scores1[1] * 100
print("Test Accuracy: %.2f%%" % (scores1[1] * 100))
print("Test Loss:%.2f%%" % (scores1[0]))
# if you want to show every figure, use plt.show()
# accuracy graph of train and validation set
plt.figure(figsize=[8, 6])
plt.plot(app_history1.history['accuracy'], 'r', linewidth=3.0)
plt.plot(app_history1.history['val_accuracy'], 'b', linewidth=3.0)
plt.legend(['Training Accuracy', 'Validation Accuracy'], fontsize=18)
plt.xlabel('Iteration ', fontsize=16)
plt.ylabel('Accuracy', fontsize=16)
plt.title('Accuracy Curves', fontsize=16)
plt.savefig('{}/{}_without_concat_atten_accuracy_{}.png'.format(save_dir, it, appacc1))
# plt.show()
plt.close()
# loss graph of train and validation set
plt.figure(figsize=[8, 6])
plt.plot(app_history1.history['loss'], 'r', linewidth=3.0)
plt.plot(app_history1.history['val_loss'], 'b', linewidth=3.0)
plt.legend(['Training Loss', 'Validation Loss'], fontsize=18)
plt.xlabel('Epochs ', fontsize=16)
plt.ylabel('Loss', fontsize=16)
plt.title('loss curves')
plt.savefig('{}/{}_without_concat_atten_loss_{}.png'.format(save_dir, it, appacc1))
# plt.show()
plt.close()
# with weighted model
model_atten.load_weights(modelweight_path)
scores1 = model_atten.evaluate([X_app_test1, X_app_test3, X_app_test2], Y_app_test1_1)
appacc1 = scores1[1] * 100
print("Test Accuracy: %.2f%%" % (scores1[1] * 100))
print("Test Loss:%.2f%%" % (scores1[0]))
# if you want to show every figure, use plt.show()
# accuracy graph of train and validation set
plt.figure(figsize=[8, 6])
plt.plot(app_history1.history['accuracy'], 'r', linewidth=3.0)
plt.plot(app_history1.history['val_accuracy'], 'b', linewidth=3.0)
plt.legend(['Training Accuracy', 'Validation Accuracy'], fontsize=18)
plt.xlabel('Epochs ', fontsize=16)
plt.ylabel('Accuracy', fontsize=16)
plt.title('Accuracy Curves', fontsize=16)
plt.savefig('{}/{}_concat_atten_accuracy_{}.png'.format(save_dir, it, appacc1))
# plt.show()
plt.close()
# loss graph of train and validation set
plt.figure(figsize=[8, 6])
plt.plot(app_history1.history['loss'], 'r', linewidth=3.0)
plt.plot(app_history1.history['val_loss'], 'b', linewidth=3.0)
plt.legend(['Training Loss', 'Validation Loss'], fontsize=18)
plt.xlabel('Epochs ', fontsize=16)
plt.ylabel('Loss', fontsize=16)
plt.title('loss curves')
plt.savefig('{}/{}_concat_atten_loss_{}.png'.format(save_dir, it, appacc1))
# plt.show()
plt.close()
K.clear_session()
# clear datasets list
X_app_train1 = None
Y_app_train1 = None
X_app_test1 = None
Y_app_test1 = None
X_app_valid1 = None
Y_app_valid1 = None
X_app_train2 = None
Y_app_train2 = None
X_app_test2 = None
Y_app_test2 = None
X_app_valid2 = None
Y_app_valid2 = None
X_app_train3 = None
Y_app_train3 = None
X_app_test3 = None
Y_app_test3 = None
X_app_valid3 = None
Y_app_valid3 = None
appx1 = None
appy1 = None
appx2 = None
appy2 = None
appx1 = None
appy1 = None
K.clear_session()
if __name__ == '__main__':
print('-----------------------------------------')
print('>> FER TRAIN SYSTEM <<')
print('-----------------------------------------')
print('-----------SELECT FER DATASET------------')
print('> (0) : CK+_minimum')
print('> (1) : MMI_minimum')
print('> (2) : GEMEP-FERA_minimum')
print('> (3) : AFEW_minimum')
print('> (4) : ALL_minimum')
print('> (5) : CK+_over')
print('> (6) : MMI_over')
print('> (7) : GEMEP-FERA_over')
print('> (8) : AFEW_over')
print('> (9) : ALL_over')
print('-----------------------------------------')
x = int(input()) # selected dataset from above
print('----------THE NUMBER OF EPOCH------------')
r = int(input()) # iteration of training & testing preprocessing list
print('-----------------------------------------')
hybrid_network(x, r)
K.clear_session()