【问题标题】:Eager execution in tensorflow custom estimators在 tensorflow 自定义估计器中渴望执行
【发布时间】:2018-07-31 15:26:01
【问题描述】:

我正在使用自定义 Estimator 逻辑重写我的代码,并且我需要启用 Eager Execution 以获得我需要的指标/预测。但是,由于某种原因,似乎没有启用 Eager Execution。为了重现,我可以使用位于https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/learn/iris.py 的示例和一些打印:

...
import tensorflow as tf
tf.enable_eager_execution()
...
def my_model(features, labels, mode):
  print("IS EAGER? (my_model) - {}".format(tf.executing_eagerly()))
...
print("IS EAGER? - {}".format(tf.executing_eagerly()))
classifier = tf.estimator.Estimator(model_fn=my_model)

当我运行脚本时,结果如下:

IS EAGER? - True
INFO:tensorflow:Using default config.
...
INFO:tensorflow:Calling model_fn.
IS EAGER? (my_model) - False
INFO:tensorflow:Done calling model_fn.

如何让我的模型快速执行?我正在使用张量流 1.9.0

【问题讨论】:

    标签: python tensorflow tensorflow-estimator


    【解决方案1】:

    Estimator API 与图构造紧密相关(每次调用 train()evaluate() 等都会重建图)。因此,它在调用时显式禁用急切执行。

    您是否可以使用自己的训练循环或使用tf.keras.Model.fit() 而不是使用Estimator API?

    【讨论】:

    • 是的,我想我需要找到一种解决方法,我只是认为也有一种方法可以使用 Estimator 来做到这一点。我可能会去我自己的循环,在每个训练“时期”的几个train()调用之外测量指标。
    猜你喜欢
    • 1970-01-01
    • 2018-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-13
    • 2019-04-20
    • 2020-10-19
    相关资源
    最近更新 更多