tensorflow - 使用 Keras model.fit,如何设置它以保存每 x 个步骤?
问题描述
我想在运行 model.fit 时每隔 x 步保存我的模型。
我正在查看文档 https://www.tensorflow.org/api_docs/python/tf/keras/Model#fit
而且似乎没有选择。但是在训练期间保存检查点是一个很常见的用例,很难想象没有办法做到这一点。所以我想知道我是否忽略了一些东西。
解决方案
这可以使用ModelCheckpoint 回调来完成:
EPOCHS = 10
checkpoint_filepath = '/tmp/checkpoint'
model_checkpoint_callback = tf.keras.callbacks.ModelCheckpoint(
filepath=checkpoint_filepath,
save_weights_only=True,
monitor='val_acc',
mode='max',
save_best_only=True)
# Model weights are saved at the end of every epoch, if it's the best seen
# so far.
model.fit(epochs=EPOCHS, callbacks=[model_checkpoint_callback])
monitor
您可以使用、mode
和参数修改回调的行为,这些save_best_only
参数控制要跟踪的指标以及检查点是否被覆盖以仅保留最佳模型。
推荐阅读
- authentication - 如何防止已经登录的用户访问 ASP.NET Core 的登录或注册页面?
- swift - Swift 中的正则表达式不能完全工作
- android - 为什么在 Android 上打开端口 25 上的套接字会导致权限被拒绝错误
- r - 从 TXT 文件中提取逻辑条件并将它们应用于 R 中的数据
- c# - 在 Unity 中,与玩家一起停留在具有物理和刚体的移动物体上不起作用
- c - 从 C 中的链表中删除时出现重复分段错误
- tensorflow - 是否可以在浏览器中缓存 tensorflow 模型,或监控下载进度?
- vbscript - 通过 VBSCRIPT 合并两个 CSV 文件时获取多个标题
- c++ - 非 const 左值引用类型 _normal_iterator<> 无法在 gcc 中绑定 _normal 迭代器类型的临时
- postgis - 在 Mac OS 中将 .osm 数据加载到 POSTGIS 时出错有人可以帮助我吗?