【问题标题】:Load checkpoint and finetuning using tf.estimator.Estimator使用 tf.estimator.Estimator 加载检查点和微调
【发布时间】:2017-09-26 10:27:41
【问题描述】:

我们正在尝试将基于旧的训练代码转换为更符合 tf.estimator.Estimator 的代码。 在初始代码中,我们微调目标数据集的原始模型。在使用 variables_to_restore 和 init_fn 与 MonitoredTrainingSession 的组合进行训练之前,仅从检查点加载一些层。 如何使用 tf.estimator.Estimator 方法实现这种权重加载?

【问题讨论】:

标签: tensorflow


【解决方案1】:

你有两个选择,第一个更简单:

1- 在您的model_fn 中使用tf.train.init_from_checkpoint

2- model_fn 返回一个 EstimatorSpec。可以通过EstimatorSpec设置脚手架。

【讨论】:

  • 我如何init_from_checkpoint 指定要从检查点恢复的变量列表?据我所知,我只能将范围名称作为映射键/值传递
【解决方案2】:
import tensorflow as tf    

def model_fn():
  # your model defintion here
  # ...

# specify your saved checkpoint path
checkpoint_path = "model.ckpt"

ws = tf.estimator.WarmStartSettings(ckpt_to_initialize_from=checkpoint_path)
est = tf.estimator.Estimator(model_fn=model_fn, warm_start_from=ws)

【讨论】:

    猜你喜欢
    • 2018-06-03
    • 1970-01-01
    • 2023-03-12
    • 2019-10-10
    • 1970-01-01
    • 1970-01-01
    • 2013-07-24
    • 1970-01-01
    • 2017-11-14
    相关资源
    最近更新 更多