-
Notifications
You must be signed in to change notification settings - Fork 0
/
train.py
61 lines (46 loc) · 1.81 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
from keras.callbacks import ModelCheckpoint, TensorBoard
import LoadBatches
from Models import FCN8, FCN32, SegNet, UNet
from keras import optimizers
import math
#############################################################################
train_images_path = "data/dataset1/images_prepped_train/"
train_segs_path = "data/dataset1/annotations_prepped_train/"
train_batch_size = 8
n_classes = 11
epochs = 500
input_height = 320
input_width = 320
val_images_path = "data/dataset1/images_prepped_test/"
val_segs_path = "data/dataset1/annotations_prepped_test/"
val_batch_size = 8
key = "unet"
##################################
method = {
"fcn32": FCN32.FCN32,
"fcn8": FCN8.FCN8,
'segnet': SegNet.SegNet,
'unet': UNet.UNet}
m = method[key](n_classes, input_height=input_height, input_width=input_width)
m.compile(
loss='categorical_crossentropy',
optimizer="adadelta",
metrics=['acc'])
G = LoadBatches.imageSegmentationGenerator(train_images_path,
train_segs_path, train_batch_size, n_classes=n_classes, input_height=input_height, input_width=input_width)
G_test = LoadBatches.imageSegmentationGenerator(val_images_path,
val_segs_path, val_batch_size, n_classes=n_classes, input_height=input_height, input_width=input_width)
checkpoint = ModelCheckpoint(
filepath="output/%s_model.h5" %
key,
monitor='acc',
mode='auto',
save_best_only='True')
tensorboard = TensorBoard(log_dir='output/log_%s_model' % key)
m.fit_generator(generator=G,
steps_per_epoch=math.ceil(367. / train_batch_size),
epochs=epochs, callbacks=[checkpoint, tensorboard],
verbose=2,
validation_data=G_test,
validation_steps=8,
shuffle=True)