checkpoints

本文档探讨了如何使用Estimators保存和恢复TensorFlow模型。介绍了两种模型格式:检查点和SavedModel。检查点依赖于创建模型的代码,而SavedModel则独立于创建模型的代码。默认情况下,Estimator会在训练过程中每10分钟保存一次检查点,并保留最近的5个检查点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

this document examines how to save and restore tensorflow models built with estimators. tensorflow provides two model formats:
checkpoints, which is a format dependent on the code that created the model
SavedModel, which is a format independent of the code that created the model


for details on SavedModel, see the saving and restoring chapter of the tensorflow programmer's guide


checkpoints, which are versions of the model created during training
event files, which contain information that tensorboard uses to create visualizations


###
classifier = tf.estimator.DNNClassifier(
feature_columns = my_feature_columns,
hidden_units = [10, 10],
n_classes = 3,
model_dir = "models/iris"
)


if you don't specify model_dir in an estimator's constructor, the estimator writes checkpoint files to a temporary directory chosen by python's tempfile.mkdtemp function


by default, the estimator saves checkpoints in the model_dir according to the following schedule:
writes a checkpoint every 10 minutes(600 seconds)
writes a checkpoint when the train method starts (first iteration) and completes (final iteration)
retains only the 5 most recent checkpoints in the directory


you may alter the default schedule by taking the following steps:
create a RunConfig object that defines the desired schedule
when instantiating the estimator, pass that RunConfig object to the estimator's config argument


###
my_checkpointing_config = tf.estimator.RunConfig(
save_checkpoints_secs = 1 * 60,
keep_checkpoint_max = 10
)


classifier = tf.estimator.DNNClassifier(
feature_columns = my_feature_columns,
hidden_units = [10, 10],
n_classes = 3,
model_dir = "models/iris",
config = my_checkpointing_config
)


the estimator builds the model's graph by running the model_fn(). (for details on the model_fn(), see creating custom estimators)


the estimator initializes the weights of the new model from the data stored in the most recent checkpoint


to run experiments in which you train and compare slightly different versions of a model, save a copy of the code that created each model_dir, possibly by creating a separate git branch for each version. this seperation will keep your checkpoints recoverable
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值