python - 如何使用 tf.train.Scaffold 初始化评估的局部变量?

标签 python tensorflow

我使用的是高级 tf.contrib.learn.Experiment 反对交叉培训和评估。但是,我面临评估和指标模块中的局部变量的问题,这些变量报告为未初始化:

Variables not initialized: mean/total, mean/count, eval_step

我提供自定义local_init_op tf.train.Scaffold 基本上看起来像这样:

scaffold = tf.train.Scaffold(
  local_init_op=tf.group(
    iterator.initializer,
    tf.tables_initializer(),
    tf.local_variables_initializer()))

(其中 iterator tf.contrib.data.Iterator 。)

然后存储在 tf.estimator.EstimatorSpec 中由 tf.estimator.Estimator 返回的model_fn功能。

我不这么认为tf.local_variables_initializer()延迟操作,这意味着这些变量尚未创建。

那么如何初始化它们呢?

最佳答案

我发现的唯一解决方案是在创建所有变量时不使用自定义 local_init_op 而是依赖 Scaffold.finalize 中内置的默认解决方案。

为了初始化我的迭代器,我只需将其添加到TABLE_INITIALIZERS集合中:

tf.add_to_collection(tf.GraphKeys.TABLE_INITIALIZERS, iterator.initializer)

关于python - 如何使用 tf.train.Scaffold 初始化评估的局部变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45054212/

相关文章:

python - 打印语句的分页输出

python - 我如何知道哪个预测针对哪个数据?那么,如何评估预测呢?

unit-testing - tensorflow Nose 测试: lots of debugging output,如何禁用

indexing - tensorflow 收集或 gather_nd

python - pandas 和 Stata 13 个文件

python - 如何在 Python+Opencv 中找到两个轮廓之间的角度

python - 如何转换 Pandas DF 以显示原始 DF 中的标记数?

python - 使用 Python 将 ISO 8601 时间格式计算为小时/分钟

tensorflow - 我从这个 TensorFlow 的 csv 阅读器中遗漏了什么?

amazon-ec2 - 最低要求的Cuda功能为3.5