-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipeline.py
55 lines (45 loc) · 2.17 KB
/
pipeline.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
import os
import utils
import imageutils
import adv_laneline_detection
import matplotlib.image as mpimg
from importlib import reload
import matplotlib.pyplot as plt
import numpy as np
import cv2
import kerasmodel
import datasetclasses
from PIL import Image
training_dir = 'bb/train/'
labels_dir = 'bb/lanelines_labels/'
training_images_paths = [(training_dir + image_name) for image_name in os.listdir(training_dir)]
label_images_paths = [(labels_dir + image_name) for image_name in os.listdir(labels_dir)]
dataset = datasetclasses.Dataset(training_images_paths, label_images_paths)
print('Training on {} images'.format(dataset.train.len))
print('Validating on {} images'.format(dataset.valid.len))
print(training_images_paths[0])
# utils.show_images(label_images)
BATCHSIZE = 8
print('Training generator')
train_generator, train_steps_per_epoch = kerasmodel.get_data_generator_and_steps_per_epoch(dataset.train,
BATCHSIZE)
print('Validation generator')
validation_generator, validation_steps_per_epoch = kerasmodel.get_data_generator_and_steps_per_epoch(dataset.valid,
BATCHSIZE,
validation=True)
print('Training steps per epoch {}'.format(train_steps_per_epoch))
print('Validation steps per epoch {}'.format(validation_steps_per_epoch))
model_file = 'model_berkely.h5'
k_model = kerasmodel.KerasModel(model_file=model_file,
load=False)
EPOCHS = 20
# k_model.model.summary()
# Training the KerasModel model and getting the metrics
model_history = k_model.train_model_with_generator(train_generator,
train_steps_per_epoch,
EPOCHS,
validation_generator,
validation_steps_per_epoch,
save_model_filepath=model_file)
# Plotting the model Loss
utils.plot_loss(model_history=model_history)