当前位置:网站首页>tf.keras.callbacks.EarlyStopping()
tf.keras.callbacks.EarlyStopping()
2022-08-02 00:18:00 【Erosion_ww】
作用
当监控的指标停止改进时停止训练
假设训练的目标是最小化损失。 这样,要监控的指标将是“loss”,模型将是“min”。 model.fit() 训练循环将在每个 epoch 结束时检查loss是否不再减少,考虑 min_delta 和patience。 一旦发现不再减少,model.stop_training 将被标记为 True 并且训练终止。
要监控的指标需要在日志字典中可用。 为此,请在 model.compile() 传递损失或指标
参数
tf.keras.callbacks.EarlyStopping(
monitor='val_loss', # 要监控的指标
min_delta=0, # 被监测指标的最小变化被认为是改进,即小于 min_delta 的绝对变化,将被视为没有改进。
patience=0, # 没有改善的 epoch达到设定的数之后训练将停止。
verbose=0, # 详细模式,0 或 1。模式 0 是静默模式,模式 1 在回调执行操作时显示消息。
mode='auto', # {"auto", "min", "max"} 之一。 在min模式下,当监测到的数量停止减少时,训练将停止;
# 在max模式下,当监控的数量停止增加时,它将停止;
# 在auto模式下,方向是根据监控量的名称自动推断的。
baseline=None, # 监控数量的基线值。 如果模型没有显示出对基线的改进,则训练将停止。
restore_best_weights=False # 是否从监测量的最佳值的epoch恢复模型权重。
# 如果为 False,则使用在训练的最后一步获得的模型权重。
)例子
model = tf.keras.models.Sequential([tf.keras.layers.Dense(10)]) # 设置模型层
model.compile(tf.keras.optimizers.SGD(), loss='mse') # 编译模型
early_stop = keras.callbacks.EarlyStopping(monitor='val_loss', patience=10) # patience 值用来检查改进 epochs 的数量
history = model.fit(np.arange(100).reshape(5, 20), np.zeros(5),
epochs=10, batch_size=1, callbacks=[callback],
verbose=0) # 训练模型
len(history.history['loss']) # 输出符合条件的epoch的个数4
主要参考:tf.keras.callbacks.EarlyStopping | TensorFlow Core v2.9.1 (google.cn)
边栏推荐
猜你喜欢
随机推荐
Automatic conversion of Oracle-style implicit joins to ANSI JOINs using jOOQ
PHP to read data from TXT file
flowable工作流所有业务概念
from origin ‘null‘ has been blocked by CORS policy Cross origin requests are only supported for
冒泡排序函数封装
146. LRU cache
unity2D横版游戏教程5-UI
Markdown (CSDN) MD编辑器(四)- 漂亮表格(表格背景色、跨行、跨列)
DFS详解
mapbox使用教程
go mode tidy出现报错go warning “all“ matched no packages
BGP first experiment
Looking back at 5 recessionary times in history: How might this time be different?
NodeJs, all kinds of path
攻防世界-web-Training-WWW-Robots
Disk and file system management
nodeJs--mime模块
[Solution] Emqx startup under win10 reports Unable to load emulator DLL, node.db_role = EMQX_NODE__DB_ROLE = core
How does JSP use the page command to make the JSP file support Chinese encoding?
【软件工程之美 - 专栏笔记】34 | 账号密码泄露成灾,应该怎样预防?









