python - 带有 SyncReplicasOptimizer Hook 的 MonitoredTrainingSession 不能用占位符初始化

标签 python tensorflow

  1. 我使用 tf.keras.Input 作为输入层构建我的网络。

    input_image = tf.keras.Input(shape=(None, None, 3), name='input_image')

  2. 遵循网络定义,我这样定义我的优化器: enter image description here

  3. 然后,我将钩子(Hook)传递给 MonitoredTrainingSession enter image description here

  4. 最后,在运行以创建 MonitoredTrainingSession 时,出现占位符错误:

    tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'input_image' with dtype float and shape [?,?,?,3] this exception is raised from ready_value = sess.run(op) in session_manager.py called by hook.after_create_session(self.tf_sess, self.coord)

任何关于带占位符的 SyncReplicasOptimizer 的想法都是值得赞赏的。

最佳答案

终于找到问题所在: 我的代码中 SyncReplicaOptimizer 和批量规范化更新之间存在冲突。

with tf.control_dependencies(update_ops):
    self.train_op = self.optimizer.minimize(self.loss, global_step=self.global_step)

这种样式更新会引发异常,但是在分离控制依赖后,同时运行train_op和update_ops可以避免这个问题。

但无论如何,我还没有弄清楚解决问题的洞察原因或下降方法。

关于python - 带有 SyncReplicasOptimizer Hook 的 MonitoredTrainingSession 不能用占位符初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51287790/

相关文章:

python - 无法在 Python 中比较字符串

python - 根据其他列中的值乘以列

python - 训练 E-net 进行人体分割

tensorflow - 将神经网络的输出限制在任意范围内

python - 导出推理图时出错(ValueError)

python - 为什么当我覆盖 base.html django-admin 时已禁用响应式界面?

python - 表 polls_choice 没有名为 poll_id 的列

python - 属性错误: module 'tensorflow' has no attribute 'enable_eager_execution'

python - PyCharm 远程解释器和 Tensorflow -> 无法导入 Cudart.so

python - 将多个基于共同键值的字典合并为一个字典