# load json model
json_file = open('model.json', 'r')
loaded_model = json_file.read()
json_file.close()
model = model_from_json(loaded_model)
print "Loaded the model"

# complie the model
model.compile(loss='mse', optimizer='adam')

# set batch_size and number of epochs
batch_size = 500
epochs = 10

# get the values of correct steering angels
y_train_data = load_data.loadY()

# training the model
for i in range(epochs):
    trainPredict = numpy.empty([0])
    for j in range(load_data.len_train_samples / batch_size):
        x_train, y_train = load_data.loadTrainData(batch_size, 'left')
        history = model.fit(x_train, y_train, nb_epoch=1, verbose=2)
        trainPredict = numpy.append(trainPredict, model.predict(x_train))
        print "Epoch" + str(i + 1)

    x_train, y_train = load_data.loadTrainData(
        load_data.len_train_samples -
        (load_data.train_batch_index % load_data.len_train_samples), 'left')
    history = model.fit(x_train, y_train, nb_epoch=1, verbose=2)
    trainPredict = numpy.append(trainPredict, model.predict(x_train))
# load json model
json_file = open('model.json', 'r')
loaded_model = json_file.read()
json_file.close()
model = model_from_json(loaded_model)
print "Loaded the model"

# complie the model
model.compile(loss='mse', optimizer='adam')

# set batch_size and number of epochs
batch_size = 500
epochs = 10

# get the values of correct steering angels
y_train_data = load_data.loadY("mixed")

# training the model
for i in range(epochs):
    trainPredict = numpy.empty([0])
    for j in range(load_data.mlen_train/batch_size):
        x_train, y_train = load_data.loadTrainDataM(batch_size)
        history = model.fit(x_train, y_train, nb_epoch = 1, verbose = 2)
        trainPredict = numpy.append(trainPredict, model.predict(x_train))
        print "Epoch" + str(i+1)

    x_train, y_train = load_data.loadTrainDataM(load_data.mlen_train - (load_data.mtrain_batch_index%load_data.mlen_train))
    history = model.fit(x_train, y_train, nb_epoch = 1, verbose = 2)
    trainPredict = numpy.append(trainPredict, model.predict(x_train))

trainPredict = numpy.expand_dims(trainPredict, axis = 1)
import matplotlib.pyplot as plt
import time

json_file = open('model_val.json', 'r')
loaded_model_val = json_file.read()
json_file.close()
model_val = model_from_json(loaded_model_val)
print "Loaded the validation/testing model"
#Load the trained weights
model_val.load_weights("weights-center-20161207-182047" + ".h5")

# compile the model
model_val.compile(loss='mse', optimizer='adam')

# get the values of correct steering angels
y_train_data = load_data.loadY("center", "train")
genT = load_data.trainDataGen('center')

trainPredict = model_val.predict_generator(genT,
                                           val_samples=load_data.clen_train)

# shift train predictions for plotting
trainPredictPlot = numpy.empty_like(y_train_data)
trainPredictPlot[:, :] = numpy.nan
trainPredictPlot[0:len(trainPredict), :] = trainPredict

#Plotting steering angle actual vs predicted
plt.figure(0)
plt.plot(y_train_data, label='Actual Dataset')
plt.plot(trainPredictPlot, label='Training Prediction')
plt.title('Steering Angle: Actual vs Predicted')
Ejemplo n.º 4
0
model = model_from_json(loaded_model)
print "Loaded the training model"

# loda the pre trained weights
# model.load_weights("200gb_set_weights-center-20161207-152038" + ".h5")
# print "Loaded the pre trained weights"

# complie the model
model.compile(loss='mse', optimizer='adam')

# generator
genT = load_data.trainDataGen('center')
genV = load_data.valDataGen('center')

# get the values of correct steering angels
y_train_data = load_data.loadY("center", "validate")

# training the model
print "compiled the model and started training..."
history = model.fit_generator(genT, samples_per_epoch = load_data.clen_train, nb_epoch = epochs, verbose = 1, validation_data = genV, nb_val_samples = load_data.clen_val)

# get time stamp
timestr = time.strftime("%Y%m%d-%H%M%S")

# serialize weights to HDF5
model.save_weights("weights-center-" + timestr + ".h5")
print("Saved weights to disk")

print "Entering Prediction please wait... Your plots will be generated soon..."

# load json model
Ejemplo n.º 5
0
# loda the pre trained weights
#model.load_weights(weights_dir)
print "Loaded pre-trained weights.. resuming the training now.."
model.load_weights("200gb_m_5epoch_weights-merged-20161217-062001" + ".h5")
print "Loaded the pre trained weights"

# complie the model
model.compile(loss='mse', optimizer='adam')

# generator
genT = load_data.trainMDataGen()
genV = load_data.valMDataGen()

# get the values of correct steering angels
y_train_data = load_data.loadY("merged", "validate")

# training the model
print "compiled the model and started training..."
history = model.fit_generator(genT,
                              samples_per_epoch=load_data.clen_train,
                              nb_epoch=epochs,
                              verbose=1,
                              validation_data=genV,
                              nb_val_samples=load_data.clen_val)

# get time stamp
timestr = time.strftime("%Y%m%d-%H%M%S")

# serialize weights to HDF5
model.save_weights("weights-merged-" + timestr + ".h5")