当前位置:网站首页>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)
边栏推荐
- 期货开户如何确定期货公司正规性?
- MySQL常用语句整理
- 管理基础知识14
- [Solution] Emqx startup under win10 reports Unable to load emulator DLL, node.db_role = EMQX_NODE__DB_ROLE = core
- An Enhanced Model for Attack Detection of Industrial Cyber-Physical Systems
- Go 1.18 的那些事——工作区、模糊测试、泛型
- 简单工厂模式
- What is the function of the JSP Taglib directive?
- These 4 computer notepad software, you have to try
- Pytorch seq2seq 模型架构实现英译法任务
猜你喜欢
Redis的集群模式
期货开户手续费的秘密成了透明
go笔记——map
go mode tidy出现报错go warning “all“ matched no packages
ERROR 1064 (42000) You have an error in your SQL syntax; check the manual that corresponds to your
管理基础知识21
【CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!)(A~D)】
期货开户是否有资金门槛?
Test Cases: Four-Step Test Design Approach
使用jOOQ将Oracle风格的隐式连接自动转换为ANSI JOIN
随机推荐
管理基础知识16
抖音数据接口API-获取用户主页信息-监控直播开启
ELK日志分析系统
管理基础知识19
Unknown CMake command "add_action_files"
管理基础知识21
ECMAScript 2022 正式发布,有你了解过的吗?
【目标检测】FCOS: Fully Convolutional One-Stage Object Detection
Grid false data injection attacks detection based on coding strategy
What does the errorPage attribute of the JSP page directive do?
2022/08/01 Study Notes (day21) Generics and Enums
管理基础知识12
These 4 computer notepad software, you have to try
辨析内存函数memset、memcmp、memmove以及memcpy
不要用jOOQ串联字符串
The Statement update Statement execution
nodeJs--mime module
go笔记——map
460. LFU cache
这 4 款电脑记事本软件,得试试