-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtrain.py
55 lines (43 loc) · 1.27 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
import loadData
import config
import keras.utils as up_utils
from sklearn.model_selection import train_test_split
import models.Googlenet as googlenet
from keras.optimizers import Adam
import models.cnn as cnn
if __name__ == '__main__':
loadData.generate_dataset(224)
data = config.data
label = config.label
label = up_utils.to_categorical(label)
# split train_set and test_set
(trainX, testX, trainY, testY) = train_test_split(
data,
label,
shuffle=True,
test_size=0.25,
random_state=40
)
# basic cnn
# model = cnn.getmodel(width=data.shape[1], height=data.shape[2], channel=3, classes=2)
# googleNet input 224*224*3
model = googlenet.getmodel(width=data.shape[1], height=data.shape[2], channel=3, classes=2)
# AlexNet
# model =
# vgg16net
# model =
# select optimizer
opt = Adam(lr=config.INIT_LR,decay=config.INIT_LR/config.EPOCHS)
model.summary()
model.compile(
loss="categorical_crossentropy",
optimizer=opt,
metrics=['accuracy']
)
H = model.fit(
trainX,
trainY,
batch_size=32,
epochs=config.EPOCHS,
validation_data=(testX,testY)
)