【问题标题】:Tensorflow, select operation giving errorTensorflow,选择操作给出错误
【发布时间】:2016-06-16 18:37:00
【问题描述】:

我需要我的模型在训练和测试期间表现不同。我正在尝试构建序列到序列模型,并且我想在训练时将预期输出输入解码器,在测试时将实际输出输入。我定义了以下占位符,它应该包含一个缩放器值。

training = tf.placeholder(tf.bool, None, 'training')

在我的解码器中,我使用以下 select 语句,它在第一个时间步中返回全零,但根据是否正在训练在最后一个输出和预期输出之间进行选择。

last_step = tf.select(training, getTimeStep(expected_output, t - 1), decoder_outputs[t - 1])if t else tf.zeros((BATCH_SIZE, 128))

当我在训练模式下运行模型时,我使用以下设置训练为 True。

sess.run([accuracy, cross_entropy, train_step], feed_dict = {input_tensor: x_train, expected_output: y_train, training: True})

运行时出现以下错误。

tensorflow.python.framework.errors.InvalidArgumentError: Inputs to operation decoder/Select of type Select must have the same size and shape.  Input 0: [] != input 1: [32,128]

似乎条件需要与我选择的张量大小相同。但是,我想选择一个或另一个表达式,而不是元素明智的选择。有一个更好的方法吗?我认为 select 应该只广播布尔值。我可以平铺它,但这似乎有点低效。

【问题讨论】:

    标签: python tensorflow


    【解决方案1】:

    你是对的,tf.select 希望条件与其他两个输入具有相同的形状。

    您应该改用tf.cond。有关在 TensorFlow 图中使用 if 条件的信息,请参阅 this detailed answer

    【讨论】:

      猜你喜欢
      • 2022-07-13
      • 1970-01-01
      • 1970-01-01
      • 2020-02-22
      • 1970-01-01
      • 1970-01-01
      • 2017-05-04
      • 2015-09-14
      • 2013-12-14
      相关资源
      最近更新 更多