加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
train_segmentation.py 1.26 KB
一键复制 编辑 原始数据 按行查看 历史
wikke 提交于 2017-11-17 16:07 . fine README.md and code refine
from keras.callbacks import TensorBoard, ModelCheckpoint, EarlyStopping
from model_UNet import get_unet, UNetEvaluator
from config import *
from generators import get_seg_batch
import time
def seg_train():
print('start seg_train')
model = get_unet()
model.summary()
run = '{}-{}'.format(time.localtime().tm_hour, time.localtime().tm_min)
log_dir = SEG_LOG_DIR.format(run)
check_point = log_dir + '/checkpoint-{epoch:02d}-{val_loss:.4f}.hdf5'
print("seg train round {}".format(run))
tensorboard = TensorBoard(log_dir=log_dir, write_graph=False)
checkpoint = ModelCheckpoint(filepath=check_point, monitor='val_loss', verbose=1, save_best_only=True)
early_stopping = EarlyStopping(monitor='val_loss', patience=TRAIN_SEG_EARLY_STOPPING_PATIENCE, verbose=1)
evaluator = UNetEvaluator()
model.fit_generator(get_seg_batch(TRAIN_SEG_TRAIN_BATCH_SIZE, from_train=True), steps_per_epoch=TRAIN_SEG_STEPS_PER_EPOCH,
validation_data=get_seg_batch(TRAIN_SEG_VALID_BATCH_SIZE, from_train=False), validation_steps=TRAIN_SEG_VALID_STEPS,
epochs=TRAIN_SEG_EPOCHS, verbose=2,
callbacks=[tensorboard, checkpoint, early_stopping, evaluator])
if __name__ == '__main__':
seg_train()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化