forked from YunYang1994/TensorFlow2.0-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
train.py
27 lines (23 loc) · 900 Bytes
/
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
#! /usr/bin/env python
# coding=utf-8
#================================================================
# Copyright (C) 2019 * Ltd. All rights reserved.
#
# Editor : VIM
# File name : train.py
# Author : YunYang1994
# Created date: 2019-10-14 19:12:36
# Description :
#
#================================================================
import tensorflow as tf
from fcn8s import FCN8s
from utils import DataGenerator
TrainSet = DataGenerator("./data/train_image.txt", "./data/train_labels", 2)
model = FCN8s(n_class=21)
model.compile(optimizer=tf.keras.optimizers.Adam(lr=1e-4),
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
## train your FCN8s model
callback = tf.keras.callbacks.ModelCheckpoint("FCN8s.h5", verbose=1, save_weights_only=True)
model.fit_generator(TrainSet, steps_per_epoch=6000, epochs=30, callbacks=[callback])