【问题标题】:Debugging a callback in TensorFlow with pdb in eager mode在 Eager 模式下使用 pdb 在 TensorFlow 中调试回调
【发布时间】:2020-07-12 21:59:09
【问题描述】:

如何正确调试 TensoFlow 中 pdb in eager 执行模式的回调?以下场景显示了该错误。回调是这种形式的度量函数:

def my_custom_metric_in_top_k(k):
    def metric_in_top_k(labels,predictions,features):
        import pdb
        pdb.set_trace()
        ...
    return metric_in_top_k

在 pdb 控制台中,我使用sess=tf.compat.v1.InteractiveSession() 创建一个会话,然后我可以通过labels.eval() 获取标签张量的值。但是,当我运行 predictions.eval() 时,出现以下错误

*** tensorflow.python.framework.errors_impl.FailedPreconditionError: 读取资源变量 group_score/dense_2/bias 时出错 容器:本地主机。这可能意味着变量是 未初始化。未找到:资源 localhost/group_score/batch_normalization_2/gamma/N10tensorflow3VarE 不存在。

导致错误的原因以及如何使predictions.eval() 工作?另外,关于在 TensorFlow 中调试回调有什么建议吗?

编辑: 我怀疑问题在于有两个不同的会话:交互式会话和用于读取模型的会话。但是,我通过在创建 Estimator 实例时提供一个包含训练检查点的目录以及在估计器上调用 evaluate 来读取模型。在我看来,会话是在估算器中的某个位置创建的。

【问题讨论】:

    标签: python tensorflow debugging pdb


    【解决方案1】:

    如果有人遇到类似问题,问题是 TF 关闭了急切执行模式。检查方法是通过tf.execusing_eagerly() 调用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-15
      • 1970-01-01
      • 2016-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多