""""
keras.py
functions to run and train autopilots using keras
"""
from tensorflow.python.keras.layers import Input
from tensorflow.python.keras.models import Model, load_model
from tensorflow.python.keras.layers import Convolution2D
from tensorflow.python.keras.layers import Dropout, Flatten, Dense
from tensorflow.python.keras.callbacks import ModelCheckpoint, EarlyStopping
class KerasPilot:
def load(self, model_path):
self.model = load_model(model_path)
def shutdown(self):
pass
def train(self, train_gen, val_gen,
saved_model_path, epochs=100, steps=100, train_split=0.8,
verbose=1, min_delta=.0005, patience=5, use_early_stop=True):
"""
train_gen: generator that yields an array of images an array of
"""
"""
filename:字符串,保存模型的路径
monitor:需要监视的值
verbose:信息展示模式,0或1(checkpoint的保存信息,类似Epoch 00001: saving model to ...)
save_best_only:当设置为True时,监测值有改进时才会保存当前的模型( the latest best model according to the quantity monitored will not be overwritten)
mode:‘auto’,‘min’,‘max’之一,在save_best_only=True时决定性能最佳模型的评判准则,例如,当监测值为val_acc时,模式应为max,当监测值为val_loss时,模式应为min。在auto模式下,评价准则由被监测值的名字自动推断。
save_weights_only:若设置为True,则只保存模型权重,否则将保存整个模型(包括模型结构,配置信息等)
period:CheckPoint之间的间隔的epoch数
"""
# checkpoint to save model after each epoch
save_best = ModelCheckpoint(saved_model_path,
monitor='val_loss',
verbose=verbose,
donkeycar的keras网络的代码解析
最新推荐文章于 2024-08-22 14:06:56 发布
本文深入解析DonkeyCar项目中使用的Keras神经网络架构,涵盖模型构建、训练过程及其实现细节,帮助读者理解自动驾驶小车的深度学习应用。
摘要由CSDN通过智能技术生成