-
Notifications
You must be signed in to change notification settings - Fork 0
/
Train.py
74 lines (62 loc) · 1.95 KB
/
Train.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
# from __future__ import print_function
from keras.models import load_model
from matplotlib import pyplot
import datasets.Datasets as Datasets
import datetime
import Models
import os
import Utils
# Configure train
nb_epoch = 1000
batch_size = 60
k = 10
# Set model shape
model_shape = (1, 100, 100)
database = 'CK+'
nb_classes = 7
# Print the train start time
startTime = datetime.datetime.now()
for i in range(7,8):
# Import model
model, model_number = Models.loadModel01(nb_classes, model_shape)
if i == 0:
model, model_number = Models.loadModel01(nb_classes, model_shape)
if i == 1:
model, model_number = Models.loadModel02(nb_classes, model_shape)
if i == 2:
model, model_number = Models.loadModel03(nb_classes, model_shape)
if i == 3:
model, model_number = Models.loadModel04(nb_classes, model_shape)
if i == 4:
model, model_number = Models.loadModel05(nb_classes, model_shape)
if i == 5:
model, model_number = Models.loadModel07(nb_classes, model_shape)
if i == 6:
model, model_number = Models.loadModel08(nb_classes, model_shape)
if i == 7:
model, model_number = Models.loadModel09(nb_classes, model_shape)
print('Training model ' + str(model_number))
# Compile model
model = Models.compileSGD(model)
# Load the fold for this iteration
X_train, Y_train, X_test, Y_test, nb_classes = Datasets.loadBatchs(k, 1, database, nb_classes)
X_train = X_train.astype('float32')
X_test = X_test.astype('float32')
X_train /= 255
X_test /= 255
# Fit the model
hist = model.fit(X_train, Y_train,
batch_size=batch_size,
nb_epoch=nb_epoch,
verbose=1,
validation_data=(X_test, Y_test),
shuffle=True)
'''
model, hist = Models.trainWithImageAugmentation(model, batch_size, nb_epoch, X_train, Y_train, X_test, Y_test)
'''
# Save iteration history
Utils.saveHistory(database, hist, model_number)
# Print the train end time
endTime = datetime.datetime.now()
print('Start Time: ' + str(startTime))
print('End Time: ' + str(endTime))