-
Notifications
You must be signed in to change notification settings - Fork 1
/
train_fcn8.py
executable file
·65 lines (54 loc) · 2.04 KB
/
train_fcn8.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
"""
# Training pipeline of FCN8 (VGG) on SUIM
"""
from __future__ import print_function, division
import os
from os.path import join, exists
from keras import callbacks
# local libs
from models.fcn import fcn_8, fcn_8_vgg
from utils.data_utils import trainDataGenerator
## dataset and experiment directories
dataset_name = "suim"
train_dir = "/mnt/data1/ImageSeg/suim/train_val/"
## ckpt directory
ckpt_dir = "ckpt/"
im_res_ = (320, 240, 3)
ckpt_name = "fcn8_vgg.hdf5"
model_ckpt_name = join(ckpt_dir, ckpt_name)
if not exists(ckpt_dir): os.makedirs(ckpt_dir)
## initialize model
## use fcn_8 for non-vgg model
model = fcn_8_vgg(n_classes=5, input_height=im_res_[1], input_width=im_res_[0])
print (model.summary())
## load saved model
#model.load_weights(join("ckpt/saved/", "***.hdf5"))
batch_size=2
num_epochs = 40
# setup data generator
data_gen_args = dict(rotation_range=0.2,
width_shift_range=0.05,
height_shift_range=0.05,
shear_range=0.05,
zoom_range=0.05,
horizontal_flip=True,
fill_mode='nearest')
model_checkpoint = callbacks.ModelCheckpoint(model_ckpt_name,
monitor = 'loss',
verbose = 1, mode= 'auto',
save_weights_only = True,
save_best_only = True)
# data generator
train_gen = trainDataGenerator(batch_size, # batch_size
train_dir,# train-data dir
"images", # image_folder
"masks", # mask_folder
data_gen_args, # aug_dict
image_color_mode="rgb",
mask_color_mode="rgb",
target_size = (im_res_[1],im_res_[0]))
## fit model
model.fit_generator(train_gen,
steps_per_epoch = 4000,
epochs = num_epochs,
callbacks = [model_checkpoint])