-
Notifications
You must be signed in to change notification settings - Fork 12
/
train_road_detector.py
68 lines (53 loc) · 2.31 KB
/
train_road_detector.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
63
64
65
66
67
68
"""
Walk-Assistant : Recognizing sidewalk for the visually impaired
Copyright (C) 2018 Yoongi Kim (devlifecode@outlook.com)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
print("""
Walk-Assistant Copyright (C) 2018 Yoongi Kim
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions.
""")
import cv2
import numpy as np
import argparse
from tqdm import tqdm, trange
from filter import Filter
from model import MyModel
from data_loader import DataLoader
from keras.callbacks import TensorBoard, ModelCheckpoint
from road_detector_generator import Generator
HEIGHT = 720
WIDTH = 1280
KERNEL = 80
STRIDE = 80
parser = argparse.ArgumentParser()
parser.add_argument('--load', type=str, default='True', help='Load last weight')
parser.add_argument('--epochs', type=int, default=3, help='Training epochs')
args = parser.parse_args()
LOADMODEL = True if str(args.load).upper() == 'TRUE' else False
print('Load model = {}'.format(LOADMODEL))
model = MyModel(LOADMODEL, HEIGHT, WIDTH, KERNEL, STRIDE, 0.01, model_name='road')
rows = int((HEIGHT-KERNEL)/STRIDE+1)
cols = int((WIDTH-KERNEL)/STRIDE+1)
generator = Generator()
if model.epoch >= args.epochs:
print("Loaded model's epochs is already bigger than desired epochs. Set --epochs {}".format(model.epoch + 1))
exit(1)
checkpoint_path = 'models/road/weight.{epoch:02d}-{acc:.2f}.h5'
checkpoint = ModelCheckpoint(checkpoint_path, monitor='acc', save_best_only=False, mode='auto')
model.model.fit_generator(generator.generator(),
steps_per_epoch=len(generator.files),
epochs=args.epochs,
callbacks=[checkpoint],
initial_epoch=model.epoch)