【发布时间】:2019-05-26 03:47:43
【问题描述】:
我正在使用tf.TPUEstimator() 实现基于 BERT 的 NLP 模型。我想实现分层训练,我只需要选择模型的一层来为每个时期训练。为了做到这一点,我想更改我的 model_fn 并获取 current_epoch 的值。
我知道如何使用 model_fn 内部的 tf.train.get_or_create_global_step() 将 current_epoch 的值计算为张量,但是我需要评估此张量的值以选择要训练和实现的层,将正确的 train_op 返回到tf.estimator(train_op 属于根据 current_epoch 的值选择的单层)。
我无法从 model_fn 内部评估这个张量(current_epoch / global_step)。我尝试了以下方法,但训练挂在步骤my_sess.run(my_global_step.initializer
global_step = tf.train.get_or_create_global_step()
graph = tf.get_default_graph()
my_sess = tf.Session(graph=graph)
current_epoch = (global_step * full_bs) // train_size
my_sess.run(my_global_step.initializer)
current_epoch = sess.run(current_epoch)
# My program hangs at the initialising step: my_sess.run(my_global_step.initializer)
有没有办法使用 tf.Estimators 默认会话来评估张量?如何获取默认会话/图表?
最重要的是,我的代码出了什么问题,为什么在使用 tpu 和 TPUEstimator 时训练会挂起?
【问题讨论】:
-
我也有类似的问题。你找到解决办法了吗?
标签: tensorflow