【发布时间】: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